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:
@@ -138,9 +138,6 @@ void main()
|
|||||||
float dist = length(toLight);
|
float dist = length(toLight);
|
||||||
vec3 L = toLight / max(dist, 0.001);
|
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);
|
float attenuation = pow(clamp(1.0 - dist / max(lightRange, 0.001), 0.0, 1.0), 2.0);
|
||||||
vec3 radiance = lightColor * lightIntensity * attenuation;
|
vec3 radiance = lightColor * lightIntensity * attenuation;
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -102,7 +102,7 @@ internal sealed unsafe class VulkanPipeline : IDisposable
|
|||||||
depthClampEnable = VkBool32.False,
|
depthClampEnable = VkBool32.False,
|
||||||
rasterizerDiscardEnable = VkBool32.False,
|
rasterizerDiscardEnable = VkBool32.False,
|
||||||
polygonMode = VkPolygonMode.Fill,
|
polygonMode = VkPolygonMode.Fill,
|
||||||
cullMode = VkCullModeFlags.None,
|
cullMode = VkCullModeFlags.Back,
|
||||||
frontFace = VkFrontFace.CounterClockwise,
|
frontFace = VkFrontFace.CounterClockwise,
|
||||||
depthBiasEnable = VkBool32.False,
|
depthBiasEnable = VkBool32.False,
|
||||||
lineWidth = 1.0f,
|
lineWidth = 1.0f,
|
||||||
|
|||||||
@@ -275,7 +275,7 @@ internal sealed unsafe class VulkanShadowMap : IDisposable
|
|||||||
depthClampEnable = VkBool32.False,
|
depthClampEnable = VkBool32.False,
|
||||||
rasterizerDiscardEnable = VkBool32.False,
|
rasterizerDiscardEnable = VkBool32.False,
|
||||||
polygonMode = VkPolygonMode.Fill,
|
polygonMode = VkPolygonMode.Fill,
|
||||||
cullMode = VkCullModeFlags.None,
|
cullMode = VkCullModeFlags.Back,
|
||||||
frontFace = VkFrontFace.CounterClockwise,
|
frontFace = VkFrontFace.CounterClockwise,
|
||||||
depthBiasEnable = VkBool32.True,
|
depthBiasEnable = VkBool32.True,
|
||||||
lineWidth = 1.0f,
|
lineWidth = 1.0f,
|
||||||
|
|||||||
Reference in New Issue
Block a user