Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class Light

  1. Object
  2. Light
A single directional light plus a global ambient term, consumed by lit materials (Material.Type.LAMBERT and Material.Type.PHONG). The direction is the direction the light travels, in world space. Set the active light on the device with GraphicsDevice.setLight(Light).

Constructors

public Light()

Methods

public Light setDirection(float x, float y, float z)Sets the world space direction the light travels.
public float getDirectionX()Returns the x component of the light direction.
public float getDirectionY()Returns the y component of the light direction.
public float getDirectionZ()Returns the z component of the light direction.
public int getColor()Returns the light color as a packed ARGB integer.
public Light setColor(int argb)Sets the light color as a packed ARGB integer.
public int getAmbientColor()Returns the ambient color as a packed ARGB integer.
public Light setAmbientColor(int argb)Sets the ambient color as a packed ARGB integer.
public Light setShadows(boolean shadows)Turns shadow casting on or off.
public boolean isShadows()Returns true if the light casts shadows.
public Light setShadowMap(int size, float extent)Sets the area and resolution of the shadow map.
public int getShadowMapSize()Returns the shadow map’s width and height in texels.
public float getShadowCenterX()Returns the x of the point the shadow map is centred on.
public float getShadowCenterZ()Returns the z of the point the shadow map is centred on.
public float getShadowExtent()Returns the half width of the area the shadow map covers.
public Light setShadowCenter(float x, float y, float z)Centres the shadow map on a world point, normally the one the camera looks at.
public Light setShadowStyle(float strength, float bias)Sets how dark a shadow is and how far a surface must be behind the shadow map before it counts as shadowed.
public float getShadowStrength()Returns how dark a shadow is, from 0 to 1.
public float getShadowBias()Returns the shadow depth bias.
public void computeShadowMatrix(float[] out)Computes the matrix that takes a world position to the shadow map’s clip space: an orthographic view along the light’s direction, centred on the shadow centre.

Inherited methods

Constructor details

Light

public Light()

Method details

setDirection

public Light setDirection(float x, float y, float z)
Sets the world space direction the light travels.

Parameters

x float
the x component
y float
the y component
z float
the z component

Returns

this light for chaining

getDirectionX

public float getDirectionX()
Returns the x component of the light direction.

getDirectionY

public float getDirectionY()
Returns the y component of the light direction.

getDirectionZ

public float getDirectionZ()
Returns the z component of the light direction.

getColor

public int getColor()
Returns the light color as a packed ARGB integer.

setColor

public Light setColor(int argb)
Sets the light color as a packed ARGB integer.

Parameters

argb int
the packed ARGB color

Returns

this light for chaining

getAmbientColor

public int getAmbientColor()
Returns the ambient color as a packed ARGB integer.

setAmbientColor

public Light setAmbientColor(int argb)
Sets the ambient color as a packed ARGB integer.

Parameters

argb int
the packed ARGB color

Returns

this light for chaining

setShadows

public Light setShadows(boolean shadows)

Turns shadow casting on or off. With shadows on, a GraphicsDevice that supports them (GpuCapabilities.isShadowsSupported) renders the scene from the light into a shadow map before each frame, and lit materials that receive shadows are darkened where it is blocked.

The map covers a square extent units either side of the shadow centre, seen along the light’s direction; move the centre with the camera (setShadowCenter) and keep the extent as small as the view allows, since the map’s resolution is spread over it.

Parameters

shadows boolean
true to cast shadows

Returns

this light for chaining

isShadows

public boolean isShadows()
Returns true if the light casts shadows.

setShadowMap

public Light setShadowMap(int size, float extent)
Sets the area and resolution of the shadow map.

Parameters

size int
the width and height of the map in texels; clamped to 256 to 4096
extent float
the half width of the square it covers, in world units

Returns

this light for chaining

getShadowMapSize

public int getShadowMapSize()
Returns the shadow map’s width and height in texels.

getShadowCenterX

public float getShadowCenterX()
Returns the x of the point the shadow map is centred on.

getShadowCenterZ

public float getShadowCenterZ()
Returns the z of the point the shadow map is centred on.

getShadowExtent

public float getShadowExtent()
Returns the half width of the area the shadow map covers.

setShadowCenter

public Light setShadowCenter(float x, float y, float z)
Centres the shadow map on a world point, normally the one the camera looks at.

Parameters

x float
the x coordinate
y float
the y coordinate
z float
the z coordinate

Returns

this light for chaining

setShadowStyle

public Light setShadowStyle(float strength, float bias)
Sets how dark a shadow is and how far a surface must be behind the shadow map before it counts as shadowed.

Parameters

strength float
0 for no darkening, 1 for no direct light at all
bias float
the depth offset in the map’s 0..1 range; raise it if surfaces shadow themselves in stripes (“acne”), lower it if shadows detach from the objects that cast them

Returns

this light for chaining

getShadowStrength

public float getShadowStrength()
Returns how dark a shadow is, from 0 to 1.

getShadowBias

public float getShadowBias()
Returns the shadow depth bias.

computeShadowMatrix

public void computeShadowMatrix(float[] out)
Computes the matrix that takes a world position to the shadow map’s clip space: an orthographic view along the light’s direction, centred on the shadow centre. Every backend uses this one, so shadows land in the same place on each.

Parameters

out float[]
a 16 element array that receives the column-major matrix