10
10
// 2 => Objects (Alpha to Coverage)
11
11
#define ALPHA 0
12
12
#endif
13
+ #ifndef SHADOW
14
+ #define SHADOW 1
15
+ #endif
16
+
17
+ #if SHADOW
18
+ #define TEXADDR_SWIZZLE zw
19
+ #else
20
+ #define TEXADDR_SWIZZLE xy
21
+ #endif
13
22
14
23
//#define SHADOW_IMPLEMENTATION_GAME
15
24
#define SHADOW_IMPLEMENTATION_GATHER
@@ -19,8 +28,10 @@ cbuffer Globals {
19
28
float nStageNum;
20
29
float vATest;
21
30
#endif
31
+ #if SHADOW
22
32
float4 scSM;
23
33
float4 scSM2;
34
+ #endif
24
35
#if ALPHA == 0
25
36
float4 texsize0;
26
37
float4 uvOffset0;
@@ -77,11 +88,17 @@ struct PSInput
77
88
#endif
78
89
#else
79
90
float4 litBase : TEXCOORD0 ;
91
+ #if SHADOW
80
92
float4 shadow : TEXCOORD1 ;
81
93
float4 litCoord : TEXCOORD2 ;
82
94
float3 baseColor : TEXCOORD3 ;
83
95
float3 texColorWeight : TEXCOORD4 ;
84
96
float3 litColor : TEXCOORD5 ;
97
+ #else // SHADOW
98
+ float3 baseColor : TEXCOORD1 ;
99
+ float3 texColorWeight : TEXCOORD2 ;
100
+ float2 litCoord : TEXCOORD3 ;
101
+ #endif // SHADOW
85
102
#endif
86
103
};
87
104
@@ -93,7 +110,9 @@ struct PSInput
93
110
94
111
float4 main (float4 pos : SV_Position , PSInput input COVERAGE_OUT) : SV_TARGET {
95
112
#if ALPHA != 0
113
+ #if SHADOW
96
114
float3 lit = sLit.Sample (smpsLit, input.litCoord.xy).xyz * input.litColor;
115
+ #endif
97
116
float aref = vATest;
98
117
// The game forgets to set a nonzero aref when fading objects in and out
99
118
// This results in bushes increasing in size when they fade out, since suddenly more of the bush is shown
@@ -104,7 +123,7 @@ float4 main(float4 pos : SV_Position, PSInput input COVERAGE_OUT) : SV_TARGET {
104
123
aref = 0.785 ;
105
124
float4 color = (1.0 ).xxxx;
106
125
if (nStageNum.x >= 0.5 ) {
107
- color = sStage0.Sample (smpsStage0, input.litCoord.zw );
126
+ color = sStage0.Sample (smpsStage0, input.litCoord.TEXADDR_SWIZZLE );
108
127
}
109
128
#if ALPHA == 1
110
129
clip (color.a - aref);
@@ -120,7 +139,7 @@ float4 main(float4 pos : SV_Position, PSInput input COVERAGE_OUT) : SV_TARGET {
120
139
coverage = 0 ;
121
140
[unroll]
122
141
for (uint bit = 0 ; bit < MSAA_SAMPLE_COUNT; bit++) {
123
- coverage |= (sStage0.Sample (smpsStage0, EvaluateAttributeAtSample (input.litCoord, bit).zw ).a > aref) << bit;
142
+ coverage |= (sStage0.Sample (smpsStage0, EvaluateAttributeAtSample (input.litCoord, bit).TEXADDR_SWIZZLE ).a > aref) << bit;
124
143
}
125
144
#if MSAA_SAMPLE_COUNT == 16
126
145
// 16 is the max we compile for
@@ -133,6 +152,7 @@ float4 main(float4 pos : SV_Position, PSInput input COVERAGE_OUT) : SV_TARGET {
133
152
#endif // MSAA_SAMPLE_COUNT == 0
134
153
#endif
135
154
#endif
155
+ #if SHADOW
136
156
float2 shadowBase = (input.shadow.xy / input.shadow.w);
137
157
shadowBase += scSM2.xy; // -1.5px offset
138
158
float shadowRef = saturate (input.shadow.z / input.shadow.w);
@@ -220,6 +240,7 @@ float4 main(float4 pos : SV_Position, PSInput input COVERAGE_OUT) : SV_TARGET {
220
240
shadow = (row01 + rows.z + row34) * (1.0 / 16.0 );
221
241
}
222
242
#endif
243
+ #endif // SHADOW
223
244
224
245
#if ALPHA == 0
225
246
@@ -256,8 +277,12 @@ float4 main(float4 pos : SV_Position, PSInput input COVERAGE_OUT) : SV_TARGET {
256
277
257
278
#else // ALPHA != 0
258
279
280
+ #if SHADOW
259
281
shadow *= max ((atColor.x - 0.7 ) * 3 , 0 );
260
282
lit = lit * shadow + input.litBase.xyz;
283
+ #else
284
+ float3 lit = input.litBase.xyz;
285
+ #endif
261
286
color.a *= input.litBase.a;
262
287
color.rgb = lerp (input.baseColor, lit * color.rgb, input.texColorWeight);
263
288
color = color * saturate (atColor) + saturate (atColor - 1 );
0 commit comments