IntroductionSo, you want to add shadows into your games. Why? Maybe it’s because it looks cool, maybe you want to brag about it to your friends, or maybe you think it will add to the game atmosphere. Whatever your reason, you’ve definitely come to the right place! Ok, ready to get started? Well, we’re going to start with the very basics here. What is a shadow? Webster defines a shadow as "an area that is not or is only partially irradiated or illuminated due to blockage of light by an opaque object," or "the rough image cast by an object blocking rays of light." For our purposes, a shadow is a dark area caused by light being blocked by an object. So why exactly do we need to know this? Simple, if we know what a shadow is, it will be that much easier to create them in our games. The most obvious solution is presented by the definition of a shadow. We could just cast a bazillion rays from the light source and determine lighting that way. While this may work, it’s computationally expensive (i.e. slow), and it isn’t very easy to implement. So, are you getting sick of definitions yet? Well, you’re in luck; you now know all you need to know to get started. Ok, so I lied, there is one more thing you have to know before we get started, these algorithms are ordered based on complexity, the easiest algorithms are first, and the more complex ones are at the end. Ok, here we go! Fake ShadowsThe simplest way to create a shadow is to add a polygon to the bottom of the object. Since this is best understood visually, you should take a look at figure 2.1 if you don’t understand the concept. Figure 2.1
This is a very simple way of doing things. Unfortunately, it’s very limited in it’s applications. The ground must be flat, the object has to remain a fixed length above the ground, the object can only rotate around the y-axis, it doesn’t take into account the direction the light is coming from, and it doesn’t shadow anything other than the floor. But, we’re only getting started, and the next three algorithms are much better, if a little bit slower and more complex. |
|||||||||||