com.jme3.water
Class WaterFilter

java.lang.Object
  extended by com.jme3.post.Filter
      extended by com.jme3.water.WaterFilter
All Implemented Interfaces:
Savable

public class WaterFilter
extends Filter

The WaterFilter is a 2D post process that simulate water. It renders water above and under water. See this blog post for more info http://jmonkeyengine.org/2011/01/15/new-advanced-water-effect-for-jmonkeyengine-3/


Nested Class Summary
static class WaterFilter.AreaShape
           
 
Nested classes/interfaces inherited from class com.jme3.post.Filter
Filter.Pass
 
Field Summary
protected  Ray ray
           
protected  Spatial reflectionScene
           
protected  ViewPort reflectionView
           
 
Fields inherited from class com.jme3.post.Filter
defaultPass, enabled, material, postRenderPasses, processor
 
Constructor Summary
WaterFilter()
          Create a Water Filter
WaterFilter(Node reflectionScene, Vector3f lightDirection)
           
 
Method Summary
 float getCausticsIntensity()
          get the intensity of caustics under water
 Vector3f getCenter()
          returns the center of this effect
 Vector3f getColorExtinction()
          Returns the color exctinction vector of the water
 ColorRGBA getDeepWaterColor()
          returns the deep water color
 Vector3f getFoamExistence()
          returns the foam existance vector
 float getFoamHardness()
          returns the foam hardness
 float getFoamIntensity()
          returns the foam intensity
 ColorRGBA getLightColor()
          returns the light color
 Vector3f getLightDirection()
          gets the light direction
protected  Material getMaterial()
          Must return the material used for this filter.
 float getMaxAmplitude()
          return the maximum wave amplitude
 float getNormalScale()
          Returns the normal scales applied to the normal map
 float getRadius()
          returns the radius of this effect
 float getReflectionDisplace()
          returns the reflection displace see setReflectionDisplace(float)
 int getReflectionMapSize()
          returns the size of the reflection map
 float getRefractionConstant()
          returns the refractoin constant
 float getRefractionStrength()
          returns the refractionStrenght
 WaterFilter.AreaShape getShapeType()
          returns the shape of the water area
 float getShininess()
          return the shininess factor of the water
 float getShoreHardness()
          Return the shoreHardeness
 float getSpeed()
          retruns the speed of the waves
 float getSunScale()
          gets the scale of the sun
 float getUnderWaterFogDistance()
          returns the distance of the fog when under water
 ColorRGBA getWaterColor()
          returns the color of the water
 float getWaterHeight()
          gets the height of the water plane
 float getWaterTransparency()
          returns the waterTransparency value
 float getWaveScale()
          returns the scale factor of the waves height map
 Vector2f getWindDirection()
          returns the wind direction
protected  void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h)
          Initialization of sub classes filters This method is called once when the filter is added to the FilterPostProcessor It should contain Material initializations and extra passes initialization
protected  boolean isRequiresDepthTexture()
          Override this method and return true if your Filter needs the depth texture
 boolean isUnderWater()
          Whether or not the camera is under the water level
 boolean isUseCaustics()
          Whether or not caustics are rendered
 boolean isUseFoam()
          Whether or not the water uses foam
 boolean isUseHQShoreline()
          Whether or not the shader is set to use high-quality shoreline.
 boolean isUseRefraction()
          Whether or not the water uses the refraction
 boolean isUseRipples()
          Whether or not the water uses ripples
 boolean isUseSpecular()
          Whether or not the water is using specular
