public class SimpleWaterProcessor extends java.lang.Object implements 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 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 and Description |
---|
SimpleWaterProcessor(AssetManager manager)
Creates a SimpleWaterProcessor
|
Modifier and Type | Method and Description |
---|---|
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) |
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
|
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 |
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(RenderManager rm,
ViewPort vp)
Called in the render thread to initialize the scene processor.
|
boolean |
isDebug()
returns 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 |
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 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 is 0.4f
|
void |
setWaveSpeed(float speed)
Sets the speed of the wave animation, default = 0.05f.
|
protected RenderManager rm
protected ViewPort vp
protected Spatial reflectionScene
protected ViewPort reflectionView
protected ViewPort refractionView
protected FrameBuffer reflectionBuffer
protected FrameBuffer refractionBuffer
protected Camera reflectionCam
protected Camera refractionCam
protected Texture2D reflectionTexture
protected Texture2D refractionTexture
protected Texture2D depthTexture
protected Texture2D normalTexture
protected Texture2D dudvTexture
protected int renderWidth
protected int renderHeight
protected Plane plane
protected float speed
protected Ray ray
protected Vector3f targetLocation
protected AssetManager manager
protected Material material
protected float waterDepth
protected float waterTransparency
protected boolean debug
public SimpleWaterProcessor(AssetManager manager)
manager
- the asset managerpublic void initialize(RenderManager rm, ViewPort vp)
SceneProcessor
initialize
in interface SceneProcessor
rm
- The render manager to which the SP was added tovp
- The viewport to which the SP is assignedpublic void reshape(ViewPort vp, int w, int h)
SceneProcessor
reshape
in interface SceneProcessor
vp
- the affected ViewPortw
- the new width (in pixels)h
- the new height (in pixels)public boolean isInitialized()
isInitialized
in interface SceneProcessor
public void preFrame(float tpf)
SceneProcessor
preFrame
in interface SceneProcessor
tpf
- Time per framepublic void postQueue(RenderQueue rq)
SceneProcessor
postQueue
in interface SceneProcessor
rq
- The render queuepublic void postFrame(FrameBuffer out)
SceneProcessor
postFrame
in interface SceneProcessor
out
- The FB to which the scene was rendered.public void cleanup()
SceneProcessor
cleanup
in interface SceneProcessor
public void setProfiler(AppProfiler profiler)
SceneProcessor
setProfiler
in interface SceneProcessor
profiler
- the profiler instance.protected void loadTextures(AssetManager manager)
protected void createTextures()
protected void applyTextures(Material mat)
protected void createPreViews()
protected void destroyViews()
public Material getMaterial()
public void setReflectionScene(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 Plane getPlane()
public void setPlane(Plane plane)
plane
- the Plane to use (not null, unaffected)public void setPlane(Vector3f origin, 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(Vector3f position)
position
- the desired location (in world coordinates,
alias created)public void setWaterColor(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 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)