Package com.jme3.water
Class SimpleWaterProcessor
java.lang.Object
com.jme3.water.SimpleWaterProcessor
- All Implemented Interfaces:
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 ClassesModifier and TypeClassDescriptionclassRefraction Processor -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected com.jme3.texture.Texture2Dprotected com.jme3.texture.Texture2Dprotected com.jme3.asset.AssetManagerprotected com.jme3.material.Materialprotected com.jme3.texture.Texture2Dprotected com.jme3.math.Planeprotected com.jme3.math.Rayprotected com.jme3.texture.FrameBufferprotected com.jme3.renderer.Cameraprotected com.jme3.scene.Spatialprotected com.jme3.texture.Texture2Dprotected com.jme3.renderer.ViewPortprotected com.jme3.texture.FrameBufferprotected com.jme3.renderer.Cameraprotected com.jme3.texture.Texture2Dprotected com.jme3.renderer.ViewPortprotected intprotected intprotected com.jme3.renderer.RenderManagerprotected floatprotected com.jme3.math.Vector3fprotected com.jme3.renderer.ViewPortprotected floatprotected float -
Constructor Summary
ConstructorsConstructorDescriptionSimpleWaterProcessor(com.jme3.asset.AssetManager manager) Creates a SimpleWaterProcessor -
Method Summary
Modifier and TypeMethodDescriptionprotected voidapplyTextures(com.jme3.material.Material mat) voidcleanup()protected voidprotected voidcom.jme3.scene.GeometrycreateWaterGeometry(float width, float height) Creates a quad with the water material applied to it.protected voidprotected voiddisplayMap(com.jme3.renderer.Renderer r, com.jme3.ui.Picture pic, int left) floatreturns how the normal and dudv map are mixed to create the wave effect, default = 0.5floatreturns the scale of distortion by the normal map, default = 0.2com.jme3.material.MaterialGet the water material from this processor, apply this to your water quad.com.jme3.math.PlanegetPlane()returns the water planefloatreturns the reflection clipping plane offsetfloatreturns the refraction clipping plane offsetintreturns the height of the reflection and refraction texturesintreturns the width of the reflection and refraction texturesfloatreturns the scale of the normal/dudv texture, default = 1.floatreturn the water depthfloatreturns water transparencyfloatreturns the speed of the wave animation.voidinitialize(com.jme3.renderer.RenderManager rm, com.jme3.renderer.ViewPort vp) booleanisDebug()returns true if the water processor is in debug modebooleanprotected voidloadTextures(com.jme3.asset.AssetManager manager) voidpostFrame(com.jme3.texture.FrameBuffer out) voidpostQueue(com.jme3.renderer.queue.RenderQueue rq) voidpreFrame(float tpf) voidreshape(com.jme3.renderer.ViewPort vp, int w, int h) voidsetDebug(boolean debug) set to true to display reflection and refraction textures in the GUI for debug purposevoidsetDistortionMix(float value) Sets how the normal and dudv map are mixed to create the wave effect, default = 0.5voidsetDistortionScale(float value) Sets the scale of distortion by the normal map, default = 0.2voidsetLightPosition(com.jme3.math.Vector3f position) Set the light Position for the processorvoidsetPlane(com.jme3.math.Plane plane) Set the water plane for this processor.voidsetPlane(com.jme3.math.Vector3f origin, com.jme3.math.Vector3f normal) Set the water plane using an origin (location) and a normal (reflection direction).voidsetProfiler(com.jme3.profile.AppProfiler profiler) voidsetReflectionClippingOffset(float reflectionClippingOffset) sets the reflection clipping plane offset set a negative value to lower the clipping plane for reflection texture rendering.voidsetReflectionScene(com.jme3.scene.Spatial spat) Sets the reflected scene, should not include the water quad! Set before adding processor.voidsetRefractionClippingOffset(float refractionClippingOffset) Sets the refraction clipping plane offset set a positive value to raise the clipping plane for refraction texture renderingvoidsetRenderSize(int width, int height) Set the reflection Texture render size, set before adding the processor!voidsetTexScale(float value) Sets the scale of the normal/dudv texture, default = 1.voidsetWaterColor(com.jme3.math.ColorRGBA color) Set the color that will be added to the refraction texture.voidsetWaterDepth(float depth) Higher values make the refraction texture shine through earlier.voidsetWaterTransparency(float waterTransparency) sets the water transparency default is 0.4fvoidsetWaveSpeed(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, waitMethods 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:
initializein interfacecom.jme3.post.SceneProcessor
-
reshape
public void reshape(com.jme3.renderer.ViewPort vp, int w, int h) - Specified by:
reshapein interfacecom.jme3.post.SceneProcessor
-
isInitialized
public boolean isInitialized()- Specified by:
isInitializedin interfacecom.jme3.post.SceneProcessor
-
preFrame
public void preFrame(float tpf) - Specified by:
preFramein interfacecom.jme3.post.SceneProcessor
-
postQueue
public void postQueue(com.jme3.renderer.queue.RenderQueue rq) - Specified by:
postQueuein interfacecom.jme3.post.SceneProcessor
-
postFrame
public void postFrame(com.jme3.texture.FrameBuffer out) - Specified by:
postFramein interfacecom.jme3.post.SceneProcessor
-
cleanup
public void cleanup()- Specified by:
cleanupin interfacecom.jme3.post.SceneProcessor
-
setProfiler
public void setProfiler(com.jme3.profile.AppProfiler profiler) - Specified by:
setProfilerin interfacecom.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 reflectionnormal- 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)
-