View Full Version : issue of clipping plane with coplanar quad

06-16-2008, 12:27 PM
I had a simple box rendered with texture quad. I want to add a user-defined clipping plane along X axis, and part of the box will be clipped. The equation for the plane will be (1, 0, 0, value).
The issue is when I set the value as min_x or max_x of the box, which means the clipping plane is coplanar with one side of the box, then this side of the box will have some artifacts. Say, if I rotate the camera, part of the quad is visible but the rest is invisible, and it flickers.

Is there a way to always hide the entire quad of the box when it is coplanar with clipping plane without flickering?


06-17-2008, 03:51 PM
This is a common problem when calculating with finite precision floating point numbers. The easiest way to force coplanar polygons to be kept or rejected is to offset your clipping plane by a small fraction by multiplying "value" by (1 +/- epsilon) for some small value of epsilon. Try with an epsilon around 1e-6.

06-17-2008, 09:19 PM
This can have to do with where the clipping is occurring in the HW. If it is post projection, then you can definitely end up with more issues than if it were to happen in eye space as the GL spec states.

One way to work around this is to output a varying scalar from your vertex shader (if you are using vertex shaders) that is the distance from that vertex to the clipping plane in eye space. In the fragment shader, if the distance is less than zero, kill the fragment.