Class SimpleWaterProcessor

java.lang.Object
com.jme3.water.SimpleWaterProcessor
All Implemented Interfaces:
com.jme3.post.SceneProcessor

public class SimpleWaterProcessor extends Object implements com.jme3.post.SceneProcessor
Simple Water renders a simple plane that use reflection and refraction to look like water. It's pretty basic, but much faster than the WaterFilter It's useful if you aim for low specs hardware and still want good-looking water. Usage is: SimpleWaterProcessor waterProcessor = new SimpleWaterProcessor(assetManager); //setting the scene to use for reflection waterProcessor.setReflectionScene(mainScene); //setting the light position waterProcessor.setLightPosition(lightPos); //setting the water plane Vector3f waterLocation=new Vector3f(0,-20,0); waterProcessor.setPlane(new Plane(Vector3f.UNIT_Y, waterLocation.dot(Vector3f.UNIT_Y))); //setting the water color waterProcessor.setWaterColor(ColorRGBA.Brown); //creating a quad to render water to Quad quad = new Quad(400,400); //the texture coordinates define the general size of the waves quad.scaleTextureCoordinates(new Vector2f(6f,6f)); //creating a geom to attach the water material Geometry water=new Geometry("water", quad); water.setLocalTranslation(-200, -20, 250); water.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X)); //finally setting the material water.setMaterial(waterProcessor.getMaterial()); //attaching the water to the root node rootNode.attachChild(water);
Author:
Normen Hansen and Rémy Bouquet
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    class 
    Refraction Processor
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
     
    protected com.jme3.texture.Texture2D
     
    protected com.jme3.texture.Texture2D
     
    protected com.jme3.asset.AssetManager
     
    protected com.jme3.material.Material
     
    protected com.jme3.texture.Texture2D
     
    protected com.jme3.math.Plane
     
    protected com.jme3.math.Ray
     
    protected com.jme3.texture.FrameBuffer
     
    protected com.jme3.renderer.Camera
     
    protected com.jme3.scene.Spatial
     
    protected com.jme3.texture.Texture2D
     
    protected com.jme3.renderer.ViewPort
     
    protected com.jme3.texture.FrameBuffer
     
    protected com.jme3.renderer.Camera
     
    protected com.jme3.texture.Texture2D
     
    protected com.jme3.renderer.ViewPort
     
    protected int
     
    protected int
     
    protected com.jme3.renderer.RenderManager
     
    protected float
     
    protected com.jme3.math.Vector3f
     
    protected com.jme3.renderer.ViewPort
     
    protected float
     
    protected float
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    SimpleWaterProcessor(com.jme3.asset.AssetManager manager)
    Creates a SimpleWaterProcessor
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    applyTextures(com.jme3.material.Material mat)
     
    void
     
    protected void
     
    protected void
     
    com.jme3.scene.Geometry
    createWaterGeometry(float width, float height)
    Creates a quad with the water material applied to it.
    protected void
     
    protected void
    displayMap(com.jme3.renderer.Renderer r, com.jme3.ui.Picture pic, int left)
     
    float
    returns how the normal and dudv map are mixed to create the wave effect, default = 0.5
    float
    returns the scale of distortion by the normal map, default = 0.2
    com.jme3.material.Material
    Get the water material from this processor, apply this to your water quad.
    com.jme3.math.Plane
    returns the water plane
    float
    returns the reflection clipping plane offset
    float
    returns the refraction clipping plane offset
    int
    returns the height of the reflection and refraction textures
    int
    returns the width of the reflection and refraction textures
    float
    returns the scale of the normal/dudv texture, default = 1.
    float
    return the water depth
    float
    returns water transparency
    float
    returns the speed of the wave animation.
    void
    initialize(com.jme3.renderer.RenderManager rm, com.jme3.renderer.ViewPort vp)
     
    boolean
    returns true if the water processor is in debug mode
    boolean
     
    protected void
    loadTextures(com.jme3.asset.AssetManager manager)
     
    void
    postFrame(com.jme3.texture.FrameBuffer out)
     
    void
    postQueue(com.jme3.renderer.queue.RenderQueue rq)
     
    void
    preFrame(float tpf)
     
    void
    reshape(com.jme3.renderer.ViewPort vp, int w, int h)
     
    void
    setDebug(boolean debug)
    set to true to display reflection and refraction textures in the GUI for debug purpose
    void
    setDistortionMix(float value)
    Sets how the normal and dudv map are mixed to create the wave effect, default = 0.5
    void
    setDistortionScale(float value)
    Sets the scale of distortion by the normal map, default = 0.2
    void
    setLightPosition(com.jme3.math.Vector3f position)
    Set the light Position for the processor
    void
    setPlane(com.jme3.math.Plane plane)
    Set the water plane for this processor.
    void
    setPlane(com.jme3.math.Vector3f origin, com.jme3.math.Vector3f normal)
    Set the water plane using an origin (location) and a normal (reflection direction).
    void
    setProfiler(com.jme3.profile.AppProfiler profiler)
     
    void
    setReflectionClippingOffset(float reflectionClippingOffset)
    sets the reflection clipping plane offset set a negative value to lower the clipping plane for reflection texture rendering.
    void
    setReflectionScene(com.jme3.scene.Spatial spat)
    Sets the reflected scene, should not include the water quad! Set before adding processor.
    void
    setRefractionClippingOffset(float refractionClippingOffset)
    Sets the refraction clipping plane offset set a positive value to raise the clipping plane for refraction texture rendering
    void
    setRenderSize(int width, int height)
    Set the reflection Texture render size, set before adding the processor!
    void
    setTexScale(float value)
    Sets the scale of the normal/dudv texture, default = 1.
    void
    setWaterColor(com.jme3.math.ColorRGBA color)
    Set the color that will be added to the refraction texture.
    void
    setWaterDepth(float depth)
    Higher values make the refraction texture shine through earlier.
    void
    setWaterTransparency(float waterTransparency)
    sets the water transparency default is 0.4f
    void
    setWaveSpeed(float speed)
    Sets the speed of the wave animation, default = 0.05f.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.jme3.post.SceneProcessor

    rescale
  • Field Details

    • rm

      protected com.jme3.renderer.RenderManager rm
    • vp

      protected com.jme3.renderer.ViewPort vp
    • reflectionScene

      protected com.jme3.scene.Spatial reflectionScene
    • reflectionView

      protected com.jme3.renderer.ViewPort reflectionView
    • refractionView

      protected com.jme3.renderer.ViewPort refractionView
    • reflectionBuffer

      protected com.jme3.texture.FrameBuffer reflectionBuffer
    • refractionBuffer

      protected com.jme3.texture.FrameBuffer refractionBuffer
    • reflectionCam

      protected com.jme3.renderer.Camera reflectionCam
    • refractionCam

      protected com.jme3.renderer.Camera refractionCam
    • reflectionTexture

      protected com.jme3.texture.Texture2D reflectionTexture
    • refractionTexture

      protected com.jme3.texture.Texture2D refractionTexture
    • depthTexture

      protected com.jme3.texture.Texture2D depthTexture
    • normalTexture

      protected com.jme3.texture.Texture2D normalTexture
    • dudvTexture

      protected com.jme3.texture.Texture2D dudvTexture
    • renderWidth

      protected int renderWidth
    • renderHeight

      protected int renderHeight
    • plane

      protected com.jme3.math.Plane plane
    • speed

      protected float speed
    • ray

      protected com.jme3.math.Ray ray
    • targetLocation

      protected com.jme3.math.Vector3f targetLocation
    • manager

      protected com.jme3.asset.AssetManager manager
    • material

      protected com.jme3.material.Material material
    • waterDepth

      protected float waterDepth
    • waterTransparency

      protected float waterTransparency
    • debug

      protected boolean debug
  • Constructor Details

    • SimpleWaterProcessor

      public SimpleWaterProcessor(com.jme3.asset.AssetManager manager)
      Creates a SimpleWaterProcessor
      Parameters:
      manager - the asset manager
  • Method Details

    • initialize

      public void initialize(com.jme3.renderer.RenderManager rm, com.jme3.renderer.ViewPort vp)
      Specified by:
      initialize in interface com.jme3.post.SceneProcessor
    • reshape

      public void reshape(com.jme3.renderer.ViewPort vp, int w, int h)
      Specified by:
      reshape in interface com.jme3.post.SceneProcessor
    • isInitialized

      public boolean isInitialized()
      Specified by:
      isInitialized in interface com.jme3.post.SceneProcessor
    • preFrame

      public void preFrame(float tpf)
      Specified by:
      preFrame in interface com.jme3.post.SceneProcessor
    • postQueue

      public void postQueue(com.jme3.renderer.queue.RenderQueue rq)
      Specified by:
      postQueue in interface com.jme3.post.SceneProcessor
    • postFrame

      public void postFrame(com.jme3.texture.FrameBuffer out)
      Specified by:
      postFrame in interface com.jme3.post.SceneProcessor
    • cleanup

      public void cleanup()
      Specified by:
      cleanup in interface com.jme3.post.SceneProcessor
    • setProfiler

      public void setProfiler(com.jme3.profile.AppProfiler profiler)
      Specified by:
      setProfiler in interface com.jme3.post.SceneProcessor
    • displayMap

      protected void displayMap(com.jme3.renderer.Renderer r, com.jme3.ui.Picture pic, int left)
    • loadTextures

      protected void loadTextures(com.jme3.asset.AssetManager manager)
    • createTextures

      protected void createTextures()
    • applyTextures

      protected void applyTextures(com.jme3.material.Material mat)
    • createPreViews

      protected void createPreViews()
    • destroyViews

      protected void destroyViews()
    • getMaterial

      public com.jme3.material.Material getMaterial()
      Get the water material from this processor, apply this to your water quad.
      Returns:
      the pre-existing Material
    • setReflectionScene

      public void setReflectionScene(com.jme3.scene.Spatial spat)
      Sets the reflected scene, should not include the water quad! Set before adding processor.
      Parameters:
      spat - the scene-graph subtree to be reflected (alias created)
    • getRenderWidth

      public int getRenderWidth()
      returns the width of the reflection and refraction textures
      Returns:
      the width (in pixels)
    • getRenderHeight

      public int getRenderHeight()
      returns the height of the reflection and refraction textures
      Returns:
      the height (in pixels)
    • setRenderSize

      public void setRenderSize(int width, int height)
      Set the reflection Texture render size, set before adding the processor!
      Parameters:
      width - the desired width (in pixels, default=512)
      height - the desired height (in pixels, default=512)
    • getPlane

      public com.jme3.math.Plane getPlane()
      returns the water plane
      Returns:
      the pre-existing instance
    • setPlane

      public void setPlane(com.jme3.math.Plane plane)
      Set the water plane for this processor.
      Parameters:
      plane - the Plane to use (not null, unaffected)
    • setPlane

      public void setPlane(com.jme3.math.Vector3f origin, com.jme3.math.Vector3f normal)
      Set the water plane using an origin (location) and a normal (reflection direction).
      Parameters:
      origin - Set to 0,-6,0 if your water quad is at that location for correct reflection
      normal - Set to 0,1,0 (Vector3f.UNIT_Y) for normal planar water
    • setLightPosition

      public void setLightPosition(com.jme3.math.Vector3f position)
      Set the light Position for the processor
      Parameters:
      position - the desired location (in world coordinates, alias created)
    • setWaterColor

      public void setWaterColor(com.jme3.math.ColorRGBA color)
      Set the color that will be added to the refraction texture.
      Parameters:
      color - the desired color (alias created)
    • setWaterDepth

      public void setWaterDepth(float depth)
      Higher values make the refraction texture shine through earlier. Default is 1
      Parameters:
      depth - the desired depth (default=1)
    • getWaterDepth

      public float getWaterDepth()
      return the water depth
      Returns:
      the depth
    • getWaterTransparency

      public float getWaterTransparency()
      returns water transparency
      Returns:
      the transparency value
    • setWaterTransparency

      public void setWaterTransparency(float waterTransparency)
      sets the water transparency default is 0.4f
      Parameters:
      waterTransparency - the desired transparency (default=0.4)
    • setWaveSpeed

      public void setWaveSpeed(float speed)
      Sets the speed of the wave animation, default = 0.05f.
      Parameters:
      speed - the desired animation speed (default=0.05)
    • getWaveSpeed

      public float getWaveSpeed()
      returns the speed of the wave animation.
      Returns:
      the speed
    • setDistortionScale

      public void setDistortionScale(float value)
      Sets the scale of distortion by the normal map, default = 0.2
      Parameters:
      value - the desired scale factor (default=0.2)
    • setDistortionMix

      public void setDistortionMix(float value)
      Sets how the normal and dudv map are mixed to create the wave effect, default = 0.5
      Parameters:
      value - the desired mix fraction (default=0.5)
    • setTexScale

      public void setTexScale(float value)
      Sets the scale of the normal/dudv texture, default = 1. Note that the waves should be scaled by the texture coordinates of the quad to avoid animation artifacts, use mesh.scaleTextureCoordinates(Vector2f) for that.
      Parameters:
      value - the desired scale factor (default=1)
    • getDistortionScale

      public float getDistortionScale()
      returns the scale of distortion by the normal map, default = 0.2
      Returns:
      the distortion scale
    • getDistortionMix

      public float getDistortionMix()
      returns how the normal and dudv map are mixed to create the wave effect, default = 0.5
      Returns:
      the distortion mix
    • getTexScale

      public float getTexScale()
      returns the scale of the normal/dudv texture, default = 1. Note that the waves should be scaled by the texture coordinates of the quad to avoid animation artifacts, use mesh.scaleTextureCoordinates(Vector2f) for that.
      Returns:
      the textures scale
    • isDebug

      public boolean isDebug()
      returns true if the water processor is in debug mode
      Returns:
      true if in debug mode, otherwise false
    • setDebug

      public void setDebug(boolean debug)
      set to true to display reflection and refraction textures in the GUI for debug purpose
      Parameters:
      debug - true to enable display, false to disable it (default=false)
    • createWaterGeometry

      public com.jme3.scene.Geometry createWaterGeometry(float width, float height)
      Creates a quad with the water material applied to it.
      Parameters:
      width - the desired width (in mesh coordinates)
      height - the desired height (in mesh coordinates)
      Returns:
      a new Geometry
    • getReflectionClippingOffset

      public float getReflectionClippingOffset()
      returns the reflection clipping plane offset
      Returns:
      the offset value
    • setReflectionClippingOffset

      public void setReflectionClippingOffset(float reflectionClippingOffset)
      sets the reflection clipping plane offset set a negative value to lower the clipping plane for reflection texture rendering.
      Parameters:
      reflectionClippingOffset - the desired offset (default=-5)
    • getRefractionClippingOffset

      public float getRefractionClippingOffset()
      returns the refraction clipping plane offset
      Returns:
      the offset value
    • setRefractionClippingOffset

      public void setRefractionClippingOffset(float refractionClippingOffset)
      Sets the refraction clipping plane offset set a positive value to raise the clipping plane for refraction texture rendering
      Parameters:
      refractionClippingOffset - the desired offset (default=0.3)