Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class EnvironmentMaps
- Object
- 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.
Fields
public static final int WIDTH = 128 | The width of the baked texture in texels. |
public static final int BAND_HEIGHT = 64 | The height of one band in texels. |
public static final int BANDS = 6 | The number of bands: five roughness levels and the irradiance. |
Methods
public static Texture fromSky(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. |
public static Texture fromImage(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. |
public static int[] bake(float[] radiance) | Bakes a radiance panorama of WIDTH by BAND_HEIGHT linear RGB triples into the band layout. |
Inherited methods
Field details
WIDTH
public static final int WIDTH = 128BAND_HEIGHT
public static final int BAND_HEIGHT = 64BANDS
public static final int BANDS = 6Method details
fromSky
public static Texture fromSky(GraphicsDevice device, Environment env, Light light)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
deviceGraphicsDevice- the device the texture is created on
envEnvironment- the environment whose sky colours to bake
lightLight- the light whose direction places the sun, or null for none
Returns
fromImage
public static Texture fromImage(GraphicsDevice device, Image panorama, float intensity)Parameters
deviceGraphicsDevice- the device the texture is created on
panoramaImage- the panorama
intensityfloat- how bright the environment is; 1 keeps the image’s own colours, up to 2
Returns
bake
public static int[] bake(float[] radiance)WIDTH by BAND_HEIGHT linear RGB
triples into the band layout. Public for tests and for applications
that compute their own environment.Parameters
radiancefloat[]WIDTH * BAND_HEIGHT * 3floats, row by row from straight up
Returns
WIDTH by BAND_HEIGHT * BANDS