Class EnvironmentMaps

java.lang.Object
com.codename1.gpu.EnvironmentMaps

public final class EnvironmentMaps extends Object

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

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The height of one band in texels.
    static final int
    The number of bands: five roughness levels and the irradiance.
    static final int
    The width of the baked texture in texels.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int[]
    bake(float[] radiance)
    Bakes a radiance panorama of WIDTH by BAND_HEIGHT linear RGB triples into the band layout.
    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.
    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.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • WIDTH

      public static final int WIDTH
      The width of the baked texture in texels.
      See Also:
    • BAND_HEIGHT

      public static final int BAND_HEIGHT
      The height of one band in texels.
      See Also:
    • BANDS

      public static final int BANDS
      The number of bands: five roughness levels and the irradiance.
      See Also:
  • Method Details

    • fromSky

      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. 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

      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.

      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 WIDTH by BAND_HEIGHT linear RGB triples into the band layout. Public for tests and for applications that compute their own environment.

      Parameters
      • radiance: WIDTH * BAND_HEIGHT * 3 floats, row by row from straight up
      Returns

      the ARGB pixels of the texture, WIDTH by BAND_HEIGHT * BANDS