protected  void preFrame(float tpf)
          Override this method if you want to modify parameters according to tpf before the rendering of the frame.
 void read(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);
 void setCausticsIntensity(float causticsIntensity)
          sets the intensity of caustics under water.
 void setCausticsTexture(Texture2D causticsTexture)
          sets the texture to use to render caustics on the ground underwater
 void setCenter(Vector3f center)
          Set the center of the effect.
 void setColorExtinction(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 thos parameters to "trouble" the water default is (5.0, 20.0, 30.0f);
 void setDeepWaterColor(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)
 void setFoamExistence(Vector3f foamExistence)
          Describes at what depth foam starts to fade out and at what it is completely invisible.
 void setFoamHardness(float foamHardness)
          Sets the foam hardness : How much the foam will blend with the shore to avoid hard edged water plane.
 void setFoamIntensity(float foamIntensity)
          sets the foam intensity default is 0.5f
 void setFoamTexture(Texture2D foamTexture)
          Sets the foam texture
 void setHeightTexture(Texture2D heightTexture)
          Sets the height texture
 void setLightColor(ColorRGBA lightColor)
          Sets the light color to use default is white
 void setLightDirection(Vector3f lightDirection)
          Sets the light direction
 void setMaxAmplitude(float maxAmplitude)
          Sets the maximum waves amplitude default is 1.0
 void setNormalScale(float normalScale)
          Sets the normal scaling factors to apply to the normal map.
 void setNormalTexture(Texture2D normalTexture)
          Sets the normal Texture
 void setRadius(float radius)
          Set the radius of the effect.
 void setReflectionDisplace(float reflectionDisplace)
          Sets the reflection displace.
 void setReflectionMapSize(int reflectionMapSize)
          Sets the size of the reflection map default is 512, the higher, the better quality, but the slower the effect.
 void setReflectionScene(Spatial reflectionScene)
          sets the scene to render in the reflection map
 void setRefractionConstant(float refractionConstant)
          This is a constant related to the index of refraction (IOR) used to compute the fresnel term.
 void setRefractionStrength(float refractionStrength)
          This value modifies current fresnel term.
 void setShapeType(WaterFilter.AreaShape shapeType)
          Set the shape of the water area (Circular (default) or Square).
 void setShininess(float shininess)
          Sets the shinines factor of the water default is 0.7f
 void setShoreHardness(float shoreHardness)
          The smaller this value is, the softer the transition between shore and water.
 void setSpeed(float speed)
          Set the speed of the waves (0.0 is still) default is 1.0
 void setSunScale(float sunScale)
          Sets the scale of the sun for specular effect
 void setUnderWaterFogDistance(float underWaterFogDistance)
          sets the distance of the fog when under water.
 void setUseCaustics(boolean useCaustics)
          set to true if you want caustics to be rendered on the ground underwater, false otherwise
 void setUseFoam(boolean useFoam)
          set to true to use foam with water default true
 void setUseHQShoreline(boolean useHQShoreline)
           
 void setUseRefraction(boolean useRefraction)
          set to true to use refraction (default is true)
 void setUseRipples(boolean useRipples)
          Set to true to use ripples
 void setUseSpecular(boolean useSpecular)
          Set to true to use specular lightings on the water
 void setWaterColor(ColorRGBA waterColor)
          Sets the color of the water see setDeepWaterColor for deep water color default is (0.0078f, 0.5176f, 0.5f,1.0f) (greenish blue)
 void setWaterHeight(float waterHeight)
          Sets the height of the water plane default is 0.0
 void setWaterTransparency(float waterTransparency)
          Sets how fast will colours fade out.
 void setWaveScale(float waveScale)
          Sets the scale factor of the waves height map the smaller the value the bigger the waves default is 0.005f
 void setWindDirection(Vector2f windDirection)
          sets the wind direction the direction where the waves move default is (0.0f, -1.0f)
 void write(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, cleanUpFilter, getDefaultPassDepthFormat, getDefaultPassTextureFormat, getName, getPostRenderPasses, getRenderedTexture, getRenderFrameBuffer, init, isEnabled, isRequiresSceneTexture, postFrame, postQueue, setDepthTexture, setEnabled, setName, setProcessor, setRenderedTexture, setRenderFrameBuffer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

reflectionScene

protected Spatial reflectionScene

reflectionView

protected ViewPort reflectionView

ray

protected Ray ray
Constructor Detail

WaterFilter

public WaterFilter()
Create a Water Filter


WaterFilter

public WaterFilter(Node reflectionScene,
                   Vector3f lightDirection)
Method Detail

isRequiresDepthTexture

protected boolean isRequiresDepthTexture()
Description copied from class: Filter
Override this method and return true if your Filter needs the depth texture

Overrides:
isRequiresDepthTexture in class Filter
Returns:
true if your Filter need the depth texture

preFrame

protected void preFrame(float tpf)
Description copied from class: Filter
Override this method if you want to modify parameters according to tpf before the rendering of the frame. This is usefull for animated filters Also it can be the place to render pre passes

Overrides:
preFrame in class Filter
Parameters:
tpf - the time used to render the previous frame

getMaterial

protected Material getMaterial()
Description copied from class: Filter
Must return the material used for this filter. this method is called every frame.

Specified by:
getMaterial in class Filter
Returns:
the material used for this filter.

initFilter

protected void initFilter(AssetManager manager,
                          RenderManager renderManager,
                          ViewPort vp,
                          int w,
                          int h)
Description copied from class: Filter
Initialization of sub classes filters This method is called once when the filter is added to the FilterPostProcessor It should contain Material initializations and extra passes initialization

Specified by:
initFilter in class Filter
Parameters:
manager - the assetManager
renderManager - the renderManager
vp - the viewPort where this filter is rendered
w - the width of the filter
h - the height of the filter

write

public void write(JmeExporter ex)
           throws java.io.IOException
Description copied from class: Filter
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);

Specified by:
write in interface Savable
Overrides:
write in class Filter
Throws:
java.io.IOException

read

public void read(JmeImporter im)
          throws java.io.IOException
Description copied from class: Filter
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);

