Long time developer, first time 3D Dev and Unity user…
Let’s say you have a bunch of primitives in a scene that are being lit by a directional light source. Now, imagine that you have a plane in the scene as well, such that shadows of the primitives are being projected onto the plane. How might one go about trying to detect where those shadows are relative to the plane?
The eventual goal is to take the 2D geometry of the shadows as a basic shape, and then extrude them into 3D objects. The important part here is that the 2D geometry needs to be in the shape of whatever shadows are being projected onto the plane.
Thanks in advance!
O = Shape that casts shadow
L = light
-
If you had a “point” light:
Find the vectors from each vertex of the O to L. These are now “rays”. Find the intersection between these “rays” and the plane on which the shadows are projected using the built-in ray-casting functions in Unity.
-
Directional light:
A directional light does not have a specific location, but it does have direction. Hence, you already have a ray, but the “location” is not specified. Add this ray to each vertex on O to get a ray that is cast from L to that specific vertex of O. Again, “ray-cast” each ray to find its intersection point on the plane on which the shadow is cast.