1 #ifndef UNITY_POSTFX_DITHERING
2 #define UNITY_POSTFX_DITHERING
4 TEXTURE2D_SAMPLER2D(_DitheringTex, sampler_DitheringTex);
5 float4 _Dithering_Coords;
7 float3 Dither(float3 color, float2 uv)
9 // Final pass dithering
10 // Symmetric triangular distribution on [-1,1] with maximal density at 0
11 float noise = SAMPLE_TEXTURE2D(_DitheringTex, sampler_DitheringTex, uv * _Dithering_Coords.xy + _Dithering_Coords.zw).a * 2.0 - 1.0;
12 noise = FastSign(noise) * (1.0 - sqrt(1.0 - abs(noise)));
14 #if UNITY_COLORSPACE_GAMMA
15 color += noise / 255.0;
17 color = SRGBToLinear(LinearToSRGB(color) + noise / 255.0);
23 #endif // UNITY_POSTFX_DITHERING