LP23.com
Account
Projects
Support
Store
Home
Tutorial #2 - Shadows - Introduction
These tutorials try to solve basic problems using easy to understand solutions rather than optimized complex math. Basically, this is a simple way of getting to the answer, not an elegant collection of mathematical skill.
Finding each point of the shadow
Projected shadow point

For every point of the object we need to shadow, we'll use the x, y and z coordinate value. Using a side view as in the diagram - the top value is the light source, middle is the object point and the ground is the bottom where the shadow will be projected. By using the proportion between the light source and polygon point (the shaded region), we can then calculate where the shadow point resides on the plane.

The proportion for this example is 1.0 / 1.6 = 0.625. By using this value we can find where the shadow will occur for both the shadow.x, shadow.y values. We are assuming the diagram shows the x and z coordinates, the position of the light is at (0.0, 5.0) and the object point is at (1.0, 3.4). We can then calculate the exact shadow point by extending the shaded triangle (what we know) to the plane.

To project the shadow, we will use the calculation 5.0 x 0.625 = 3.125 which is multiplying the total height by the triangle proportion to give the Shadow.x value. Algebraically, we are basically doing (1.6 / 1.0) = (5.0 / x) -> (1.0 * 5.0) = 1.6x -> x = 5.0 / 1.6 = 3.125. By extending this into 3D, some simple and pretty good shadows can be produced.

Rendering example
Rendering the shadow
Rendering the shadow can be done by calculating a shadow triangle for each corresponding object triangle and rendering that onto the plane. Another simple way to add shadows would be to break the ground up into a lot of small triangles and darken them appropriately if the shadow point intersects. This way would also work for calculating resulting shadows onto other 3D objects.
Conclusion
This ends the tutorial. As indicated in the beginning, this tutorial is only to give an idea of how to get things going and because of that some cases and/or calculations may be missing or just skipped to simplify things. If anyone has any comments or questions, please feel free to email.
© 2024 Luigi Pino. All rights reserved.
Privacy | Links