- created a FilterParmeter annotation to use reflection (java.util.reflection) to display filter's properties in the editor
- using WaterFilter() empty constructor will now use the first scene of the viewport as the reflection scene (the water reflection), and use the direction of the first directional light found in this scene.

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7757 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 14 years ago
parent 0604418b3c
commit e1338dfea3
  1. 8
      engine/src/core/com/jme3/post/Filter.java
  2. 89
      engine/src/desktop-fx/com/jme3/water/WaterFilter.java

@ -46,6 +46,8 @@ import com.jme3.texture.FrameBuffer;
import com.jme3.texture.Image.Format;
import com.jme3.texture.Texture2D;
import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@ -64,10 +66,16 @@ import java.util.List;
*/
public abstract class Filter implements Savable {
@Retention(RetentionPolicy.RUNTIME)
public @interface FilterParameter {
String name();
}
@FilterParameter (name="Name")
private String name;
protected Pass defaultPass;
protected List<Pass> postRenderPasses;
protected Material material;
@FilterParameter (name="Enabled")
protected boolean enabled = true;
protected FilterPostProcessor processor;

@ -35,6 +35,8 @@ import com.jme3.asset.AssetManager;
import com.jme3.export.InputCapsule;
import com.jme3.export.JmeExporter;
import com.jme3.export.JmeImporter;
import com.jme3.light.DirectionalLight;
import com.jme3.light.Light;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Matrix4f;
@ -77,45 +79,74 @@ public class WaterFilter extends Filter {
private float speed = 1;
protected Ray ray = new Ray();
private Vector3f targetLocation = new Vector3f();
private Vector3f lightDirection;
private ReflectionProcessor reflectionProcessor;
private Matrix4f biasMatrix = new Matrix4f(0.5f, 0.0f, 0.0f, 0.5f,
0.0f, 0.5f, 0.0f, 0.5f,
0.0f, 0.0f, 0.0f, 0.5f,
0.0f, 0.0f, 0.0f, 1.0f);
private Matrix4f textureProjMatrix = new Matrix4f();
private boolean underWater;
private RenderManager renderManager;
private ViewPort viewPort;
private float time = 0;
@FilterParameter(name = "Light direction")
private Vector3f lightDirection = new Vector3f(0, -1, 0);
@FilterParameter(name = "Light color")
private ColorRGBA lightColor = ColorRGBA.White;
@FilterParameter(name = "Water height")
private float waterHeight = 0.0f;
@FilterParameter(name = "Water color")
private ColorRGBA waterColor = new ColorRGBA(0.0078f, 0.3176f, 0.5f, 1.0f);
@FilterParameter(name = "Deep water color")
private ColorRGBA deepWaterColor = new ColorRGBA(0.0039f, 0.00196f, 0.145f, 1.0f);
@FilterParameter(name = "Color extinction")
private Vector3f colorExtinction = new Vector3f(5.0f, 20.0f, 30.0f);
@FilterParameter(name = "Water transparency")
private float waterTransparency = 0.1f;
private float normalScale = 3.0f;
private float refractionConstant = 0.5f;
@FilterParameter(name = "Max amplitude")
private float maxAmplitude = 1.5f;
private ColorRGBA lightColor = ColorRGBA.White;
@FilterParameter(name = "Shore hardness")
private float shoreHardness = 0.1f;
@FilterParameter(name = "Use Foam")
private boolean useFoam = true;
@FilterParameter(name = "Foam intensity")
private float foamIntensity = 0.5f;
@FilterParameter(name = "Foam hardness")
private float foamHardness = 1.0f;
private float refractionStrength = 0.0f;
private float waveScale = 0.005f;
@FilterParameter(name = "Foam existance")
private Vector3f foamExistence = new Vector3f(0.45f, 4.35f, 1.5f);
private Vector3f colorExtinction = new Vector3f(5.0f, 20.0f, 30.0f);
@FilterParameter(name = "Wave scale")
private float waveScale = 0.005f;
@FilterParameter(name = "Sun scale")
private float sunScale = 3.0f;
@FilterParameter(name = "Shininess")
private float shininess = 0.7f;
private ColorRGBA waterColor = new ColorRGBA(0.0078f, 0.3176f, 0.5f, 1.0f);
private ColorRGBA deepWaterColor = new ColorRGBA(0.0039f, 0.00196f, 0.145f, 1.0f);
@FilterParameter(name = "Wind direction")
private Vector2f windDirection = new Vector2f(0.0f, -1.0f);
@FilterParameter(name = "Reflection map size")
private int reflectionMapSize = 512;
@FilterParameter(name = "Use ripples")
private boolean useRipples = true;
@FilterParameter(name = "Normals scale")
private float normalScale = 3.0f;
@FilterParameter(name = "Use HQ shorelines")
private boolean useHQShoreline = true;
@FilterParameter(name = "Use Specular")
private boolean useSpecular = true;
private boolean useFoam = true;
private boolean useCaustics = true;
@FilterParameter(name = "Use refraction")
private boolean useRefraction = true;
private float time = 0;
@FilterParameter(name = "Refraction strength")
private float refractionStrength = 0.0f;
@FilterParameter(name = "Refraction constant")
private float refractionConstant = 0.5f;
@FilterParameter(name = "Refleciton displace")
private float reflectionDisplace = 30;
private float foamIntensity = 0.5f;
private boolean underWater;
@FilterParameter(name = "Fog distance (underwater)")
private float underWaterFogDistance = 120;
@FilterParameter(name = "Caustics intensity (underwater)")
private float causticsIntensity = 0.5f;
private RenderManager renderManager;
private ViewPort viewPort;
@FilterParameter(name = "Use caustics (underwater)")
private boolean useCaustics = true;
/**
* Create a Water Filter
@ -207,8 +238,34 @@ public class WaterFilter extends Filter {
return material;
}
private DirectionalLight findLight(Node node) {
for (Light light : node.getWorldLightList()) {
System.out.println(light);
if (light instanceof DirectionalLight) {
return (DirectionalLight) light;
}
}
for (Spatial child : node.getChildren()) {
if (child instanceof Node) {
return findLight((Node) child);
}
}
return null;
}
@Override
protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
if (reflectionScene == null) {
reflectionScene = vp.getScenes().get(0);
DirectionalLight l = findLight((Node) reflectionScene);
if (l != null) {
lightDirection = l.getDirection();
}
}
this.renderManager = renderManager;
this.viewPort = vp;
reflectionPass = new Pass();

Loading…
Cancel
Save