• Create Account

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1menohack  Members   -  Reputation: 216

Like
0Likes
Like

Posted 23 April 2013 - 12:48 PM

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.

### #2eppo  Crossbones+   -  Reputation: 4494

Like
1Likes
Like

Posted 24 April 2013 - 06:45 AM

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, 24 April 2013 - 06:48 AM.

### #3menohack  Members   -  Reputation: 216

Like
0Likes
Like

Posted 24 April 2013 - 01:08 PM

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.

### #4eppo  Crossbones+   -  Reputation: 4494

Like
1Likes
Like

Posted 24 April 2013 - 01:54 PM

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, 24 April 2013 - 02:03 PM.

### #5menohack  Members   -  Reputation: 216

Like
0Likes
Like

Posted 24 April 2013 - 02:36 PM

Thanks!

### #6menohack  Members   -  Reputation: 216

Like
0Likes
Like

Posted 25 April 2013 - 01:03 PM

Check out my results:

#### Attached Thumbnails

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS