Class SkyOptions

java.lang.Object
com.massifmaps.components.SkyOptions

public class SkyOptions extends Object
Shader-based sky configuration, attached to the map via Options::setSkyOptions.

The sky is drawn as a single full-screen pass before everything else, so it costs one
quad regardless of the camera. Type picks what that pass draws: a physical atmosphere
(the default) or the older two-colour gradient. Either way the sun direction comes from
Options::getLightOptions and the fog comes from Options::getFogOptions, so the sky is
hazed by exactly what the ground is hazed by.

The whole appearance can be replaced with setShaderSource. The supplied GLSL must define

vec4 skyColor(vec3 rayDir);

where rayDir is the normalised world-space view ray for the fragment (x east, y north,
z up), and the result is the non-premultiplied sky colour. These are available to it:

uniform vec3 u_sunDir; // unit vector towards the sun, world space
uniform vec4 u_sunColor; // sun colour, rgba 0..1
uniform vec4 u_skyColor; // configured sky colour (zenith), rgba 0..1
uniform vec4 u_horizonColor; // configured horizon colour, rgba 0..1
uniform vec4 u_groundColor; // configured colour below the horizon, rgba 0..1
uniform float u_horizonBlend; // gradient width in radians
uniform float u_sunIntensity; // LightOptions sun intensity
uniform float u_sunDisc; // 1 when the sun disc is enabled
uniform vec4 u_atmosphere; // sun intensity, luminance, unused, unused
uniform vec4 u_atmosphereColor; // Rayleigh tint, a = strength
uniform vec4 u_haloColor; // Mie tint, a = strength
uniform float u_starIntensity; // FogOptions star intensity
uniform float u_time; // seconds since the map view was created
uniform float u_zoom; // current fractional map zoom
uniform float u_cameraHeight; // camera height above the map plane, in metres
uniform vec2 u_resolution; // viewport size in pixels

plus the fog block documented on FogOptions::setShaderSource. Redeclaring any of them is a
compile error, and the renderer then falls back to the built-in sky.

