Class EnvMapUtils

java.lang.Object
com.jme3.environment.util.EnvMapUtils

public class EnvMapUtils extends Object
This class holds several utility method useful for Physically Based Rendering. It allows us to compute useful prefiltered maps from an env map.
  • Field Details

    • NUM_SH_COEFFICIENT

      public static final int NUM_SH_COEFFICIENT
      See Also:
    • shBandFactor

      public static float[] shBandFactor
  • Method Details

    • makeCubeMap

      public static TextureCubeMap makeCubeMap(Image rightImg, Image leftImg, Image upImg, Image downImg, Image backImg, Image frontImg, Image.Format format)
      Creates a cube map from 6 images
      Parameters:
      leftImg - the west side image, also called negative x (negX) or left image
      rightImg - the east side image, also called positive x (posX) or right image
      downImg - the bottom side image, also called negative y (negY) or down image
      upImg - the top side image, also called positive y (posY) or up image
      backImg - the south side image, also called positive z (posZ) or back image
      frontImg - the north side image, also called negative z (negZ) or front image
      format - the format of the image
      Returns:
      a cube map
    • duplicateCubeMap

      public static TextureCubeMap duplicateCubeMap(TextureCubeMap sourceMap)
      Make a duplicate of this cube Map. That means that it's another instant od TextureCubeMap, but the underlying buffers are duplicates of the original ones. see ByteBuffer.duplicate() Use this if you need to read from the map from multiple threads, it should guaranty the thread safety. Note that if you want to write to the cube map you have to make sure that the different thread do not write to the same area of the buffer. The position, limit and mark are not an issue.
      Parameters:
      sourceMap - the map to be copied (not null, unaffected)
      Returns:
      a new instance
    • getVectorFromCubemapFaceTexCoord

      public static Vector3f getVectorFromCubemapFaceTexCoord(int x, int y, int mapSize, int face, Vector3f store, EnvMapUtils.FixSeamsMethod fixSeamsMethod)
      Computes the 3 component vector coordinates for the given face and coords
      Parameters:
      x - the x texture coordinate
      y - the y texture coordinate
      mapSize - the size of a face of the cube map
      face - the face to consider
      store - a vector3f where the resulting vector will be stored
      fixSeamsMethod - the method to fix the seams
      Returns:
      either store or a new vector
    • getCubemapFaceTexCoordFromVector

      public static int getCubemapFaceTexCoordFromVector(Vector3f texelVect, int mapSize, Vector2f store, EnvMapUtils.FixSeamsMethod fixSeamsMethod)
      Computes the texture coordinates and the face of the cube map from the given vector
      Parameters:
      texelVect - the vector to fetch texels from the cube map
      fixSeamsMethod - the method to fix the seams
      mapSize - the size of one face of the cube map
      store - a Vector2f where the texture coordinates will be stored
      Returns:
      the face from which to fetch the texel
    • getSampleFromMip

      public static int getSampleFromMip(int mipLevel, int miptot)
    • getRoughnessFromMip

      public static float getRoughnessFromMip(int mipLevel, int miptot)
    • getMipFromRoughness

      public static float getMipFromRoughness(float roughness, int miptot)
    • getSphericalHarmonicsCoefficents

      public static Vector3f[] getSphericalHarmonicsCoefficents(TextureCubeMap cubeMap)
      Parameters:
      cubeMap - the environment cube map to compute SH for
      Returns:
      an array of 9 vectors representing the coefficients for each RGB channel
    • getSphericalHarmonicsCoefficents

      public static Vector3f[] getSphericalHarmonicsCoefficents(TextureCubeMap cubeMap, EnvMapUtils.FixSeamsMethod fixSeamsMethod)
      Returns the Spherical Harmonics coefficients for this cube map. The method used is the one from this article: http://graphics.stanford.edu/papers/envmap/envmap.pdf Another good resource for spherical harmonics: http://dickyjim.wordpress.com/2013/09/04/spherical-harmonics-for-beginners/
      Parameters:
      cubeMap - the environment cube map to compute SH for
      fixSeamsMethod - method to fix seams when computing the SH coefficients
      Returns:
      an array of 9 vectors representing the coefficients for each RGB channel
    • evalShBasis

      public static void evalShBasis(Vector3f texelVect, float[] shDir)
      Computes SH coefficient for a given textel dir The method used is the one from this article : http://graphics.stanford.edu/papers/envmap/envmap.pdf
      Parameters:
      texelVect - the input texel (not null, unaffected)
      shDir - storage for the results
    • prepareShCoefs

      public static void prepareShCoefs(Vector3f[] shCoefs)
    • getHammersleyPoint

      public static Vector4f getHammersleyPoint(int i, int nbrSample, Vector4f store)
    • importanceSampleGGX

      public static Vector3f importanceSampleGGX(Vector4f xi, float a2, Vector3f normal, Vector3f store, TempVars vars)
    • getCubeMapCrossDebugView

      public static Node getCubeMapCrossDebugView(TextureCubeMap cubeMap, AssetManager assetManager)
      Creates a debug Node of the given cube map to attach to the gui node the cube map is layered this way :
               _____
              |     |
              | +Y  |
         _____|_____|_____ _____
        |     |     |     |     |
        | -X  | +Z  | +X  | -Z  |
        |_____|_____|_____|_____|
              |     |
              | -Y  |
              |_____|
      
      
      Parameters:
      cubeMap - the cube map
      assetManager - the asset Manager
      Returns:
      a new Node
    • getCubeMapCrossDebugViewWithMipMaps

      public static Node getCubeMapCrossDebugViewWithMipMaps(TextureCubeMap cubeMap, AssetManager assetManager)
    • createIrradianceMap

      public static TextureCubeMap createIrradianceMap(int size, Image.Format imageFormat)
      initialize the irradiance map
      Parameters:
      size - the size of the map
      imageFormat - the format of the image
      Returns:
      the initialized Irradiance map
    • createPrefilteredEnvMap

      public static TextureCubeMap createPrefilteredEnvMap(int size, Image.Format imageFormat)
      initialize the pem map
      Parameters:
      size - the size of the map
      imageFormat - the format of the image
      Returns:
      the initialized prefiltered env map