Problems in understanding how lighting works

Oct 20, 2011 at 12:43 PM

A typical scene is a DisplayObject containing some lights (AmbientLight/DirectionalLight) and some models (DrawableModel). A model has a material (such as BasicMaterial) or several, and a material has an effect (such as BasicEffect). Each light, model, material and effect has lighting properties that can be set. Some seem to produce an effect, others do not.

What I am trying to understand is how those four sources of lighting information (light, model, material, effect) are combined into the final result. From experimentation it seems that lights are effective, materials are effective if lighting is enabled, and models and effects are not (but I could easily be missing something). My purpose is to produce dynamic lighting effects that effect an entire model.

Oct 20, 2011 at 1:34 PM
There are 2 lighting techniques used, forward and deferred lighting.

In a forward lighting scenario, the final result is determined by the light settings and the specified material.
The renderer will first look at the capability of the material to see how many lights are supported. In case of BasicMaterial, it supports 3 directional lights and 1 ambient light, then the renderer will try to find 3 directional lights and 1 ambient light and feed them to the material. This find process is pretty random at the moment, but I think it will search from the first added light.

For spotlights and pointlights, the ModelMaterial has a SpotLightCount and PointLightCount property to let you specify the max number of lights that can be affecting a model.

It is very hard to let all lights affects an object using this method and it is not so flexable, but it is the nature of forward lighting and it is fast.

For the relationship between materials and effects, you can think of a material and an instance of a effect that keeps a local copy of the parameters. Effects are expensive to create and clone, but you can create a new material for each object. When the material gets applied, it will update the underlying effect.

If you are trying to have 3+ dynamic lights of different types affecting the entire scene, deferred lighting is approach, but sadly it's not so available at the moment
Oct 21, 2011 at 1:54 AM

OK, I get that. No, I don't need dynamic lights affecting the whole scene, and I don't think I need deferred lighting. And I guess you're saying that the effect lighting is determined by the material.

What I am trying to do is apply a lighting effect to a single model. like making it glow or flash or fade out. I can get some interesting effects by cloning the Material and changing its lighting, but I'm trying to understand to what extent the final result is the consequence of lighting at the scene, model and material level. Does the lighting of a material replace that from the scene, or combine with it? Does the model lighting do anything at all?