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