fix: increase shadow bias — slope-dependent + larger depth bias

- Fragment shader: bias = 0.3 + 0.5 * (1 - NdotL) — slope-dependent
  Grazing angles get larger bias to prevent acne on cube faces
- vkCmdSetDepthBias: 2.5/0/3.5 (was 1.25/0/1.75) — more aggressive
  polygon offset for shadow map rendering
- Early exit tolerance reduced from 4x to 3x bias
This commit is contained in:
emil28092005
2026-06-18 21:38:48 +03:00
parent 7e33b64ac9
commit 23b38f8f17
3 changed files with 4 additions and 4 deletions
@@ -103,12 +103,12 @@ float calcShadow(vec3 worldPos, vec3 lightPos, vec3 N, vec3 L)
// Base shadow check (center sample)
float closestDepth = texture(shadowCube, dirNorm).r;
float mappedDepth = closestDepth * FAR_PLANE;
float bias = 0.15;
float bias = 0.3 + 0.5 * (1.0 - max(dot(N, L), 0.0));
float baseResult = dist - bias < mappedDepth ? 1.0 : 0.0;
// If clearly lit or clearly shadowed, skip PCF
if (dist - bias * 4.0 < mappedDepth) return 1.0;
if (dist + bias * 4.0 > mappedDepth && baseResult > 0.5) return 1.0;
if (dist - bias * 3.0 < mappedDepth) return 1.0;
if (dist + bias * 3.0 > mappedDepth && baseResult > 0.5) return 1.0;
// Poisson disk PCF — 16 samples
float shadow = 0.0;
Binary file not shown.
+1 -1
View File
@@ -255,7 +255,7 @@ internal sealed unsafe class VulkanRenderer : IRenderer, Engine.Graphics.IScreen
};
Vk.vkCmdSetScissor(cmd, 0, 1, &shadowScissor);
Vk.vkCmdSetDepthBias(cmd, 1.25f, 0.0f, 1.75f);
Vk.vkCmdSetDepthBias(cmd, 2.5f, 0.0f, 3.5f);
foreach (var dc in drawCalls)
{