com.jme3.water
Class SimpleWaterProcessor

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

public class SimpleWaterProcessor
extends java.lang.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 low specs hardware and still want a 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);


Nested Class Summary
 class SimpleWaterProcessor.RefractionProcessor
          Refraction Processor
 
Field Summary
protected  boolean debug
           
protected  Texture2D depthTexture
           
protected  Texture2D dudvTexture
           
protected  AssetManager manager
           
protected  Material material
           
protected  Texture2D normalTexture
           
protected  Plane plane
           
protected  Ray ray
           
protected  FrameBuffer reflectionBuffer
           
protected  Camera reflectionCam
           
protected  Spatial reflectionScene
           
protected  Texture2D reflectionTexture
           
protected  ViewPort reflectionView
           
protected  FrameBuffer refractionBuffer
           
protected  Camera refractionCam
           
protected  Texture2D refractionTexture
           
protected  ViewPort refractionView
           
protected  int renderHeight
           
protected  int renderWidth
           
protected  RenderManager rm
           
protected  float speed
           
protected  Vector3f targetLocation
           
protected  ViewPort vp
           
protected  float waterDepth
           
protected  float waterTransparency
           
 
Constructor Summary
SimpleWaterProcessor(AssetManager manager)
          Creates a SimpleWaterProcessor
 
Method Summary
protected  void applyTextures(Material mat)
           
 void cleanup()
          Called when the SP is removed from the RM.
protected  void createPreViews()
           
protected  void createTextures()
           
 Geometry createWaterGeometry(float width, float height)
          Creates a quad with the water material applied to it.
protected  void destroyViews()
           
protected  void displayMap(Renderer r, Picture pic, int left)
           
 Material getMaterial()
          Get the water material from this processor, apply this to your water quad.
 Plane getPlane()
          returns the water plane
 float getReflectionClippingOffset()
          returns the reflection clipping plane offset
 float getRefractionClippingOffset()
          returns the refraction clipping plane offset
 int getRenderHeight()
          returns the height of the reflection and refraction textures
 int getRenderWidth()
          returns the width of the reflection and refraction textures
 float getWaterDepth()
          return the water depth
 float getWaterTransparency()
          returns water transparency
 void initialize(RenderManager rm, ViewPort vp)
          Called in the render thread to initialize the scene processor.
 boolean isDebug()
          retruns true if the waterprocessor is in debug mode
 boolean isInitialized()
           
protected  void loadTextures(AssetManager manager)
           
 void postFrame(FrameBuffer out)
          Called after a frame has been rendered and the queue flushed.
 void postQueue(RenderQueue rq)
          Called after the scene graph has been queued, but before it is flushed.
 void preFrame(float tpf)
          Called before a frame
 void reshape(ViewPort vp, int w, int h)
          Called when the resolution of the viewport has been changed.
 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(Vector3f position)
          Set the light Position for the processor
 void setPlane(Plane plane)
          Set the water plane for this processor.
 void setPlane(Vector3f origin, Vector3f normal)
          Set the water plane using an origin (location) and a normal (reflection direction).
 void setReflectionClippingOffset(float reflectionClippingOffset)
          sets the reflection clipping plane offset set a nagetive value to lower the clipping plane for relection texture rendering.
 void setReflectionScene(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(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 os 0.1f
 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
 

Field Detail

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 Detail

SimpleWaterProcessor

public SimpleWaterProcessor(AssetManager manager)
Creates a SimpleWaterProcessor

Parameters:
manager - the asset manager
Method Detail

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
Parameters:
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

isInitialized

public boolean isInitialized()
Specified by:
isInitialized in interface SceneProcessor
Returns:
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
Parameters:
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
Parameters:
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
Parameters:
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

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.

Returns:

setReflectionScene

public void setReflectionScene(Spatial spat)
Sets the reflected scene, should not include the water quad! Set before adding processor.

Parameters:
spat -

getRenderWidth

public int getRenderWidth()
returns the width of the reflection and refraction textures

Returns:

getRenderHeight

public int getRenderHeight()
returns the height of the reflection and refraction textures

Returns:

setRenderSize

public void setRenderSize(int width,
                          int height)
Set the reflection Texture render size, set before adding the processor!

Parameters:
width -
height -

getPlane

public Plane getPlane()
returns the water plane

Returns:

setPlane

public void setPlane(Plane plane)
Set the water plane for this processor.

Parameters:
plane -

setPlane

public void setPlane(Vector3f origin,
                     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(Vector3f position)
Set the light Position for the processor

Parameters:
position -

setWaterColor

public void setWaterColor(ColorRGBA color)
Set the color that will be added to the refraction texture.

Parameters:
color -

setWaterDepth

public void setWaterDepth(float depth)
Higher values make the refraction texture shine through earlier. Default is 4

Parameters:
depth -

getWaterDepth

public float getWaterDepth()
return the water depth

Returns:

getWaterTransparency

public float getWaterTransparency()
returns water transparency

Returns:

setWaterTransparency

public void setWaterTransparency(float waterTransparency)
sets the water transparency default os 0.1f

Parameters:
waterTransparency -

setWaveSpeed

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

Parameters:
speed -

setDistortionScale

public void setDistortionScale(float value)
Sets the scale of distortion by the normal map, 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


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.


isDebug

public boolean isDebug()
retruns true if the waterprocessor is in debug mode

Returns:

setDebug

public void setDebug(boolean debug)
set to true to display reflection and refraction textures in the GUI for debug purpose

Parameters:
debug -

createWaterGeometry

public Geometry createWaterGeometry(float width,
                                    float height)
Creates a quad with the water material applied to it.

Parameters:
width -
height -
Returns:

getReflectionClippingOffset

public float getReflectionClippingOffset()
returns the reflection clipping plane offset

Returns:

setReflectionClippingOffset

public void setReflectionClippingOffset(float reflectionClippingOffset)
sets the reflection clipping plane offset set a nagetive value to lower the clipping plane for relection texture rendering.

Parameters:
reflectionClippingOffset -

getRefractionClippingOffset

public float getRefractionClippingOffset()
returns the refraction clipping plane offset

Returns:

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 -