123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- Shader "Hidden/Post FX/Monitors/Histogram Render"
- {
- SubShader
- {
- ZTest Always Cull Off ZWrite Off
- Fog { Mode off }
- CGINCLUDE
- #pragma fragmentoption ARB_precision_hint_fastest
- #pragma target 5.0
- #include "UnityCG.cginc"
- StructuredBuffer<uint4> _Histogram;
- float2 _Size;
- uint _Channel;
- float4 _ColorR;
- float4 _ColorG;
- float4 _ColorB;
- float4 _ColorL;
- float4 FragSingleChannel(v2f_img i) : SV_Target
- {
- const float4 COLORS[4] = { _ColorR, _ColorG, _ColorB, _ColorL };
- float remapI = i.uv.x * 255.0;
- uint index = floor(remapI);
- float delta = frac(remapI);
- float v1 = _Histogram[index][_Channel];
- float v2 = _Histogram[min(index + 1, 255)][_Channel];
- float h = v1 * (1.0 - delta) + v2 * delta;
- uint y = (uint)round(i.uv.y * _Size.y);
- float4 color = float4(0.1, 0.1, 0.1, 1.0);
- float fill = step(y, h);
- color = lerp(color, COLORS[_Channel], fill);
- return color;
- }
- float4 FragRgbMerged(v2f_img i) : SV_Target
- {
- const float4 COLORS[3] = { _ColorR, _ColorG, _ColorB };
- float4 targetColor = float4(0.1, 0.1, 0.1, 1.0);
- float4 emptyColor = float4(0.0, 0.0, 0.0, 1.0);
- float remapI = i.uv.x * 255.0;
- uint index = floor(remapI);
- float delta = frac(remapI);
- for (int j = 0; j < 3; j++)
- {
- float v1 = _Histogram[index][j];
- float v2 = _Histogram[min(index + 1, 255)][j];
- float h = v1 * (1.0 - delta) + v2 * delta;
- uint y = (uint)round(i.uv.y * _Size.y);
- float fill = step(y, h);
- float4 color = lerp(emptyColor, COLORS[j], fill);
- targetColor += color;
- }
- return saturate(targetColor);
- }
- float4 FragRgbSplitted(v2f_img i) : SV_Target
- {
- const float4 COLORS[3] = {_ColorR, _ColorG, _ColorB};
- const float limitB = round(_Size.y / 3.0);
- const float limitG = limitB * 2;
- float4 color = float4(0.1, 0.1, 0.1, 1.0);
- uint channel;
- float offset;
- if (i.pos.y < limitB)
- {
- channel = 2;
- offset = 0.0;
- }
- else if (i.pos.y < limitG)
- {
- channel = 1;
- offset = limitB;
- }
- else
- {
- channel = 0;
- offset = limitG;
- }
- float remapI = i.uv.x * 255.0;
- uint index = floor(remapI);
- float delta = frac(remapI);
- float v1 = offset + _Histogram[index][channel] / 3.0;
- float v2 = offset + _Histogram[min(index + 1, 255)][channel] / 3.0;
- float h = v1 * (1.0 - delta) + v2 * delta;
- uint y = (uint)round(i.uv.y * _Size.y);
- float fill = step(y, h);
- color = lerp(color, COLORS[channel], fill);
- return color;
- }
- ENDCG
- // (0) Channel
- Pass
- {
- CGPROGRAM
- #pragma vertex vert_img
- #pragma fragment FragSingleChannel
- ENDCG
- }
- // (1) RGB merged
- Pass
- {
- CGPROGRAM
- #pragma vertex vert_img
- #pragma fragment FragRgbMerged
- ENDCG
- }
- // (2) RGB splitted
- Pass
- {
- CGPROGRAM
- #pragma vertex vert_img
- #pragma fragment FragRgbSplitted
- ENDCG
- }
- }
- FallBack off
- }
|