Specified by:
read in interface Savable
Overrides:
read in class Filter
Throws:
java.io.IOException

getWaterHeight

public float getWaterHeight()
gets the height of the water plane

Returns:

setWaterHeight

public void setWaterHeight(float waterHeight)
Sets the height of the water plane default is 0.0

Parameters:
waterHeight -

setReflectionScene

public void setReflectionScene(Spatial reflectionScene)
sets the scene to render in the reflection map

Parameters:
reflectionScene -

getWaterTransparency

public float getWaterTransparency()
returns the waterTransparency value

Returns:

setWaterTransparency

public void setWaterTransparency(float waterTransparency)
Sets how fast will colours fade out. You can also think about this values as how clear water is. Therefore use smaller values (eg. 0.05) to have crystal clear water and bigger to achieve "muddy" water. default is 0.1f

Parameters:
waterTransparency -

getNormalScale

public float getNormalScale()
Returns the normal scales applied to the normal map

Returns:

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 1.0

Parameters:
normalScale -

getRefractionConstant

public float getRefractionConstant()
returns the refractoin constant

Returns:

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 tne view vector. It usually depend on the material you are lookinh through (here water). Default value is 0.3f In practice, the lowest the value and the less the reflection can be seen on water

Parameters:
refractionConstant -

getMaxAmplitude

public float getMaxAmplitude()
return the maximum wave amplitude

Returns:

setMaxAmplitude

public void setMaxAmplitude(float maxAmplitude)
Sets the maximum waves amplitude default is 1.0

Parameters:
maxAmplitude -

getLightDirection

public Vector3f getLightDirection()
gets the light direction

Returns:

setLightDirection

public void setLightDirection(Vector3f lightDirection)
Sets the light direction

Parameters:
lightDirection -

getLightColor

public ColorRGBA getLightColor()
returns the light color

Returns:

setLightColor

public void setLightColor(ColorRGBA lightColor)
Sets the light color to use default is white

Parameters:
lightColor -

getShoreHardness

public float getShoreHardness()
Return the shoreHardeness

Returns:

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 -

getFoamHardness

public float getFoamHardness()
returns the foam hardness

Returns:

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 -

getRefractionStrength

public float getRefractionStrength()
returns the refractionStrenght

Returns:

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 empasize them use value smaller then 0. Default is 0.0f.

Parameters:
refractionStrength -

getWaveScale

