You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.0 KiB

  1. #include "ColorGrading.cginc"
  2. // Grain
  3. half2 _Grain_Params1; // x: lum_contrib, y: intensity
  4. half4 _Grain_Params2; // x: xscale, h: yscale, z: xoffset, w: yoffset
  5. sampler2D _GrainTex;
  6. // Dithering
  7. sampler2D _DitheringTex;
  8. float4 _DitheringCoords;
  9. float3 UberSecondPass(half3 color, float2 uv)
  10. {
  11. // Grain
  12. #if GRAIN
  13. {
  14. float3 grain = tex2D(_GrainTex, uv * _Grain_Params2.xy + _Grain_Params2.zw).rgb;
  15. // Noisiness response curve based on scene luminance
  16. float lum = 1.0 - sqrt(AcesLuminance(color));
  17. lum = lerp(1.0, lum, _Grain_Params1.x);
  18. color += color * grain * _Grain_Params1.y * lum;
  19. }
  20. #endif
  21. // Blue noise dithering
  22. #if DITHERING
  23. {
  24. // Symmetric triangular distribution on [-1,1] with maximal density at 0
  25. float noise = tex2D(_DitheringTex, uv * _DitheringCoords.xy + _DitheringCoords.zw).a * 2.0 - 1.0;
  26. noise = sign(noise) * (1.0 - sqrt(1.0 - abs(noise))) / 255.0;
  27. color += noise;
  28. }
  29. #endif
  30. return color;
  31. }