public class SimpleWaterProcessor
extends java.lang.Object
implements com.jme3.post.SceneProcessor
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);
| Modifier and Type | Class and Description |
|---|---|
class |
SimpleWaterProcessor.RefractionProcessor
Refraction Processor
|
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
debug |
protected com.jme3.texture.Texture2D |
depthTexture |
protected com.jme3.texture.Texture2D |
dudvTexture |
protected com.jme3.asset.AssetManager |
manager |
protected com.jme3.material.Material |
material |
protected com.jme3.texture.Texture2D |
normalTexture |
protected com.jme3.math.Plane |
plane |
protected com.jme3.math.Ray |
ray |
protected com.jme3.texture.FrameBuffer |
reflectionBuffer |
protected com.jme3.renderer.Camera |
reflectionCam |
protected com.jme3.scene.Spatial |
reflectionScene |
protected com.jme3.texture.Texture2D |
reflectionTexture |
protected com.jme3.renderer.ViewPort |
reflectionView |
protected com.jme3.texture.FrameBuffer |
refractionBuffer |
protected com.jme3.renderer.Camera |
refractionCam |
protected com.jme3.texture.Texture2D |
refractionTexture |
protected com.jme3.renderer.ViewPort |
refractionView |
protected int |
renderHeight |
protected int |
renderWidth |
protected com.jme3.renderer.RenderManager |
rm |
protected float |
speed |
protected com.jme3.math.Vector3f |
targetLocation |
protected com.jme3.renderer.ViewPort |
vp |
protected float |
waterDepth |
protected float |
waterTransparency |
| Constructor and Description |
|---|
SimpleWaterProcessor(com.jme3.asset.AssetManager manager)
Creates a SimpleWaterProcessor
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
applyTextures(com.jme3.material.Material mat) |
void |
cleanup() |
protected void |
createPreViews() |
protected void |
createTextures() |
com.jme3.scene.Geometry |
createWaterGeometry(float width,
float height)
Creates a quad with the water material applied to it.
|
protected void |
destroyViews() |
protected void |
displayMap(com.jme3.renderer.Renderer r,
com.jme3.ui.Picture pic,
int left) |
float |
getDistortionMix()
returns how the normal and dudv map are mixed to create the wave effect,
default = 0.5
|
float |
getDistortionScale()
returns the scale of distortion by the normal map, default = 0.2
|
com.jme3.material.Material |
getMaterial()
Get the water material from this processor, apply this to your water quad.
|
com.jme3.math.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 |
getTexScale()
returns the scale of the normal/dudv texture, default = 1.
|
float |
getWaterDepth()
return the water depth
|
float |
getWaterTransparency()
returns water transparency
|
float |
getWaveSpeed()
returns the speed of the wave animation.
|
void |
initialize(com.jme3.renderer.RenderManager rm,
com.jme3.renderer.ViewPort vp) |
boolean |
isDebug()
returns true if the waterprocessor is in debug mode
|
boolean |
isInitialized() |
protected void |
loadTextures(com.jme3.asset.AssetManager manager) |
void |
postFrame(com.jme3.texture.FrameBuffer out) |
void |
postQueue(com.jme3.renderer.queue.RenderQueue rq) |
void |
preFrame(float tpf) |
void |
reshape(com.jme3.renderer.ViewPort vp,
int w,
int h) |
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(com.jme3.math.Vector3f position)
Set the light Position for the processor
|
void |
setPlane(com.jme3.math.Plane plane)
Set the water plane for this processor.
|
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).
|
void |
setProfiler(com.jme3.profile.AppProfiler profiler) |
void |
setReflectionClippingOffset(float reflectionClippingOffset)
sets the reflection clipping plane offset
set a negative value to lower the clipping plane for relection texture rendering.
|
void |
setReflectionScene(com.jme3.scene.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(com.jme3.math.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.4f
|
void |
setWaveSpeed(float speed)
Sets the speed of the wave animation, default = 0.05f.
|
protected com.jme3.renderer.RenderManager rm
protected com.jme3.renderer.ViewPort vp
protected com.jme3.scene.Spatial reflectionScene
protected com.jme3.renderer.ViewPort reflectionView
protected com.jme3.renderer.ViewPort refractionView
protected com.jme3.texture.FrameBuffer reflectionBuffer
protected com.jme3.texture.FrameBuffer refractionBuffer
protected com.jme3.renderer.Camera reflectionCam
protected com.jme3.renderer.Camera refractionCam
protected com.jme3.texture.Texture2D reflectionTexture
protected com.jme3.texture.Texture2D refractionTexture
protected com.jme3.texture.Texture2D depthTexture
protected com.jme3.texture.Texture2D normalTexture
protected com.jme3.texture.Texture2D dudvTexture
protected int renderWidth
protected int renderHeight
protected com.jme3.math.Plane plane
protected float speed
protected com.jme3.math.Ray ray
protected com.jme3.math.Vector3f targetLocation
protected com.jme3.asset.AssetManager manager
protected com.jme3.material.Material material
protected float waterDepth
protected float waterTransparency
protected boolean debug
public SimpleWaterProcessor(com.jme3.asset.AssetManager manager)
manager - the asset managerpublic void initialize(com.jme3.renderer.RenderManager rm,
com.jme3.renderer.ViewPort vp)
initialize in interface com.jme3.post.SceneProcessorpublic void reshape(com.jme3.renderer.ViewPort vp,
int w,
int h)
reshape in interface com.jme3.post.SceneProcessorpublic boolean isInitialized()
isInitialized in interface com.jme3.post.SceneProcessorpublic void preFrame(float tpf)
preFrame in interface com.jme3.post.SceneProcessorpublic void postQueue(com.jme3.renderer.queue.RenderQueue rq)
postQueue in interface com.jme3.post.SceneProcessorpublic void postFrame(com.jme3.texture.FrameBuffer out)
postFrame in interface com.jme3.post.SceneProcessorpublic void cleanup()
cleanup in interface com.jme3.post.SceneProcessorpublic void setProfiler(com.jme3.profile.AppProfiler profiler)
setProfiler in interface com.jme3.post.SceneProcessorprotected void displayMap(com.jme3.renderer.Renderer r,
com.jme3.ui.Picture pic,
int left)
protected void loadTextures(com.jme3.asset.AssetManager manager)
protected void createTextures()
protected void applyTextures(com.jme3.material.Material mat)
protected void createPreViews()
protected void destroyViews()
public com.jme3.material.Material getMaterial()
public void setReflectionScene(com.jme3.scene.Spatial spat)
spat - the scene-graph subtree to be reflected (alias created)public int getRenderWidth()
public int getRenderHeight()
public void setRenderSize(int width,
int height)
width - the desired width (in pixels, default=512)height - the desired height (in pixels, default=512)public com.jme3.math.Plane getPlane()
public void setPlane(com.jme3.math.Plane plane)
plane - the Plane to use (not null, unaffected)public void setPlane(com.jme3.math.Vector3f origin,
com.jme3.math.Vector3f normal)
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 waterpublic void setLightPosition(com.jme3.math.Vector3f position)
position - the desired location (in world coordinates,
alias created)public void setWaterColor(com.jme3.math.ColorRGBA color)
color - the desired color (alias created)public void setWaterDepth(float depth)
depth - the desired depth (default=1)public float getWaterDepth()
public float getWaterTransparency()
public void setWaterTransparency(float waterTransparency)
waterTransparency - the desired transparency (default=0.4)public void setWaveSpeed(float speed)
speed - the desired animation speed (default=0.05)public float getWaveSpeed()
public void setDistortionScale(float value)
value - the desired scale factor (default=0.2)public void setDistortionMix(float value)
value - the desired mix fraction (default=0.5)public void setTexScale(float value)
value - the desired scale factor (default=1)public float getDistortionScale()
public float getDistortionMix()
public float getTexScale()
public boolean isDebug()
public void setDebug(boolean debug)
debug - true to enable display, false to disable it (default=false)public com.jme3.scene.Geometry createWaterGeometry(float width,
float height)
width - the desired width (in mesh coordinates)height - the desired height (in mesh coordinates)public float getReflectionClippingOffset()
public void setReflectionClippingOffset(float reflectionClippingOffset)
reflectionClippingOffset - the desired offset (default=-5)public float getRefractionClippingOffset()
public void setRefractionClippingOffset(float refractionClippingOffset)
refractionClippingOffset - the desired offset (default=0.3)