Class WaterFilter

All Implemented Interfaces:
Savable, JmeCloneable, Cloneable

public class WaterFilter extends Filter implements 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
  • Field Details

  • Constructor Details

    • WaterFilter

      public WaterFilter()
      Create a Water Filter
    • WaterFilter

      public WaterFilter(Node reflectionScene, Vector3f lightDirection)
  • Method Details

    • isRequiresDepthTexture

      protected boolean isRequiresDepthTexture()
      Description copied from class: Filter
      Override this method and return true if your Filter needs the depth texture
      isRequiresDepthTexture in class Filter
      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 useful for animated filters Also it can be the place to render pre passes
      preFrame in class Filter
      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
      the material used for this filter.
    • useDirectionLightFromScene

      protected boolean useDirectionLightFromScene()
      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: Filter
      Initialization 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:
      initFilter in class Filter
      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
    • cleanUpFilter

      protected void cleanUpFilter(Renderer r)
      Description copied from class: Filter
      override this method if you have some cleanup to do
      cleanUpFilter in class Filter
      r - the renderer
    • write

      public void write(JmeExporter ex) throws 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
      write in class Filter
      ex - the exporter (not null)
      IOException - from the exporter
    • read

      public void read(JmeImporter im) throws 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;
      Specified by:
      read in interface Savable
      read in class Filter
    • getWaterHeight

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

      public void setWaterHeight(float waterHeight)
      Sets the height of the water plane default is 0.0
      waterHeight - the desired height (default=0)
    • setReflectionScene

      public void setReflectionScene(Spatial reflectionScene)
      Sets the scene to render in the reflection map.
      reflectionScene - the refraction scene.
    • getReflectionScene

      public Spatial getReflectionScene()
      Gets the scene which is used to render in the reflection map.
      the refraction scene.
    • getWaterTransparency

      public float getWaterTransparency()
      returns the waterTransparency value
      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
      waterTransparency - the desired muddiness (default=0.1)
    • getNormalScale

      public float getNormalScale()
      Returns the normal scales applied to the normal map
      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
      normalScale - the scaling factor (default=3)
    • getRefractionConstant

      public float getRefractionConstant()
      returns the refraction constant
      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
      refractionConstant - the desired R0 value (default=0.5)
    • getMaxAmplitude

      public float getMaxAmplitude()
      return the maximum wave amplitude
      the maximum amplitude
    • setMaxAmplitude

      public void setMaxAmplitude(float maxAmplitude)
      Sets the maximum waves amplitude default is 1.5
      maxAmplitude - the desired maximum amplitude (default=1.5)
    • getLightDirection

      public Vector3f getLightDirection()
      gets the light direction
      the pre-existing vector
    • setLightDirection

      public void setLightDirection(Vector3f lightDirection)
      Sets the light direction
      lightDirection - the direction vector to use (alias created, default=(0,-1,0))
    • getLightColor

      public ColorRGBA getLightColor()
      returns the light color
      the pre-existing instance
    • setLightColor

      public void setLightColor(ColorRGBA lightColor)
      Sets the light color to use default is white
      lightColor - the color to use (alias created, default=(1,1,1,1))
    • getShoreHardness

      public float getShoreHardness()
      Return the shore hardness.
      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.
      shoreHardness - the desired hardness (default=0.1)
    • getFoamHardness

      public float getFoamHardness()
      returns the foam hardness
      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
      foamHardness - the desired hardness (default=1)
    • getRefractionStrength

      public float getRefractionStrength()
      returns the refractionStrength
      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.
      refractionStrength - the desired strength (default=0)
    • getWaveScale

      public float getWaveScale()
      Returns the scale factor of the waves' height map.
      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 .
      waveScale - the desired scale factor (default=0.005)
    • getFoamExistence

      public Vector3f getFoamExistence()
      returns the foam existence vector
      the pre-existing vector
    • 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);
      foamExistence - the desired parameters (alias created)
    • getSunScale

      public float getSunScale()
      gets the scale of the sun
      the scale factor
    • setSunScale

      public void setSunScale(float sunScale)
      Sets the scale of the sun for specular effect
      sunScale - the desired scale factor (default=3)
    • getColorExtinction

      public Vector3f getColorExtinction()
      Returns the color extinction vector of the water
      the pre-existing vector
    • 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 those parameters to "trouble" the water default is (5.0, 20.0, 30.0f);
      colorExtinction - the desired depth for each color component (alias created, default=(5,20,30))
    • setFoamTexture

      public void setFoamTexture(Texture2D foamTexture)
      Sets the foam texture.
      foamTexture - the foam texture.
    • getFoamTexture

      public Texture2D getFoamTexture()
      Gets the foam texture.
      the foam texture.
    • setHeightTexture

      public void setHeightTexture(Texture2D heightTexture)
      Sets the height texture
      heightTexture - the texture to use (alias created)
    • getHeightTexture

      public Texture2D getHeightTexture()
      Gets the height texture.
      the height texture.
    • setNormalTexture

      public void setNormalTexture(Texture2D normalTexture)
      Sets the normal texture.
      normalTexture - the normal texture.
    • getNormalTexture

      public Texture2D getNormalTexture()
      Gets the normal texture.
      the normal texture.
    • getShininess

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

      public void setShininess(float shininess)
      Sets the shininess factor of the water default is 0.7f
      shininess - the desired factor (default=0.7)
    • getSpeed

      public float getSpeed()
      returns the speed of the waves
      the speed value
    • setSpeed

      public void setSpeed(float speed)
      Set the speed of the waves (0.0 is still) default is 1.0
      speed - the desired speedup factor (default=1)
    • getWaterColor

      public ColorRGBA getWaterColor()
      returns the color of the water
      the pre-existing instance
    • setWaterColor

      public void setWaterColor(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)
      waterColor - the color to use (alias created, default=(0.0078,0.3176,0.5,1))
    • getDeepWaterColor

      public ColorRGBA getDeepWaterColor()
      returns the deep water color
      the pre-existing instance
    • 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)
      deepWaterColor - the color to use (alias created, default=(0.0039,0.00196,0.145,1))
    • getWindDirection

      public Vector2f getWindDirection()
      returns the wind direction
      the pre-existing direction vector
    • setWindDirection

      public void setWindDirection(Vector2f windDirection)
      sets the wind direction the direction where the waves move default is (0.0f, -1.0f)
      windDirection - the direction vector to use (alias created, default=(0,-1))
    • getReflectionMapSize

      public int getReflectionMapSize()
      returns the size of the reflection map
      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.
      reflectionMapSize - the desired size (in pixels per side, default=512)
    • isUseFoam

      public boolean isUseFoam()
      Whether or not the water uses foam
      true if the water uses foam
    • setUseFoam

      public void setUseFoam(boolean useFoam)
      set to true to use foam with water default true
      useFoam - true for foam, false for no foam (default=true)
    • setCausticsTexture

      public void setCausticsTexture(Texture2D causticsTexture)
      Sets the texture to use to render caustics on the ground underwater.
      causticsTexture - the caustics texture.
    • getCausticsTexture

      public Texture2D getCausticsTexture()
      Gets the texture which is used to render caustics on the ground underwater.
      the caustics texture.
    • isUseCaustics

      public boolean isUseCaustics()
      Whether or not caustics are rendered
      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
      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.
      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
      true if the water uses refraction
    • setUseRefraction

      public void setUseRefraction(boolean useRefraction)
      set to true to use refraction (default is true)
      useRefraction - true to enable refraction, false to disable it (default=true)
    • isUseRipples

      public boolean isUseRipples()
      Whether or not the water uses ripples
      true if the water is set to use ripples
    • setUseRipples

      public void setUseRipples(boolean useRipples)
      Set to true to use ripples
      useRipples - true to enable ripples, false to disable them (default=true)
    • isUseSpecular

      public boolean isUseSpecular()
      Whether or not the water is using specular
      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
      useSpecular - true to enable the specular effect, false to disable it (default=true)
    • getFoamIntensity

      public float getFoamIntensity()
      returns the foam intensity
      the intensity value
    • setFoamIntensity

      public void setFoamIntensity(float foamIntensity)
      sets the foam intensity default is 0.5f
      foamIntensity - the desired intensity (default=0.5)
    • getReflectionDisplace

      public float getReflectionDisplace()
      returns the reflection displace see setReflectionDisplace(float)
      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
      reflectionDisplace - the desired displacement (default=30)
    • isUnderWater

      public boolean isUnderWater()
      Whether or not the camera is under the water level
      true if the camera is under the water level
    • getUnderWaterFogDistance

      public float getUnderWaterFogDistance()
      returns the distance of the fog when underwater
      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.
      underWaterFogDistance - the desired distance (in world units, default=120)
    • getCausticsIntensity

      public float getCausticsIntensity()
      Gets the intensity of caustics underwater
      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.
      causticsIntensity - the desired intensity (≥0, ≤1, default=0.5)
    • getCenter

      public Vector3f getCenter()
      returns the center of this effect
      the center of this effect
    • setCenter

      public void setCenter(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.
      center - the center of the effect
    • getRadius

      public float getRadius()
      returns the radius of this effect
      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.
      radius - the radius of the effect
    • getShapeType

      public WaterFilter.AreaShape getShapeType()
      returns the shape of the water area
      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.
      shapeType - the shape type
    • jmeClone

      public Object jmeClone()
      Description copied from interface: JmeCloneable
      Performs 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:
      jmeClone in interface JmeCloneable
      a new instance
    • cloneFields

      public void cloneFields(Cloner cloner, Object original)
      Description copied from interface: JmeCloneable
      Implemented 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:
      cloneFields in interface JmeCloneable
      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.
      needSaveReflectionScene - true if need to save reflection scene.
    • isNeedSaveReflectionScene

      public boolean isNeedSaveReflectionScene()
      true if need to save reflection scene.