Light State

See Javadoc

The LightState RenderState provides the means to add lighting to a scene graph.

A LightState can contain 0 or more Lights. A given object in the scene graph can only have one LightState set on it, but multiple LightStates can merge together (and do by default) to light any given object in the scene. This merging occurs as inheritance down the tree. OpenGL requires the video card to support at least 8 lights effecting a primitive, but it is possible to bypass this limitation by optimizing which lights have the most influence on an object, using Light Controllers.

The light combine mode is set in the Spatial class, but the mode constants are maintained in LightState.

There are 6 different combine modes available for LightStates.

  • OFF - Do not light this object. Ignores all lightstates.
  • INHERIT - Inherit mode from parent. This is the default mode.
  • REPLACE - Do not combine light states, just use the most recent one.
  • COMBINE_FIRST - Combine light states starting from the root node and working towards the given Spatial. Ignore disabled states. Stops combining when lights == MAX_LIGHTS_ALLOWED or no more states to combine.
  • COMBINE_CLOSEST - Combine light states starting from the given Spatial and working towards the root. Ignore disabled states. Stops combining when lights == MAX_LIGHTS_ALLOWED or no more states to combine.
  • COMBINE_RECENT_ENABLED - Similar to COMBINE_CLOSEST, but if a disabled state is encountered, it will stop combining at that point. Will also stop combining when lights == MAX_LIGHTS_ALLOWED or no more states to combine.

The LightState provides a means to turn two-sided lighting on and off. Two-sided lighting is significantly slower than one-sided, but provides the means to illuminate both sides of a polygon. Simply calling setTwoSidedLighting with true will enabled it. Usually you would enable two-sided lighting for objects which have surfaces visible from both sides (e.g a flag for example), it is useless to enable two-sided lighting if backface culling is enabled since those surfaces will never get drawn anyway.

Global ambient specifies an ambient color to be applied to all objects under the lightstate, without the need to create a light object for it.

The seperate specular flag causes the GL system to calculate specular color seperately (without applying it to the texture) which keeps the specular color the same as the light specular color (it is not modulated by the texture color), this allows for more dramatic specular effects.

LightStates can be better controlled through the use of a LightNode. Using this LightNode will allow you to control a Light as if it were a scene object. See LightNode for more information.

Example - Create a Standard LightState with Two Sided Lighting on

//light is defined elsewhere
LightState ls = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
ls.attach(light);
ls.setTwoSidedLighting(true);
rootNode.setRenderState(ls);

/var/www/wiki/data/pages/lightstate.txt · Last modified: 2009/07/28 18:44 (external edit)  
Recent changes · Show pagesource · Login

Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki

subscribe to jME latest jme headlines


site design by bleedcrimson designs © 2008