Hello guys,
i am implementing deferred lighting with light-volumes and try to mark only pixels within the light-range using the stencil-test.
I failed so far
Here is my code:
// Framebuffer with a color + depth/stencil attachment. Color + Depth will be loaded. Stencil will be cleared
loadRenderpass->begin(cmd, frameResources[frameDataIndex].framebuffer);
{
// Bind descriptor-set referencing the G-Buffer
frameResources[frameDataIndex].gBuffer->bind(cmd, pointLightShader.getPipelineLayout());
// Bind Camera-Descriptor-Set
camera->bind(cmd, pointLightShader.getPipelineLayout());
// Bind Index- & Vertex-Buffer
sphereMesh.bind(cmd);
for (const auto& pointLight : SceneGraph::getVisiblePointLights())
{
// Bind pipeline which writes into the stencil-buffer (THIS DONT WORK)
lightStencilShader.bind(cmd);
// Update model-matrix through push-constant
const Mat4f& worldMat = pointLight->getWorldMatrix();
vkCmdPushConstants(cmd, lightStencilShader.getPipelineLayout()->get(), VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(Mat4f), &worldMat);
// Draw sphere scaled with range of the light. Only Updates the Stencil-Buffer. FS is disabled. Depth-Test is enabled.
sphereMesh.draw(cmd);
// Bind point-light shader. Uses the stencil buffer. If value in it is NOT 0 it will execute the FS. (THIS WORKS FINE)
pointLightShader.bind(cmd);
// Bind Light-Descriptor-Set
pointLight->bind(cmd, pointLightShader.getPipelineLayout());
// Draw sphere scaled with range of the light
sphereMesh.draw(cmd);
}
So just the writes from the lightStencilShader with drawing the sphere does not occur. Clearing the Stencil buffer with arbritary-values works fine. I have no plan what kind of information i am missing.
I have found sth interesting in the spec:
The depth bounds test, stencil test, depth test, and occlusion query sample counting are performed before fragment shading if and only if early fragment tests are enabled by the fragment shader (see Early Fragment Tests).
How do i enable early fragment tests?
Thanks in Advance