1 Shader "Hidden/PostProcessing/Debug/LightMeter"
5 #pragma exclude_renderers gles gles3 d3d11_9x
7 #include "../StdLib.hlsl"
8 #include "../Builtins/ExposureHistogram.hlsl"
9 #pragma multi_compile __ COLOR_GRADING_HDR
10 #pragma multi_compile __ AUTO_EXPOSURE
12 float4 _Params; // x: lowPercent, y: highPercent, z: minBrightness, w: maxBrightness
13 float4 _ScaleOffsetRes; // x: scale, y: offset, w: histogram pass width, h: histogram pass height
15 TEXTURE3D_SAMPLER3D(_Lut3D, sampler_Lut3D);
17 StructuredBuffer<uint> _HistogramBuffer;
19 struct VaryingsLightMeter
21 float4 vertex : SV_POSITION;
22 float2 texcoord : TEXCOORD0;
23 float maxValue : TEXCOORD1;
24 float avgLuminance : TEXCOORD2;
27 VaryingsLightMeter Vert(AttributesDefault v)
30 o.vertex = float4(v.vertex.xy, 0.0, 1.0);
31 o.texcoord = TransformTriangleVertexToUV(v.vertex.xy);
33 #if UNITY_UV_STARTS_AT_TOP
34 o.texcoord = o.texcoord * float2(1.0, -1.0) + float2(0.0, 1.0);
37 o.maxValue = 1.0 / FindMaxHistogramValue(_HistogramBuffer);
38 o.avgLuminance = GetAverageLuminance(_HistogramBuffer, _Params, o.maxValue, _ScaleOffsetRes.xy);
43 float4 Frag(VaryingsLightMeter i) : SV_Target
45 uint ix = (uint)(round(i.texcoord.x * HISTOGRAM_BINS));
46 float bin = saturate(float(_HistogramBuffer[ix]) * i.maxValue);
47 float fill = step(i.texcoord.y, bin);
49 float4 color = float4(lerp(0.0, 0.75, fill).xxx, 1.0);
52 const float3 kRangeColor = float3(0.05, 0.3, 0.4);
53 const float3 kAvgColor = float3(0.75, 0.1, 1.0);
55 // Min / max brightness markers
56 float luminanceMin = GetHistogramBinFromLuminance(_Params.z, _ScaleOffsetRes.xy);
57 float luminanceMax = GetHistogramBinFromLuminance(_Params.w, _ScaleOffsetRes.xy);
59 if (i.texcoord.x > luminanceMin && i.texcoord.x < luminanceMax)
61 color.rgb = fill.rrr * kRangeColor;
62 color.rgb += kRangeColor;
67 // Draw color curves on top
69 float3 lut = SAMPLE_TEXTURE3D(_Lut3D, sampler_Lut3D, i.texcoord.xxx).rgb;
71 if (abs(lut.r - i.texcoord.y) < _ScaleOffsetRes.w)
72 curves.ra += (1.0).xx;
74 if (abs(lut.g - i.texcoord.y) < _ScaleOffsetRes.w)
75 curves.ga += (1.0).xx;
77 if (abs(lut.b - i.texcoord.y) < _ScaleOffsetRes.w)
78 curves.gba += float3(0.5, (1.0).xx);
80 color = any(curves) ? curves : color;
84 // Current average luminance marker
85 float luminanceAvg = GetHistogramBinFromLuminance(i.avgLuminance, _ScaleOffsetRes.xy);
86 float avgPx = luminanceAvg * _ScaleOffsetRes.z;
88 if (abs(i.texcoord.x - luminanceAvg) < _ScaleOffsetRes.z * 2.0)
89 color.rgb = kAvgColor;
99 Cull Off ZWrite Off ZTest Always
106 #pragma fragment Frag