Skip to content

Instantly share code, notes, and snippets.

View Torgo13's full-sized avatar

TW0 Torgo13

View GitHub Profile
@maoyeedy
maoyeedy / CameraAmbientOverride.cs
Last active June 28, 2025 07:09
[Unity] Override Camera Ambient Color for SRP
using UnityEngine;
using UnityEngine.Rendering;
namespace CameraAmbientOverride
{
/// <summary>
/// Attach it to camera. Supports both URP and HDRP.
/// </summary>
[DisallowMultipleComponent]
[RequireComponent(typeof(Camera))]
@unitycoder
unitycoder / OptimalSpatialHashing.cs
Created October 6, 2024 14:16 — forked from adammyhre/OptimalSpatialHashing.cs
Unity Spatial Hashing with Jobs and Burst
using System;
using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class OptimalSpatialHashing : MonoBehaviour {
@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.
@unitycoder
unitycoder / VertexBillboard.shader
Created September 4, 2024 21:49 — forked from camnewnham/VertexBillboard.shader
Point cloud shaders
Shader "Points/Billboard"
{
Properties
{
_PointSize("PointSize", Range(0, 0.1)) = 0.01
[Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend("Source Blend", Float) = 1 // "One"
[Enum(UnityEngine.Rendering.BlendMode)] _DstBlend("Destination Blend", Float) = 0 // "Zero"
[Enum(UnityEngine.Rendering.CompareFunction)] _ZTest("Depth Test", Float) = 4 // "LessEqual"
[Enum(DepthWrite)] _ZWrite("Depth Write", Float) = 1 // "On"
}
@kurtdekker
kurtdekker / FilterUtilities.cs
Created August 12, 2024 01:37
Filter utilities: a deadband expander
public static partial class FilterUtilities
{
// @kurtdekker
//
// Part of Jetpack Kurt Space Flight available for iOS/Android
//
// Evalutes a normalized analog input signal (such as an analog
// axis) and filters it:
//
@runevision
runevision / BurstMethodTester.cs
Last active April 5, 2025 08:05
Using Unity Burst directly on methods without jobs - unofficial example code
using Unity.Burst;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Jobs;
using UnityEngine;
// This example code demonstrates using Unity Burst directly on a static method without jobs.
// Unity NativeArrays can't be used directly in Unity Burst methods (only in Burst jobs),
// so we have to pass pointers to arrays instead.
@LizzyFox-code
LizzyFox-code / collections.md
Last active February 17, 2025 22:23
Unity.Collections cheat sheet

Unity.Collections cheat sheet

The collections provided by this package fall into three categories:

  • The collection types in Unity.Collections whose names start with Native- have safety checks for ensuring that they're properly disposed and are used in a thread-safe manner.
  • The collection types in Unity.Collections.LowLevel.Unsafe whose names start with Unsafe- do not have these safety checks.
  • The remaining collection types are not allocated and contain no pointers, so effectively their disposal and thread safety are never a concern. These types hold only small amounts of data.

Allocators

@LizzyFox-code
LizzyFox-code / mathematics.md
Created January 24, 2024 15:54
Unity.Mathematics cheat sheet
@runevision
runevision / Shadows.cginc
Last active January 1, 2025 21:33
Water Foam Particle Shader
UNITY_DECLARE_SHADOWMAP(_SunCascadedShadowMap);
float4 _SunCascadedShadowMap_TexelSize;
#define GET_CASCADE_WEIGHTS(wpos, z) getCascadeWeights_splitSpheres(wpos)
#define GET_SHADOW_FADE(wpos, z) getShadowFade_SplitSpheres(wpos)
#define GET_SHADOW_COORDINATES(wpos,cascadeWeights) getShadowCoord(wpos,cascadeWeights)
/**
* Gets the cascade weights based on the world position of the fragment and the poisitions of the split spheres for each cascade.