Visually improve the simulation of shadows, reflexions and lighting on cars
Thanks to Eckhard, here's the current state (r3778) of things in SD code and artwork base, and a proposal about how to improve it.
Definition: The shadows of the car and of the "world" objects (buildings, trees, ...) on the cars and on the track ground.
They are a fake, they come from textures (car: shadow.png; track: shadow2.png) and are just simple projected from top to down. They are independent of the light position but they look real when angle of the shadows at the texture fit to the light position.
Main Problem: As described shadows do not depend on the position of light source and moving objects. In modern game engines you have shadows depending on on the position of movable objects and the light source combined with statics shadows (like SD do now).
Solution: We leave them as they are for SD 2.0 ; later, when we have pixel and vertex shaders, we can add real projected shadows too.
Definition: The "projection" of the the "world" objects (buildings, trees, ...) (1), and of the sky (cloud layers) (2) on the car body.
They are also a fake and also come from textures.
Tracks don't have reflections but cars do have.
They use (1) the env.png located inside the track directory for front, left, back and right sides, and (2) the envshadow.png from the data/textures folder for bottom and top.
Main Problem: Reflections are applied with the "Multiply" operator that only adds dark areas to an image and ignore bright areas. This does not fit with nature.
Problem 2: The env.png fits to the appearance of the track, but the envshadow.png from data/textures does not always fit to the weather conditions.
- Reflections on cars should use a blending mode equivalent to the "Overlay" mode in Gimp, in order to reflect dark and bright areas:
- We use different reflection maps that fit to the weather condition or night (naming is like envshadow-weather-condition.png) and we use the good old envshadow.png as a fall-back when sky dome is off:
Definition: The appearance of an object (dark and light areas) without shadows.
For cars and tracks, it is defined by the material, but depends on the structure of the mesh because it is just a simple color blending between the vertices of the mesh.
The lighting is set by the material and the shading method:
In nature any light is reflected by any object but not in real time 3D.
Main Problem: Bad to use for reflections because we use low poly meshes and so we can't have always nice bright and dark areas.
Solution: We should define standard materials for any track and cars (incl. the wheels):
- Shiny metallic object
- Low shiny object
- Natural objects (very low shininess) Setting the standard materials to any track and car is very easy because it is located in the *.ac/acc files, once at the beginning of the file.
Cars skin rendering stack
The graphics engine uses multi-texturing in order to combine these multiple textures.
Here's the order of the texturing "pipeline" (each time, using a "multiply" operator) :
- Texture unit 0 : car skin (cars/models/<car>/<car>.png)
- Texture unit 1 : horizontal reflections (tracks/<category>/<track>/env.png)
- Texture unit 2 : vertical reflections (data/textures/envshadow.png)
- Texture unit 3 : track shadows (tracks/<category>/<track>/shadow2.png)
Then the lighting is applied, according to the material specs (as specified in the .ac file : MATERIAL "ac3dmat1" rgb 1 1 1 amb 0 0 0 emis 0.25 0.25 0.25 spec 0.25 0.25 0.25 shi 128 trans 0).
Note: Multi-texturig should be available on every video back-end nowadays, but may be not with as many units as 4 ; if only 3 units are available, the 4th step is not achieved, neither the 3rd step if only 2 are available.
Conclusion and action plan (work-in-progress)
Pushing the appearance in SD 2.0 should not be hard to implement. Eckhard could change all the cars / tracks material after we agreed to the standard materials.
No problem for Jaime or Eckhard making nice new reflection maps working with mode overlay. So, as far as the code is concerned, the only needed changes are :
- the "overlay" blending mode for reflections on cars
- the weather/time-of-day-depending envshadow-....png.
For these code changes a first set of one env.png and one envshadow.png is quickly made.