fix: enable back-face culling — removes self-shadowing artifacts

Root cause: CULL_MODE_NONE in both main and shadow pipelines caused
back faces to render, creating self-shadowing acne on all objects:
- Shadow map: back faces written at closer depth → false shadows on front
- Main render: back faces visible through objects → wrong lighting

Fix:
- Main pipeline: CULL_MODE_BACK (was None) — only front faces render
- Shadow pipeline: CULL_MODE_BACK (was None) — only front faces cast shadows
- Removed normal flip hack (if dot(N,V) < 0 N = -N) — no longer needed
  with proper culling + correct CCW winding in cube.obj
- This is the standard approach: correct geometry + back-face culling
This commit is contained in:
emil28092005
2026-06-18 22:00:03 +03:00
parent d2078f3ee0
commit ed919edb0a
4 changed files with 2 additions and 5 deletions
@@ -138,9 +138,6 @@ void main()
float dist = length(toLight);
vec3 L = toLight / max(dist, 0.001);
// Flip normal to face camera — fixes cubes with bad winding without breaking spheres
if (dot(N, V) < 0.0) N = -N;
float attenuation = pow(clamp(1.0 - dist / max(lightRange, 0.001), 0.0, 1.0), 2.0);
vec3 radiance = lightColor * lightIntensity * attenuation;
Binary file not shown.
+1 -1
View File
@@ -102,7 +102,7 @@ internal sealed unsafe class VulkanPipeline : IDisposable
depthClampEnable = VkBool32.False,
rasterizerDiscardEnable = VkBool32.False,
polygonMode = VkPolygonMode.Fill,
cullMode = VkCullModeFlags.None,
cullMode = VkCullModeFlags.Back,
frontFace = VkFrontFace.CounterClockwise,
depthBiasEnable = VkBool32.False,
lineWidth = 1.0f,
@@ -275,7 +275,7 @@ internal sealed unsafe class VulkanShadowMap : IDisposable
depthClampEnable = VkBool32.False,
rasterizerDiscardEnable = VkBool32.False,
polygonMode = VkPolygonMode.Fill,
cullMode = VkCullModeFlags.None,
cullMode = VkCullModeFlags.Back,
frontFace = VkFrontFace.CounterClockwise,
depthBiasEnable = VkBool32.True,
lineWidth = 1.0f,