Package 

Class LightManager


  • 
    public class LightManager
    
                        

    LightManager allows you to create a light source in the scene, such as a sun or street lights.

    At least one light must be added to a scene in order to see anything (unless the UNLIT is used).

    A Light component is created using the LightManager.Builder and destroyed by calling destroy.

     Engine engine = Engine.create();
     int sun = EntityManager.get().create();
    
     LightManager.Builder(Type.SUN)
                 .castShadows(true)
                 .build(engine, sun);
    
     engine.getLightManager().destroy(sun);
    
    Lights come in three flavors:
    • directional lights
    • point lights
    • spot lights

    Directional lights have a direction, but don't have a position. All light rays are parallel and come from infinitely far away and from everywhere. Typically a directional light is used to simulate the sun.

    Directional lights and spot lights are able to cast shadows.

    To create a directional light use DIRECTIONAL or SUN, both are similar, but the later also draws a sun's disk in the sky and its reflection on glossy objects.

    warning: Currently, only a single directional light is supported. If several directional lights are added to the scene, the dominant one will be used.

    Unlike directional lights, point lights have a position but emit light in all directions. The intensity of the light diminishes with the inverse square of the distance to the light. falloff controls the distance beyond which the light has no more influence.

    A scene can have multiple point lights.

    Spot lights are similar to point lights but the light they emit is limited to a cone defined by spotLightCone and the light's direction.

    A spot light is therefore defined by a position, a direction and inner and outer cones. The spot light's influence is limited to inside the outer cone. The inner cone defines the light's falloff attenuation.

    A physically correct spot light is a little difficult to use because changing the outer angle of the cone changes the illumination levels, as the same amount of light is spread over a changing volume. The coupling of illumination and the outer cone means that an artist cannot tweak the influence cone of a spot light without also changing the perceived illumination. It therefore makes sense to provide artists with a parameter to disable this coupling. This is the difference between FOCUSED_SPOT (physically correct) and SPOT (decoupled).

    Generally, adding lights to the scene hurts performance, however filament is designed to be able to handle hundreds of lights in a scene under certain conditions. Here are some tips to keep good performance.

    • Prefer spot lights to point lights and use the smallest outer cone angle possible.
    • Use the smallest possible falloff distance for point and spot lights. Performance is very sensitive to overlapping lights. The falloff distance essentially defines a sphere of influence for the light, so try to position point and spot lights such that they don't overlap too much.
    • Method Summary

      Modifier and Type Method Description
      int getComponentCount() Returns the number of components in the LightManager, note that components are notguaranteed to be active.
      boolean hasComponent(int entity) Returns whether a particular Entity is associated with a component of this LightManager
      int getInstance(int entity) Gets an Instance representing the Light component associated with the given Entity.
      void destroy(int entity) Destroys this component from the given entity
      LightManager.Type getType(int i)
      void setLightChannel(int i, @IntRange(from = 0, to = 7) int channel, boolean enable) Enables or disables a light channel.Light channel 0 is enabled by default.
      boolean getLightChannel(int i, @IntRange(from = 0, to = 7) int channel) Returns whether a light channel is enabled on a specified renderable.
      void setPosition(int i, float x, float y, float z) Dynamically updates the light's position.
      Array<float> getPosition(int i, @Nullable() @Size(min = 3) Array<float> out) returns the light's position in world space
      void setDirection(int i, float x, float y, float z) Dynamically updates the light's directionThe light direction is specified in world space and should be a unit vector.
      Array<float> getDirection(int i, @Nullable() @Size(min = 3) Array<float> out) returns the light's direction in world space
      void setColor(int i, float linearR, float linearG, float linearB) Dynamically updates the light's hue as linear sRGB
      Array<float> getColor(int i, @Nullable() @Size(min = 3) Array<float> out) Returns the light color
      void setIntensity(int i, float intensity) Dynamically updates the light's intensity.
      void setIntensityCandela(int i, float intensity) Dynamically updates the light's intensity in candela.
      void setIntensity(int i, float watts, float efficiency) Dynamically updates the light's intensity.
      float getIntensity(int i) returns the light's luminous intensity in lumens.
      void setFalloff(int i, float falloff) Set the falloff distance for point lights and spot lights.
      float getFalloff(int i) returns the falloff distance of this light.
      void setSpotLightCone(int i, float inner, float outer) Dynamically updates a spot light's cone as angles
      void setSunAngularRadius(int i, float angularRadius) Dynamically updates the angular radius of a Type.SUN lightThe Sun as seen from Earth has an angular size of 0.526° to 0.
      float getSunAngularRadius(int i) returns the angular radius if the sun in degrees.
      void setSunHaloSize(int i, float haloSize) Dynamically updates the halo radius of a Type.SUN light.
      float getSunHaloSize(int i) returns the halo size of a Type.SUN light as a multiplier of thesun angular radius.
      void setSunHaloFalloff(int i, float haloFalloff) Dynamically updates the halo falloff of a Type.SUN light.
      float getSunHaloFalloff(int i) returns the halo falloff of a Type.SUN light as a dimensionless value.
      void setShadowCaster(int i, boolean shadowCaster) Whether this Light casts shadows (disabled by default)warning:POINT cannot cast shadows.
      boolean isShadowCaster(int i) returns whether this light casts shadows.
      float getOuterConeAngle(int i)
      float getInnerConeAngle(int i)
      long getNativeObject()
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getComponentCount

         int getComponentCount()

        Returns the number of components in the LightManager, note that components are notguaranteed to be active. Use the isAlive before use if needed.

      • hasComponent

         boolean hasComponent(int entity)

        Returns whether a particular Entity is associated with a component of this LightManager

        Parameters:
        entity - An Entity.
      • getInstance

         int getInstance(int entity)

        Gets an Instance representing the Light component associated with the given Entity.

        Parameters:
        entity - An Entity.
      • destroy

         void destroy(int entity)

        Destroys this component from the given entity

        Parameters:
        entity - An Entity.
      • setLightChannel

         void setLightChannel(int i, @IntRange(from = 0, to = 7) int channel, boolean enable)

        Enables or disables a light channel.Light channel 0 is enabled by default.

        Parameters:
        i - Instance of the component obtained from getInstance().
        channel - Light channel to set
        enable - true to enable, false to disable
      • getLightChannel

         boolean getLightChannel(int i, @IntRange(from = 0, to = 7) int channel)

        Returns whether a light channel is enabled on a specified renderable.

        Parameters:
        i - Instance of the component obtained from getInstance().
        channel - Light channel to query
      • setPosition

         void setPosition(int i, float x, float y, float z)

        Dynamically updates the light's position.

        note: The Light's position is ignored for directional lights(DIRECTIONAL or SUN)

        Parameters:
        i - Instance of the component obtained from getInstance().
        x - Light's position x coordinate in world space.
        y - Light's position y coordinate in world space.
        z - Light's position z coordinate in world space.
      • getPosition

        @NonNull() Array<float> getPosition(int i, @Nullable() @Size(min = 3) Array<float> out)

        returns the light's position in world space

        Parameters:
        i - Instance of the component obtained from getInstance().
        out - An array of 3 float to receive the result or null.
      • setDirection

         void setDirection(int i, float x, float y, float z)

        Dynamically updates the light's direction

        The light direction is specified in world space and should be a unit vector.

        note: The Light's direction is ignored for POINT lights.

        Parameters:
        i - Instance of the component obtained from getInstance().
        x - light's direction x coordinate (default is 0)
        y - light's direction y coordinate (default is -1)
        z - light's direction z coordinate (default is 0)
      • getDirection

        @NonNull() Array<float> getDirection(int i, @Nullable() @Size(min = 3) Array<float> out)

        returns the light's direction in world space

        Parameters:
        i - Instance of the component obtained from getInstance().
        out - An array of 3 float to receive the result or null.
      • setColor

         void setColor(int i, float linearR, float linearG, float linearB)

        Dynamically updates the light's hue as linear sRGB

        Parameters:
        i - Instance of the component obtained from getInstance().
        linearR - red component of the color (default is 1)
        linearG - green component of the color (default is 1)
        linearB - blue component of the color (default is 1)
      • getColor

        @NonNull() Array<float> getColor(int i, @Nullable() @Size(min = 3) Array<float> out)

        Returns the light color

        Parameters:
        i - Instance of the component obtained from getInstance().
      • setIntensity

         void setIntensity(int i, float intensity)

        Dynamically updates the light's intensity. The intensity can be negative.

        Parameters:
        i - Instance of the component obtained from getInstance().
        intensity - This parameter depends on the Type, for directional lights,it specifies the illuminance in lux (or lumen/m^2).
      • setIntensityCandela

         void setIntensityCandela(int i, float intensity)

        Dynamically updates the light's intensity in candela. The intensity can be negative.This method is equivalent to calling setIntensity for directional lights (Type.DIRECTIONALor Type.SUN).

        Parameters:
        i - Instance of the component obtained from getInstance().
        intensity - Luminous intensity in candela.
      • setIntensity

         void setIntensity(int i, float watts, float efficiency)

        Dynamically updates the light's intensity. The intensity can be negative.

         Lightbulb type  | Efficiency
        -----------------+------------
            Incandescent |  2.2%
                Halogen  |  7.0%
                    LED  |  8.7%
            Fluorescent  | 10.7%
        
        This call is equivalent to:
        Builder.intensity(efficiency * 683 * watts);
        
        Parameters:
        i - Instance of the component obtained from getInstance().
        watts - Energy consumed by a lightbulb.
        efficiency - Efficiency in percent.
      • getIntensity

         float getIntensity(int i)

        returns the light's luminous intensity in lumens.

        note: for FOCUSED_SPOT lights, the returned value depends on the outer cone angle.

        Parameters:
        i - Instance of the component obtained from getInstance().
      • setFalloff

         void setFalloff(int i, float falloff)

        Set the falloff distance for point lights and spot lights.

        Parameters:
        i - Instance of the component obtained from getInstance().
        falloff - falloff distance in world units.
      • getFalloff

         float getFalloff(int i)

        returns the falloff distance of this light.

        Parameters:
        i - Instance of the component obtained from getInstance().
      • setSpotLightCone

         void setSpotLightCone(int i, float inner, float outer)

        Dynamically updates a spot light's cone as angles

        Parameters:
        i - Instance of the component obtained from getInstance().
        inner - inner cone angle in *radians* between 0 and pi/2
        outer - outer cone angle in *radians* between inner and pi/2
      • setSunAngularRadius

         void setSunAngularRadius(int i, float angularRadius)

        Dynamically updates the angular radius of a Type.SUN lightThe Sun as seen from Earth has an angular size of 0.526° to 0.545°

        Parameters:
        i - Instance of the component obtained from getInstance().
        angularRadius - sun's radius in degrees.
      • getSunAngularRadius

         float getSunAngularRadius(int i)

        returns the angular radius if the sun in degrees.

        Parameters:
        i - Instance of the component obtained from getInstance().
      • setSunHaloSize

         void setSunHaloSize(int i, float haloSize)

        Dynamically updates the halo radius of a Type.SUN light. The radiusof the halo is defined as a multiplier of the sun angular radius.

        Parameters:
        i - Instance of the component obtained from getInstance().
        haloSize - radius multiplier.
      • getSunHaloSize

         float getSunHaloSize(int i)

        returns the halo size of a Type.SUN light as a multiplier of thesun angular radius.

        Parameters:
        i - Instance of the component obtained from getInstance().
      • setSunHaloFalloff

         void setSunHaloFalloff(int i, float haloFalloff)

        Dynamically updates the halo falloff of a Type.SUN light. The falloffis a dimensionless number used as an exponent.

        Parameters:
        i - Instance of the component obtained from getInstance().
        haloFalloff - halo falloff.
      • getSunHaloFalloff

         float getSunHaloFalloff(int i)

        returns the halo falloff of a Type.SUN light as a dimensionless value.

        Parameters:
        i - Instance of the component obtained from getInstance().
      • setShadowCaster

         void setShadowCaster(int i, boolean shadowCaster)

        Whether this Light casts shadows (disabled by default)

        warning:POINT cannot cast shadows.

        Parameters:
        i - Instance of the component obtained from getInstance().
        shadowCaster - Enables or disables casting shadows from this Light.
      • isShadowCaster

         boolean isShadowCaster(int i)

        returns whether this light casts shadows.

        Parameters:
        i - Instance of the component obtained from getInstance().