August 13, 2010

Lights & shadows

The last few days we were working on the integrated lighting system. First we gave OpenGLs basic lighting/shading system a try. That's either a "flat" (per face) or "smooth" model (per vertex). Basically, the system calculates the distance and angle between the lightsource and the target (face/vertex) along with some optional material components and shades the target using the results. We eventually developed an own system because of some restrictions we encountered:
- Lighting has to be recalculated in realtime every frame
- No shadows
... and beside that, the results don't look oldschool enough :)

We startet by utilizing the already implemented raycaster system to make it cast lightsources. The result is a per-vertex lighting system, that only needs to be recalculated when the light is moved or switched on/off. The lighting data is then stored permanently within the tiledata when the calculations are done. The system also casts shadows around solid tiles which can be smoothed by an optional post processing routine.

This is the 2d editor view showing two lightsources casting shadows with activated smoothing.

A similiar scene in 3d editor mode to demonstrate the difference with activated shadow smooting. We activated smoothing only for floor tiles so you will notice the difference to the ceiling.