Dithering.hlsl 680 B

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