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