Skip to content

Instantly share code, notes, and snippets.

View D4KU's full-sized avatar

David Kutschke D4KU

  • Berlin, Germany
View GitHub Profile
@D4KU
D4KU / show_rows.py
Created July 16, 2024 21:31
Show and update a list of lists as a table in a terminal window
import curses
from time import sleep
from os import get_terminal_size
from functools import partial
from itertools import cycle
from random import random
def display_rows(stdscr, getter, interval=10, timeout=0.1, pad=2, **kwargs):
try:
@D4KU
D4KU / marked_tqdm.py
Last active June 30, 2024 17:44
A tqdm subclass to highlight individual iterations in the progress bar
from io import StringIO
from math import ceil
from tqdm import tqdm
from colorama import Fore, Style, init
# Replace the {bar} placeholder in the bar format with the given string
def replace_bar(bar_format=None, bar=''):
return '{l_bar}' + bar + '{r_bar}' \
if bar_format is None \
@D4KU
D4KU / RenderingExtensions.cs
Created October 17, 2022 20:06
Collection of C# extension methods for writing graphics code for Unity
using UnityEngine;
using RTF = UnityEngine.RenderTextureFormat;
using TF = UnityEngine.TextureFormat;
public static class RenderingExtensions
{
public static TextureFormat ToTextureFormat(this RenderTextureFormat format)
=> format switch
{
RTF.ARGB32 => TF.ARGB32,
@D4KU
D4KU / ShadowCatcher.shader
Created October 17, 2022 19:57
Unity Universal Render Pipeline shadow catcher shader
Shader "Custom/ShadowCatcher"
{
Properties
{
// Specular vs Metallic workflow
[HideInInspector] _WorkflowMode("WorkflowMode", Float) = 1.0
[MainColor] _BaseColor("Color", Color) = (0.5,0.5,0.5,1)
[MainTexture] _BaseMap("Albedo", 2D) = "white" {}
@D4KU
D4KU / ClampRotationToCone.cs
Created August 16, 2022 22:17
Unity clamp rotation to view cone
using System;
using UnityEngine;
/// <summary>
/// Clamps its local rotation to a view cone. Think of the view cone of a
/// spot light.
/// </summary>
[ExecuteAlways]
public class ClampRotationToCone : MonoBehaviour
{
using UnityEngine;
using MathNet.Numerics.LinearAlgebra;
/// <summary>
/// Apply transformation matrix reconstructed from four points to a material.
/// The matrix describes the transformation of the screen rectangle to the
/// quadrilateral spanned by the points after being projected in the screen
/// space of the connected camera.
/// </summary>
/// <author>David Kutschke</author>
@D4KU
D4KU / Comment.cs
Created January 8, 2022 01:22
Unity Comment Component
using UnityEngine;
/// <summary>
/// This component serves no functional purpose.
/// Use it to document objects in the scene.
/// </summary>
public class Comment : MonoBehaviour
{
[TextArea]
[Tooltip("Actual content of the comment.")]
@D4KU
D4KU / FileWatcher.cs
Created January 8, 2022 01:14
Unity File Watcher
// Adapted from
// https://forum.unity.com/threads/editor-compile-in-background.627952/#post-6989918
using System.IO;
using System.Threading;
using UnityEditor;
using UnityEngine;
/// <summary>
/// Refreshes Asset Database as soon as file change was detected in
@D4KU
D4KU / LitRetroreflective.shader
Last active January 14, 2021 19:50 — forked from phi-lira/UniversalPipelineTemplateShader.shader
Universal Pipeline shader with retroreflective behaviour. This shader works with Universal Render Pipeline 7.1.x and above.
Shader "Custom/Lit Retroreflective"
{
Properties
{
// Specular vs Metallic workflow
[HideInInspector] _WorkflowMode("WorkflowMode", Float) = 1.0
[MainColor] _BaseColor("Color", Color) = (0.5,0.5,0.5,1)
[MainTexture] _BaseMap("Albedo", 2D) = "white" {}
@D4KU
D4KU / MatCapImproved.shader
Last active November 22, 2024 08:38
Unity Universal Render Pipeline MatCap shader that also looks nice on flat surfaces.
Shader "Custom/MatCapImproved"
{
Properties
{
[NoScaleOffset] _MainTex("MatCap", 2D) = "black" {}
_ViewDirBlend("View direction blend", Range(0,1)) = 0
}
SubShader
{