Computing Line Of Sight in a Shader


I am looking at approaches to use a material to color a surface based on whether that location as direct line of sight (no object obstruction) to a given position in model space. I am intending to use this to show on a terrain mesh where line of sight with an antenna is available.

I want to add the color computed for the line of sight (ex: red if not LOS, green if there is) as a semi-transparent color on top of what the Common/MatDefs/Light/Lighting.j3md is providing (shading, etc). I have implemented a similar idea for adding a color based on the angle between the mesh normal and the gravity vector and it works well: I have copied the Lighting.j3md material vertex and fragment shader and my function adds a color on top of what the original fragment shader computes.

From what I could gather through searching the Web, it seems that what I want to do is similar to what is done to compute cast shadows (in my application, the antenna would be considered the light source). I do not know how to get started on this, does anyone has suggestions ?


If constraining the implementation to only 2 dimensions is acceptable, the following link (to one of Amit Patel’s pages) provides a very approachable article which could serve as a conceptual starting point (along with some example implementations):