Package org.xjge.core

Class ShadowMap

java.lang.Object
org.xjge.core.ShadowMap

public final class ShadowMap
extends java.lang.Object
Shadow maps generate a 2D texture that is then projected over the scene to create the appearance of dynamic shadows.

More specifically, the shadow map projects a frustum from the position of the global light source towards the scenes origin point (0, 0, 0) and renders the scene an extra time. The texture created by this process is then formatted as a depth attachment within a framebuffer object.

NOTE: Entities that wish to produce shadows can do so by supplying their model matrix (and texture if necessary) to the depth shader program made accessible through their renderShadow() methods.

Since:
2.0.0
  • Field Summary

    Fields
    Modifier and Type Field Description
    float frustumSize  
    float maxBias  
    float minBias  
    int PCFValue  
    float range  
  • Constructor Summary

    Constructors
    Constructor Description
    ShadowMap()
    Creates a new shadow map object using the default settings provided by the engine.
    ShadowMap​(float minBias, float maxBias, float frustumSize, float range, boolean useLinearFilter, int textureWidth, int textureHeight, boolean showBounds, int PCFValue)
    Creates a new shadow map object using the settings specified.
  • Method Summary

    Modifier and Type Method Description
    void setLightDirection​(float x, float y, float z)
    Sets the direction the world light will point towards.
    void setShowBounds​(boolean value)
    Sets whether the areas beyond the shadow maps frustum are darkened or not.
    void setTextureFilter​(boolean useLinearFilter)
    Sets the type of filtering (linear or nearest neighbor) the shadow maps texture will use.
    void setTextureSize​(int width, int height)
    Sets the dimensions of the texture the shadow map will generate.

    Methods inherited from class java.lang.Object

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

    • PCFValue

      public int PCFValue
    • minBias

      public float minBias
    • maxBias

      public float maxBias
    • frustumSize

      public float frustumSize
    • range

      public float range
  • Constructor Details

    • ShadowMap

      public ShadowMap​(float minBias, float maxBias, float frustumSize, float range, boolean useLinearFilter, int textureWidth, int textureHeight, boolean showBounds, int PCFValue)
      Creates a new shadow map object using the settings specified. The settings listed here can be used to combat issues such as peter-panning and shadow acne.
      Parameters:
      minBias - a small value indicating the minimum amount of shadow bias to offset the depth of all surfaces by
      maxBias - a small value indicating the maximum amount of shadow bias to offset the depth of all surfaces by
      frustumSize - the size of the area the shadow map will attempt to cover. Values may not correspond perfectly to world space.
      range - the maximum distance or depth of the shadow maps influence
      useLinearFilter - if true, the texture will exhibit linear filtering otherwise nearest neighbor filtering will be used
      textureWidth - the width of the shadow map texture (in pixels)
      textureHeight - the height of the shadow map texture (in pixels)
      showBounds - if true, the edges of the shadow texture will be darkened. This is useful in instances where the effected area of the shadow map needs to be exposed for debugging purposes
      PCFValue - indicates how much to blur the edges of shadows. Passing a value of zero will produce hard edges whereas higher numbers will apply the filter more.
    • ShadowMap

      public ShadowMap()
      Creates a new shadow map object using the default settings provided by the engine.
  • Method Details

    • setTextureSize

      public void setTextureSize​(int width, int height)
      Sets the dimensions of the texture the shadow map will generate.
      Parameters:
      width - the width of the shadow map texture (in pixels)
      height - the height of the shadow map texture (in pixels)
    • setTextureFilter

      public void setTextureFilter​(boolean useLinearFilter)
      Sets the type of filtering (linear or nearest neighbor) the shadow maps texture will use.
      Parameters:
      useLinearFilter - if true, the texture will exhibit linear filtering otherwise nearest neighbor filtering will be used
    • setShowBounds

      public void setShowBounds​(boolean value)
      Sets whether the areas beyond the shadow maps frustum are darkened or not. It's often useful to expose the edges of the shadow maps influence for debugging purposes.
      Parameters:
      value - if true, the edges beyond the shadow maps influence will be darkened
    • setLightDirection

      public void setLightDirection​(float x, float y, float z)
      Sets the direction the world light will point towards. By default this is the scenes origin point (0, 0, 0).
      Parameters:
      x - the location along the x axis to point towards
      y - the location along the y axis to point towards
      z - the location along the z axis to point towards