fix: move light data from UBO to push constants — fixes std140 layout issue

Root cause: GLSL std140 layout adds padding after mat4 for vec4 fields,
causing light data to be read at wrong offsets → NaN/artifacts.

Fix:
- UBO back to 64 bytes (mat4 vp only)
- Light data (pos + color, 32 bytes) sent via push constants at offset 64
- Two push constant ranges: Vertex (0-64, model) + Fragment (64-96, light)
- Both vertex and fragment shaders read from same push_constant block
- PBR shader fully restored with Cook-Torrance BRDF
- Dynamic point light follows physics ball
This commit is contained in:
emil28092005
2026-06-18 19:53:45 +03:00
parent ad8a14a4f7
commit 1dde764342
7 changed files with 110 additions and 24 deletions
+11 -4
View File
@@ -150,12 +150,19 @@ internal sealed unsafe class VulkanPipeline : IDisposable
pDynamicStates = dynamicStates,
};
var pushConstantRange = new VkPushConstantRange
var pushConstantRanges = stackalloc VkPushConstantRange[2];
pushConstantRanges[0] = new VkPushConstantRange
{
stageFlags = VkShaderStageFlags.Vertex | VkShaderStageFlags.Fragment,
stageFlags = VkShaderStageFlags.Vertex,
offset = 0,
size = 64,
};
pushConstantRanges[1] = new VkPushConstantRange
{
stageFlags = VkShaderStageFlags.Fragment,
offset = 64,
size = 32,
};
var descLayout = DescriptorSetLayout;
var layoutInfo = new VkPipelineLayoutCreateInfo
@@ -163,8 +170,8 @@ internal sealed unsafe class VulkanPipeline : IDisposable
sType = VkStructureType.PipelineLayoutCreateInfo,
setLayoutCount = 1,
pSetLayouts = &descLayout,
pushConstantRangeCount = 1,
pPushConstantRanges = (nint)(&pushConstantRange),
pushConstantRangeCount = 2,
pPushConstantRanges = (nint)pushConstantRanges,
};
fixed (VkPipelineLayout* layoutPtr = &PipelineLayout)