Zombie simulator: shadowed walls PDF Print E-mail
Monday, 04 January 2010 09:05

Previously I'd been using a simple directional light source to create shadows on the walls, but that merely shaded the sides of the wall object base on their orientation to the light, which meant that interior walls, those that are under the roof of a building, would have been shaded to appear as if they were outside.

The usual solution is to use some sort of shadow mapping, but that involves rendering extra passes, which will get expensive because of the way I've designed this world.

After thinking about this for a while, I came up with a workaround that produced the kind of shadowing I'm after, with very little overhead.

As you can see, the buildings now appear to cast shadows and building interiors are in shadow, both of which has been done without a light source or shadow mapping, using two different techniques.

Shadowed interiors

I went back and reworked my brick model, separating out the triangles that are facing the three axes, X, Y and Z and assigning them different vertex colours depending on the orientation of the face. Then, when the mesh is added to the building list, the code simply changes the vertex colour depending on whether the face is considered "inside" or "outside".

In order to get the solid shading that is expected of a wall, I had to exclude normals when exporting using Gandalf's b3d exporter. If normals were included then the wall object would appear to be soft shaded and the vertex colours would bleed between faces.

Shadows cast by buildings

All I've done here is create a flat polygon in the shape of the shadow and placed it one unit above the roads and sidewalk polygons, then set it to use the vertex alpha component for transparency, making all the vertices of the object black, with 50% transparency. In total, each shadow only adds six polygons to the world per building, and they can be culled in exactly the same way as the rest of the triangles in the scene which makes for a very efficient fake shadow effect.

This method does place a limit on how tall buildings can be, otherwise the shadow will overlap another building and be visible inside, so I'll have to adjust the length of the shadows so that they are never long enough for the tallest buildings to cast shadows on another. It'll just look like the sun is closer to being directly overhead where shadows are at their shortest, and besides, due to the camera style and position, the buildings can only be about 4 or 5 stories tall at most without obscuring too much detail behind them.

The pink buildings in the image above are three stories tall.

Shadows cast on people and props

As usual, I've arranged all the shadows into one huge mesh, so I can exploit that to determine if a character or prop is standing in a shadow by simply working out if the sprite's position overlaps one of the shadow triangles, a simple 2D test. Easy.

 

blog comments powered by Disqus