Class Environment
The atmosphere every draw is shaded in: fog, the sky and ground colours that light a surface from above and below, and how the result is exposed and tone mapped to the display.
A default environment changes nothing: no fog, the light's own ambient
colour and no tone mapping, so a scene that never sets one renders exactly
as before. Set it with GraphicsDevice.setEnvironment, or
GameView.getEnvironment() in a game.
GameView view = new GameView() {
protected void update(double deltaSeconds) {
}
};
view.getEnvironment()
.setFog(0xffa9b3ba, 0.035f, 0.08f)
.setHemisphere(0xff9fb4c8, 0xff4a4036)
.setToneMapping(true)
.setExposure(1.1f);
Fog is exponential squared in distance from the eye, thinned with height by
heightFalloff, so a valley fills with haze while a rooftop stays clear. It
applies to every material type except Material.Type.SKYBOX.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGoes back to the light's own flat ambient colour.clearSky()Goes back to drawingMaterial.Type.SKYBOXsurfaces in their own colour and texture.floatReturns how much of the sky is cloud, from 0 to 1.floatReturns the exposure multiplier.floatReturns the height at which fog is at its full density.intReturns the fog colour as ARGB.floatReturns the fog density per world unit, 0 when there is no fog.floatReturns how quickly fog thins with height, per world unit.intReturns the ground colour as ARGB.intReturns the sky colour at the horizon, as ARGB.Returns the part of the shader variant key that depends on this environment: whether fog, hemisphere lighting, tone mapping and the open sky are on.intReturns the sky colour as ARGB.intReturns the colour of the sun in the sky, as ARGB.intReturns a number that changes whenever a setting does, so a backend can tell that a shader variant or a uniform it cached is stale.intReturns the sky colour straight up, as ARGB.booleanisFog()Returns true if fog is on.booleanReturns true if surfaces are lit by the sky and ground colours.booleanisSky()Returns true if skybox surfaces are painted as an open sky.booleanReturns true if shaded colours are tone mapped.setExposure(float exposure) Scales the light reaching the camera before it is tone mapped.setFog(int color, float density, float heightFalloff) Turns fog on.setFogBaseHeight(float y) Sets the height at which fog is at its full density; it thins above it.setHemisphere(int sky, int ground) Lights surfaces with a sky colour from above and a ground colour from below, blended by the surface normal, in place of the light's flat ambient colour.setSky(int zenith, int horizon, int sun, float clouds) PaintsMaterial.Type.SKYBOXsurfaces as an open sky: a gradient from the horizon to the zenith, the sun where the light comes from with a glow around it, and soft clouds.setToneMapping(boolean toneMapping) Maps shaded colours through a filmic (ACES) curve, so bright light rolls off instead of clipping to white.
-
Constructor Details
-
Environment
public Environment()
-
-
Method Details
-
setFog
Turns fog on. A density of 0 turns it off.
Parameters
-
color: the colour of the fog, as ARGB -
density: how thick it is, per world unit; a surface1 / densityunits away is about 63% fog -
heightFalloff: how quickly it thins with height abovesetFogBaseHeight, per world unit; 0 is the same thickness everywhere
Returns
this environment for chaining
-
-
setFogBaseHeight
Sets the height at which fog is at its full density; it thins above it.
Parameters
y: the world height
Returns
this environment for chaining
-
setHemisphere
Lights surfaces with a sky colour from above and a ground colour from below, blended by the surface normal, in place of the light's flat ambient colour. It is what gives an outdoor scene its shape in shadow.
Parameters
-
sky: the colour that lights upward facing surfaces, as ARGB -
ground: the colour that lights downward facing surfaces, as ARGB
Returns
this environment for chaining
-
-
clearHemisphere
Goes back to the light's own flat ambient colour.
Returns
this environment for chaining
-
setToneMapping
Maps shaded colours through a filmic (ACES) curve, so bright light rolls off instead of clipping to white. Lit and physically based materials are affected; unlit ones, sprites and the sky are not.
Parameters
toneMapping: true to tone map
Returns
this environment for chaining
-
setExposure
Scales the light reaching the camera before it is tone mapped.
Parameters
exposure: the multiplier, 1 for none
Returns
this environment for chaining
-
setSky
Paints
Material.Type.SKYBOXsurfaces as an open sky: a gradient from the horizon to the zenith, the sun where the light comes from with a glow around it, and soft clouds. Draw it on a large sphere around the camera, seen from inside; it is computed per pixel from the view direction, so it needs no texture and has no seams.Parameters
-
zenith: the colour straight up, as ARGB -
horizon: the colour at the horizon, as ARGB; match it to the fog colour so distant geometry melts into the sky -
sun: the colour of the sun disc and its glow, as ARGB; black for none -
clouds: how much of the sky is cloud, from 0 to 1
Returns
this environment for chaining
-
-
clearSky
Goes back to drawing
Material.Type.SKYBOXsurfaces in their own colour and texture.Returns
this environment for chaining
-
isSky
public boolean isSky()Returns true if skybox surfaces are painted as an open sky. -
getZenithColor
public int getZenithColor()Returns the sky colour straight up, as ARGB. -
getHorizonColor
public int getHorizonColor()Returns the sky colour at the horizon, as ARGB. -
getSunColor
public int getSunColor()Returns the colour of the sun in the sky, as ARGB. -
getCloudCover
public float getCloudCover()Returns how much of the sky is cloud, from 0 to 1. -
getFogColor
public int getFogColor()Returns the fog colour as ARGB. -
getFogDensity
public float getFogDensity()Returns the fog density per world unit, 0 when there is no fog. -
getFogHeightFalloff
public float getFogHeightFalloff()Returns how quickly fog thins with height, per world unit. -
getFogBaseHeight
public float getFogBaseHeight()Returns the height at which fog is at its full density. -
isFog
public boolean isFog()Returns true if fog is on. -
isHemisphere
public boolean isHemisphere()Returns true if surfaces are lit by the sky and ground colours. -
getSkyColor
public int getSkyColor()Returns the sky colour as ARGB. -
getGroundColor
public int getGroundColor()Returns the ground colour as ARGB. -
isToneMapping
public boolean isToneMapping()Returns true if shaded colours are tone mapped. -
getExposure
public float getExposure()Returns the exposure multiplier. -
getVersion
public int getVersion()Returns a number that changes whenever a setting does, so a backend can tell that a shader variant or a uniform it cached is stale. -
getShaderKey
Returns the part of the shader variant key that depends on this environment: whether fog, hemisphere lighting, tone mapping and the open sky are on. Values such as the fog colour are uniforms and are not part of it.
-