Skip to content

Commit 502856e

Browse files
committed
Add a2c shader for tree leaves
1 parent 5a35de5 commit 502856e

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

Environment.hlsl

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@
1010
// 2 => Objects (Alpha to Coverage)
1111
#define ALPHA 0
1212
#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
1322

1423
//#define SHADOW_IMPLEMENTATION_GAME
1524
#define SHADOW_IMPLEMENTATION_GATHER
@@ -19,8 +28,10 @@ cbuffer Globals {
1928
float nStageNum;
2029
float vATest;
2130
#endif
31+
#if SHADOW
2232
float4 scSM;
2333
float4 scSM2;
34+
#endif
2435
#if ALPHA == 0
2536
float4 texsize0;
2637
float4 uvOffset0;
@@ -77,11 +88,17 @@ struct PSInput
7788
#endif
7889
#else
7990
float4 litBase : TEXCOORD0;
91+
#if SHADOW
8092
float4 shadow : TEXCOORD1;
8193
float4 litCoord : TEXCOORD2;
8294
float3 baseColor : TEXCOORD3;
8395
float3 texColorWeight : TEXCOORD4;
8496
float3 litColor : TEXCOORD5;
97+
#else // SHADOW
98+
float3 baseColor : TEXCOORD1;
99+
float3 texColorWeight : TEXCOORD2;
100+
float2 litCoord : TEXCOORD3;
101+
#endif // SHADOW
85102
#endif
86103
};
87104

@@ -93,7 +110,9 @@ struct PSInput
93110

94111
float4 main(float4 pos : SV_Position, PSInput input COVERAGE_OUT) : SV_TARGET {
95112
#if ALPHA != 0
113+
#if SHADOW
96114
float3 lit = sLit.Sample(smpsLit, input.litCoord.xy).xyz * input.litColor;
115+
#endif
97116
float aref = vATest;
98117
// The game forgets to set a nonzero aref when fading objects in and out
99118
// 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 {
104123
aref = 0.785;
105124
float4 color = (1.0).xxxx;
106125
if (nStageNum.x >= 0.5) {
107-
color = sStage0.Sample(smpsStage0, input.litCoord.zw);
126+
color = sStage0.Sample(smpsStage0, input.litCoord.TEXADDR_SWIZZLE);
108127
}
109128
#if ALPHA == 1
110129
clip(color.a - aref);
@@ -120,7 +139,7 @@ float4 main(float4 pos : SV_Position, PSInput input COVERAGE_OUT) : SV_TARGET {
120139
coverage = 0;
121140
[unroll]
122141
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;
124143
}
125144
#if MSAA_SAMPLE_COUNT == 16
126145
// 16 is the max we compile for
@@ -133,6 +152,7 @@ float4 main(float4 pos : SV_Position, PSInput input COVERAGE_OUT) : SV_TARGET {
133152
#endif // MSAA_SAMPLE_COUNT == 0
134153
#endif
135154
#endif
155+
#if SHADOW
136156
float2 shadowBase = (input.shadow.xy / input.shadow.w);
137157
shadowBase += scSM2.xy; // -1.5px offset
138158
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 {
220240
shadow = (row01 + rows.z + row34) * (1.0 / 16.0);
221241
}
222242
#endif
243+
#endif // SHADOW
223244

224245
#if ALPHA == 0
225246

@@ -256,8 +277,12 @@ float4 main(float4 pos : SV_Position, PSInput input COVERAGE_OUT) : SV_TARGET {
256277

257278
#else // ALPHA != 0
258279

280+
#if SHADOW
259281
shadow *= max((atColor.x - 0.7) * 3, 0);
260282
lit = lit * shadow + input.litBase.xyz;
283+
#else
284+
float3 lit = input.litBase.xyz;
285+
#endif
261286
color.a *= input.litBase.a;
262287
color.rgb = lerp(input.baseColor, lit * color.rgb, input.texColorWeight);
263288
color = color * saturate(atColor) + saturate(atColor - 1);

ShaderSampleRateConverter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ bool shouldUseSampleRate(const void* data, SIZE_T length) {
5353
{0x576b6302, 0xf209d2fa, 0x542b7c05, 0xb45b37af}, // Accessory Edges
5454
{0x19cce3ab, 0x52dfbaf0, 0x302d710c, 0xd90bc983}, // Character Transparent
5555
// {0x0cd1b9e5, 0x22e7069e, 0x476455ff, 0x98bfd850}, // Semi-transparent objects (e.g. grass) [expensive, gets used for a lot of non-transparent objects too]
56-
{0xd74438d8, 0xa2667a70, 0x5c3cae10, 0x1944d91e}, // Semi-transparent background (e.g. background tree leaves)
56+
// {0xd74438d8, 0xa2667a70, 0x5c3cae10, 0x1944d91e}, // Semi-transparent background (e.g. background tree leaves)
5757
};
5858
for (const ShaderHash& hash : sampleRateShaders)
5959
if (config.ssaaCharacters && hash == header->hash)

build-shaders.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Add-Shader -File Environment.hlsl -Hash "982709b2-2274a731-43455c36-104eb2a8" -F
7272
Add-Shader -File Environment.hlsl -Hash "d757bed5-09656d6f-43997a9c-c92777f9" -FxcArgs "/DBLEND=6"
7373
Add-Shader -File Environment.hlsl -Hash "0cd1b9e5-22e7069e-476455ff-98bfd850" -FxcArgs "/DALPHA=1"
7474
Add-Shader -File Environment.hlsl -Hash "0cd1b9e5-22e7069e-476455ff-98bfd850" -FxcArgs "/DALPHA=2" -AlphaToCoverage
75+
Add-Shader -File Environment.hlsl -Hash "d74438d8-a2667a70-5c3cae10-1944d91e" -FxcArgs "/DALPHA=2", "/DSHADOW=0" -AlphaToCoverage
7576

7677
function Add-ShaderList($name, $array) {
7778
$line = "constexpr static ShaderReplacement ${name}Data[] = {`n"

0 commit comments

Comments
 (0)