Class SimpleWaterProcessor

All Implemented Interfaces:

public class SimpleWaterProcessor extends Object implements 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,; //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);
  • Field Details

    • rm

      protected RenderManager rm
    • vp

      protected ViewPort vp
    • reflectionScene

      protected Spatial reflectionScene
    • reflectionView

      protected ViewPort reflectionView
    • refractionView

      protected ViewPort refractionView
    • reflectionBuffer

      protected FrameBuffer reflectionBuffer
    • refractionBuffer

      protected FrameBuffer refractionBuffer
    • reflectionCam

      protected Camera reflectionCam
    • refractionCam

      protected Camera refractionCam
    • reflectionTexture

      protected Texture2D reflectionTexture
    • refractionTexture

      protected Texture2D refractionTexture
    • depthTexture

      protected Texture2D depthTexture
    • normalTexture

      protected Texture2D normalTexture
    • dudvTexture

      protected Texture2D dudvTexture
    • renderWidth

      protected int renderWidth
    • renderHeight

      protected int renderHeight
    • plane

      protected Plane plane
    • speed

      protected float speed
    • ray

      protected Ray ray
    • targetLocation

      protected Vector3f targetLocation
    • manager

      protected AssetManager manager
    • material

      protected Material material
    • waterDepth

      protected float waterDepth
    • waterTransparency

      protected float waterTransparency
    • debug

      protected boolean debug
  • Constructor Details

    • SimpleWaterProcessor

      public SimpleWaterProcessor(AssetManager manager)
      Creates a SimpleWaterProcessor
      manager - the asset manager
  • Method Details

    • initialize

      public void initialize(RenderManager rm, ViewPort vp)
      Description copied from interface: SceneProcessor
      Called in the render thread to initialize the scene processor.
      Specified by:
      initialize in interface SceneProcessor
      rm - The render manager to which the SP was added to
      vp - The viewport to which the SP is assigned
    • reshape

      public void reshape(ViewPort vp, int w, int h)
      Description copied from interface: SceneProcessor
      Called when the resolution of the viewport has been changed.
      Specified by:
      reshape in interface SceneProcessor
      vp - the affected ViewPort
      w - the new width (in pixels)
      h - the new height (in pixels)
    • isInitialized

      public boolean isInitialized()
      Specified by:
      isInitialized in interface SceneProcessor
      True if initialize() has been called on this SceneProcessor, false if otherwise.
    • preFrame

      public void preFrame(float tpf)
      Description copied from interface: SceneProcessor
      Called before a frame
      Specified by:
      preFrame in interface SceneProcessor
      tpf - Time per frame
    • postQueue

      public void postQueue(RenderQueue rq)
      Description copied from interface: SceneProcessor
      Called after the scene graph has been queued, but before it is flushed.
      Specified by:
      postQueue in interface SceneProcessor
      rq - The render queue
    • postFrame

      public void postFrame(FrameBuffer out)
      Description copied from interface: SceneProcessor
      Called after a frame has been rendered and the queue flushed.
      Specified by:
      postFrame in interface SceneProcessor
      out - The FB to which the scene was rendered.
    • cleanup

      public void cleanup()
      Description copied from interface: SceneProcessor
      Called when the SP is removed from the RM.
      Specified by:
      cleanup in interface SceneProcessor
    • setProfiler

      public void setProfiler(AppProfiler profiler)
      Description copied from interface: SceneProcessor
      Sets a profiler Instance for this processor.
      Specified by:
      setProfiler in interface SceneProcessor
      profiler - the profiler instance.
    • displayMap

      protected void displayMap(Renderer r, Picture pic, int left)
    • loadTextures

      protected void loadTextures(AssetManager manager)
    • createTextures

      protected void createTextures()
    • applyTextures

      protected void applyTextures(Material mat)
    • createPreViews

      protected void createPreViews()
    • destroyViews

      protected void destroyViews()
    • getMaterial

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

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

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

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

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

      public Plane getPlane()
      returns the water plane
      the pre-existing instance
    • setPlane

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

      public void setPlane(Vector3f origin, Vector3f normal)
      Set the water plane using an origin (location) and a normal (reflection direction).
      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(Vector3f position)
      Set the light Position for the processor
      position - the desired location (in world coordinates, alias created)
    • setWaterColor

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

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

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

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

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

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

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

      public void setDistortionScale(float value)
      Sets the scale of distortion by the normal map, default = 0.2
      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
      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.
      value - the desired scale factor (default=1)
    • getDistortionScale

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

      public float getDistortionMix()
      returns how the normal and dudv map are mixed to create the wave effect, default = 0.5
      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.
      the textures scale
    • isDebug

      public boolean isDebug()
      returns true if the water processor is in debug mode
      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
      debug - true to enable display, false to disable it (default=false)
    • createWaterGeometry

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

      public float getReflectionClippingOffset()
      returns the reflection clipping plane offset
      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.
      reflectionClippingOffset - the desired offset (default=-5)
    • getRefractionClippingOffset

      public float getRefractionClippingOffset()
      returns the refraction clipping plane offset
      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
      refractionClippingOffset - the desired offset (default=0.3)