Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
172 commits
Select commit Hold shift + click to select a range
b3b810b
feat: simpler effect shadows
doodlum Jan 26, 2026
d03c949
chore: remove getwatershadow
doodlum Jan 26, 2026
015c016
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Jan 26, 2026
3dd8cbf
fix: fix sampling
doodlum Jan 27, 2026
b9b04ef
feat: optimise shadow samples further
doodlum Jan 28, 2026
429754c
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Jan 28, 2026
233736c
Merge branch 'dev' into simple-effect-shadows
doodlum Jan 28, 2026
fdb4987
chore: remove lighting mult
doodlum Jan 28, 2026
2d71569
fix: make ai happy
doodlum Jan 28, 2026
8ff9162
fix: use gatherred
doodlum Jan 28, 2026
57aa59c
chore: remove watercolor variable
doodlum Jan 28, 2026
8f00c7f
chore: use skylighting specular in water
doodlum Jan 28, 2026
20ffbb1
chore: simplify math
doodlum Jan 28, 2026
9a45f8b
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Jan 28, 2026
d5329f5
Merge branch 'dev' into simple-effect-shadows
doodlum Jan 28, 2026
17465ae
fix: fix skylighting lobe
doodlum Jan 28, 2026
227d23c
Merge branch 'simple-effect-shadows' of https://github.com/doodlum/sk…
doodlum Jan 28, 2026
38042a6
chore: minor tweaks
doodlum Jan 28, 2026
3149c7b
chore: minor cleanup
doodlum Jan 28, 2026
b2de122
fix: make rabbit happy
doodlum Jan 28, 2026
fb6c66a
chore: cleaner code
doodlum Jan 28, 2026
b3d117d
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Jan 28, 2026
374a0c8
fix: fix shader error
doodlum Jan 28, 2026
302872b
chore: optimise sampling
doodlum Jan 28, 2026
01fef2a
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Jan 28, 2026
f8eac98
Update src/Hooks.cpp
doodlum Jan 28, 2026
2160b5b
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Jan 28, 2026
b5cade5
fix: fix compile issue
doodlum Jan 28, 2026
7abdb94
chore: minor optimisations
doodlum Jan 28, 2026
09ffee3
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Jan 28, 2026
3188479
chore: clean up macros
doodlum Jan 28, 2026
6ffed08
Merge branch 'simple-effect-shadows' of https://github.com/doodlum/sk…
doodlum Jan 28, 2026
50a9516
chore: cleanup
doodlum Jan 28, 2026
d45b5fa
fix: fix water compiler errors
doodlum Jan 28, 2026
5ea5715
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Jan 28, 2026
026f525
fix: fix terrain shadows compile error
doodlum Jan 28, 2026
3773a33
Merge branch 'simple-effect-shadows' of https://github.com/doodlum/sk…
doodlum Jan 28, 2026
dfc5a44
fix: fix compile error
doodlum Jan 29, 2026
2709ffc
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Jan 29, 2026
c015b40
fix: terrain shadow fixes
doodlum Jan 29, 2026
93372fc
Merge branch 'simple-effect-shadows' of https://github.com/doodlum/sk…
doodlum Jan 29, 2026
61e6bec
feat: sky static lighting
doodlum Jan 29, 2026
1e92d25
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Jan 29, 2026
61372c4
Merge branch 'dev' into simple-effect-shadows
doodlum Jan 29, 2026
994c772
refactor: cleanup
doodlum Jan 29, 2026
92dbb89
Merge branch 'simple-effect-shadows' of https://github.com/doodlum/sk…
doodlum Jan 29, 2026
e002dc5
chore: cleanup
doodlum Jan 29, 2026
3ddff54
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Jan 29, 2026
3a15227
Merge branch 'simple-effect-shadows' of https://github.com/doodlum/sk…
doodlum Jan 29, 2026
bd5e34a
chore: improvements
doodlum Jan 29, 2026
19e3f03
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Jan 29, 2026
1aefbb5
chore: more optimisations
doodlum Jan 29, 2026
4cf6308
Merge branch 'simple-effect-shadows' of https://github.com/doodlum/sk…
doodlum Jan 29, 2026
5b6bbec
Update package/Shaders/Common/ShadowSampling.hlsli
doodlum Jan 29, 2026
82f5e84
Merge branch 'dev' into simple-effect-shadows
doodlum Jan 29, 2026
148f831
fix: fix compiler error
doodlum Jan 29, 2026
9c89bd6
fix: fix color space
doodlum Jan 29, 2026
ff066fd
fix: fix compiler warning
doodlum Jan 30, 2026
eb115a0
chore: reduce noise
doodlum Jan 30, 2026
a8a461a
chore: optimise sky static shadow
doodlum Jan 30, 2026
7a768f6
Merge branch 'dev' into simple-effect-shadows
alandtse Feb 2, 2026
3c0b2a1
fix(unified-water): fix normal data for correct lod texture
davo0411 Feb 2, 2026
d98a4b4
chore: optimise mip level
doodlum Feb 2, 2026
3e63452
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Feb 2, 2026
ea81731
feat: third cascade
doodlum Feb 2, 2026
f66f8fa
Merge branch 'simple-effect-shadows' of https://github.com/doodlum/sk…
doodlum Feb 2, 2026
edf6714
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Feb 2, 2026
92a1a59
chore: auto set shadow settings
doodlum Feb 2, 2026
99859f8
Merge branch 'simple-effect-shadows' of https://github.com/doodlum/sk…
doodlum Feb 2, 2026
2029401
chore: optimise cascade selection
doodlum Feb 2, 2026
64160e9
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Feb 2, 2026
84c6a85
chore: further optimisation
doodlum Feb 2, 2026
c16adac
Merge branch 'simple-effect-shadows' of https://github.com/doodlum/sk…
doodlum Feb 2, 2026
2c1fdd2
chore: less blur
doodlum Feb 2, 2026
a77cac3
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Feb 2, 2026
57f4d5b
fix: fix compiler error
doodlum Feb 2, 2026
58d874a
chore: revert some changes
doodlum Feb 2, 2026
672734b
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Feb 2, 2026
e4986a9
fix: fixes
doodlum Feb 3, 2026
7467fb3
Merge branch 'simple-effect-shadows' of https://github.com/doodlum/sk…
doodlum Feb 3, 2026
4d98bf1
chore: vsm effect shadow idea
doodlum Feb 3, 2026
6f48e47
feat: fast shadow maps
doodlum Feb 3, 2026
615a402
chore: cleanup
doodlum Feb 3, 2026
9a35507
chore: start moving shadows into its own feature
doodlum Feb 5, 2026
7baa5c5
chore: more cleanup
doodlum Feb 6, 2026
b9abcf3
fix: dont clear cache
doodlum Feb 6, 2026
740ff88
chore: tweaks
doodlum Feb 6, 2026
80fb0c4
chore: downscale further
doodlum Feb 6, 2026
a46bf1c
chore: optimise
doodlum Feb 6, 2026
5e0fe54
chore: even faster
doodlum Feb 6, 2026
47b2a37
chore: link paper
doodlum Feb 6, 2026
405ccd7
fix: fixes
doodlum Feb 7, 2026
e318bb1
fix: fix fog depth
doodlum Feb 7, 2026
cf37641
feat: add surface shadow
doodlum Feb 9, 2026
fd56ce1
fix: fix nonsense
doodlum Feb 9, 2026
f95dea7
Merge branch 'dev' into vsm-effect-shadow
doodlum Feb 9, 2026
f23e447
fix: fix nonsense
doodlum Feb 9, 2026
f51f89f
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Feb 9, 2026
c9bdb69
fix: fix nonsense
doodlum Feb 9, 2026
0b94492
Merge branch 'vsm-effect-shadow' of https://github.com/doodlum/skyrim…
doodlum Feb 9, 2026
c4fcf0e
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Feb 9, 2026
61d5e53
feat: add 2d shadow
doodlum Feb 9, 2026
2c5ae84
Merge branch 'vsm-effect-shadow' of https://github.com/doodlum/skyrim…
doodlum Feb 9, 2026
6dd0703
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Feb 9, 2026
80a8d56
chore: add to particle
doodlum Feb 9, 2026
26af1b2
Merge branch 'vsm-effect-shadow' of https://github.com/doodlum/skyrim…
doodlum Feb 9, 2026
3507558
fix: fix more nonsense
doodlum Feb 9, 2026
ae3bcc4
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Feb 9, 2026
a34ca4e
fix: fix nonsense
doodlum Feb 9, 2026
2e9b9c5
fix: fix more nonsense
doodlum Feb 9, 2026
a6bc8ed
fix: fix luma
doodlum Feb 9, 2026
ea3d830
fix: fix nosense, the nosequeal
doodlum Feb 9, 2026
fffbf4f
Merge branch 'dev' into vsm-effect-shadow
doodlum Feb 9, 2026
05f69c3
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Feb 9, 2026
303da05
fix: fix warning
doodlum Feb 9, 2026
fc6360b
fix: fix seams
doodlum Feb 10, 2026
5c73283
chore: rename to sound cooler
doodlum Feb 10, 2026
c6e2d04
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Feb 10, 2026
62adf1b
fix: fix compile errors
doodlum Feb 10, 2026
4402542
Merge branch 'vsm-effect-shadow' of https://github.com/doodlum/skyrim…
doodlum Feb 10, 2026
90a301d
feat: sss shadow
doodlum Feb 10, 2026
80f0435
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Feb 10, 2026
ccd348b
feat: moment shadow maps
doodlum Feb 11, 2026
9c3bcc5
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Feb 11, 2026
b232daa
chore: add bias
doodlum Feb 11, 2026
1f58cca
Merge branch 'vsm-effect-shadow' of https://github.com/doodlum/skyrim…
doodlum Feb 11, 2026
23a6dc2
chore: move back to VSM
doodlum Feb 13, 2026
7e809d5
chore: simplify
doodlum Feb 13, 2026
756a356
fix: fix missing shadows
doodlum Feb 13, 2026
f686cb5
chore: always resize to the same size
doodlum Feb 13, 2026
f3b9e74
chore: remove IsTree
doodlum Feb 13, 2026
941eebf
feat: fix for objects with no shadows
doodlum Feb 13, 2026
069efbb
chore: patch volumetric lighting shadow map
doodlum Feb 13, 2026
fcf99fe
chore: touch ups
doodlum Feb 13, 2026
042b933
Merge branch 'dev' into vsm-effect-shadow
doodlum Feb 13, 2026
713783b
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Feb 13, 2026
cf4286e
fix: dont replace detailed shadow
doodlum Feb 13, 2026
502b77d
Merge branch 'vsm-effect-shadow' of https://github.com/doodlum/skyrim…
doodlum Feb 13, 2026
4d12e7d
fix: detect menu and interiors
doodlum Feb 13, 2026
5563906
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Feb 13, 2026
1c629db
fix: fix shader errors
doodlum Feb 13, 2026
63ee8ab
Merge branch 'vsm-effect-shadow' of https://github.com/doodlum/skyrim…
doodlum Feb 13, 2026
e58bc72
fix: fix multilayerparallax brightness
doodlum Feb 13, 2026
59258f1
chore: apply skylighting to mlp
doodlum Feb 13, 2026
513839b
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Feb 13, 2026
714b07c
fix: fix nonsense
doodlum Feb 13, 2026
bce8c09
Merge branch 'vsm-effect-shadow' of https://github.com/doodlum/skyrim…
doodlum Feb 13, 2026
a61ef4f
fix: less long marching
doodlum Feb 13, 2026
43fc64e
fix: fix nonsense
doodlum Feb 13, 2026
75090f1
chore: make coderabbit happy
doodlum Feb 13, 2026
36be385
fix: fix double application of shadow
doodlum Feb 13, 2026
6923a0c
fix: compile water
jiayev Feb 15, 2026
4280548
feat: add exp fog dir light attenuation to effect
jiayev Feb 15, 2026
e200ba8
chore: minor changes
doodlum Feb 15, 2026
2ad8759
Merge branch 'dev' into vsm-shadow
doodlum Feb 15, 2026
7c35aa1
Update src/Features/VolumetricShadows.cpp
doodlum Feb 15, 2026
ef48ce8
style: 🎨 apply pre-commit.ci formatting
pre-commit-ci[bot] Feb 15, 2026
e8ec5f5
fix: dont touch map menu
doodlum Feb 15, 2026
a93aba8
Merge branch 'vsm-shadow' of https://github.com/doodlum/skyrim-commun…
doodlum Feb 15, 2026
31e2643
chore: add to grass
doodlum Feb 15, 2026
249c509
perf: make rabbit happy
doodlum Feb 15, 2026
0fc2495
fix: fix nonsense
doodlum Feb 16, 2026
a762522
fix: apply some fixes
doodlum Feb 16, 2026
40d8aab
fix: fix hair lighting
doodlum Feb 16, 2026
2dd7391
fix: missing pbr shadow
jiayev Feb 17, 2026
9a3cd15
fix: marschner self shadow
jiayev Feb 17, 2026
54238ef
Merge branch 'dev' into vsm-shadow
doodlum Feb 19, 2026
0365244
Merge branch 'dev' into vsm-shadow
doodlum Feb 19, 2026
be4b14c
Merge branch 'dev' into vsm-shadow
doodlum Feb 20, 2026
8ee5637
Merge branch 'dev' of https://github.com/doodlum/skyrim-community-sha…
alandtse Feb 22, 2026
8ea6ec8
fix(VR): ctd due to missing iNumFocusShadow
alandtse Feb 22, 2026
8f8e7b3
Merge branch 'dev' into vsm-shadow
doodlum Feb 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions features/Hair Specular/Shaders/Hair/Hair.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ namespace Hair

