• Create Account

### #ActualMatthew Meeks

Posted 08 January 2013 - 03:50 PM

Yeah sorry wrote that with a migraine and tried to do it as fast as possible, it didn't work.  I've changed some things around and got closer to what I wanted, getting values in-between 0 and 1, except now the farther objects are 0 and the closer are 1.  My understanding is that farther objects return depths closer to 1.

In the vs:

float4 worldPosition = mul(Output.position, World);
float4 viewPosition = mul(worldPosition, View);
Output.position = mul(viewPosition, Projection);

In the ps:

return input.position.z / input.position.w;

Really simple yet I still can't figure out why.

And just in case the problem lies in the matrices:

View:

View = Matrix.LookAtLH(Position, cameraFinalTarget, up);

Projection:

Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, (float)Width / (float)Height, 0.01f, 800f);

Thanks for the help and apologies for the vagueness of the original post.

### #1Matthew Meeks

Posted 08 January 2013 - 03:45 PM

Yeah sorry wrote that with a migraine and tried to do it as fast as possible, it didn't work.  I've changed some things around and got closer to what I wanted, getting values in-between 0 and 1, except now the farther objects are 0 and the closer are 1.  My understanding is that farther objects return depths closer to 1.

In the vs:

float4 worldPosition = mul(Output.position, World);
float4 viewPosition = mul(worldPosition, View);
Output.position = mul(viewPosition, Projection);

In the ps:

return input.position.z / input.position.w;

Really simple yet I still can't figure out why.

And just in case the problem lies in the matrices:

View:

View = Matrix.LookAtLH(Position, cameraFinalTarget, up);

Projection:

Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, (float)Width / (float)Height, 0.01f, 800f);

Thanks for the help apologies for the vagueness of the original post.

PARTNERS