There is a light phenomena that we haven’t discussed yet. It is seen everywhere around you. Shadows. You might think we’ve already covered this, since a cube doesn’t get light when it’s not facing the light, but that’s not what we’re going to do right now. What if a light shines on that cube and there’s something below the cube? That would cast a shadow. In Truevision3D, it is not too hard to add shadows. It’s actually quite easy. It doesn’t suit all purposes and doesn’t always look like the most high end shadow solution, but it’s decent and well worth looking at.
What do we need?
- We need some thing that can actually cast a shadow. This is solved by loading room model 2, this is a floor with 4 pillars that will cast a shadow, since we’re going to place the light in the middle of the pillars.
How do we set things up?
- It really comes down to just 2 steps. The first step:
This will tell the light engine that this light source is casting shadows. The first parameter is of course the ID of the light.
The second parameter will tell the engine it is a managed light. It is a leftover from previous builds of the engine. You should always have this on true now.
The third parameter enables or disables the shadow casting, so in this case, we want the light to be able to cast shadows.
The last parameter enables or disables the light from the lightmapping solution. This is not what we want, we want this to be a dynamic light, not a lightmapped light. More info about lightmapping can be found here: wiki.
- We now only need to tell the mesh that it can cast and receive shadows.
How easy is that? The first parameter will tell the engine to make this mesh cast shadows. The second parameter will tell it to either make the shadows additive or not. Additive means you can have shadows overlap and have them be darker if more than 1 light has a shadow there.
How do we render this?
- There’s not much to add when rendering, just need to tell the engine we want to draw the shadows last by calling:
Things you can add/change yourself
- Play around with the position of the light to see the shadows move, or place other objects in order to see the shadows change.