Class LightState

java.lang.Object
com.ardor3d.renderer.state.RenderState
com.ardor3d.renderer.state.LightState
All Implemented Interfaces:
Savable

public class LightState extends RenderState
LightState maintains a collection of lights up to the set number of maximum lights allowed. Any subclass of Light can be added to the light state. Each light is processed and used to modify the color of the scene.
  • Field Details

    • LIGHTS_ENABLED

      public static boolean LIGHTS_ENABLED
      Debug flag for turning off all lighting.
    • MAX_LIGHTS_ALLOWED

      public static final int MAX_LIGHTS_ALLOWED
      defines the maximum number of lights that are allowed to be maintained at one time.
      See Also:
    • MASK_AMBIENT

      public static final int MASK_AMBIENT
      When applied to lightMask, implies ambient light should be set to 0 for this lightstate
      See Also:
    • MASK_DIFFUSE

      public static final int MASK_DIFFUSE
      When applied to lightMask, implies diffuse light should be set to 0 for this lightstate
      See Also:
    • MASK_SPECULAR

      public static final int MASK_SPECULAR
      When applied to lightMask, implies specular light should be set to 0 for this lightstate
      See Also:
    • MASK_GLOBALAMBIENT

      public static final int MASK_GLOBALAMBIENT
      When applied to lightMask, implies global ambient light should be set to 0 for this lightstate
      See Also:
    • lightMask

      protected int lightMask
    • backLightMask

      protected int backLightMask
    • twoSidedOn

      protected boolean twoSidedOn
      When true, both sides of the model will be lighted.
    • _globalAmbient

      protected ColorRGBA _globalAmbient
    • DEFAULT_GLOBAL_AMBIENT

      public static final ReadOnlyColorRGBA DEFAULT_GLOBAL_AMBIENT
    • localViewerOn

      protected boolean localViewerOn
      When true, the eye position (as opposed to just the view direction) will be taken into account when computing specular reflections.
    • separateSpecularOn

      protected boolean separateSpecularOn
      When true, specular highlights will be computed separately and added to fragments after texturing.
  • Constructor Details

    • LightState

      public LightState()
      Constructor instantiates a new LightState object. Initially there are no lights set.
  • Method Details

    • getType

      public RenderState.StateType getType()
      Specified by:
      getType in class RenderState
      Returns:
      An statetype enum value for the subclass.
      See Also:
    • attach

      public boolean attach(Light light)
      attach places a light in the queue to be processed. If there are already eight lights placed in the queue, the light is ignored and false is returned. Otherwise, true is returned to indicate success.
      Parameters:
      light - the light to add to the queue.
      Returns:
      true if the light was added successfully, false if there are already eight lights in the queue.
    • detach

      public void detach(Light light)
      detach removes a light from the queue for processing.
      Parameters:
      light - the light to be removed.
    • detachAll

      public void detachAll()
      detachAll clears the queue of all lights to be processed.
    • getLightList

      public List<Light> getLightList()
      Retrieves all lights handled by this LightState
      Returns:
      List of lights handled
    • get

      public Light get(int i)
      get retrieves a particular light defined by an index. If there exists no light at a particular index, null is returned.
      Parameters:
      i - the index to retrieve the light from the queue.
      Returns:
      the light at the given index, null if no light exists at this index.
    • getNumberOfChildren

      public int getNumberOfChildren()
      getNumberOfChildren returns the number of lights currently in the queue.
      Returns:
      the number of lights currently in the queue.
    • setTwoSidedLighting

      public void setTwoSidedLighting(boolean twoSidedOn)
      Sets if two sided lighting should be enabled for this LightState. Two sided lighting will cause the back of surfaces to be colored using the inverse of the surface normal as well as the Material properties set for MaterialFace.Back.
      Parameters:
      twoSidedOn - If true, two sided lighting is enabled.
    • getTwoSidedLighting

      public boolean getTwoSidedLighting()
      Returns the current state of two sided lighting for this LightState. By default, it is off.
      Returns:
      True if two sided lighting is enabled.
    • setLocalViewer

      public void setLocalViewer(boolean localViewerOn)
      Sets if local viewer mode should be enabled for this LightState.
      Parameters:
      localViewerOn - If true, local viewer mode is enabled.
    • getLocalViewer

      public boolean getLocalViewer()
      Returns the current state of local viewer mode for this LightState. By default, it is off.
      Returns:
      True if local viewer mode is enabled.
    • setSeparateSpecular

      public void setSeparateSpecular(boolean separateSpecularOn)
      Sets if separate specular mode should be enabled for this LightState.
      Parameters:
      separateSpecularOn - If true, separate specular mode is enabled.
    • getSeparateSpecular

      public boolean getSeparateSpecular()
      Returns the current state of separate specular mode for this LightState. By default, it is off.
      Returns:
      True if separate specular mode is enabled.
    • setGlobalAmbient

      public void setGlobalAmbient(ReadOnlyColorRGBA color)
    • getGlobalAmbient

      public ReadOnlyColorRGBA getGlobalAmbient()
      Returns:
      the global ambient color
    • getLightMask

      public int getLightMask()
      Returns:
      Returns the lightMask - default is 0 or not masked.
    • setLightMask

      public void setLightMask(int lightMask)
      setLightMask sets what attributes of this lightstate to apply as an int comprised of bitwise or'ed values.
      Parameters:
      lightMask - The lightMask to set.
    • pushLightMask

      public void pushLightMask()
      Saves the light mask to a back store. That backstore is recalled with popLightMask. Despite the name, this is not a stack and additional pushes will simply overwrite the backstored value.
    • popLightMask

      public void popLightMask()
      Recalls the light mask from a back store or 0 if none was pushed.
      See Also:
    • write

      public void write(OutputCapsule capsule) throws IOException
      Specified by:
      write in interface Savable
      Overrides:
      write in class RenderState
      Throws:
      IOException
    • read

      public void read(InputCapsule capsule) throws IOException
      Specified by:
      read in interface Savable
      Overrides:
      read in class RenderState
      Throws:
      IOException
    • extract

      public RenderState extract(Stack<? extends RenderState> stack, Spatial spat)
      Description copied from class: RenderState
      Extracts from the stack the correct renderstate that should apply to the given spatial. This is mainly used for RenderStates that can be cumulitive such as TextureState or LightState. By default, the top of the static is returned. This function should not be called by users directly.
      Overrides:
      extract in class RenderState
      Parameters:
      stack - The stack to extract render states from.
      spat - The spatial to apply the render states too.
      Returns:
      The render state to use.
    • createStateRecord

      public StateRecord createStateRecord(ContextCapabilities caps)
      Specified by:
      createStateRecord in class RenderState