void GetHairDirectLightMarschner(out float3 dirDiffuse, out float3 dirSpecular, out float3 dirTransmission, float3 T, float3 L, float3 V, float3 N, float3 VN, float3 lightColor, float shininess, float selfShadow, float2 uv, float3 baseColor)
{
lightColor *= Color::PBRLightingCompensation * selfShadow;
lightColor *= Color::PBRLightingCompensation;
dirDiffuse = 0;
dirSpecular = 0;
dirTransmission = 0;
Expand All @@ -205,7 +205,7 @@ namespace Hair
T = ShiftTangent(T, N, shift);
}

float backlit = SharedData::hairSpecularSettings.Transmission;
float backlit = SharedData::hairSpecularSettings.Transmission * selfShadow;

dirTransmission += D_Marschner(L, V, T, roughness, baseColor, 0, backlit) * lightColor * SharedData::hairSpecularSettings.SpecularMult;
dirTransmission += GetHairDiffuseAttenuationKajiyaKay(T, V, L, selfShadow, baseColor) * lightColor * SharedData::hairSpecularSettings.DiffuseMult;
Expand All @@ -219,10 +219,13 @@ namespace Hair
const float3 VN = normalize(tbnTr[2]);
const float3 L = normalize(context.lightDir);

float3 lightColor = context.lightColor * context.detailedShadow;
float selfShadow = context.hairShadow * context.softShadow;

