Package com.jme3.water
Class WaterFilter
java.lang.Object
com.jme3.post.Filter
com.jme3.water.WaterFilter
- All Implemented Interfaces:
com.jme3.export.Savable,com.jme3.util.clone.JmeCloneable,Cloneable
public class WaterFilter
extends com.jme3.post.Filter
implements com.jme3.util.clone.JmeCloneable, Cloneable
The WaterFilter is a 2-D post process that simulates water.
It renders water from both above and below the surface.
See the jMonkeyEngine wiki for more info https://jmonkeyengine.github.io/wiki/jme3/advanced/post-processor_water.html.
- Author:
- Rémy Bouquet aka Nehon
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class com.jme3.post.Filter
com.jme3.post.Filter.Pass -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected com.jme3.scene.Spatialprotected com.jme3.renderer.ViewPortprotected com.jme3.scene.SpatialFields inherited from class com.jme3.post.Filter
defaultPass, enabled, material, postRenderPasses, processor -
Constructor Summary
ConstructorsConstructorDescriptionCreate a Water FilterWaterFilter(com.jme3.scene.Node reflectionScene, com.jme3.math.Vector3f lightDirection) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcleanUpFilter(com.jme3.renderer.Renderer r) voidcloneFields(com.jme3.util.clone.Cloner cloner, Object original) floatGets the intensity of caustics underwatercom.jme3.texture.Texture2DGets the texture which is used to render caustics on the ground underwater.com.jme3.math.Vector3freturns the center of this effectcom.jme3.math.Vector3fReturns the color extinction vector of the watercom.jme3.math.ColorRGBAreturns the deep water colorcom.jme3.math.Vector3freturns the foam existence vectorfloatreturns the foam hardnessfloatreturns the foam intensitycom.jme3.texture.Texture2DGets the foam texture.com.jme3.texture.Texture2DGets the height texture.com.jme3.math.ColorRGBAreturns the light colorcom.jme3.math.Vector3fgets the light directionprotected com.jme3.material.Materialfloatreturn the maximum wave amplitudefloatReturns the normal scales applied to the normal mapcom.jme3.texture.Texture2DGets the normal texture.floatreturns the radius of this effectfloatreturns the reflection displace seesetReflectionDisplace(float)intreturns the size of the reflection mapcom.jme3.scene.SpatialGets the scene which is used to render in the reflection map.com.jme3.renderer.ViewPortGets the view port used to render reflection scene.floatreturns the refraction constantfloatreturns the refractionStrengthreturns the shape of the water areafloatreturn the shininess factor of the waterfloatReturn the shore hardness.floatgetSpeed()returns the speed of the wavesfloatgets the scale of the sunfloatreturns the distance of the fog when underwatercom.jme3.math.ColorRGBAreturns the color of the waterfloatgets the height of the water planefloatreturns the waterTransparency valuefloatReturns the scale factor of the waves' height map.com.jme3.math.Vector2freturns the wind directionprotected voidinitFilter(com.jme3.asset.AssetManager manager, com.jme3.renderer.RenderManager renderManager, com.jme3.renderer.ViewPort vp, int w, int h) booleanprotected booleanbooleanWhether or not the camera is under the water levelbooleanWhether or not caustics are renderedbooleanWhether or not the water uses foambooleanWhether or not the shader is set to use high-quality shoreline.booleanWhether or not the water uses the refractionbooleanWhether or not the water uses ripplesbooleanWhether or not the water is using specularjmeClone()protected voidpreFrame(float tpf) voidread(com.jme3.export.JmeImporter im) voidsetCausticsIntensity(float causticsIntensity) Sets the intensity of caustics underwater.voidsetCausticsTexture(com.jme3.texture.Texture2D causticsTexture) Sets the texture to use to render caustics on the ground underwater.voidsetCenter(com.jme3.math.Vector3f center) Set the center of the effect.voidsetColorExtinction(com.jme3.math.Vector3f colorExtinction) Return at what depth the refraction color extinct the first value is for red the second is for green the third is for blue Play with those parameters to "trouble" the water default is (5.0, 20.0, 30.0f);voidsetDeepWaterColor(com.jme3.math.ColorRGBA deepWaterColor) sets the deep water color see setWaterColor for general color default is (0.0039f, 0.00196f, 0.145f,1.0f) (very dark blue)voidsetFoamExistence(com.jme3.math.Vector3f foamExistence) Describes at what depth foam starts to fade out and at what it is completely invisible.voidsetFoamHardness(float foamHardness) Sets the foam hardness : How much the foam will blend with the shore to avoid hard edged water plane.voidsetFoamIntensity(float foamIntensity) sets the foam intensity default is 0.5fvoidsetFoamTexture(com.jme3.texture.Texture2D foamTexture) Sets the foam texture.voidsetHeightTexture(com.jme3.texture.Texture2D heightTexture) Sets the height texturevoidsetLightColor(com.jme3.math.ColorRGBA lightColor) Sets the light color to use default is whitevoidsetLightDirection(com.jme3.math.Vector3f lightDirection) Sets the light directionvoidsetMaxAmplitude(float maxAmplitude) Sets the maximum waves amplitude default is 1.5voidsetNeedSaveReflectionScene(boolean needSaveReflectionScene) Sets the flag.voidsetNormalScale(float normalScale) Sets the normal scaling factors to apply to the normal map.voidsetNormalTexture(com.jme3.texture.Texture2D normalTexture) Sets the normal texture.voidsetRadius(float radius) Set the radius of the effect.voidsetReflectionDisplace(float reflectionDisplace) Sets the reflection displace.voidsetReflectionMapSize(int reflectionMapSize) Sets the size of the reflection map default is 512, the higher, the better quality, but the slower the effect.voidsetReflectionScene(com.jme3.scene.Spatial reflectionScene) Sets the scene to render in the reflection map.voidsetRefractionConstant(float refractionConstant) This is a constant related to the index of refraction (IOR) used to compute the fresnel term.voidsetRefractionStrength(float refractionStrength) This value modifies current fresnel term.voidsetShapeType(WaterFilter.AreaShape shapeType) Set the shape of the water area (Circular (default) or Square).voidsetShininess(float shininess) Sets the shininess factor of the water default is 0.7fvoidsetShoreHardness(float shoreHardness) The smaller this value is, the softer the transition between shore and water.voidsetSpeed(float speed) Set the speed of the waves (0.0 is still) default is 1.0voidsetSunScale(float sunScale) Sets the scale of the sun for specular effectvoidsetUnderWaterFogDistance(float underWaterFogDistance) Sets the distance of the fog when underwater.voidsetUseCaustics(boolean useCaustics) set to true if you want caustics to be rendered on the ground underwater, false otherwisevoidsetUseFoam(boolean useFoam) set to true to use foam with water default truevoidsetUseHQShoreline(boolean useHQShoreline) voidsetUseRefraction(boolean useRefraction) set to true to use refraction (default is true)voidsetUseRipples(boolean useRipples) Set to true to use ripplesvoidsetUseSpecular(boolean useSpecular) Set to true to use specular lighting on the watervoidsetWaterColor(com.jme3.math.ColorRGBA waterColor) Sets the color of the water see setDeepWaterColor for deep water color default is (0.0078f, 0.3176f, 0.5f,1.0f) (greenish blue)voidsetWaterHeight(float waterHeight) Sets the height of the water plane default is 0.0voidsetWaterTransparency(float waterTransparency) Sets how fast colours fade out.voidsetWaveScale(float waveScale) Sets the scale factor of the waves' height map.voidsetWindDirection(com.jme3.math.Vector2f windDirection) sets the wind direction the direction where the waves move default is (0.0f, -1.0f)protected booleanvoidwrite(com.jme3.export.JmeExporter ex) Methods inherited from class com.jme3.post.Filter
cleanup, getDefaultPassDepthFormat, getDefaultPassTextureFormat, getName, getPostRenderPasses, getRenderedTexture, getRenderFrameBuffer, init, isEnabled, isRequiresBilinear, isRequiresSceneTexture, postFilter, postFrame, postQueue, setDepthTexture, setEnabled, setName, setProcessor, setRenderedTexture, setRenderFrameBuffer
-
Field Details
-
DEFAULT_NORMAL_MAP
- See Also:
-
DEFAULT_FOAM
- See Also:
-
DEFAULT_CAUSTICS
- See Also:
-
DEFAULT_HEIGHT_MAP
- See Also:
-
reflectionScene
protected com.jme3.scene.Spatial reflectionScene -
rootScene
protected com.jme3.scene.Spatial rootScene -
reflectionView
protected com.jme3.renderer.ViewPort reflectionView
-
-
Constructor Details
-
WaterFilter
public WaterFilter()Create a Water Filter -
WaterFilter
public WaterFilter(com.jme3.scene.Node reflectionScene, com.jme3.math.Vector3f lightDirection)
-
-
Method Details
-
isRequiresDepthTexture
protected boolean isRequiresDepthTexture()- Overrides:
isRequiresDepthTexturein classcom.jme3.post.Filter
-
preFrame
protected void preFrame(float tpf) - Overrides:
preFramein classcom.jme3.post.Filter
-
getMaterial
protected com.jme3.material.Material getMaterial()- Specified by:
getMaterialin classcom.jme3.post.Filter
-
useDirectionLightFromScene
protected boolean useDirectionLightFromScene()- Returns:
- true to try using directional light from a scene
-
initFilter
protected void initFilter(com.jme3.asset.AssetManager manager, com.jme3.renderer.RenderManager renderManager, com.jme3.renderer.ViewPort vp, int w, int h) - Specified by:
initFilterin classcom.jme3.post.Filter
-
cleanUpFilter
protected void cleanUpFilter(com.jme3.renderer.Renderer r) - Overrides:
cleanUpFilterin classcom.jme3.post.Filter
-
write
- Specified by:
writein interfacecom.jme3.export.Savable- Overrides:
writein classcom.jme3.post.Filter- Throws:
IOException
-
read
- Specified by:
readin interfacecom.jme3.export.Savable- Overrides:
readin classcom.jme3.post.Filter- Throws:
IOException
-
getWaterHeight
public float getWaterHeight()gets the height of the water plane- Returns:
- the height
-
setWaterHeight
public void setWaterHeight(float waterHeight) Sets the height of the water plane default is 0.0- Parameters:
waterHeight- the desired height (default=0)
-
setReflectionScene
public void setReflectionScene(com.jme3.scene.Spatial reflectionScene) Sets the scene to render in the reflection map.- Parameters:
reflectionScene- the refraction scene.
-
getReflectionScene
public com.jme3.scene.Spatial getReflectionScene()Gets the scene which is used to render in the reflection map.- Returns:
- the refraction scene.
-
getReflectionView
public com.jme3.renderer.ViewPort getReflectionView()Gets the view port used to render reflection scene.- Returns:
- the reflection view port.
-
getWaterTransparency
public float getWaterTransparency()returns the waterTransparency value- Returns:
- the transparency value
-
setWaterTransparency
public void setWaterTransparency(float waterTransparency) Sets how fast colours fade out. You can also think about this as how clear water is. Therefore, use smaller values (e.g. 0.05) for crystal-clear water and bigger values for "muddy" water. default is 0.1f- Parameters:
waterTransparency- the desired muddiness (default=0.1)
-
getNormalScale
public float getNormalScale()Returns the normal scales applied to the normal map- Returns:
- the scale factor
-
setNormalScale
public void setNormalScale(float normalScale) Sets the normal scaling factors to apply to the normal map. the higher the value the more small ripples will be visible on the waves. default is 3- Parameters:
normalScale- the scaling factor (default=3)
-
getRefractionConstant
public float getRefractionConstant()returns the refraction constant- Returns:
- the refraction constant
-
setRefractionConstant
public void setRefractionConstant(float refractionConstant) This is a constant related to the index of refraction (IOR) used to compute the fresnel term. F = R0 + (1-R0)( 1 - N.V)^5 where F is the fresnel term, R0 the constant, N the normal vector and V the view vector. It depends on the substance you are looking through (here water). Default value is 0.5 In practice, the lowest the value and the less the reflection can be seen on water- Parameters:
refractionConstant- the desired R0 value (default=0.5)
-
getMaxAmplitude
public float getMaxAmplitude()return the maximum wave amplitude- Returns:
- the maximum amplitude
-
setMaxAmplitude
public void setMaxAmplitude(float maxAmplitude) Sets the maximum waves amplitude default is 1.5- Parameters:
maxAmplitude- the desired maximum amplitude (default=1.5)
-
getLightDirection
public com.jme3.math.Vector3f getLightDirection()gets the light direction- Returns:
- the pre-existing vector
-
setLightDirection
public void setLightDirection(com.jme3.math.Vector3f lightDirection) Sets the light direction- Parameters:
lightDirection- the direction vector to use (alias created, default=(0,-1,0))
-
getLightColor
public com.jme3.math.ColorRGBA getLightColor()returns the light color- Returns:
- the pre-existing instance
-
setLightColor
public void setLightColor(com.jme3.math.ColorRGBA lightColor) Sets the light color to use default is white- Parameters:
lightColor- the color to use (alias created, default=(1,1,1,1))
-
getShoreHardness
public float getShoreHardness()Return the shore hardness.- Returns:
- the hardness value
-
setShoreHardness
public void setShoreHardness(float shoreHardness) The smaller this value is, the softer the transition between shore and water. If you want hard edges use very big value. Default is 0.1f.- Parameters:
shoreHardness- the desired hardness (default=0.1)
-
getFoamHardness
public float getFoamHardness()returns the foam hardness- Returns:
- the hardness value
-
setFoamHardness
public void setFoamHardness(float foamHardness) Sets the foam hardness : How much the foam will blend with the shore to avoid hard edged water plane. Default is 1.0- Parameters:
foamHardness- the desired hardness (default=1)
-
getRefractionStrength
public float getRefractionStrength()returns the refractionStrength- Returns:
- the strength value
-
setRefractionStrength
public void setRefractionStrength(float refractionStrength) This value modifies current fresnel term. If you want to weaken reflections use bigger value. If you want to emphasize them use a value smaller than 0. Default is 0.- Parameters:
refractionStrength- the desired strength (default=0)
-
getWaveScale
public float getWaveScale()Returns the scale factor of the waves' height map.- Returns:
- the scale factor
-
setWaveScale
public void setWaveScale(float waveScale) Sets the scale factor of the waves' height map. The smaller the value, the bigger the waves. Default is 0.005 .- Parameters:
waveScale- the desired scale factor (default=0.005)
-
getFoamExistence
public com.jme3.math.Vector3f getFoamExistence()returns the foam existence vector- Returns:
- the pre-existing vector
-
setFoamExistence
public void setFoamExistence(com.jme3.math.Vector3f foamExistence) Describes at what depth foam starts to fade out and at what it is completely invisible. The third value is at what height foam for waves appear (+ waterHeight). default is (0.45, 4.35, 1.0);- Parameters:
foamExistence- the desired parameters (alias created)
-
getSunScale
public float getSunScale()gets the scale of the sun- Returns:
- the scale factor
-
setSunScale
public void setSunScale(float sunScale) Sets the scale of the sun for specular effect- Parameters:
sunScale- the desired scale factor (default=3)
-
getColorExtinction
public com.jme3.math.Vector3f getColorExtinction()Returns the color extinction vector of the water- Returns:
- the pre-existing vector
-
setColorExtinction
public void setColorExtinction(com.jme3.math.Vector3f colorExtinction) Return at what depth the refraction color extinct the first value is for red the second is for green the third is for blue Play with those parameters to "trouble" the water default is (5.0, 20.0, 30.0f);- Parameters:
colorExtinction- the desired depth for each color component (alias created, default=(5,20,30))
-
setFoamTexture
public void setFoamTexture(com.jme3.texture.Texture2D foamTexture) Sets the foam texture.- Parameters:
foamTexture- the foam texture.
-
getFoamTexture
public com.jme3.texture.Texture2D getFoamTexture()Gets the foam texture.- Returns:
- the foam texture.
-
setHeightTexture
public void setHeightTexture(com.jme3.texture.Texture2D heightTexture) Sets the height texture- Parameters:
heightTexture- the texture to use (alias created)
-
getHeightTexture
public com.jme3.texture.Texture2D getHeightTexture()Gets the height texture.- Returns:
- the height texture.
-
setNormalTexture
public void setNormalTexture(com.jme3.texture.Texture2D normalTexture) Sets the normal texture.- Parameters:
normalTexture- the normal texture.
-
getNormalTexture
public com.jme3.texture.Texture2D getNormalTexture()Gets the normal texture.- Returns:
- the normal texture.
-
getShininess
public float getShininess()return the shininess factor of the water- Returns:
- the shininess factor
-
setShininess
public void setShininess(float shininess) Sets the shininess factor of the water default is 0.7f- Parameters:
shininess- the desired factor (default=0.7)
-
getSpeed
public float getSpeed()returns the speed of the waves- Returns:
- the speed value
-
setSpeed
public void setSpeed(float speed) Set the speed of the waves (0.0 is still) default is 1.0- Parameters:
speed- the desired speedup factor (default=1)
-
getWaterColor
public com.jme3.math.ColorRGBA getWaterColor()returns the color of the water- Returns:
- the pre-existing instance
-
setWaterColor
public void setWaterColor(com.jme3.math.ColorRGBA waterColor) Sets the color of the water see setDeepWaterColor for deep water color default is (0.0078f, 0.3176f, 0.5f,1.0f) (greenish blue)- Parameters:
waterColor- the color to use (alias created, default=(0.0078,0.3176,0.5,1))
-
getDeepWaterColor
public com.jme3.math.ColorRGBA getDeepWaterColor()returns the deep water color- Returns:
- the pre-existing instance
-
setDeepWaterColor
public void setDeepWaterColor(com.jme3.math.ColorRGBA deepWaterColor) sets the deep water color see setWaterColor for general color default is (0.0039f, 0.00196f, 0.145f,1.0f) (very dark blue)- Parameters:
deepWaterColor- the color to use (alias created, default=(0.0039,0.00196,0.145,1))
-
getWindDirection
public com.jme3.math.Vector2f getWindDirection()returns the wind direction- Returns:
- the pre-existing direction vector
-
setWindDirection
public void setWindDirection(com.jme3.math.Vector2f windDirection) sets the wind direction the direction where the waves move default is (0.0f, -1.0f)- Parameters:
windDirection- the direction vector to use (alias created, default=(0,-1))
-
getReflectionMapSize
public int getReflectionMapSize()returns the size of the reflection map- Returns:
- the size (in pixels)
-
setReflectionMapSize
public void setReflectionMapSize(int reflectionMapSize) Sets the size of the reflection map default is 512, the higher, the better quality, but the slower the effect.- Parameters:
reflectionMapSize- the desired size (in pixels per side, default=512)
-
isUseFoam
public boolean isUseFoam()Whether or not the water uses foam- Returns:
- true if the water uses foam
-
setUseFoam
public void setUseFoam(boolean useFoam) set to true to use foam with water default true- Parameters:
useFoam- true for foam, false for no foam (default=true)
-
setCausticsTexture
public void setCausticsTexture(com.jme3.texture.Texture2D causticsTexture) Sets the texture to use to render caustics on the ground underwater.- Parameters:
causticsTexture- the caustics texture.
-
getCausticsTexture
public com.jme3.texture.Texture2D getCausticsTexture()Gets the texture which is used to render caustics on the ground underwater.- Returns:
- the caustics texture.
-
isUseCaustics
public boolean isUseCaustics()Whether or not caustics are rendered- Returns:
- true if caustics are rendered
-
setUseCaustics
public void setUseCaustics(boolean useCaustics) set to true if you want caustics to be rendered on the ground underwater, false otherwise- Parameters:
useCaustics- true to enable rendering fo caustics, false to disable it (default=true)
-
isUseHQShoreline
public boolean isUseHQShoreline()Whether or not the shader is set to use high-quality shoreline.- Returns:
- true if high-quality shoreline is enabled
-
setUseHQShoreline
public void setUseHQShoreline(boolean useHQShoreline) -
isUseRefraction
public boolean isUseRefraction()Whether or not the water uses the refraction- Returns:
- true if the water uses refraction
-
setUseRefraction
public void setUseRefraction(boolean useRefraction) set to true to use refraction (default is true)- Parameters:
useRefraction- true to enable refraction, false to disable it (default=true)
-
isUseRipples
public boolean isUseRipples()Whether or not the water uses ripples- Returns:
- true if the water is set to use ripples
-
setUseRipples
public void setUseRipples(boolean useRipples) Set to true to use ripples- Parameters:
useRipples- true to enable ripples, false to disable them (default=true)
-
isUseSpecular
public boolean isUseSpecular()Whether or not the water is using specular- Returns:
- true if the water is set to use specular
-
setUseSpecular
public void setUseSpecular(boolean useSpecular) Set to true to use specular lighting on the water- Parameters:
useSpecular- true to enable the specular effect, false to disable it (default=true)
-
getFoamIntensity
public float getFoamIntensity()returns the foam intensity- Returns:
- the intensity value
-
setFoamIntensity
public void setFoamIntensity(float foamIntensity) sets the foam intensity default is 0.5f- Parameters:
foamIntensity- the desired intensity (default=0.5)
-
getReflectionDisplace
public float getReflectionDisplace()returns the reflection displace seesetReflectionDisplace(float)- Returns:
- the displacement value
-
setReflectionDisplace
public void setReflectionDisplace(float reflectionDisplace) Sets the reflection displace. define how troubled will look the reflection in the water. default is 30- Parameters:
reflectionDisplace- the desired displacement (default=30)
-
isUnderWater
public boolean isUnderWater()Whether or not the camera is under the water level- Returns:
- true if the camera is under the water level
-
getUnderWaterFogDistance
public float getUnderWaterFogDistance()returns the distance of the fog when underwater- Returns:
- the distance
-
setUnderWaterFogDistance
public void setUnderWaterFogDistance(float underWaterFogDistance) Sets the distance of the fog when underwater. Default is 120 (120 world units). Use a high value to raise the view range underwater.- Parameters:
underWaterFogDistance- the desired distance (in world units, default=120)
-
getCausticsIntensity
public float getCausticsIntensity()Gets the intensity of caustics underwater- Returns:
- the intensity value (≥0, ≤1)
-
setCausticsIntensity
public void setCausticsIntensity(float causticsIntensity) Sets the intensity of caustics underwater. Goes from 0 to 1, default is 0.5.- Parameters:
causticsIntensity- the desired intensity (≥0, ≤1, default=0.5)
-
getCenter
public com.jme3.math.Vector3f getCenter()returns the center of this effect- Returns:
- the center of this effect
-
setCenter
public void setCenter(com.jme3.math.Vector3f center) Set the center of the effect. By default, the water will extend across the entire scene. By setting a center and a radius you can restrain it to a portion of the scene.- Parameters:
center- the center of the effect
-
getRadius
public float getRadius()returns the radius of this effect- Returns:
- the radius of this effect
-
setRadius
public void setRadius(float radius) Set the radius of the effect. By default, the water will extend across the entire scene. By setting a center and a radius you can restrain it to a portion of the scene.- Parameters:
radius- the radius of the effect
-
getShapeType
returns the shape of the water area- Returns:
- the shape of the water area
-
setShapeType
Set the shape of the water area (Circular (default) or Square). if the shape is square the radius is considered as an extent.- Parameters:
shapeType- the shape type
-
jmeClone
- Specified by:
jmeClonein interfacecom.jme3.util.clone.JmeCloneable
-
cloneFields
- Specified by:
cloneFieldsin interfacecom.jme3.util.clone.JmeCloneable
-
setNeedSaveReflectionScene
public void setNeedSaveReflectionScene(boolean needSaveReflectionScene) Sets the flag.- Parameters:
needSaveReflectionScene- true if need to save reflection scene.
-
isNeedSaveReflectionScene
public boolean isNeedSaveReflectionScene()- Returns:
- true if need to save reflection scene.
-