Note: this class is experimental and may change or even be removed in future SDK versions.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a SkyOptions object with default values.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the tint applied to Rayleigh scattering.
    float
    Returns the exposure applied to the scattered light.
    float
    Returns the brightness of the sun driving the atmosphere.
    Returns the ground color.
    Returns the tint applied to Mie scattering.
    float
    Returns the angular blend width between the horizon color and the sky color.
    Returns the horizon color.
    int
    Returns how finely the atmosphere is integrated.
    Returns the custom sky fragment shader source, or an empty string if the built-in
    shader is used.
    Returns the zenith sky color.
    int
    Returns what the sky pass draws.
    boolean
    Returns whether the shader sky is enabled.
    boolean
    Returns whether the built-in shader draws a sun disc.
    void
    Sets the tint of the Rayleigh term - the blue of the sky - as Mapbox sky-atmosphere-color.
    The alpha channel scales how much of it there is, so a lower alpha thins the atmosphere.
    Style property: "sky-atmosphere-color".
    void
    setAtmosphereLuminance(float luminance)
    Sets the exposure the scattered light is tonemapped with.
    void
    setAtmosphereSunIntensity(float intensity)
    Sets how bright the sun that lights the atmosphere is - Mapbox sky-atmosphere-sun-intensity.
    This is the scattering model's own sun, not LightOptions' ground light; raising it
    brightens the whole sky rather than only the disc.
    Style property: "sky-atmosphere-sun-intensity".
    void
    setEnabled(boolean enabled)
    Enables or disables the shader sky.
    void
    Sets the color drawn below the horizon.
    void
    Sets the tint of the Mie term - the halo around the sun and the whiteness near the
    horizon - as Mapbox sky-atmosphere-halo-color.
    void
    setHorizonBlend(float degrees)
    Sets how far above the horizon, in degrees, the horizon color fades into the sky color.
    void
    Sets the horizon color, used by the built-in shader at the horizon line.
    void
    setQuality(int quality)
    Sets how finely the atmosphere is integrated.
    void
    setShaderSource(String shaderSource)
    Sets a custom sky fragment shader.
    void
    Sets the zenith sky color, used by the built-in shader at the top of the sky.
    void
    setSunDiscEnabled(boolean enabled)
    Enables or disables the sun disc and its glow in the built-in shader.
    void
    setType(int type)
    Sets what the sky pass draws - a physical atmosphere or the two-colour gradient.
    SKY_TYPE_GRADIENT is what the SDK drew before the atmosphere existed and is the one to
    pick for a flat or stylised sky; it ignores every Atmosphere* property.
    Style property: "sky-type" ("gradient" or "atmosphere").

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SkyOptions

      public SkyOptions()
      Constructs a SkyOptions object with default values.
  • Method Details

    • isEnabled

      public boolean isEnabled()
      Returns whether the shader sky is enabled.
      Returns:
      True if the shader sky is drawn. The default is true.
    • setEnabled

      public void setEnabled(boolean enabled)
      Enables or disables the shader sky. When disabled, the legacy sky bitmap band
      (Options::setSkyColor / the style sky bitmap) is drawn instead.
      Parameters:
      enabled - True to draw the shader sky.
    • getType

      public int getType()
      Returns what the sky pass draws.
      Returns:
      The sky type. The default is SKY_TYPE_ATMOSPHERE.
    • setType

      public void setType(int type)
      Sets what the sky pass draws - a physical atmosphere or the two-colour gradient.
      SKY_TYPE_GRADIENT is what the SDK drew before the atmosphere existed and is the one to
      pick for a flat or stylised sky; it ignores every Atmosphere* property.
      Style property: "sky-type" ("gradient" or "atmosphere").
      Parameters:
      type - The new sky type.
    • getQuality

      public int getQuality()
      Returns how finely the atmosphere is integrated.
      Returns:
      The quality. The default is SKY_QUALITY_MEDIUM.
    • setQuality

      public void setQuality(int quality)
      Sets how finely the atmosphere is integrated. The cost is per fragment of visible sky,
      so a low-tilt camera that fills the screen with sky is what this pays for. Ignored by
      SKY_TYPE_GRADIENT.
      Parameters:
      quality - The new quality.
    • getAtmosphereSunIntensity

      public float getAtmosphereSunIntensity()
      Returns the brightness of the sun driving the atmosphere.
      Returns:
      The sun intensity. The default is 10.
    • setAtmosphereSunIntensity

      public void setAtmosphereSunIntensity(float intensity)
      Sets how bright the sun that lights the atmosphere is - Mapbox sky-atmosphere-sun-intensity.
      This is the scattering model's own sun, not LightOptions' ground light; raising it
      brightens the whole sky rather than only the disc.
      Style property: "sky-atmosphere-sun-intensity".
      Parameters:
      intensity - The new sun intensity (clamped to 0 and above).
    • getAtmosphereColor

      public Color getAtmosphereColor()
      Returns the tint applied to Rayleigh scattering.
      Returns:
      The atmosphere color. The default is opaque white, i.e. no tint.
    • setAtmosphereColor

      public void setAtmosphereColor(Color color)
      Sets the tint of the Rayleigh term - the blue of the sky - as Mapbox sky-atmosphere-color.
      The alpha channel scales how much of it there is, so a lower alpha thins the atmosphere.
      Style property: "sky-atmosphere-color".
      Parameters:
      color - The new atmosphere color.
    • getHaloColor

      public Color getHaloColor()
      Returns the tint applied to Mie scattering.
      Returns:
      The halo color. The default is opaque white, i.e. no tint.
    • setHaloColor

      public void setHaloColor(Color color)
      Sets the tint of the Mie term - the halo around the sun and the whiteness near the
      horizon - as Mapbox sky-atmosphere-halo-color. The alpha channel scales its strength.
      Style property: "sky-atmosphere-halo-color".
      Parameters:
      color - The new halo color.
    • getAtmosphereLuminance

      public float getAtmosphereLuminance()
      Returns the exposure applied to the scattered light.
      Returns:
      The luminance. The default is 1.
    • setAtmosphereLuminance

      public void setAtmosphereLuminance(float luminance)
      Sets the exposure the scattered light is tonemapped with. Lower values brighten the sky,
      which is what a night or a heavily tinted atmosphere needs to stay readable.
      Style property: "sky-atmosphere-luminance".
      Parameters:
      luminance - The new luminance (clamped to 0.01 and above).
    • getSkyColor

      public Color getSkyColor()
      Returns the zenith sky color.
      Returns:
      The sky color. The default is a light blue.
    • setSkyColor

      public void setSkyColor(Color color)
      Sets the zenith sky color, used by the built-in shader at the top of the sky.
      Parameters:
      color - The new sky color.
    • getHorizonColor

      public Color getHorizonColor()
      Returns the horizon color.
      Returns:
      The horizon color. The default is a pale blue-white.
    • setHorizonColor

      public void setHorizonColor(Color color)
      Sets the horizon color, used by the built-in shader at the horizon line.
      Parameters:
      color - The new horizon color.
    • getGroundColor

      public Color getGroundColor()
      Returns the ground color.
      Returns:
      The color drawn below the horizon. The default is the horizon color.
    • setGroundColor

      public void setGroundColor(Color color)
      Sets the color drawn below the horizon. The map normally covers that part of the
      screen, so this only shows in the wedge between the far edge of the drawn map and
      the mathematical horizon - it should stay close to the horizon color, which is the
      default. Setting it transparent leaves the clear color there.
      Parameters:
      color - The new ground color.
    • getHorizonBlend

      public float getHorizonBlend()
      Returns the angular blend width between the horizon color and the sky color.
      Returns:
      The blend width in degrees. The default is 12.
    • setHorizonBlend

      public void setHorizonBlend(float degrees)
      Sets how far above the horizon, in degrees, the horizon color fades into the sky color.
      Parameters:
      degrees - The new blend width in degrees (clamped to 0..90).
    • isSunDiscEnabled

      public boolean isSunDiscEnabled()
      Returns whether the built-in shader draws a sun disc.
      Returns:
      True if the sun disc is drawn. The default is true.
    • setSunDiscEnabled

      public void setSunDiscEnabled(boolean enabled)
      Enables or disables the sun disc and its glow in the built-in shader.
      Parameters:
      enabled - True to draw the sun disc.
    • getShaderSource

      public String getShaderSource()
      Returns the custom sky fragment shader source, or an empty string if the built-in
      shader is used.
      Returns:
      The custom shader source.
    • setShaderSource

      public void setShaderSource(String shaderSource)
      Sets a custom sky fragment shader. The source must define
      "vec4 skyColor(vec3 rayDir)" and may use the uniforms documented on this class.
      Pass an empty string to go back to the built-in shader. If the shader fails to
      compile, the built-in shader is used and the error is logged.
      Parameters:
      shaderSource - The GLSL source, or an empty string for the built-in shader.