Sign in to follow this  
menohack

Translation within geometry shader

Recommended Posts

menohack    216

Quick question: I am trying to translate vertices by a vector from a constant buffer in my geometry shader and something is not working out. My vertex shader multiplies the vertices by the world, view, and projection matrix. I pass in my vector (1,1,1) and set the w-component to 1 as well to allow translation. Then I multiply the vector by the view and the projection matrices and add it to the position of the vertex. I am expecting this to give me a new position further from the screen but it makes it closer instead. It also causes lines that I expect to be parallel to come closer together towards the new point. Please look at the attached image for an example. The purpose of this is to generate shadow volumes with an orthographic light source. I have even tried doing the projection matrix multiply in the geometry shader after calculating the position but I get the same result. Help would really be appreciated! Thanks.

Share this post


Link to post
Share on other sites
eppo    4877

You have to offset back-facing faces before transforming them into view space, so you'll need to do the both the view and projection multiplications in the GS.

 

Make sure the vertex shader only transforms vertices into world space: out.pos = mul(in.pos, matrixW).xyz;

 

Your geometry shader will have to do something similar to: out.pos = mul(float4(in.pos.xyz + lightExtrudeVector,1.0), matrixVP);

Edited by eppo

Share this post


Link to post
Share on other sites
menohack    216

Thanks! Something worked.

 

I moved the view multiplication into the GS and added the vector's three components like you said. I think I might have been adding the w-component to the original position.

 

But I still don't understand why I have to do the view matrix multiplication in the GS.

 

Thanks so much for the help, I was completely stuck without it.

Share this post


Link to post
Share on other sites
eppo    4877

Shadow volume are extruded in the direction of the light vector in world space. Since this happens in the geometry shader, you'll have to do the view/projection transformation afterwards in the GS as well. The extruded volumes are transformed the same way as any other object in the scene.

 

Note that clipping and depth division takes place after the GS stage. The w-component has no meaning when passing data from the VS to GS. SV_Position is a required output of the geometry shader, not the vertex shader (when a GS is active).

Edited by eppo

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this