mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-17 15:49:57 -04:00
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:
@@ -3852,6 +3852,15 @@ static VkViewport draw_viewport(VkExec *ex) {
|
||||
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) {
|
||||
VkCommandBuffer cb = ex->cb;
|
||||
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;
|
||||
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++;
|
||||
}
|
||||
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->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->ib = ib, q->ib_off = ib_off;
|
||||
q->it = d->itype == NVN_INDEX_TYPE_UNSIGNED_SHORT ? VK_INDEX_TYPE_UINT16 : VK_INDEX_TYPE_UINT32;
|
||||
|
||||
@@ -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,
|
||||
// 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),
|
||||
// copies scale their regions (vk_exec_xfer.c sub_resolve), 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,
|
||||
// copies scale their regions (vk_exec_xfer.c sub_resolve), draws into them scale the game's slope-scaled depth bias
|
||||
// (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.
|
||||
static int shadow_scale(void) {
|
||||
static int scale = -1;
|
||||
|
||||
Reference in New Issue
Block a user