So, i managed to do deferred shading like yesterday or 2 days ago. I got pretty big impact which causes my fps to drop from 1000fps to around 300~fps for 25 lights (after some optimization, i don't know if this is even normal lol).
Then i read about this bounding volume, so then i implemented this with stencil cubes and it is capable of bumping my fps to 400~fps. The problem is whenever i enter those bounding boxes, lighting for fragments inside the box is now gone. Like so:
I resize the bounding box to half of the size for testing. And i already disable GL_CULL_FACE
when rendering those bounding volume cubes. Here is how i handle the rendering:
glEnable(GL_STENCIL_TEST);
glDisable(GL_CULL_FACE);
for (int i = 0; i < sizeof(lights) / sizeof(Light); i++) {
glStencilFunc(GL_ALWAYS, 1, 0xFF);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glStencilMask(0xFF);
glClear(GL_STENCIL_BUFFER_BIT);
// Bind and unbind vao & shaders here for stencil
// Setting up matrices and uniforms for bounding volume cube
glDrawArrays(GL_TRIANGLES, 0, 36);
// Bind and unbind vao & shaders here for lighting
glStencilMask(0x00);
glStencilFunc(GL_EQUAL, 1, 0xFF);
// Setting up uniforms for light's properties
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
glEnable(GL_CULL_FACE);
glDisable(GL_STENCIL_TEST);
Though i don't think the code i supply above is where the problem lies. I think it is because the stencil only draws where the cubes is (the cubes walls) and not the volume inside of it.
Is there a way so that the stencil draws the volume too? Or perhaps a trick so that the lighting is still occur when i'm inside the bounding volumes?
Edit: I thought of checking cam position if it is inside those cubes, if yes then don't use bounding volume for that particular light. But i don't think that's the best solution here..