-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDarkDirectly.shader
More file actions
85 lines (68 loc) · 1.55 KB
/
DarkDirectly.shader
File metadata and controls
85 lines (68 loc) · 1.55 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
Shader "Hidden/DarkDirectly"
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
}
CGINCLUDE
#include "UnityCG.cginc"
#include "Utils.cginc"
Texture2D _MainTex;
SamplerState my_trilinear_clamp_sampler;
Texture2D _FoveationLUT;
SamplerState sampler_FoveationLUT;
int _useLUT;
float4 _MainTex_TexelSize;
float _screenWidth;
float _screenHeight;
float _texSize;
float _darkLevel;
struct Input
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct Varyings
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
};
Varyings vertex(in Input input)
{
Varyings output;
output.vertex = UnityObjectToClipPos(input.vertex.xyz);
output.uv = input.uv;
#if UNITY_UV_STARTS_AT_TOP
if (_MainTex_TexelSize.y < 0)
output.uv.y = 1. - input.uv.y;
#endif
return output;
}
float4 fragment(in Varyings input) : SV_Target
{
float lod = 0;
float sx = _texSize / _screenWidth;
float sy = _texSize / _screenHeight;
float2 lutuv = float2(input.uv.x * sx, input.uv.y * sy);
lod = _FoveationLUT.SampleLevel(sampler_FoveationLUT, lutuv, 0).r;
// Y Cr Cb components
float4 YCrCb = _MainTex.SampleLevel(my_trilinear_clamp_sampler, input.uv, 0);
float Y = YCrCb.x;
float Cr = YCrCb.y;
float Cb = YCrCb.z;
Y = lod >= _darkLevel ? 0 : Y;
return float4(Y, Cr, Cb, 1);
}
ENDCG
SubShader
{
Cull Off ZWrite Off ZTest Always
Pass
{
CGPROGRAM
#pragma vertex vertex
#pragma fragment fragment
ENDCG
}
}
}