PDA

View Full Version : FBO, post processing effects and gluUnproject



potatosoftware
10-18-2010, 03:29 AM
Hi
I'm adding a glow effect to my scene by rendering to an FBO then blend it to the backbuffer.
Before the use of FBO, I have a code that correctly translates the 2D screen coordinates to 3D objects to achieve selection.
With the use of an FBO, gluUnproject is giving other unusable results.
What could be the reason ?

Alfonse Reinheart
10-18-2010, 04:08 AM
With the use of an FBO, gluUnproject is giving other unusable results.

gluUnproject, being a part of GLU, was written long before the FBO extensions came into existence. It relies in part on state that is different when an FBO is bound.

What you will need to do instead is use the viewport and depth values you have set, as well as your projection matrix to essentially reverse-transform values the way gluUnproject does. Basically, you need to write a version of gluUnproject.

potatosoftware
10-18-2010, 05:06 AM
Disaster to me !

ZbuffeR
10-18-2010, 05:24 AM
Come on :
http://www.opengl.org/wiki/GluProject_and_gluUnProject_code

potatosoftware
10-18-2010, 05:43 AM
@ZbuffeR Thank you very much for the link !

@Alfonse Reinheart,
The previous link posted by BuffeR seems to be the actual implementation (GLU version) of gluUnproject,
I can't see what would have made the difference when FBO was used.
In concrete terms, I am only seeing purely mathematical code,
there is no "state that is different when an FBO is bound" in it..

potatosoftware
10-18-2010, 06:56 AM
With more examination, I discover that gluUnproject is picking the farthest object !

Before Adding FBO => gluUnproject returns nearest object
After adding FBO => gluUnproject returns the farthest object

Where are those smileys ?

skynet
10-18-2010, 07:10 AM
Maybe your FBO has no depthbuffer attached...?

potatosoftware
10-18-2010, 07:19 AM
So ?

potatosoftware
10-18-2010, 07:26 AM
I've made a look at the source code and it seems there is a depth buffer attached to FBO :


// initialize depth renderbuffer
//
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_rb);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, w, h);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
GL_RENDERBUFFER_EXT, depth_rb);

potatosoftware
10-18-2010, 03:57 PM
I've tested with the gluUnproject version of which source code was posted by ZbuffeR. It works in abscence of FBO but again fails when I create an FBO and blend it to the scene.

However I've discovered that the same weird behavior of gluUnproject that was caused by the FBO is the same when I do'nt use FBO but also disable depth testing, ie do not call :

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);


So the use of FBO is sort of disabling depth testing.
Adding the above calls to the FBO rendering code does not solve the issue.