Skip to content

Instantly share code, notes, and snippets.

@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