I want to utilize shaders to not only discard fragments if they are on one side of a predefined plane but also render a contour along the intersection.
My fragment shader currently does something along the lines of:
float dot = dot(world_coordinate, normalize(clipping_normal.xyz)) - clipping_normal.w;
if (dot > 0.0f)
discard;
this works but without the desired contour. I tried comparing the dot product against values close to 0.0 but this results in a contour with varying width depending on view etc...
This is what I am trying to achieve. Notice that the white contour/edge of where the plane intersects the sphere is of consistent width:
So below is what the result I currently see:
With the fragment shader:
in vec4 color;
in vec3 world_position;
out vec4 frag_color;
void main()
{
float dist = (dot(clipping_plane.xyz, world_position) - clipping_plane.w) /
dot(clipping_plane.xyz, clipping_plane.xyz);
if(dist >= 0.0f && dist < 0.05f)
frag_color = vec4(0.0f, 0.0f, 0.0f, 1.0f);
else if(dist < 0.0f)
discard;
else
frag_color = ComputePhong(color);
}