// Calculate window depth coordinate which would be the value written to the depth buffer [0,1]
s_Position.z= s_Position.z * 0.5f + 0.5f;

This should give me s_Position's x and y in a range [-1,1] and z in a range [0,1].
I hope that is correct so far.

Now I want to achieve the same thing but with a ModelViewProjectionMatrix which contains
an orthographic projection matrix.

But in this case w is always 1 so there is no "perpsective-divide".

So which step is performed between vertex and fragment shader to
get the NDC and how can I achieve the same result on CPU side?

Help is really appreciated!

Alfonse Reinheart

06-01-2012, 02:53 PM

It is the exact same math. Dividing by 1 is legal math; it simply does nothing.

RealtimeSlave

06-02-2012, 07:10 AM

I just noticed that I did a mistake in my high level code when switching to orthographic projection.
The result was that my debug output showed me not normalized values in s_Position and I started
to debug this "perspective-divide" stuff with w = 1 and so on. Sorry as you said it works fine.