Skip to content

Instantly share code, notes, and snippets.

View brihernandez's full-sized avatar

Brian Hernandez brihernandez

View GitHub Profile
@brihernandez
brihernandez / InterpolatedCurve.cs
Last active August 24, 2021 19:45
Like AnimationCurve, but dead simple and linear only. Is it really even a curve?
using System.Collections.Generic;
/// <summary>
/// Creates a very simple linear graph that can be sampled along arbitrary points. Clamps to
/// the nearest value when sampled out of range. This class assumes that all points given are
/// ALREADY SORTED from smallest to largest in the X axis. There is NO automatic sorting.
/// </summary>
public class InterpolatedCurve
{
public List<(float, float)> Points = new List<(float, float)>();
@brihernandez
brihernandez / NavMeshAreaIDs.cs
Last active June 20, 2022 19:07
Simple wrapper classes for handling Navmesh Area related operations in Unity.
using UnityEngine.AI;
/// <summary>
/// Convenience class for handling NavMesh Area related operations and lookups in Unity.
/// </summary>
public readonly struct UnityNavMeshLayer
{
/// <summary>
/// Name of the Area as defined in the Navigation window in Unity.
/// </summary>
@brihernandez
brihernandez / SASExample.cs
Created October 5, 2022 01:32
I wrote a Stability Augmentation System once. I forgot what I read that explained it, but I was really surprised how effective it was at stabilizing a Halo Pelican. I ended up not needing a PID for the stick and rudder, since this kept the oscillations under control.
// This is a basic dummy version of a Stability Augmentation System. There's a bunch of technical
// terms for this, but I'm not a control systems engineer so feel free to correct me. I found a
// really awesome document (video?) somewhere that explained all this stuff but it was a while ago
// but I forgot where I saw it.
// This is meant to be set up per channel. It's serializable so you can change
// the authority and power of it per channel in the Inspector.
[System.Serializable]
public class SASChannel
@brihernandez
brihernandez / Bayer4x4.hlsl
Last active February 26, 2025 13:13
Bayer 4x4 dithering shader for use with Unity's FullscreenRenderPassFeature. This is meant to be plugged into a simple Shader Graph Custom Function node which takes in raw screen position and the URP sample buffer. Also includes 2x2 and 8x8 Bayer matrices in case you want to try those out.
inline half3 GammaToLinearSpace (half3 sRGB)
{
// Approximate version from http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1
return sRGB * (sRGB * (sRGB * 0.305306011h + 0.682171111h) + 0.012522878h);
}
inline half3 LinearToGammaSpace (half3 linRGB)
{
linRGB = max(linRGB, half3(0.h, 0.h, 0.h));
// An almost-perfect approximation from http://chilliant.blogspot.com.au/2012/08/srgb-approximations-for-hlsl.html?m=1