Scale the slope-scaled depth bias with the shadow map scale, so the larger maps keep the bias the game asked for.

The slope term is a bias per unit of depth slope across one pixel of the target. A shadow map made k times larger on
each side (shadow_scale 2 to 4) has 1/k of the slope across each texel, so the game's factor alone gave k times less
bias on sloped surfaces than at the game's own size, which is what shows as acne. vk_exec_draw.c slope_bias
multiplies the factor by the pass's scale for both the direct draws (record_fixed) and the queued mesh draws; the
constant term counts the depth format's smallest steps and keeps its value. Nothing changes at shadow_scale 1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
FIocker
2026-11-12 17:22:34 +01:00
committed by chrg6
parent a74f7695c8
commit 58efccd883
3 changed files with 15 additions and 5 deletions

View File

@@ -468,7 +468,8 @@
# Shadow map resolution: the game's sun cascades are 960x960 (and its static shadow maps 1440 and 720) whatever the game # Shadow map resolution: the game's sun cascades are 960x960 (and its static shadow maps 1440 and 720) whatever the game
# resolution; 2 to 4 draws them that many times larger on each side, for sharper shadows. 1 = the game's. The game's # resolution; 2 to 4 draws them that many times larger on each side, for sharper shadows. 1 = the game's. The game's
# shadow edge filter is narrowed by the same factor (translator patch 0011), so close shadow edges don't look doubled. # shadow edge filter is narrowed by the same factor (translator patch 0011), so close shadow edges don't look doubled,
# and the game's slope-scaled depth bias grows by it, so the larger maps don't shadow the surfaces they are cast on.
# Read at start. # Read at start.
# shadow_scale = 1 # shadow_scale = 1
# Sun shadow cascade range in percent of the game's (its cascades end at 20, 40, 80 and 160 m), 50 to 400: higher moves # Sun shadow cascade range in percent of the game's (its cascades end at 20, 40, 80 and 160 m), 50 to 400: higher moves

View File

@@ -3852,6 +3852,15 @@ static VkViewport draw_viewport(VkExec *ex) {
return v; return v;
} }
// The slope-scaled depth bias of a draw. The term is the bias per unit of depth slope across one pixel of the target,
// and a shadow map made k times larger on each side (NX2NAVI_SHADOW_SCALE, vk_texture.c shadow_scale_of, pass_scale)
// has 1/k of the slope across each of its texels: the game's factor alone gives k times less bias than it asked for
// on sloped surfaces, which is what shows as acne (stripes of self-shadow over slanted ground and walls). The
// constant term counts the depth format's smallest steps, which do not change with the size, and keeps its value.
static float slope_bias(const VkExec *ex) {
return ex->pass_scale > 1 ? ex->poly_offset.factor * (float)ex->pass_scale : ex->poly_offset.factor;
}
static void record_fixed(VkExec *ex) { static void record_fixed(VkExec *ex) {
VkCommandBuffer cb = ex->cb; VkCommandBuffer cb = ex->cb;
if (ex->dirty & VK_EXEC_DIRTY_VIEWPORT) { if (ex->dirty & VK_EXEC_DIRTY_VIEWPORT) {
@@ -3874,7 +3883,7 @@ static void record_fixed(VkExec *ex) {
bx = e && *e ? (float)atof(e) : 1.0f; bx = e && *e ? (float)atof(e) : 1.0f;
if (bx != 1.0f) rt_log("vk: NX2NAVI_DEPTH_BIAS_X: constant depth bias multiplied by %.1f", bx); if (bx != 1.0f) rt_log("vk: NX2NAVI_DEPTH_BIAS_X: constant depth bias multiplied by %.1f", bx);
} }
vkCmdSetDepthBias(cb, ex->poly_offset.units * bx, ex->poly_offset.clamp, ex->poly_offset.factor); vkCmdSetDepthBias(cb, ex->poly_offset.units * bx, ex->poly_offset.clamp, slope_bias(ex));
ex->recorded++; ex->recorded++;
} }
if (ex->dirty & VK_EXEC_DIRTY_BLEND_CONST) { if (ex->dirty & VK_EXEC_DIRTY_BLEND_CONST) {
@@ -5386,7 +5395,7 @@ static void mvobj_draw_(VkExec *ex, const p_draw_idx *d, VkBuffer ib, VkDeviceSi
} }
q->st = (uint32_t)MQ.nst - 1; q->st = (uint32_t)MQ.nst - 1;
q->v = draw_viewport(ex), q->sc = vk_exec_scissor(ex); q->v = draw_viewport(ex), q->sc = vk_exec_scissor(ex);
q->bias[0] = ex->poly_offset.units, q->bias[1] = ex->poly_offset.clamp, q->bias[2] = ex->poly_offset.factor; q->bias[0] = ex->poly_offset.units, q->bias[1] = ex->poly_offset.clamp, q->bias[2] = slope_bias(ex);
q->vb = mo_vertex_buffers(ex); q->vb = mo_vertex_buffers(ex);
q->ib = ib, q->ib_off = ib_off; q->ib = ib, q->ib_off = ib_off;
q->it = d->itype == NVN_INDEX_TYPE_UNSIGNED_SHORT ? VK_INDEX_TYPE_UINT16 : VK_INDEX_TYPE_UINT32; q->it = d->itype == NVN_INDEX_TYPE_UNSIGNED_SHORT ? VK_INDEX_TYPE_UINT16 : VK_INDEX_TYPE_UINT32;

View File

@@ -933,8 +933,8 @@ static void init_new(Tex *e) {
// sun cascades into a 960x960 DEPTH16 2D array of 4 layers and its static shadows into 1440x1440 and 720x720 arrays of 2, // sun cascades into a 960x960 DEPTH16 2D array of 4 layers and its static shadows into 1440x1440 and 720x720 arrays of 2,
// whatever the output resolution, and shrinks the cascades under load (872, 848, 800, 480 and so on). Those are made // whatever the output resolution, and shrinks the cascades under load (872, 848, 800, 480 and so on). Those are made
// larger here: render passes into them scale the game's viewports and scissors (vk_exec.c resolve_rt, pass_scale), // larger here: render passes into them scale the game's viewports and scissors (vk_exec.c resolve_rt, pass_scale),
// copies scale their regions (vk_exec_xfer.c sub_resolve), and shaders sample them with normalised coordinates, so the // copies scale their regions (vk_exec_xfer.c sub_resolve), draws into them scale the game's slope-scaled depth bias
// game sees nothing of it. A map whose storage the CPU writes (mirrored) or that aliases pool memory keeps its size, // (vk_exec_draw.c slope_bias), and shaders sample them with normalised coordinates, so the game sees nothing of it. A map whose storage the CPU writes (mirrored) or that aliases pool memory keeps its size,
// as its texels must match the guest layout. // as its texels must match the guest layout.
static int shadow_scale(void) { static int shadow_scale(void) {
static int scale = -1; static int scale = -1;