Files
totk-pc-recomp/tools/xlate/patches/0017-pcss-per-cascade.patch
T
itaskaev2andClaude Opus 5.5 4edf63a6dd Soft shadows keep their width on the ground across the sun cascades
The pcss radii and penumbra factor were in UV of whichever cascade map a pixel read, the same in every cascade. Each cascade's map spans 3.5 to 5 times the ground of the one before (measured on 1.4.3: the cascades end at about 4, 27, 120 and 450 m), so a soft shadow turned that much softer at every cascade step, a step that moves with the camera (issue #1291).

The runtime now measures each cascade from the camera block the lighting shaders read (c4 rows 42 to 57, a projective matrix per cascade, and row 58, the cascade ends): the UV and depth per metre where the cascade begins and ends. It passes two factors per cascade in two new support buffer fields, pcss_depth and pcss_scale, and translator patch 0017 applies them in the PCSS lookup. The values keep their meaning in the second cascade, which holds most shadows on screen, so the look at a given pcss value stays where most players see it. The narrowest radius stays in texels. The HDR field moves from byte 1440 to 1472. With pcss = 0 nothing changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 11:41:00 +01:00

58 lines
3.6 KiB
Diff

--- a/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Instructions.cs
+++ b/src/Ryujinx.Graphics.Shader/CodeGen/Spirv/Instructions.cs
@@ -1583,6 +1583,24 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
SpvInstruction uv = context.VectorShuffle(v2, pCoords, pCoords, 0, 1);
SpvInstruction layerF = context.CompositeExtract(f32, pCoords, 2);
SpvInstruction layerI = context.ConvertFToS(s32, layerF);
+
+ // TOTK: soft shadows per cascade. The radii and the penumbra factor above hold for the second cascade, in
+ // UV of its map; each cascade's map spans a different amount of ground per UV. The runtime measures each
+ // cascade against the second (runtime/vk_exec_draw.c, pcss_cascades) and gives pcss_depth[layer], the
+ // penumbra factor's multiplier, and pcss_scale[layer], the UV of this cascade's map that one UV of the
+ // second's ground spans. The search and widest radius take the scale, so a shadow keeps its width on the
+ // ground from one cascade to the next; the narrowest radius stays in texels, the map's own filter. A value
+ // of 0 or below counts as 1.
+ SpvInstruction layerC = context.GlslSClamp(s32, layerI, context.Constant(s32, 0), context.Constant(s32, 3));
+ SpvInstruction cascDepth = context.VectorExtractDynamic(f32, context.Load(v4, context.AccessChain(context.TypePointer(StorageClass.Uniform, v4),
+ context.ConstantBuffers[SupportBuffer.Binding], context.Constant(s32, (int)SupportBufferField.PcssDepth))), layerC);
+ SpvInstruction cascScale = context.VectorExtractDynamic(f32, context.Load(v4, context.AccessChain(context.TypePointer(StorageClass.Uniform, v4),
+ context.ConstantBuffers[SupportBuffer.Binding], context.Constant(s32, (int)SupportBufferField.PcssScale))), layerC);
+ cascDepth = context.Select(f32, context.FOrdGreaterThan(b, cascDepth, zero), cascDepth, one);
+ cascScale = context.Select(f32, context.FOrdGreaterThan(b, cascScale, zero), cascScale, one);
+ lightSize = context.FMul(f32, lightSize, cascDepth);
+ searchR = context.FMul(f32, searchR, cascScale);
+ maxR = context.GlslFMax(f32, context.FMul(f32, maxR, cascScale), minR);
SpvInstruction searchV = context.CompositeConstruct(v2, searchR, searchR);
SpvInstruction sum = zero, count = zero;
--- a/src/Ryujinx.Graphics.Shader/SupportBuffer.cs
+++ b/src/Ryujinx.Graphics.Shader/SupportBuffer.cs
@@ -27,6 +27,8 @@ namespace Ryujinx.Graphics.Shader
PointSize,
Pcss,
ShadowSpread,
+ PcssDepth,
+ PcssScale,
}
public struct SupportBuffer
@@ -86,7 +88,9 @@ namespace Ryujinx.Graphics.Shader
new StructureField(AggregateType.S32, "tfe_vertex_count"),
new StructureField(AggregateType.FP32, "point_size"),
new StructureField(AggregateType.Vector4 | AggregateType.FP32, "pcss"),
- new StructureField(AggregateType.Vector4 | AggregateType.FP32, "shadow_spread")
+ new StructureField(AggregateType.Vector4 | AggregateType.FP32, "shadow_spread"),
+ new StructureField(AggregateType.Vector4 | AggregateType.FP32, "pcss_depth"),
+ new StructureField(AggregateType.Vector4 | AggregateType.FP32, "pcss_scale")
]);
}
@@ -104,5 +108,7 @@ namespace Ryujinx.Graphics.Shader
public Vector4<float> PointSize;
public Vector4<float> Pcss;
public Vector4<float> ShadowSpread;
+ public Vector4<float> PcssDepth;
+ public Vector4<float> PcssScale;
}
}