VectorscopeRender.shader
2.99 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
Shader "Hidden/Post FX/Monitors/Vectorscope 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<uint> _Vectorscope;
float2 _Size;
float _Exposure;
float Tonemap(float x, float exposure)
{
const float a = 6.2;
const float b = 0.5;
const float c = 1.7;
const float d = 0.06;
x *= exposure;
x = max(0.0, x - 0.004);
x = (x * (a * x + b)) / (x * (a * x + c) + d);
return x * x;
}
float3 YuvToRgb(float3 c)
{
float R = c.x + 0.000 * c.y + 1.403 * c.z;
float G = c.x - 0.344 * c.y - 0.714 * c.z;
float B = c.x - 1.773 * c.y + 0.000 * c.z;
return float3(R, G, B);
}
float4 FragBackground(v2f_img i) : SV_Target
{
i.uv.x = 1.0 - i.uv.x;
float2 uv = i.uv - (0.5).xx;
float3 c = YuvToRgb(float3(0.5, uv.x, uv.y));
float dist = sqrt(dot(uv, uv));
float delta = fwidth(dist);
float alphaOut = 1.0 - smoothstep(0.5 - delta, 0.5 + delta, dist);
float alphaIn = smoothstep(0.495 - delta, 0.495 + delta, dist);
uint2 uvI = i.pos.xy;
uint v = _Vectorscope[uvI.x + uvI.y * _Size.x];
float vt = saturate(Tonemap(v, _Exposure));
float4 color = float4(lerp(c, (0.0).xxx, vt), alphaOut);
color.rgb += alphaIn;
return color;
}
float4 FragNoBackground(v2f_img i) : SV_Target
{
i.uv.x = 1.0 - i.uv.x;
float2 uv = i.uv - (0.5).xx;
float dist = sqrt(dot(uv, uv));
float delta = fwidth(dist);
float alphaOut = 1.0 - smoothstep(0.5 - delta, 0.5 + delta, dist);
float alphaIn = smoothstep(0.495 - delta, 0.495 + delta, dist);
uint2 uvI = i.pos.xy;
uint v = _Vectorscope[uvI.x + uvI.y * _Size.x];
float vt = saturate(Tonemap(v, _Exposure));
float4 color = float4((1.0).xxx, vt + alphaIn * alphaOut);
return color;
}
ENDCG
// (0)
Pass
{
CGPROGRAM
#pragma vertex vert_img
#pragma fragment FragBackground
ENDCG
}
// (1)
Pass
{
CGPROGRAM
#pragma vertex vert_img
#pragma fragment FragNoBackground
ENDCG
}
}
FallBack off
}