mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-25 14:05:57 +00:00
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>
This commit is contained in:
1 parent
ebce67b367
commit
4edf63a6dd
6 files changed
+179
-29
No files matched your search
@@ -1,7 +1,7 @@
|
||||
"""Build the shader translator: build/xlate/totk_xlate.exe (Ryujinx 1.3.2 + patches, NativeAOT, SPIR-V for Vulkan).
|
||||
|
||||
Copies tools/vendor/ryujinx to build/xlate/ryujinx, applies tools/xlate/patches/*.patch there (tools/vendor stays
|
||||
byte-identical; 0001-0004 are MNG's, 0005-0013, 0015 and 0016 are ours), then runs `dotnet publish`. Needs the .NET 10 SDK, the MSVC build
|
||||
byte-identical; 0001-0004 are MNG's, 0005-0013 and 0015-0017 are ours), then runs `dotnet publish`. Needs the .NET 10 SDK, the MSVC build
|
||||
tools and vswhere.exe (docs/building.md). Run with .venv. On Linux it builds build/xlate/totk_xlate for linux-x64, which
|
||||
NativeAOT links with the system's clang (no MSVC); NativeAOT builds for the OS it runs on only.
|
||||
|
||||
@@ -99,8 +99,8 @@ def prepare_sources() -> Path:
|
||||
for junk in list(src.glob("src/*/obj")) + list(src.glob("src/*/bin")):
|
||||
shutil.rmtree(junk)
|
||||
patches = sorted((XLATE / "patches").glob("*.patch"))
|
||||
if len(patches) != 15:
|
||||
sys.exit(f"expected 15 patches, found {len(patches)}")
|
||||
if len(patches) != 16:
|
||||
sys.exit(f"expected 16 patches, found {len(patches)}")
|
||||
for patch in patches:
|
||||
# git apply works outside a repository when given a directory; --check first so a failure names the patch.
|
||||
for extra in (["--check"], []):
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
--- 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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user