I want to draw a line where an object intersects a plane, in the fragment shader.
I pass the plane equation to the fragment shader (a, b, c, d) and want to draw in red the intersection between my object and this uniform plane.
I want the width of the intersection to be always the same no matter how much we zoom in.
Right now I get the distance from my object to the plane in the fragment shader as:
// uPlane: vec4 where values are a.b.c.d (plane equation)
// vPos: wodlPosition of the fragment
vec4 prod = uPlane*vPos;
float distance = (prod.r + prod.g + prod.g + prod.a) / length(uPlane.xyz);
if(abs(distance) < 1.) {
gl_FragColor = vec4(1., 0., 0., .5);
} else {
gl_FragColor = vec4(0., 1., 0., .5);
}
Problem with this approach is that as I zoom in/out, the "width" of the intersection changes (see screenshots below).
Which would be the best approach to draw a "2px width" line at the intersection between my object and the plane uniform?