if (SharedData::hairSpecularSettings.HairMode == 0) {
GetHairDirectLightScheuermann(lightingOutput.diffuse, lightingOutput.specular, lightingOutput.transmission, T, L, V, N, VN, context.lightColor, material.Shininess, context.hairShadow, uv, material.BaseColor);
GetHairDirectLightScheuermann(lightingOutput.diffuse, lightingOutput.specular, lightingOutput.transmission, T, L, V, N, VN, lightColor, material.Shininess, selfShadow, uv, material.BaseColor);
} else {
GetHairDirectLightMarschner(lightingOutput.diffuse, lightingOutput.specular, lightingOutput.transmission, T, L, V, N, VN, context.lightColor, material.Shininess, context.hairShadow, uv, material.BaseColor);
GetHairDirectLightMarschner(lightingOutput.diffuse, lightingOutput.specular, lightingOutput.transmission, T, L, V, N, VN, lightColor, material.Shininess, selfShadow, uv, material.BaseColor);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[Info]
Version = 1-0-1
Version = 1-0-2
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ groupshared float2 g_shadowHeight[NTHREADS];
float2 threadUV = rawThreadUV - floor(rawThreadUV); // wraparound
float2 threadPxCoord = threadUV * dims;

float2 pastHeights = 0.0f.xx;
float2 pastHeights = 0.0;
if (isValid) {
pastHeights = RWTexShadowHeights[uint2(threadPxCoord)];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace TerrainShadows

float GetTerrainZ(float norm_z)
{
return lerp(SharedData::terraOccSettings.ZRange.x, SharedData::terraOccSettings.ZRange.y, norm_z) - 1024;
return lerp(SharedData::terraOccSettings.ZRange.x, SharedData::terraOccSettings.ZRange.y, norm_z) - 256;
}

float2 GetTerrainZ(float2 norm_z)
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Info]
Version = 2-0-0
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// 11x11 separable Gaussian blur for VSM shadow map
// BLUR_HORIZONTAL - horizontal pass
// BLUR_VERTICAL - vertical pass

Texture2D<float2> InputTexture : register(t0);
RWTexture2D<float2> OutputTexture : register(u0);

// Gaussian weights for 11-tap kernel (sigma ~= 2.5)
static const float weights[6] = {
0.198596, // center
0.175713, // +/- 1
0.121703, // +/- 2
0.065984, // +/- 3
0.028002, // +/- 4
0.009302 // +/- 5
};

#define KERNEL_RADIUS 5
#define GROUP_SIZE 128

// Shared memory for efficient loading
// We need GROUP_SIZE + 2 * KERNEL_RADIUS elements
groupshared float2 g_cache[GROUP_SIZE + 2 * KERNEL_RADIUS];

#if defined(BLUR_HORIZONTAL)
[numthreads(GROUP_SIZE, 1, 1)]
void main(uint3 groupID : SV_GroupID, uint3 groupThreadID : SV_GroupThreadID, uint3 dispatchThreadID : SV_DispatchThreadID)
{
uint width, height;
InputTexture.GetDimensions(width, height);

int2 baseCoord = int2(groupID.x * GROUP_SIZE - KERNEL_RADIUS, groupID.y);
int localIdx = groupThreadID.x;

// Load main data
int2 coord = baseCoord + int2(localIdx, 0);
coord.x = clamp(coord.x, 0, (int)width - 1);
g_cache[localIdx] = InputTexture[coord];

// Load extra data for kernel overlap
if (localIdx < 2 * KERNEL_RADIUS) {
coord = baseCoord + int2(GROUP_SIZE + localIdx, 0);
coord.x = clamp(coord.x, 0, (int)width - 1);
g_cache[GROUP_SIZE + localIdx] = InputTexture[coord];
}

GroupMemoryBarrierWithGroupSync();

// Only process valid pixels
if (dispatchThreadID.x >= width || dispatchThreadID.y >= height)
return;

// Apply horizontal blur
float2 result = g_cache[localIdx + KERNEL_RADIUS] * weights[0];

[unroll]
for (int i = 1; i <= KERNEL_RADIUS; i++) {
result += g_cache[localIdx + KERNEL_RADIUS - i] * weights[i];
result += g_cache[localIdx + KERNEL_RADIUS + i] * weights[i];
}

OutputTexture[dispatchThreadID.xy] = result;
}

#elif defined(BLUR_VERTICAL)
[numthreads(1, GROUP_SIZE, 1)]
void main(uint3 groupID : SV_GroupID, uint3 groupThreadID : SV_GroupThreadID, uint3 dispatchThreadID : SV_DispatchThreadID)
{
uint width, height;
InputTexture.GetDimensions(width, height);

int2 baseCoord = int2(groupID.x, groupID.y * GROUP_SIZE - KERNEL_RADIUS);
int localIdx = groupThreadID.y;

// Load main data
int2 coord = baseCoord + int2(0, localIdx);
coord.y = clamp(coord.y, 0, (int)height - 1);
g_cache[localIdx] = InputTexture[coord];

// Load extra data for kernel overlap
if (localIdx < 2 * KERNEL_RADIUS) {
coord = baseCoord + int2(0, GROUP_SIZE + localIdx);
coord.y = clamp(coord.y, 0, (int)height - 1);
g_cache[GROUP_SIZE + localIdx] = InputTexture[coord];
}

GroupMemoryBarrierWithGroupSync();

// Only process valid pixels
if (dispatchThreadID.x >= width || dispatchThreadID.y >= height)
return;

// Apply vertical blur
float2 result = g_cache[localIdx + KERNEL_RADIUS] * weights[0];

[unroll]
for (int i = 1; i <= KERNEL_RADIUS; i++) {
result += g_cache[localIdx + KERNEL_RADIUS - i] * weights[i];
result += g_cache[localIdx + KERNEL_RADIUS + i] * weights[i];
}

OutputTexture[dispatchThreadID.xy] = result;
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,4 @@ RWStructuredBuffer<PerGeometry> ShadowData : register(u0);
perGeometry.FocusShadowFadeParam = FocusShadowFadeParam;

ShadowData[0] = perGeometry;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
Texture2DArray<float> InputTexture : register(t0);
Texture2DArray<float> ESRAMShadow : register(t1);
RWTexture2D<float2> OutputTexture : register(u0);
SamplerState LinearSampler : register(s0);

float2 GetVSMMoments(in float depth)
{
return float2(depth, depth * depth);
}

float2 ReduceMoments(float2 a, float2 b, float2 c, float2 d)
{
return (a + b + c + d) * 0.25;
}

groupshared float2 g_scratchDepths[8][8];

#if defined(DOWNSAMPLE_SHADOW_MIP0)
static const uint CASCADE = 1;
#elif defined(DOWNSAMPLE_SHADOW_MIP1)
static const uint CASCADE = 0;
#endif

[numthreads(8, 8, 1)]
void main(uint3 dispatchThreadID : SV_DispatchThreadID, uint3 groupThreadID : SV_GroupThreadID) {
uint2 pixCoord = dispatchThreadID.xy * 2;

uint inputW, inputH, inputSlices;
InputTexture.GetDimensions(inputW, inputH, inputSlices);
float2 uv = (pixCoord + 0.5) / float2(inputW, inputH);

uint outputW, outputH;
OutputTexture.GetDimensions(outputW, outputH);

// Determine reduction levels from input/output ratio
// Gather handles 2x, each group reduction handles another 2x
uint totalReduction = inputW / outputW;
uint groupReductions = 0;
if (totalReduction >= 4) groupReductions = 1;
if (totalReduction >= 8) groupReductions = 2;
if (totalReduction >= 16) groupReductions = 3;

// Gather from shadow cascades and mix with ESRAM shadow
float4 depths = InputTexture.GatherRed(LinearSampler, float3(uv, CASCADE));
float4 esramDepths = ESRAMShadow.GatherRed(LinearSampler, float3(uv, CASCADE));
depths = min(depths, esramDepths);

float2 vsmDepth = 0;
for(uint i = 0; i < 4; i++)
vsmDepth += GetVSMMoments(depths[i]);
vsmDepth *= 0.25;

g_scratchDepths[groupThreadID.x][groupThreadID.y] = vsmDepth;

GroupMemoryBarrierWithGroupSync();

// First reduction: 2x2
if (groupReductions >= 1) {
if (all((groupThreadID.xy % 2) == 0)) {
uint2 tid = groupThreadID.xy;
g_scratchDepths[tid.x][tid.y] = ReduceMoments(
g_scratchDepths[tid.x + 0][tid.y + 0],
g_scratchDepths[tid.x + 1][tid.y + 0],
g_scratchDepths[tid.x + 0][tid.y + 1],
g_scratchDepths[tid.x + 1][tid.y + 1]);
}
GroupMemoryBarrierWithGroupSync();
}

// Second reduction: 4x4
if (groupReductions >= 2) {
if (all((groupThreadID.xy % 4) == 0)) {
uint2 tid = groupThreadID.xy;
g_scratchDepths[tid.x][tid.y] = ReduceMoments(
g_scratchDepths[tid.x + 0][tid.y + 0],
g_scratchDepths[tid.x + 2][tid.y + 0],
g_scratchDepths[tid.x + 0][tid.y + 2],
g_scratchDepths[tid.x + 2][tid.y + 2]);
}
GroupMemoryBarrierWithGroupSync();
}

// Third reduction: 8x8
if (groupReductions >= 3) {
if (all(groupThreadID.xy == 0)) {
g_scratchDepths[0][0] = ReduceMoments(
g_scratchDepths[0][0],
g_scratchDepths[4][0],
g_scratchDepths[0][4],
g_scratchDepths[4][4]);
}
GroupMemoryBarrierWithGroupSync();
}

// Write output - only threads aligned to the output grid
uint outputDiv = max(totalReduction / 2, 1);
if (all((groupThreadID.xy % outputDiv) == 0)) {
OutputTexture[dispatchThreadID.xy / outputDiv] = g_scratchDepths[groupThreadID.x][groupThreadID.y];
}
}
Loading