# Horde3D

Next-Generation Graphics Engine
 It is currently 31.03.2023, 04:42

 All times are UTC + 1 hour

 Page 1 of 1 [ 1 post ]
 Print view Previous topic | Next topic
Author Message
 Posted: 27.04.2012, 20:01

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;
}
}

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

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 1 post ]

 All times are UTC + 1 hour

#### Who is online

Users browsing this forum: Bing [Bot] and 7 guests

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

Search for:
 Jump to:  Select a forum ------------------ Horde3D Usage    General Discussion    Support    Bug Reports    Asset Creation    Showcase    Advanced Rendering Techniques    Tools    Free Discussion Horde3D Development    Developer Discussion