Handling light bounding volume

by Greffin28   Last Updated May 29, 2016 08:05 AM

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 500~fps. The problem is whenever i enter those bounding boxes, lighting for fragments inside the box is now gone. Like so:

Problem screenshot

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:

for (int i = 0; i < sizeof(lights) / sizeof(Light); i++) {
    glStencilFunc(GL_ALWAYS, 1, 0xFF);
    glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);

    // 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

    glStencilFunc(GL_EQUAL, 1, 0xFF);

    // Setting up uniforms for light's properties
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

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?

Tags : opengl lighting

Answers 1

Okay, after some hours of research, i finally ran into this site which work exactly how i wanted.

The techique works as follows:

  1. Render the objects as usual into the G buffer so that the depth buffer will be properly populated.
  2. Disable writing into the depth buffer. From now on we want it to be read-only
  3. Disable back face culling. We want the rasterizer to process all polygons of the sphere.
  4. Set the stencil test to always succeed. What we really care about is the stencil operation.
  5. Configure the stencil operation for the back facing polygons to increment the value in the stencil buffer when the depth test fails but to keep it unchanged when either depth test or stencil test succeed.
  6. Configure the stencil operation for the front facing polygons to decrement the value in the stencil buffer when the depth test fails but to keep it unchanged when either depth test or stencil test succeed.
  7. Render the light sphere.

Though, this actually lower my fps a little somehow.. I got 100-200~fps for 125 lights now and 300~fps for 25 lights..

May 30, 2016 05:41 AM

Related Questions

Incorrect Normal Matrix

Updated April 19, 2015 20:05 PM

GL_SPOT_CUTOFF not working properly

Updated April 22, 2015 04:05 AM

How to generate a multiplier map for radiosity

Updated August 27, 2016 08:05 AM

Negating directional light's direction

Updated January 27, 2017 14:05 PM