Package com.jme3.water
Class SimpleWaterProcessor
java.lang.Object
com.jme3.water.SimpleWaterProcessor
- All Implemented Interfaces:
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);
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
Refraction Processor -
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
protected Texture2D
protected Texture2D
protected AssetManager
protected Material
protected Texture2D
protected Plane
protected Ray
protected FrameBuffer
protected Camera
protected Spatial
protected Texture2D
protected ViewPort
protected FrameBuffer
protected Camera
protected Texture2D
protected ViewPort
protected int
protected int
protected RenderManager
protected float
protected Vector3f
protected ViewPort
protected float
protected float
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
applyTextures
(Material mat) void
cleanup()
Called when the SP is removed from the RM.protected void
protected void
createWaterGeometry
(float width, float height) Creates a quad with the water material applied to it.protected void
protected void
displayMap
(Renderer r, Picture pic, int left) float
returns how the normal and dudv map are mixed to create the wave effect, default = 0.5float
returns the scale of distortion by the normal map, default = 0.2Get the water material from this processor, apply this to your water quad.getPlane()
returns the water planefloat
returns the reflection clipping plane offsetfloat
returns the refraction clipping plane offsetint
returns the height of the reflection and refraction texturesint
returns the width of the reflection and refraction texturesfloat
returns the scale of the normal/dudv texture, default = 1.float
return the water depthfloat
returns water transparencyfloat
returns the speed of the wave animation.void
initialize
(RenderManager rm, ViewPort vp) Called in the render thread to initialize the scene processor.boolean
isDebug()
returns true if the water processor is in debug modeboolean
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 framevoid
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 purposevoid
setDistortionMix
(float value) Sets how the normal and dudv map are mixed to create the wave effect, default = 0.5void
setDistortionScale
(float value) Sets the scale of distortion by the normal map, default = 0.2void
setLightPosition
(Vector3f position) Set the light Position for the processorvoid
Set the water plane for this processor.void
Set the water plane using an origin (location) and a normal (reflection direction).void
setProfiler
(AppProfiler profiler) Sets a profiler Instance for this processor.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
(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 renderingvoid
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 is 0.4fvoid
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
-
vp
-
reflectionScene
-
reflectionView
-
refractionView
-
reflectionBuffer
-
refractionBuffer
-
reflectionCam
-
refractionCam
-
reflectionTexture
-
refractionTexture
-
depthTexture
-
normalTexture
-
dudvTexture
-
renderWidth
protected int renderWidth -
renderHeight
protected int renderHeight -
plane
-
speed
protected float speed -
ray
-
targetLocation
-
manager
-
material
-
waterDepth
protected float waterDepth -
waterTransparency
protected float waterTransparency -
debug
protected boolean debug
-
-
Constructor Details
-
SimpleWaterProcessor
Creates a SimpleWaterProcessor- Parameters:
manager
- the asset manager
-
-
Method Details
-
initialize
Description copied from interface:SceneProcessor
Called in the render thread to initialize the scene processor.- Specified by:
initialize
in interfaceSceneProcessor
- Parameters:
rm
- The render manager to which the SP was added tovp
- The viewport to which the SP is assigned
-
reshape
Description copied from interface:SceneProcessor
Called when the resolution of the viewport has been changed.- Specified by:
reshape
in interfaceSceneProcessor
- Parameters:
vp
- the affected ViewPortw
- the new width (in pixels)h
- the new height (in pixels)
-
isInitialized
public boolean isInitialized()- Specified by:
isInitialized
in interfaceSceneProcessor
- 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 interfaceSceneProcessor
- Parameters:
tpf
- Time per frame
-
postQueue
Description copied from interface:SceneProcessor
Called after the scene graph has been queued, but before it is flushed.- Specified by:
postQueue
in interfaceSceneProcessor
- Parameters:
rq
- The render queue
-
postFrame
Description copied from interface:SceneProcessor
Called after a frame has been rendered and the queue flushed.- Specified by:
postFrame
in interfaceSceneProcessor
- 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 interfaceSceneProcessor
-
setProfiler
Description copied from interface:SceneProcessor
Sets a profiler Instance for this processor.- Specified by:
setProfiler
in interfaceSceneProcessor
- Parameters:
profiler
- the profiler instance.
-
displayMap
-
loadTextures
-
createTextures
protected void createTextures() -
applyTextures
-
createPreViews
protected void createPreViews() -
destroyViews
protected void destroyViews() -
getMaterial
Get the water material from this processor, apply this to your water quad.- Returns:
- the pre-existing Material
-
setReflectionScene
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
returns the water plane- Returns:
- the pre-existing instance
-
setPlane
Set the water plane for this processor.- Parameters:
plane
- the Plane to use (not null, unaffected)
-
setPlane
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 reflectionnormal
- Set to 0,1,0 (Vector3f.UNIT_Y) for normal planar water
-
setLightPosition
Set the light Position for the processor- Parameters:
position
- the desired location (in world coordinates, alias created)
-
setWaterColor
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
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)
-