Package com.jme3.environment.util
Class EnvMapUtils
java.lang.Object
com.jme3.environment.util.EnvMapUtils
This class holds several utility method useful for Physically Based
Rendering. It allows us to compute useful prefiltered maps from an env map.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
static enum
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic TextureCubeMap
createIrradianceMap
(int size, Image.Format imageFormat) initialize the irradiance mapstatic TextureCubeMap
createPrefilteredEnvMap
(int size, Image.Format imageFormat) initialize the pem mapstatic TextureCubeMap
duplicateCubeMap
(TextureCubeMap sourceMap) Make a duplicate of this cube Map.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.pdfstatic 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 :static Node
getCubeMapCrossDebugViewWithMipMaps
(TextureCubeMap cubeMap, AssetManager assetManager) 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 vectorstatic Vector4f
getHammersleyPoint
(int i, int nbrSample, Vector4f store) static float
getMipFromRoughness
(float roughness, int miptot) static float
getRoughnessFromMip
(int mipLevel, int miptot) static int
getSampleFromMip
(int mipLevel, int miptot) static Vector3f[]
static Vector3f[]
getSphericalHarmonicsCoefficents
(TextureCubeMap cubeMap, EnvMapUtils.FixSeamsMethod fixSeamsMethod) Returns the Spherical Harmonics coefficients for this cube map.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 coordsstatic Vector3f
importanceSampleGGX
(Vector4f xi, float a2, Vector3f normal, Vector3f store, TempVars vars) static TextureCubeMap
makeCubeMap
(Image rightImg, Image leftImg, Image upImg, Image downImg, Image backImg, Image frontImg, Image.Format format) Creates a cube map from 6 imagesstatic void
prepareShCoefs
(Vector3f[] shCoefs)
-
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 imagerightImg
- the east side image, also called positive x (posX) or right imagedownImg
- the bottom side image, also called negative y (negY) or down imageupImg
- the top side image, also called positive y (posY) or up imagebackImg
- the south side image, also called positive z (posZ) or back imagefrontImg
- the north side image, also called negative z (negZ) or front imageformat
- the format of the image- Returns:
- a cube map
-
duplicateCubeMap
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. seeByteBuffer.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 coordinatey
- the y texture coordinatemapSize
- the size of a face of the cube mapface
- the face to considerstore
- a vector3f where the resulting vector will be storedfixSeamsMethod
- 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 mapfixSeamsMethod
- the method to fix the seamsmapSize
- the size of one face of the cube mapstore
- 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
same asgetSphericalHarmonicsCoefficents(com.jme3.texture.TextureCubeMap, com.jme3.environment.util.EnvMapUtils.FixSeamsMethod)
the fix method used isEnvMapUtils.FixSeamsMethod.Wrap
- 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 forfixSeamsMethod
- method to fix seams when computing the SH coefficients- Returns:
- an array of 9 vectors representing the coefficients for each RGB channel
-
evalShBasis
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
-
getHammersleyPoint
-
importanceSampleGGX
-
getCubeMapCrossDebugView
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 mapassetManager
- the asset Manager- Returns:
- a new Node
-
getCubeMapCrossDebugViewWithMipMaps
public static Node getCubeMapCrossDebugViewWithMipMaps(TextureCubeMap cubeMap, AssetManager assetManager) -
createIrradianceMap
initialize the irradiance map- Parameters:
size
- the size of the mapimageFormat
- the format of the image- Returns:
- the initialized Irradiance map
-
createPrefilteredEnvMap
initialize the pem map- Parameters:
size
- the size of the mapimageFormat
- the format of the image- Returns:
- the initialized prefiltered env map
-