Model and Lighting

As we've seen in the first tutorial, must be assigned to use realtime lighting, its default value is LightingMode.None which disable normals and lighting for the model.

To use lighting, the usual value is LightingMode.Default which detect the best suitable algorithm for normal computation depending on the file format used. Some format defines smooth group and angle which will automatically be used with LightingMode.Default.

Here's the difference between PerFace (flat/sharp edges) and PerVertex (smooth):
Spawn with flat normal (PerFace)

Spawn with smooth normal (PerVertex/Default)

An additional parameter ModelReaderSettings.html.lightingSmoothAngle gives more control on normal computation and allow both sharp and smooth edges. The smooth angle threshold is the angle limit between two faces when the edges between those faces will be sharp or smooth.

Let see the result in picture (click to maximize them). The two first pictures shows flat and smooth lighting. The last uses smooth angle of 40° which smooth edges when face angle is below 40° and keep sharp adges above (notice smooth edges on upper leg while other are sharp)
Robot with flat lighting

Robot with smooth lighting

Robot with smooth angle 40°

and with desert house model:
Desert house (Default)

Desert house with smooth angle


Realtime lighting can be achieve with opengl's fixed pipeline and with shader (programmable pipeline). For the later, the engine provides glsl shaders for various lights, see the shader article for more details about using shaders.

LightManager defines the light source properties.
LightManager is required when using engine's lighting shaders. It is optional with fixed pipeline by settings opengl's lights states directly, but doing that will break compatibility when fixed pipeline is not available support (which is becomming dominant these days on mobile devices and recent version of opengl). Hence it is recommended to use LightManager in both cases.

The first tutorial shows how to use LightManager:
 * assigned to a RenderOptions
 * bind (in the render loop) to associate light sources positioning with current modelview matrix and to send light properties to opengl if applicable (ie fixed pipeline)