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
Nested ClassesModifier and TypeClassDescriptionclassRefraction Processor -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprotected Texture2Dprotected Texture2Dprotected AssetManagerprotected Materialprotected Texture2Dprotected Planeprotected Rayprotected FrameBufferprotected Cameraprotected Spatialprotected Texture2Dprotected ViewPortprotected FrameBufferprotected Cameraprotected Texture2Dprotected ViewPortprotected intprotected intprotected RenderManagerprotected floatprotected Vector3fprotected ViewPortprotected floatprotected float -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidapplyTextures(Material mat) voidcleanup()Called when the SP is removed from the RM.protected voidprotected voidcreateWaterGeometry(float width, float height) Creates a quad with the water material applied to it.protected voidprotected voiddisplayMap(Renderer r, 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.2Get the water material from this processor, apply this to your water quad.getPlane()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(RenderManager rm, ViewPort vp) Called in the render thread to initialize the scene processor.booleanisDebug()returns true if the water processor is in debug modebooleanprotected voidloadTextures(AssetManager manager) voidpostFrame(FrameBuffer out) Called after a frame has been rendered and the queue flushed.voidpostQueue(RenderQueue rq) Called after the scene graph has been queued, but before it is flushed.voidpreFrame(float tpf) Called before a framevoidCalled when the resolution of the viewport has been changed.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(Vector3f position) Set the light Position for the processorvoidSet the water plane for this processor.voidSet the water plane using an origin (location) and a normal (reflection direction).voidsetProfiler(AppProfiler profiler) Sets a profiler Instance for this processor.voidsetReflectionClippingOffset(float reflectionClippingOffset) sets the reflection clipping plane offset set a negative value to lower the clipping plane for reflection texture rendering.voidsetReflectionScene(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(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
-
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:SceneProcessorCalled in the render thread to initialize the scene processor.- Specified by:
initializein 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:SceneProcessorCalled when the resolution of the viewport has been changed.- Specified by:
reshapein interfaceSceneProcessor- Parameters:
vp- the affected ViewPortw- the new width (in pixels)h- the new height (in pixels)
-
isInitialized
public boolean isInitialized()- Specified by:
isInitializedin interfaceSceneProcessor- Returns:
- True if initialize() has been called on this SceneProcessor, false if otherwise.
-
preFrame
public void preFrame(float tpf) Description copied from interface:SceneProcessorCalled before a frame- Specified by:
preFramein interfaceSceneProcessor- Parameters:
tpf- Time per frame
-
postQueue
Description copied from interface:SceneProcessorCalled after the scene graph has been queued, but before it is flushed.- Specified by:
postQueuein interfaceSceneProcessor- Parameters:
rq- The render queue
-
postFrame
Description copied from interface:SceneProcessorCalled after a frame has been rendered and the queue flushed.- Specified by:
postFramein interfaceSceneProcessor- Parameters:
out- The FB to which the scene was rendered.
-
cleanup
public void cleanup()Description copied from interface:SceneProcessorCalled when the SP is removed from the RM.- Specified by:
cleanupin interfaceSceneProcessor
-
setProfiler
Description copied from interface:SceneProcessorSets a profiler Instance for this processor.- Specified by:
setProfilerin 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)
-