PDA

View Full Version : RTT using FBO shows scene as if light was enabled



jmfairlie
04-05-2010, 04:35 PM
I'm rendering a scene to a texture using FBOs and then rendering a textured cube to the default framebuffer using the created texture.

I'm not using light at all, but the scene seems to be lighted. The farther I get from the cube the darker it gets.

If I use a normal texture everything is ok.
I'm also blitting the texture directly to the screen (glBlitFramebuffer), and the texture looks ok (no light)

Using OpenGL version 3.2.0 NVIDIA 195.36.15 on Ubuntu karmic

Any ideas why could this be happening?



http://www.cs.uta.fi/~jf88209/docs/fbo.png
Download code from here (http://www.cs.uta.fi/~jf88209/docs/tkgraf_h10_2.cpp)

Kelvin
04-05-2010, 08:00 PM
The farther I get from the cube the darker it gets.
...
Any ideas why could this be happening?


Perhaps you have fog enabled?

jmfairlie
04-06-2010, 07:06 AM
Nope, no fog, no light.

dorbie
04-06-2010, 10:09 AM
Nope, no fog, no light.

I think you are mistaken.

jmfairlie
04-06-2010, 12:11 PM
I might be but as far as I can tell there is no light or fog enabled, please check the code if you have the time, its there in my original post...

Kelvin
04-07-2010, 06:11 PM
Nope, no fog, no light.

OK, I've looked at the code, and I see another possibility.

You call glGenerateMipmap() after the texture is defined (with a NULL data pointer), and before the texture image has been drawn with the FBO. Therefore, the mipmaps will be generated based on whatever data happens be be in the reserved texture memory. Based on the appearance, I would say that's black (at least in that test run). Your rendering redefines the top layer, but not the lower level mips.

As the cube recedes into the distance the texture sampling starts to blend in the black mip layers.

If my guess is right, then the solution is to call glGenerateMipmap() after any time that you update the base texture.

You could also test this by choosing a texture minification mode that does not involve mipmap sampling.

jmfairlie
04-08-2010, 03:27 PM
Kelvin, you are right indeed, recreating the mipmaps solved the problem.

Thank you very much!

http://www.cs.uta.fi/~jf88209/docs/fbo1.png

Kelvin
04-08-2010, 09:43 PM
Whoo hoo!

That was a good one. :)

ZbuffeR
04-09-2010, 12:59 AM
Impressive guess Kelvin, I really had no clue about this !

Fugitive
04-09-2010, 01:16 AM
wow, that was smart!