Class EnvironmentMaps
Bakes the environment map that image based lighting reads
(Environment.setEnvironmentMap): what a shiny or rough surface reflects,
and the soft light every surface receives from all around it.
The bake runs once, on the CPU, into an ordinary RGB texture every backend
samples the same way -- no cube maps and no float textures, so it works on
the oldest GL ES and WebGL devices too. The texture is WIDTH texels wide
and holds BANDS equirectangular bands of BAND_HEIGHT texels stacked
top to bottom: the sharp environment, three progressively blurred copies
for rougher surfaces, the roughest, and last the diffuse irradiance. Colours
are stored at half intensity, so an environment may be up to twice as
bright as white.
import com.codename1.gpu.*;
import com.codename1.gpu.shaders.ScenePresets;
void light(GraphicsDevice device, ScenePresets.Preset look, Light light) {
Environment env = look.getEnvironment();
env.setEnvironmentMap(EnvironmentMaps.fromSky(device, env, light));
}
Rebake when the sky changes; a bake costs a few tens of milliseconds.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe height of one band in texels.static final intThe number of bands: five roughness levels and the irradiance.static final intThe width of the baked texture in texels. -
Method Summary
Modifier and TypeMethodDescriptionstatic int[]bake(float[] radiance) Bakes a radiance panorama ofWIDTHbyBAND_HEIGHTlinear RGB triples into the band layout.static TexturefromImage(GraphicsDevice device, Image panorama, float intensity) Bakes an equirectangular panorama -- an image twice as wide as it is tall whose x runs once around the horizon and whose y runs from straight up to straight down -- into an environment map texture.static TexturefromSky(GraphicsDevice device, Environment env, Light light) Bakes the procedural sky of an environment (Environment.setSky), lit by a light's sun, into an environment map texture.
-
Field Details
-
WIDTH
public static final int WIDTHThe width of the baked texture in texels.- See Also:
-
BAND_HEIGHT
public static final int BAND_HEIGHTThe height of one band in texels.- See Also:
-
BANDS
public static final int BANDSThe number of bands: five roughness levels and the irradiance.- See Also:
-
-
Method Details
-
fromSky
Bakes the procedural sky of an environment (
Environment.setSky), lit by a light's sun, into an environment map texture. Below the horizon it reflects the hemisphere ground colour, or a darkened horizon when the environment has none.Parameters
-
device: the device the texture is created on -
env: the environment whose sky colours to bake -
light: the light whose direction places the sun, or null for none
Returns
the environment map texture
-
-
fromImage
Bakes an equirectangular panorama -- an image twice as wide as it is tall whose x runs once around the horizon and whose y runs from straight up to straight down -- into an environment map texture.
Parameters
-
device: the device the texture is created on -
panorama: the panorama -
intensity: how bright the environment is; 1 keeps the image's own colours, up to 2
Returns
the environment map texture
-
-
bake
public static int[] bake(float[] radiance) Bakes a radiance panorama of
WIDTHbyBAND_HEIGHTlinear RGB triples into the band layout. Public for tests and for applications that compute their own environment.Parameters
radiance:WIDTH * BAND_HEIGHT * 3floats, row by row from straight up
Returns
the ARGB pixels of the texture,
WIDTHbyBAND_HEIGHT * BANDS
-