hch
1 天以前 45ad1dadba57b9f55b7cb89457e5c6420d321ed2
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
 
#if !defined(DYNAMICSHADOWPROJECTOR_DOWNSAMPLE_CGINC)
#define DYNAMICSHADOWPROJECTOR_DOWNSAMPLE_CGINC
 
#include "UnityCG.cginc"
 
sampler2D _MainTex;
half4 _MainTex_TexelSize;
fixed4 _Color;
 
struct v2f_blit
{
    float4 pos : SV_POSITION;
    half2  uv0 : TEXCOORD0;
};
struct v2f_downsample
{
    float4 pos : SV_POSITION;
    half2  uv0 : TEXCOORD0;
    half2  uv1 : TEXCOORD1;
    half2  uv2 : TEXCOORD2;
    half2  uv3 : TEXCOORD3;
};
 
v2f_blit vert_blit(appdata_img v)
{
    v2f_blit o;
    o.pos = UnityObjectToClipPos(v.vertex);
       o.uv0 = v.texcoord.xy;
    return o;
}
 
fixed4 frag_blit(v2f_blit i) : COLOR
{
    return tex2D(_MainTex, i.uv0);
}
 
fixed4 frag_blit_withShadowColor(v2f_blit i) : COLOR
{
    return lerp(fixed4(1,1,1,0), _Color, tex2D(_MainTex, i.uv0).a);
}
 
v2f_downsample vert_downsample(appdata_img v)
{
    v2f_downsample o;
    o.pos = UnityObjectToClipPos(v.vertex);
       o.uv0 = v.texcoord.xy + _MainTex_TexelSize.xy;
    o.uv1 = v.texcoord.xy - _MainTex_TexelSize.xy;
    o.uv2 = v.texcoord.xy + _MainTex_TexelSize.xy * half2(1,-1);
    o.uv3 = v.texcoord.xy + _MainTex_TexelSize.xy * half2(-1,1);
    return o;
}
 
fixed4 frag_downsample(v2f_downsample i) : COLOR
{
    fixed4 color = 0.25*tex2D(_MainTex, i.uv0);
    color += 0.25*tex2D(_MainTex, i.uv1);
    color += 0.25*tex2D(_MainTex, i.uv2);
    color += 0.25*tex2D(_MainTex, i.uv3);
    return color;
}
 
fixed4 frag_downsample_withShadowColor(v2f_downsample i) : COLOR
{
    fixed a = 0.25*tex2D(_MainTex, i.uv0).a;
    a += 0.25*tex2D(_MainTex, i.uv1).a;
    a += 0.25*tex2D(_MainTex, i.uv2).a;
    a += 0.25*tex2D(_MainTex, i.uv3).a;
    return lerp(fixed4(1,1,1,0), _Color, a);
}
 
#define DSP_OFFSET_TYPE4 fixed4
#define DSP_OFFSET_TYPE2 fixed2
DSP_OFFSET_TYPE4 _Offset0;
DSP_OFFSET_TYPE4 _Offset1;
DSP_OFFSET_TYPE4 _Offset2;
DSP_OFFSET_TYPE4 _Offset3;
fixed4 _Weight;
 
fixed4 frag_downsample_with_blur(v2f_blit i) : COLOR
{
    DSP_OFFSET_TYPE2 uv = i.uv0 + _Offset0.xy;
    fixed4 c0 = tex2D(_MainTex, uv);
    uv = i.uv0 + _Offset1.xy;
    fixed4 c1 = tex2D(_MainTex, uv);
    uv = i.uv0 + _Offset2.xy;
    fixed4 c2 = tex2D(_MainTex, uv);
    uv = i.uv0 + _Offset3.xy;
    fixed4 c3 = tex2D(_MainTex, uv);
 
    uv = i.uv0 + _Offset0.xw;
    fixed4 color = _Weight.x * c0;
    c0 = tex2D(_MainTex, uv);
    uv = i.uv0 + _Offset1.xw;
    color += _Weight.y * c1;
    c1 = tex2D(_MainTex, uv);
    uv = i.uv0 + _Offset2.xw;
    color += _Weight.z * c2;
    c2 = tex2D(_MainTex, uv);
    uv = i.uv0 + _Offset3.xw;
    color += _Weight.w * c3;
    c3 = tex2D(_MainTex, uv);
 
    uv = i.uv0 + _Offset0.zy;
    color += _Weight.x * c0;
    c0 = tex2D(_MainTex, uv);
    uv = i.uv0 + _Offset1.zy;
    color += _Weight.y * c1;
    c1 = tex2D(_MainTex, uv);
    uv = i.uv0 + _Offset2.zy;
    color += _Weight.z * c2;
    c2 = tex2D(_MainTex, uv);
    uv = i.uv0 + _Offset3.zy;
    color += _Weight.w * c3;
    c3 = tex2D(_MainTex, uv);
 
    uv = i.uv0 + _Offset0.zw;
    color += _Weight.x * c0;
    c0 = tex2D(_MainTex, uv);
    uv = i.uv0 + _Offset1.zw;
    color += _Weight.y * c1;
    c1 = tex2D(_MainTex, uv);
    uv = i.uv0 + _Offset2.zw;
    color += _Weight.z * c2;
    c2 = tex2D(_MainTex, uv);
    uv = i.uv0 + _Offset3.zw;
    color += _Weight.w * c3;
    c3 = tex2D(_MainTex, uv);
 
    color += _Weight.x * c0;
    color += _Weight.y * c1;
    color += _Weight.z * c2;
    color += _Weight.w * c3;
 
    return color;
}
#endif // !defined(DYNAMICSHADOWPROJECTOR_DOWNSAMPLE_CGINC)