Class Light
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).-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcomputeShadowMatrix(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.intReturns the ambient color as a packed ARGB integer.intgetColor()Returns the light color as a packed ARGB integer.floatReturns the x component of the light direction.floatReturns the y component of the light direction.floatReturns the z component of the light direction.floatReturns the shadow depth bias.floatReturns the x of the point the shadow map is centred on.floatReturns the z of the point the shadow map is centred on.floatReturns the half width of the area the shadow map covers.intReturns the shadow map's width and height in texels.floatReturns how dark a shadow is, from 0 to 1.booleanReturns true if the light casts shadows.setAmbientColor(int argb) Sets the ambient color as a packed ARGB integer.setColor(int argb) Sets the light color as a packed ARGB integer.setDirection(float x, float y, float z) Sets the world space direction the light travels.setShadowCenter(float x, float y, float z) Centres the shadow map on a world point, normally the one the camera looks at.setShadowMap(int size, float extent) Sets the area and resolution of the shadow map.setShadows(boolean shadows) Turns shadow casting on or off.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.
-
Constructor Details
-
Light
public Light()
-
-
Method Details
-
setDirection
Sets the world space direction the light travels.
Parameters
-
x: the x component -
y: the y component -
z: 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
Sets the light color as a packed ARGB integer.
Parameters
argb: the packed ARGB color
Returns
this light for chaining
-
getAmbientColor
public int getAmbientColor()Returns the ambient color as a packed ARGB integer. -
setAmbientColor
Sets the ambient color as a packed ARGB integer.
Parameters
argb: the packed ARGB color
Returns
this light for chaining
-
setShadows
Turns shadow casting on or off. With shadows on, a
GraphicsDevicethat 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
extentunits 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: true to cast shadows
Returns
this light for chaining
-
isShadows
public boolean isShadows()Returns true if the light casts shadows. -
setShadowMap
Sets the area and resolution of the shadow map.
Parameters
-
size: the width and height of the map in texels; clamped to 256 to 4096 -
extent: 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
Centres the shadow map on a world point, normally the one the camera looks at.
Parameters
-
x: the x coordinate -
y: the y coordinate -
z: the z coordinate
Returns
this light for chaining
-
-
setShadowStyle
Sets how dark a shadow is and how far a surface must be behind the shadow map before it counts as shadowed.
Parameters
-
strength: 0 for no darkening, 1 for no direct light at all -
bias: 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: a 16 element array that receives the column-major matrix
-