From 7ff62786c394a6e534a8312eccbb7068a61ac192 Mon Sep 17 00:00:00 2001 From: shinodanpen Date: Mon, 16 Nov 2026 20:46:11 +0000 Subject: [PATCH 1/3] Make shadow_range move the sun cascades on 1.2.1 by scaling the boundaries the shadow controller writes each frame (#606) On 1.2.1 the constructor values of depth_shadow_near_0_0..3 (main+0x114c2f8..) are only defaults: the shadow controller sets bit 1 of the scene's depth shadow flags when it starts (main+0xc7b0e8), the per-view update skips its copy of those parameters while the bit is set (main+0xa2cff4), and main+0xcebdf4 writes the cascade boundaries itself every frame. The cascade set scales d[1..n] where they are stored (main+0xcec314, main+0xcec36c) by page +64 over 20, i.e. shadow_range / 100; d[0], the first cascade's start, stays. Off at shadow_range = 100. Co-Authored-By: Claude --- recomp/patches-v121.txt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/recomp/patches-v121.txt b/recomp/patches-v121.txt index f1749df4..106a13cb 100644 --- a/recomp/patches-v121.txt +++ b/recomp/patches-v121.txt @@ -11,6 +11,7 @@ set output TOTK_PATCH_OUTPUT 0 set scene TOTK_PATCH_SCENE 0 set shadow TOTK_PATCH_SHADOW 0 set grass TOTK_PATCH_GRASS 0 +set cascade TOTK_PATCH_CASCADE 0 # 60 fps: the adaptive present-interval controller (main+0x8f26c8, 1.0.0 0x8f6bec) gets the minimum interval 1. site fps60 main 8f273c 6b08015f 7100055f # clamp: cmp w10, #1 (was cmp w10, w8 = minimum) @@ -1128,6 +1129,18 @@ spin sdk 3d3250 3d3270 # 9 instructions; loads # computation). Found by a write watch on the size field (the writer was this function, and no other). site shadow main cec22c 11001d6b @page:x11 b9405d6b 11001d6b # add w11, w11, #7 -> adrp x11, page; ldr w11, [x11, #92]; add w11, w11, #7 +# Sun shadow cascade distances (runtime/resolution.c res_shadow_range switches the set on; issue #606). On 1.2.1 the +# depth shadow parameters (depth_shadow_near_0_0..3 and depth_shadow_far_0, whose constructor defaults at +# main+0x114c2f8.. are 20, 40, 80, 160 and 2000 m) do not reach the sun's cascades: the game's shadow controller sets +# bit 1 of the scene's depth shadow flags when it starts (main+0xc7b0e8), and with that bit the per-view update +# (main+0xa2cff4) skips its copy of those parameters into the cascade boundaries. The controller writes the boundaries +# itself each frame in main+0xcebdf4: d[0] at main+0xcec2ac, d[1..n-1] at main+0xcec314 and the far d[n] at +# main+0xcec36c (d = [cascade set + 0x308], read by main+0xa2d6ec). The set multiplies d[1..n] where they are stored, +# by page +64 (20 m times shadow_range / 100) over 20; d[0], the first cascade's start, stays. x3, s16 and s17 are +# dead at both sites. +site cascade main cec314 bd000446 @page:x3 bd404070 1e269011 1e311a10 1e3008d0 bd000450 # str s6, [x2, #4] -> adrp x3, page; ldr s16, [x3, #64]; fmov s17, #20.0; fdiv s16, s16, s17; fmul s16, s6, s16; str s16, [x2, #4] +site cascade main cec36c bc29d945 @page:x3 bd404070 1e269011 1e311a10 1e3008b0 bc29d950 # str s5, [x10, w9, sxtw #2] -> the same with fmul s16, s5, s16; str s16, [x10, w9, sxtw #2] + # Grass range (runtime/resolution.c res_grass_range; patches-v143.txt describes the set and the page). The near grass # map's constructor loads its extent, step and texture sizes at main+0xfe58b4..0xfe5950, and main+0x1a30a28 sets the # extent to 62.5 or 31.25 m, as on 1.4.3. From 051ec978f91741588211c686d4989abcbd95a288 Mon Sep 17 00:00:00 2001 From: shinodanpen Date: Mon, 16 Nov 2026 21:35:36 +0000 Subject: [PATCH 2/3] Make shadow_range move the sun cascades on 1.4.3 by scaling the boundaries the shadow controller writes each frame (#606) The cascade set loads the four constructor defaults of the depth shadow parameters (main+0x6fabb8, 0x6fac40, 0x6facc8, 0x6fad4c) from page +64..+76. In Hyrule Field that does not move the sun's cascades: frame dumps of the 0.4.1 release at shadow_range 100 and 300 show the same draws per layer and the same cascade transforms, though the log names the new distances. As on 1.2.1, the shadow controller sets bit 1 of the scene's depth shadow flags when it starts (main+0xb74494), the per-view update skips its copy of the parameters while the bit is set (main+0x567f6c), and main+0x68318c writes the boundaries every frame. Two more sites scale d[1..n] where the controller stores them (main+0x6836ec, main+0x683740) by page +64 over 20, i.e. shadow_range / 100; d[0], the first cascade's start, stays. The four constructor sites stay for the path where bit 1 is clear. Off at shadow_range = 100. Co-Authored-By: Claude --- recomp/patches-v143.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/recomp/patches-v143.txt b/recomp/patches-v143.txt index 0b05ab02..27584ac3 100644 --- a/recomp/patches-v143.txt +++ b/recomp/patches-v143.txt @@ -1104,6 +1104,18 @@ site cascade main 6fabb8 52a83408 @page:x8 b9404108 # mov w8, #20.0 -> ldr w8 site cascade main 6fac40 52a84408 @page:x8 b9404508 # mov w8, #40.0 -> ldr w8, [page+68] site cascade main 6facc8 52a85408 @page:x8 b9404908 # mov w8, #80.0 -> ldr w8, [page+72] site cascade main 6fad4c 52a86408 @page:x8 b9404d08 # mov w8, #160.0 -> ldr w8, [page+76] +# The four sites above reach the cascades only through the copy of the parameters into the cascade boundaries +# (main+0x5680ec, in the per-view update). The game's shadow controller sets bit 1 of the scene's depth shadow flags +# when it starts (main+0xb74494), with that bit the per-view update skips the copy (main+0x567f6c), and the controller +# writes the boundaries itself each frame in main+0x68318c: d[0] at main+0x683680, d[1..n-1] at main+0x6836ec and the +# far d[n] at main+0x683740 (d = [cascade set + 0x308]). In Hyrule Field the four sites alone leave the cascades as +# they are at 100 (issue #606 has the same on 1.2.1). These two multiply d[1..n] where the controller stores them, by +# page +64 (20 m times shadow_range / 100) over 20; d[0], the first cascade's start, stays. The function computes the +# boundaries from the controller's own fields and its arguments and reads neither the parameters nor d, so a boundary +# is scaled once on either path. x25 (written at main+0x683704 before any read), x16, s18 and s19 are dead at the +# sites. +site cascade main 6836ec bd000711 @page:x25 bd404332 1e269013 1e331a52 1e320a32 bd000712 # str s17, [x24, #4] -> adrp x25, page; ldr s18, [x25, #64]; fmov s19, #20.0; fdiv s18, s18, s19; fmul s18, s17, s18; str s18, [x24, #4] +site cascade main 683740 bc2ed9b0 @page:x16 bd404212 1e269013 1e331a52 1e320a12 bc2ed9b2 # str s16, [x13, w14, sxtw #2] -> the same through x16 with fmul s18, s16, s18; str s18, [x13, w14, sxtw #2] # Climbing (issues #35, #276, #1001): the climb controller's velocity step (main+0x1f49754, shared by wall and ladder # climbing, climb jumps and climb-overs) multiplies the requested velocity by a factor that makes up for a movement loss From 4613d9b45893a6491dc8d4ffc4b70476ed535db6 Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Tue, 17 Nov 2026 19:58:02 +0300 Subject: [PATCH 3/3] res_shadow_range's comment names both cascade tables and the controller's boundaries they scale (#606) Co-Authored-By: Claude Opus 5.5 --- runtime/resolution.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/runtime/resolution.c b/runtime/resolution.c index 313967fd..9a6f8140 100644 --- a/runtime/resolution.c +++ b/runtime/resolution.c @@ -510,9 +510,10 @@ static void shadow_init(uint8_t *page) { // ---- start: the patch page and the sets static uint64_t pack(unsigned w, unsigned h) { return (uint64_t)h << 32 | w; } -// TOTK_SHADOW_RANGE (percent, 50 to 400; 100 = the game's): the sun's shadow cascades end at 20, 40, 80 and 160 m. -// Other values multiply those distances through the cascade patch set (recomp/patches-v143.txt), so the sharp first -// cascade reaches further and the visible steps between cascades move away from the player, at the cost of shadow +// TOTK_SHADOW_RANGE (percent, 50 to 400; 100 = the game's): the sun's shadow cascades end at 20, 40, 80 and 160 m by +// the depth shadow parameters' defaults; in the field the shadow controller computes the boundaries from the camera +// each frame instead. Other values multiply the boundaries through the cascade patch set (recomp/patches-v143.txt and +// patches-v121.txt; the controller's sites take page +64 over 20 as the factor), so the sharp first cascade reaches further and the visible steps between cascades move away from the player, at the cost of shadow // texels per metre (TOTK_SHADOW_SCALE pays that back). static void res_shadow_range(void) { int pct = cfg_int("TOTK_SHADOW_RANGE"), set = rt_patch_set("cascade");