tags:

views:

269

answers:

0

My algorithm is this:

Render the scene to a FBO with shadow mapping from multiple locations Render the scene to the screen with shadow mapping ...black magic that I still have to imlement... Combine the samples from step 1 with the image from step 2

I'm trying to debug steps 1 and 2 and am coming across STRANGE behavior. My algorithm for each shadow mapped pass is: render the scene to a FBO connected to a depth array texture from the POV of each light render the scene from the viewpoint and use vertex/frag shaders to compare the depths

When I run my algorithm this way:

render from point to FBO render from point to screen glutSwapBuffers()

The normal vectors in the screen pass appear to be incorrect (inverted possibly). I'm pretty sure that's the issue because my diffuse lighting calculation is incorrect, but the material colors are correct, and the shadows appear in the correct places. So, it seems like the only thing that could be the culprit is the normals.

However if I do

render from point to FBO render from point to Screen glutSwapBuffers() //wrong here render from point to Screen glutSwapBuffers()

the second pass is correct. I assume there's a problem with my framebuffer calls. Can anyone see what the problem is from the log below? Its from a bugle trace grepped for 'buffer' with a few edits to make it a little more clear.

Thanks!

[INFO] trace.call: glGenFramebuffersEXT(1, 0xdfeb90 -> { 1 })
[INFO] trace.call: glGenFramebuffersEXT(1, 0xdfebac -> { 2 })
[INFO] trace.call: glBindFramebufferEXT(GL_FRAMEBUFFER, 1)
[INFO] trace.call: glDrawBuffer(GL_NONE)
[INFO] trace.call: glReadBuffer(GL_NONE)
[INFO] trace.call: glBindFramebufferEXT(GL_FRAMEBUFFER, 0)
//start render to FBO
[INFO] trace.call: glBindFramebufferEXT(GL_FRAMEBUFFER, 2)
[INFO] trace.call: glReadBuffer(GL_NONE)
[INFO] trace.call: glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 2, 0)
[INFO] trace.call: glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 3, 0)
[INFO] trace.call: glDrawBuffer(GL_COLOR_ATTACHMENT0)
//bind to the FBO attached to a depth tex array for shadows
[INFO] trace.call: glBindFramebufferEXT(GL_FRAMEBUFFER, 1)
[INFO] trace.call: glFramebufferTextureLayerARB(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, 1, 0, 0)
[INFO] trace.call: glClear(GL_DEPTH_BUFFER_BIT)
//draw geometry
//bind to the FBO I want the shadow mapped image rendered to
[INFO] trace.call: glBindFramebufferEXT(GL_FRAMEBUFFER, 2)
[INFO] trace.call: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
//draw geometry

//draw to screen pass
//again shadow mapping FBO
[INFO] trace.call: glBindFramebufferEXT(GL_FRAMEBUFFER, 1)
[INFO] trace.call: glFramebufferTextureLayerARB(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, 1, 0, 0)
[INFO] trace.call: glClear(GL_DEPTH_BUFFER_BIT)
//draw geometry
//bind to the screen
[INFO] trace.call: glBindFramebufferEXT(GL_FRAMEBUFFER, 0)
[INFO] trace.call: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
//finished, swap buffers
[INFO] trace.call: glXSwapBuffers(0xd5fc10, 0x05800002)
//INCORRECT OUTPUT

//second try at render to screen:
[INFO] trace.call: glBindFramebufferEXT(GL_FRAMEBUFFER, 1)
[INFO] trace.call: glFramebufferTextureLayerARB(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, 1, 0, 0)
[INFO] trace.call: glClear(GL_DEPTH_BUFFER_BIT)
//draw geometry
[INFO] trace.call: glBindFramebufferEXT(GL_FRAMEBUFFER, 0)
[INFO] trace.call: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
draw geometry
[INFO] trace.call: glXSwapBuffers(0xd5fc10, 0x05800002)
//correct output