Directional Lighting
Posted: 09 Feb 2019, 16:44
I noticed that in New Super Mario Bros Wii (and DS), the characters are shaded differently in some levels.
In the castle, it looks like light comes from the bottom (see the toad's chin):
For comparison, another level (see the yellow toad):
I think that something like this could be added to supertux, too.
The current lighting could be called Ambient Light and the directional light can be denoted as Directional Light.
For each level, the ratio between Ambient and Directional Light can be set, e.g. low Directional Light in foggy levels. The sun light vector is another additional setting which is used for the Directional Light.
To calculate the Directional Light, for each texture (also tiles, not only Tux and enemies) a normalmap defines the normal vectors. If the normalmap is missing, the texture is simply assumed to be flat. Since supertux is 2D, light sources (e.g. a lamp) are modelled approximately as a stripe which goes in -z direction. When calculating the Directional Light for a pixel, the minimum angle between the normal (from the normalmap) and a vector to the light source (which directs to the stripe) is used. (directional light similar to Gouraud shading)
Much of the lighting does not need to be calculated dynamically in every frame; for non-moving light sources, it can be calculated when loading the level or combining the tiles. Directional Light for moving light sources can be disabled so that light calculation is not needed for every frame (for performance).
Many current textures are already lighted directionally (with fixed direction), so when enabling Directional Light, different ones need to be used.
In the castle, it looks like light comes from the bottom (see the toad's chin):
For comparison, another level (see the yellow toad):
I think that something like this could be added to supertux, too.
The current lighting could be called Ambient Light and the directional light can be denoted as Directional Light.
For each level, the ratio between Ambient and Directional Light can be set, e.g. low Directional Light in foggy levels. The sun light vector is another additional setting which is used for the Directional Light.
To calculate the Directional Light, for each texture (also tiles, not only Tux and enemies) a normalmap defines the normal vectors. If the normalmap is missing, the texture is simply assumed to be flat. Since supertux is 2D, light sources (e.g. a lamp) are modelled approximately as a stripe which goes in -z direction. When calculating the Directional Light for a pixel, the minimum angle between the normal (from the normalmap) and a vector to the light source (which directs to the stripe) is used. (directional light similar to Gouraud shading)
Much of the lighting does not need to be calculated dynamically in every frame; for non-moving light sources, it can be calculated when loading the level or combining the tiles. Directional Light for moving light sources can be disabled so that light calculation is not needed for every frame (for performance).
Many current textures are already lighted directionally (with fixed direction), so when enabling Directional Light, different ones need to be used.