Package com.jme3.water
Class WaterFilter
java.lang.Object
com.jme3.post.Filter
com.jme3.water.WaterFilter
- All Implemented Interfaces:
Savable,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.
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class com.jme3.post.Filter
Filter.Pass -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected Spatialprotected ViewPortprotected SpatialFields inherited from class com.jme3.post.Filter
defaultPass, enabled, material, postRenderPasses, processor -
Constructor Summary
ConstructorsConstructorDescriptionCreate a Water FilterWaterFilter(Node reflectionScene, Vector3f lightDirection) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidoverride this method if you have some cleanup to dovoidcloneFields(Cloner cloner, Object original) Implemented to perform deep cloning for this object, resolving local cloned references using the specified cloner.floatGets the intensity of caustics underwaterGets the texture which is used to render caustics on the ground underwater.returns the center of this effectReturns the color extinction vector of the waterreturns the deep water colorreturns the foam existence vectorfloatreturns the foam hardnessfloatreturns the foam intensityGets the foam texture.Gets the height texture.returns the light colorgets the light directionprotected MaterialMust return the material used for this filter.floatreturn the maximum wave amplitudefloatReturns the normal scales applied to the normal mapGets the normal texture.floatreturns the radius of this effectfloatreturns the reflection displace seesetReflectionDisplace(float)intreturns the size of the reflection mapGets the scene which is used to render in the reflection map.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 underwaterreturns the color of the waterfloatgets the height of the water planefloatreturns the waterTransparency valuefloatReturns the scale factor of the waves' height map.returns the wind directionprotected voidinitFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) Initialization of filter subclasses.booleanprotected booleanOverride this method and return true if your Filter needs the depth texturebooleanWhether 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()Performs a regular shallow clone of the object.protected voidpreFrame(float tpf) Override this method if you want to modify parameters according to tpf before the rendering of the frame.voidread(JmeImporter im) Override this method if you want to load extra properties when the filter is loaded else only basic properties of the filter will be loaded This method should always begin by super.read(im);voidsetCausticsIntensity(float causticsIntensity) Sets the intensity of caustics underwater.voidsetCausticsTexture(Texture2D causticsTexture) Sets the texture to use to render caustics on the ground underwater.voidSet the center of the effect.voidsetColorExtinction(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(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(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(Texture2D foamTexture) Sets the foam texture.voidsetHeightTexture(Texture2D heightTexture) Sets the height texturevoidsetLightColor(ColorRGBA lightColor) Sets the light color to use default is whitevoidsetLightDirection(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(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(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(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(Vector2f windDirection) sets the wind direction the direction where the waves move default is (0.0f, -1.0f)protected booleanvoidwrite(JmeExporter ex) Override this method if you want to save extra properties when the filter is saved else only basic properties of the filter will be saved This method should always begin by super.write(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
-
rootScene
-
reflectionView
-
-
Constructor Details
-
WaterFilter
public WaterFilter()Create a Water Filter -
WaterFilter
-
-
Method Details
-
isRequiresDepthTexture
protected boolean isRequiresDepthTexture()Description copied from class:FilterOverride this method and return true if your Filter needs the depth texture- Overrides:
isRequiresDepthTexturein classFilter- Returns:
- true if your Filter need the depth texture
-
preFrame
protected void preFrame(float tpf) Description copied from class:FilterOverride this method if you want to modify parameters according to tpf before the rendering of the frame. This is useful for animated filters Also it can be the place to render pre passes -
getMaterial
Description copied from class:FilterMust return the material used for this filter. this method is called every frame.- Specified by:
getMaterialin classFilter- Returns:
- the material used for this filter.
-
useDirectionLightFromScene
protected boolean useDirectionLightFromScene()- Returns:
- true to try using directional light from a scene
-
initFilter
protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) Description copied from class:FilterInitialization of filter subclasses. This method is called once when the filter is added to the FilterPostProcessor It should contain Material initializations and extra passes initialization- Specified by:
initFilterin classFilter- Parameters:
manager- the assetManagerrenderManager- the renderManagervp- the viewPort where this filter is renderedw- the width of the filterh- the height of the filter
-
cleanUpFilter
Description copied from class:Filteroverride this method if you have some cleanup to do- Overrides:
cleanUpFilterin classFilter- Parameters:
r- the renderer
-
write
Description copied from class:FilterOverride this method if you want to save extra properties when the filter is saved else only basic properties of the filter will be saved This method should always begin by super.write(ex);- Specified by:
writein interfaceSavable- Overrides:
writein classFilter- Parameters:
ex- the exporter (not null)- Throws:
IOException- from the exporter
-
read
Description copied from class:FilterOverride this method if you want to load extra properties when the filter is loaded else only basic properties of the filter will be loaded This method should always begin by super.read(im);- Specified by:
readin interfaceSavable- Overrides:
readin classFilter- 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
Sets the scene to render in the reflection map.- Parameters:
reflectionScene- the refraction scene.
-
getReflectionScene
Gets the scene which is used to render in the reflection map.- Returns:
- the refraction scene.
-
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
gets the light direction- Returns:
- the pre-existing vector
-
setLightDirection
Sets the light direction- Parameters:
lightDirection- the direction vector to use (alias created, default=(0,-1,0))
-
getLightColor
returns the light color- Returns:
- the pre-existing instance
-
setLightColor
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
returns the foam existence vector- Returns:
- the pre-existing vector
-
setFoamExistence
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
Returns the color extinction vector of the water- Returns:
- the pre-existing vector
-
setColorExtinction
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
Sets the foam texture.- Parameters:
foamTexture- the foam texture.
-
getFoamTexture
Gets the foam texture.- Returns:
- the foam texture.
-
setHeightTexture
Sets the height texture- Parameters:
heightTexture- the texture to use (alias created)
-
getHeightTexture
Gets the height texture.- Returns:
- the height texture.
-
setNormalTexture
Sets the normal texture.- Parameters:
normalTexture- the normal texture.
-
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
returns the color of the water- Returns:
- the pre-existing instance
-
setWaterColor
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
returns the deep water color- Returns:
- the pre-existing instance
-
setDeepWaterColor
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
returns the wind direction- Returns:
- the pre-existing direction vector
-
setWindDirection
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
Sets the texture to use to render caustics on the ground underwater.- Parameters:
causticsTexture- the caustics texture.
-
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
returns the center of this effect- Returns:
- the center of this effect
-
setCenter
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
Description copied from interface:JmeCloneablePerforms a regular shallow clone of the object. Some fields may also be cloned but generally only if they will never be shared with other objects. (For example, local Vector3fs and so on.)This method is separate from the regular clone() method so that objects might still maintain their own regular java clone() semantics (perhaps even using Cloner for those methods). However, because Java's clone() has specific features in the sense of Object's clone() implementation, it's usually best to have some path for subclasses to bypass the public clone() method that might be cloning fields and instead get at the superclass protected clone() methods. For example, through super.jmeClone() or another protected clone method that some base class eventually calls super.clone() in.
- Specified by:
jmeClonein interfaceJmeCloneable- Returns:
- a new instance
-
cloneFields
Description copied from interface:JmeCloneableImplemented to perform deep cloning for this object, resolving local cloned references using the specified cloner. The object can call cloner.clone(fieldValue) to deep clone any of its fields.Note: during normal clone operations the original object will not be needed as the clone has already had all of the fields shallow copied.
- Specified by:
cloneFieldsin interfaceJmeCloneable- Parameters:
cloner- The cloner that is performing the cloning operation. The cloneFields method can call back into the cloner to make clones of its subordinate fields.original- The original object from which this object was cloned. This is provided for the very rare case that this object needs to refer to its original for some reason. In general, all of the relevant values should have been transferred during the shallow clone, and this object need only clone what it wants.
-
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.
-