Horde3D

Next-Generation Graphics Engine
It is currently 19.03.2024, 06:00

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: 27.04.2012, 20:01 
Offline

Joined: 27.04.2012, 19:50
Posts: 1
Hello everyone,

I am asking here for help as I have been working on a very simple way to reconstruct the World Position from the Depth buffer inside the lighting pass of the deferred renderer, and I can't seem to find what is wrong.

Here is the code, this is the main function from the FS_LIGHTING shader to which I have simply added uniform mat4 viewProjMatInv; to get the Inverse View Projection Matrix.
I have also bound the depth buffer in the pipeline through <BindBuffer sampler="depthBuf" sourceRT="GBUFFER" bufIndex="32" />.

Code:
void main( void )
{
   vec2 fragCoord = (vpos.xy / vpos.w) * 0.5 + 0.5;
   
   if( getMatID( fragCoord ) == 1.0 )   // Standard phong material
   {
      // World Position taken from the GBuffer for comparison
      vec3 posR = getPos( fragCoord ) + viewerPos;

      float z = texture2D( depthBuf, fragCoord ).r;
      
      // Get x/w and y/w from the viewport position
      float x = fragCoord.x * 2 - 1;
      float y = fragCoord.y * 2 - 1;
      vec4 vProjectedPos = vec4(x, y, z, 1.0f);
      
      // Transform by the inverse projection matrix
      vec4 vPositionVS = mul(vProjectedPos, viewProjMatInv); 

      // Divide by w to get the view-space position and visualize the World Position
      gl_FragColor.rgb = vPositionVS.xyz / vPositionVS.w;
   }
   else discard;
}


So I build the position of the pixel in Projected Space [-1;1]*[-1;1]*[-1;1] and through the matrix multiplication, I should go back to the World Position.

Even though every step seems to do what I expect, the Transform does not give me the correct World Position, any comments on something I do wrong or a false assumption is welcome!

Thank you


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group