An explanation of the World shaders used in Live for Speed - 3 December 2015
----------------------------------------------------------
NOTE: The shaders are in an early stage.

They are based on the old DX8 shaders, translated into HLSL, with a few new features.
There will be incompatible updates of these shaders that will make user edited shaders obsolete.

TIP: If you edit a shader, you can reload all shaders in LFS using this command: /rsh

This document refers to the shaders in World.vsh and World.psh.
It is provided to help make sense of the shaders and how they are used by LFS.

The shaders work in pairs, a vertex shader (VSHADER_x) and a pixel shader (PSHADER_x).
Often the same simple pixel shader is used with a different vertex shader.

Different shaders (or pairs of shaders) are used for matt / shiny / solid / transparent surfaces.
World objects have prelit vertices.  In some cases the shaders are very simple.

When drawing an object that may have a car shadow on it, this is how it works:

1) Draw the surfaces but with direct lighting only (usually the sun).
2) Draw the car shadows in black over that to remove the direct lighting where it should not be.
3) Add the ambient light contribution to what remains (lighting from environment, mostly the sky).

This is done for the plain prelit surfaces and the prelit shiny objects (which are not common).

Shader pairs
------------
1) Simple prelit shaders for flexible objects such as flags / people / moving trees.

Note that the vertices are supplied at half the lighting intensity to allow saturation.
This is why there is a doubling in PSHADER_SIMPLE_2

For vertices supplied in view space : VSHADER_PRELIT_VIEW
For vertices supplied in world space : VSHADER_PRELIT_WORLD
Textured : PSHADER_SIMPLE_2
Untextured : PSHADER_NO_TEXTURE

2) The most commonly used shader - solid or transparent, matt objects :

Not shadowed : VSHADER_PRELIT_WORLD / PSHADER_SIMPLE_2

3) New shader for shiny solid objects (e.g. fire extinguishers) :

Not shadowed : VSHADER_WORLD_SHINY / PSHADER_WORLD_SHINY_SOLID

4) New shader for shiny transparent glass, similar to car windows :

Not shadowed : VSHADER_WORLD_SHINY / PSHADER_WORLD_SHINY_ALPHA

5) Shaders mainly for building windows, often with an overlay.  Reflection only.

Mirrored glass / aluminium : VSHADER_SKY_ENVMAP / PSHADER_REFLECT_METAL
Non-transparent glass : VSHADER_SKY_ENVMAP / PSHADER_REFLECT_GLASS

6) Solid objects that may be in shadow, first pass, direct lighting contribution only :

Shadowed, first pass, shiny or matt : VSHADER_LIGHT_ONLY / PSHADER_SIMPLE_2

7) Shaders for the final pass of shadowed objects (after drawing the car shadows) :

Shadowed, final pass, matt : VSHADER_MATT_ADD_AMBIENT / PSHADER_SIMPLE_2
Shadowed, final pass, shiny : VSHADER_SHINY_ADD_AMBIENT / PSHADER_WORLD_SHINY_SOLID

Post-processing shader
----------------------
Post-processing can be enabled in Misc Options.
If enabled, the ps_main shader in PostProcess.psh is used to create the final image.