0
$\begingroup$

I have a camera I have placed zunits away from a billboarded rect. My goal is to discard all other geometry that is closer to the camera/in front of this rect.

With perspective projection I have always set the near plane to 0.1 and called it a day however here I tried to set it to z thinking it would clip anything in front of this rect.

No such luck. This ended up clipping that rect and seemingly even more. Z-1 also did not have the desired result.

This leads me to think the near clipping plane might not be in the same coordinate space as the world? If not what space is it in?

$\endgroup$
1
$\begingroup$

The perspective projection matrix transforms from camera space to clip space. The near-plane value is the position of the near plane in camera space. So in case that your world space to camera space transformation does not use any scaling, only rotations and translations, then if you place the camera $z$ units away from the billboard surface and look directly onto it, a near plane value of $z$ will cause the billboard plane to lie on the near plane. Due to rounding errors, it might get clipped away, so your idea of setting it to $z-offset$ should solve the problem.

Why it doesn't work is hard to tell without any code. Maybe your implementation of the perspective matrix is wrong. Maybe you have a hidden scaling when you transform between world and camera space. To debug this you can try to multiply $z$ with values between 0 and 1 until you get the desired result. The resulting factor might be a clue. For example if you get $0.5$ we know that there is either a 2 missing or too much in your transformation matrices. Also, make sure that your far plane value is larger than your near plane value (even though I think from your description that this isn't the problem - but who knows)

In case you are using OpenGL, here is a link to how the perspective projection matrix has to look like. Maybe you have to transpose the matrix. That depends on your vector layout - column vectors or row vectors.

Here is a link to an answer of mine to another question. It has a Python script at the end that you can use to visualize how the different values affect the view frustum in the different spaces. Some pictures are also included in the answer. Maybe that is already enough to help you out.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.