0
$\begingroup$

I don't understand something about the near clipping plane. It's there to avoid the division by $0$ but when we compute the pixel coordinates, we just need to multiply by the clipping plane to clip the object?

For example in this code, from https://www.scratchapixel.com/lessons/3d-basic-rendering/3d-viewing-pinhole-camera/implementing-virtual-pinhole-camera

pScreen.x = pCamera.x / -pCamera.z * near; 
pScreen.y = pCamera.y / -pCamera.z * near; 

Vec2f pNDC; 
pNDC.x = (pScreen.x + r) / (2 * r); 
pNDC.y = (pScreen.y + t) / (2 * t); 
pRaster.x = (int)(pNDC.x * imageWidth); 
pRaster.y = (int)((1 - pNDC.y) * imageHeight); 

bool visible = true; 
if (pScreen.x < l || pScreen.x > r || pScreen.y < b || pScreen.y > t) 
    visible = false; 

return visible; 

When do they actually discard points that have a z component smaller than the near clipping plane? They just discard those which have a x and y coordinate not visible to the screen.

$\endgroup$
  • $\begingroup$ Admittedly the meanings of the variable names aren't entirely clear to me, (eg does camera refer to the camera or a vertex transformed into camera space...I'll assume the latter) but that does not look like the correct thing to do. You can't do the division by Z before doing clipping. You must clip each line/primitive first before the division. $\endgroup$ – Simon F Jan 2 at 11:41
0
$\begingroup$

When do they actually discard points that have a z component smaller than the near clipping plane?

For actual rendering hardware, they don't. Clipping happens in clip space, before the NDC transform. "Points" outside of the clipping volume are never seen by the rasterizer (in theory, at least. In practice, guard-band clipping is often used to minimize the need for clipping against the sizes).

The renderer presented at that site doesn't appear to do clipping at all. It has an approximation of what would be clipped, but it doesn't actually do the clipping.

| 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.