jmfairlie

04-24-2010, 01:28 AM

I have the following projection matrix which doesn't work (doesn't show anything on the screen):

-2n/w 0 0 0

0 -2n/h 0 0

0 0 f+n/f-n 2fn/f-n

0 0 1 0

On the other hand this other projection matrix does work correctly:

2n/w 0 0 0

0 2n/h 0 0

0 0 f+n/n-f 2fn/n-f

0 0 -1 0

Note:

*n=near plane, f=far plane, w=proj plane width, h=proj plane height

*the only difference between the 2 is the sign of the elements.

My question is:

Why the second works but the first doesn't if the multiplication of any of the 2 by any vector yields the same results after perspective division?

I'm thinking that it might have something to do with how GL clips geometry in clip space. Like, is it a requirement for the w clip coordinates to be always positive?

Any ideas?

zeoverlord

04-24-2010, 05:32 AM

The second one is the one use by openGL so it's only natural that it works, the first one however seems to make the x and y go form -1 to 0 instead of 0 to 1.

Now the way cliping works in openGL is to only use whats between 0 and 1 and discard the rest so the reason it doesn't work might depend on how you are testing that it works.

may i suggest a skybox or something similar that covers everything around the "camera", that way you will instantly see the effects of what your doing.

jmfairlie

04-24-2010, 03:16 PM

Based on what I've read and the simple experiments I've been carrying out these last few days, it seems to me that the viewable range in Normalized Device Coordinates (NDC), this is, after perspective division is [-1,1] in all three dimensions. With left, bottom and front being -1, and 1 the rest.

This is easy to prove by drawing elements in GL without using any transformations. The only visible geometry is the one that is contained within these ranges, everything else won't show up.

So going back to my question.

if we take some point in eye space, lets say conveniently:

P = (w/2, h/2, -n, 1.0)

We know by definition that this point should end up, after projection and perspective divide (NDC) as (1,1,-1)

Now, lets call the first matrix M1 (which doesn't work) and the second M2 (which does work), and lets multiply them by the point P manually and see what happens:

M1*P = [-n, -n, -n*(f+n)/(f-n) + 2fn/(f-n), -n]

M2*P = [n, n, -n*(f+n)/(n-f) + 2fn/(n-f), n]

Now we do perspective divide and we have:

M1*P/-n = [1,1,-1]

M2*P/n = [1,1,-1]

The results are the same. And this will happen for any vector.

So my question again is why M2 works but M1 doesn't?

I read that clipping is carried out in Clip coordinates, this is, before perspective division. Something is happening in that stage that is clipping the results of M1*P but not M2*P.

What is it? What is the exact logic behind the clipping in Clip space?

According to a computer graphics book I have (Watt)

The clipping operations must be performed on the homogeneous coordinates before the perspective divide, and translating the definition of the viewing frustum into homogeneous coordinates gives us the clipping limits

-w <= x <= w

-w <= y <= w

0 <= z <= w

I guess in GL context the range for z would be also:

-w <= z <= w

and I assume that that w would be the w coordinate of each individual vertex(?)

Anyone know what is the exact clipping algorithm?

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.