Skip to content

Instantly share code, notes, and snippets.

@runevision
runevision / BurstSDFGenerator.cs
Created September 11, 2024 07:48
Signed Distance Field generator for Unity with Burst support
/*
Based on the Anti-aliased Euclidean distance transform described by Stefan Gustavson and
Robin Strand. For further information, see https://contourtextures.wikidot.com/ and
https://web.archive.org/web/20220503051209/https://weber.itn.liu.se/~stegu/edtaa/
The algorithm is an adapted version of Stefan Gustavson's code, it inherits the copyright
statement below, which applies to this file only.
The rewrite with Unity Burst support makes the execution 40 times faster by default,
and 75 times faster if the passed in textures are both of type TextureFormat.RGBAFloat.
@WolframGroetsch
WolframGroetsch / gist:018a127820fe11867e1816dc3fb08608
Created November 21, 2023 19:27
FishNet prediction movement code for KCC
public struct PlayerCharacterInputs // This struct only handles the local input and is used to pass it to SetInput method
{
public float MoveAxisForward;
public float MoveAxisRight;
public Vector3 CameraRotationEuler;
public bool JumpDown;
public bool JumpHeld;
public bool CrouchDown;
public bool CrouchUp;
@bgolus
bgolus / PristineMajorMinorGrid.shader
Last active March 9, 2026 01:12
Pristine Grid applied to a grid that has support for major and minor lines and colored axis lines
Shader "Pristine Major Minor Grid"
{
Properties
{
[KeywordEnum(X, Y, Z)] _Axis ("Plane Axis", Float) = 1.0
[IntRange] _MajorGridDiv ("Major Grid Divisions", Range(2,25)) = 10.0
_AxisLineWidth ("Axis Line Width", Range(0,1.0)) = 0.04
_MajorLineWidth ("Major Line Width", Range(0,1.0)) = 0.02
_MinorLineWidth ("Minor Line Width", Range(0,1.0)) = 0.01
@takumifukasawa
takumifukasawa / ConvertLinear01DepthToRawDepth.hlsl
Created May 15, 2023 02:47
Unity: Convert Linear01Depth To Raw Depth
float ConvertLinear01DepthToRawDepth(float d)
{
// Linear01Depth
// return 1.0 / (_ZBufferParams.x * z + _ZBufferParams.y);
// d = 1.0 / (_ZBufferParams.x * z + _ZBufferParams.y);
// d * (_ZBufferParams.x * z + _ZBufferParams.y) = 1.0;
// _ZBufferParams.x * z * d + _ZBufferParams.y * d = 1.0;
// _ZBufferParams.x * z * d = 1.0 - _ZBufferParams.y * d;
// z = (1.0 - _ZBufferParams.y * d) / (_ZBufferParams.x * d);
@alexanderameye
alexanderameye / CircularMenu.cs
Last active January 2, 2026 21:02
Circular menu for the Unity Editor
/*
MIT License
Copyright (c) [year] [fullname]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
extends Node3D
# FABRIK for Skeletons in Godot4 based on https://github.com/joaen/EasyIK/blob/master/EasyIK/Assets/Scripts/EasyIK.cs
# Usage:
# - add the script to a node
# call the activate function
# fabrik.activate(bone_ids, skeleton, left_hand_target, left_hand_pole)
# bone_ids is an Array with the bone ids of the chain
# skeleton is the skeleton
# left_hand_target is a Node3D
@kurtdekker
kurtdekker / MusicManager.cs
Last active March 25, 2025 16:53
Ultra simple Music Manager
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// @kurtdekker - example of an ultra-simple music manager.
//
// How to use:
// MusicManager.Instance.PlayMusic( Audioclip clip);
//
// Call the above with null to stop music.
/***************************************************************/
/********** Simple target orientation camera script. ***********/
/*** You can change parameters, such as rotation/zoom speed. ***/
/***************************************************************/
// Original: https://github.com/steaklive/Orbit-Camera-for-Unity-Demos
using UnityEngine;
using System.Collections;
@EricHu33
EricHu33 / DrawFullScreenFeature.cs
Last active April 16, 2022 21:48
An example of how to write custom grab pass renderer feature in Unity URP
namespace UnityEngine.Rendering.Universal
{
public enum BufferType
{
CameraColor,
Custom
}
public class DrawFullScreenFeature : ScriptableRendererFeature
{
@laundmo
laundmo / lerp.py
Last active October 7, 2025 10:05
lerp, inverse lerp and remap in python
def lerp(a: float, b: float, t: float) -> float:
"""Linear interpolate on the scale given by a to b, using t as the point on that scale.
Examples
--------
50 == lerp(0, 100, 0.5)
4.2 == lerp(1, 5, 0.8)
"""
return (1 - t) * a + t * b