public float getWaveScale()
returns the scale factor of the waves height map

Returns:

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.005f

Parameters:
waveScale -

getFoamExistence

public Vector3f getFoamExistence()
returns the foam existance vector

Returns:

setFoamExistence

public void setFoamExistence(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 -

getSunScale

public float getSunScale()
gets the scale of the sun

Returns:

setSunScale

public void setSunScale(float sunScale)
Sets the scale of the sun for specular effect

Parameters:
sunScale -

getColorExtinction

public Vector3f getColorExtinction()
Returns the color exctinction vector of the water

Returns:

setColorExtinction

public void setColorExtinction(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 thos parameters to "trouble" the water default is (5.0, 20.0, 30.0f);

Parameters:
colorExtinction -

setFoamTexture

public void setFoamTexture(Texture2D foamTexture)
Sets the foam texture

Parameters:
foamTexture -

setHeightTexture

public void setHeightTexture(Texture2D heightTexture)
Sets the height texture

Parameters:
heightTexture -

setNormalTexture

public void setNormalTexture(Texture2D normalTexture)
Sets the normal Texture

Parameters:
normalTexture -

getShininess

public float getShininess()
return the shininess factor of the water

Returns:

setShininess

public void setShininess(float shininess)
Sets the shinines factor of the water default is 0.7f

Parameters:
shininess -

getSpeed

public float getSpeed()
retruns the speed of the waves

Returns:

setSpeed

public void setSpeed(float speed)
Set the speed of the waves (0.0 is still) default is 1.0

Parameters:
speed -

getWaterColor

public ColorRGBA getWaterColor()
returns the color of the water

Returns:

setWaterColor

public void setWaterColor(ColorRGBA waterColor)
Sets the color of the water see setDeepWaterColor for deep water color default is (0.0078f, 0.5176f, 0.5f,1.0f) (greenish blue)

Parameters:
waterColor -

getDeepWaterColor

public ColorRGBA getDeepWaterColor()
returns the deep water color

Returns:

setDeepWaterColor

public void setDeepWaterColor(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 -

getWindDirection

public Vector2f getWindDirection()
returns the wind direction

Returns:

setWindDirection

public void setWindDirection(Vector2f windDirection)
sets the wind direction the direction where the waves move default is (0.0f, -1.0f)

Parameters:
windDirection -

getReflectionMapSize

public int getReflectionMapSize()
returns the size of the reflection map

Returns:

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 -

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 -

setCausticsTexture

public void setCausticsTexture(Texture2D causticsTexture)
sets the texture to use to render caustics on the ground underwater

Parameters:
causticsTexture -

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 -

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 -

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 -

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 lightings on the water

Parameters:
useSpecular -

getFoamIntensity

public float getFoamIntensity()
returns the foam intensity

Returns:

setFoamIntensity

public void setFoamIntensity(float foamIntensity)
sets the foam intensity default is 0.5f

Parameters:
foamIntensity -

getReflectionDisplace

public float getReflectionDisplace()
returns the reflection displace see setReflectionDisplace(float)

Returns:

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 -

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 under water

Returns:

setUnderWaterFogDistance

public void setUnderWaterFogDistance(float underWaterFogDistance)
sets the distance of the fog when under water. default is 120 (120 world units) use a high value to raise the view range under water

Parameters:
underWaterFogDistance -

getCausticsIntensity

public float getCausticsIntensity()
get the intensity of caustics under water

Returns:

setCausticsIntensity

public void setCausticsIntensity(float causticsIntensity)
sets the intensity of caustics under water. goes from 0 to 1, default is 0.5f

Parameters:
causticsIntensity -

getCenter

public Vector3f getCenter()
returns the center of this effect

Returns:
the center of this effect

setCenter

public void setCenter(Vector3f center)
Set the center of the effect. By default the water will extent to 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 extent to 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

public WaterFilter.AreaShape getShapeType()
returns the shape of the water area

Returns:
the shape of the water area

setShapeType

public void setShapeType(WaterFilter.AreaShape shapeType)
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