WaterFilter : the size of the reflection map can now be changed at run time.
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10476 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
c1efd70e3d
commit
c591260ab5
@ -853,6 +853,11 @@ public class WaterFilter extends Filter {
|
|||||||
*/
|
*/
|
||||||
public void setReflectionMapSize(int reflectionMapSize) {
|
public void setReflectionMapSize(int reflectionMapSize) {
|
||||||
this.reflectionMapSize = reflectionMapSize;
|
this.reflectionMapSize = reflectionMapSize;
|
||||||
|
reflectionPass.init(renderManager.getRenderer(), reflectionMapSize, reflectionMapSize, Format.RGBA8, Format.Depth);
|
||||||
|
reflectionCam.resize(reflectionMapSize, reflectionMapSize, true);
|
||||||
|
reflectionProcessor.setReflectionBuffer(reflectionPass.getRenderFrameBuffer());
|
||||||
|
material.setTexture("ReflectionMap", reflectionPass.getRenderedTexture());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -5,6 +5,7 @@ import com.jme3.audio.AudioNode;
|
|||||||
import com.jme3.audio.LowPassFilter;
|
import com.jme3.audio.LowPassFilter;
|
||||||
import com.jme3.effect.ParticleEmitter;
|
import com.jme3.effect.ParticleEmitter;
|
||||||
import com.jme3.effect.ParticleMesh;
|
import com.jme3.effect.ParticleMesh;
|
||||||
|
import com.jme3.input.KeyInput;
|
||||||
import com.jme3.input.controls.ActionListener;
|
import com.jme3.input.controls.ActionListener;
|
||||||
import com.jme3.input.controls.KeyTrigger;
|
import com.jme3.input.controls.KeyTrigger;
|
||||||
import com.jme3.light.DirectionalLight;
|
import com.jme3.light.DirectionalLight;
|
||||||
@ -38,6 +39,7 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* test
|
* test
|
||||||
|
*
|
||||||
* @author normenhansen
|
* @author normenhansen
|
||||||
*/
|
*/
|
||||||
public class TestPostWater extends SimpleApplication {
|
public class TestPostWater extends SimpleApplication {
|
||||||
@ -104,7 +106,7 @@ public class TestPostWater extends SimpleApplication {
|
|||||||
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
|
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
|
||||||
|
|
||||||
fpp.addFilter(water);
|
fpp.addFilter(water);
|
||||||
BloomFilter bloom=new BloomFilter();
|
BloomFilter bloom = new BloomFilter();
|
||||||
//bloom.getE
|
//bloom.getE
|
||||||
bloom.setExposurePower(55);
|
bloom.setExposurePower(55);
|
||||||
bloom.setBloomIntensity(1.0f);
|
bloom.setBloomIntensity(1.0f);
|
||||||
@ -112,7 +114,7 @@ public class TestPostWater extends SimpleApplication {
|
|||||||
LightScatteringFilter lsf = new LightScatteringFilter(lightDir.mult(-300));
|
LightScatteringFilter lsf = new LightScatteringFilter(lightDir.mult(-300));
|
||||||
lsf.setLightDensity(1.0f);
|
lsf.setLightDensity(1.0f);
|
||||||
fpp.addFilter(lsf);
|
fpp.addFilter(lsf);
|
||||||
DepthOfFieldFilter dof=new DepthOfFieldFilter();
|
DepthOfFieldFilter dof = new DepthOfFieldFilter();
|
||||||
dof.setFocusDistance(0);
|
dof.setFocusDistance(0);
|
||||||
dof.setFocusRange(100);
|
dof.setFocusRange(100);
|
||||||
fpp.addFilter(dof);
|
fpp.addFilter(dof);
|
||||||
@ -135,14 +137,14 @@ public class TestPostWater extends SimpleApplication {
|
|||||||
//water.setFoamHardness(0.6f);
|
//water.setFoamHardness(0.6f);
|
||||||
|
|
||||||
water.setWaterHeight(initialWaterHeight);
|
water.setWaterHeight(initialWaterHeight);
|
||||||
uw=cam.getLocation().y<waterHeight;
|
uw = cam.getLocation().y < waterHeight;
|
||||||
|
|
||||||
waves = new AudioNode(assetManager, "Sound/Environment/Ocean Waves.ogg", false);
|
waves = new AudioNode(assetManager, "Sound/Environment/Ocean Waves.ogg", false);
|
||||||
waves.setLooping(true);
|
waves.setLooping(true);
|
||||||
waves.setReverbEnabled(true);
|
waves.setReverbEnabled(true);
|
||||||
if(uw){
|
if (uw) {
|
||||||
waves.setDryFilter(new LowPassFilter(0.5f, 0.1f));
|
waves.setDryFilter(new LowPassFilter(0.5f, 0.1f));
|
||||||
}else{
|
} else {
|
||||||
waves.setDryFilter(aboveWaterAudioFilter);
|
waves.setDryFilter(aboveWaterAudioFilter);
|
||||||
}
|
}
|
||||||
audioRenderer.playSource(waves);
|
audioRenderer.playSource(waves);
|
||||||
@ -150,7 +152,6 @@ public class TestPostWater extends SimpleApplication {
|
|||||||
viewPort.addProcessor(fpp);
|
viewPort.addProcessor(fpp);
|
||||||
|
|
||||||
inputManager.addListener(new ActionListener() {
|
inputManager.addListener(new ActionListener() {
|
||||||
|
|
||||||
public void onAction(String name, boolean isPressed, float tpf) {
|
public void onAction(String name, boolean isPressed, float tpf) {
|
||||||
if (isPressed) {
|
if (isPressed) {
|
||||||
if (name.equals("foam1")) {
|
if (name.equals("foam1")) {
|
||||||
@ -162,12 +163,23 @@ public class TestPostWater extends SimpleApplication {
|
|||||||
if (name.equals("foam3")) {
|
if (name.equals("foam3")) {
|
||||||
water.setFoamTexture((Texture2D) assetManager.loadTexture("Common/MatDefs/Water/Textures/foam3.jpg"));
|
water.setFoamTexture((Texture2D) assetManager.loadTexture("Common/MatDefs/Water/Textures/foam3.jpg"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (name.equals("upRM")) {
|
||||||
|
water.setReflectionMapSize(Math.min(water.getReflectionMapSize() * 2, 4096));
|
||||||
|
System.out.println("Reflection map size : " + water.getReflectionMapSize());
|
||||||
|
}
|
||||||
|
if (name.equals("downRM")) {
|
||||||
|
water.setReflectionMapSize(Math.max(water.getReflectionMapSize() / 2, 32));
|
||||||
|
System.out.println("Reflection map size : " + water.getReflectionMapSize());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, "foam1", "foam2", "foam3");
|
}
|
||||||
inputManager.addMapping("foam1", new KeyTrigger(keyInput.KEY_1));
|
}, "foam1", "foam2", "foam3", "upRM", "downRM");
|
||||||
inputManager.addMapping("foam2", new KeyTrigger(keyInput.KEY_2));
|
inputManager.addMapping("foam1", new KeyTrigger(KeyInput.KEY_1));
|
||||||
inputManager.addMapping("foam3", new KeyTrigger(keyInput.KEY_3));
|
inputManager.addMapping("foam2", new KeyTrigger(KeyInput.KEY_2));
|
||||||
|
inputManager.addMapping("foam3", new KeyTrigger(KeyInput.KEY_3));
|
||||||
|
inputManager.addMapping("upRM", new KeyTrigger(KeyInput.KEY_PGUP));
|
||||||
|
inputManager.addMapping("downRM", new KeyTrigger(KeyInput.KEY_PGDN));
|
||||||
// createBox();
|
// createBox();
|
||||||
// createFire();
|
// createFire();
|
||||||
}
|
}
|
||||||
@ -200,7 +212,9 @@ public class TestPostWater extends SimpleApplication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void createFire() {
|
private void createFire() {
|
||||||
/** Uses Texture from jme3-test-data library! */
|
/**
|
||||||
|
* Uses Texture from jme3-test-data library!
|
||||||
|
*/
|
||||||
ParticleEmitter fire = new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 30);
|
ParticleEmitter fire = new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 30);
|
||||||
Material mat_red = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
|
Material mat_red = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
|
||||||
mat_red.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
|
mat_red.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
|
||||||
@ -273,8 +287,9 @@ public class TestPostWater extends SimpleApplication {
|
|||||||
//This part is to emulate tides, slightly varrying the height of the water plane
|
//This part is to emulate tides, slightly varrying the height of the water plane
|
||||||
private float time = 0.0f;
|
private float time = 0.0f;
|
||||||
private float waterHeight = 0.0f;
|
private float waterHeight = 0.0f;
|
||||||
private float initialWaterHeight = 0.8f;
|
private float initialWaterHeight = 90f;//0.8f;
|
||||||
private boolean uw=false;
|
private boolean uw = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simpleUpdate(float tpf) {
|
public void simpleUpdate(float tpf) {
|
||||||
super.simpleUpdate(tpf);
|
super.simpleUpdate(tpf);
|
||||||
@ -282,13 +297,13 @@ private boolean uw=false;
|
|||||||
time += tpf;
|
time += tpf;
|
||||||
waterHeight = (float) Math.cos(((time * 0.6f) % FastMath.TWO_PI)) * 1.5f;
|
waterHeight = (float) Math.cos(((time * 0.6f) % FastMath.TWO_PI)) * 1.5f;
|
||||||
water.setWaterHeight(initialWaterHeight + waterHeight);
|
water.setWaterHeight(initialWaterHeight + waterHeight);
|
||||||
if(water.isUnderWater() && !uw){
|
if (water.isUnderWater() && !uw) {
|
||||||
|
|
||||||
waves.setDryFilter(new LowPassFilter(0.5f, 0.1f));
|
waves.setDryFilter(new LowPassFilter(0.5f, 0.1f));
|
||||||
uw=true;
|
uw = true;
|
||||||
}
|
}
|
||||||
if(!water.isUnderWater() && uw){
|
if (!water.isUnderWater() && uw) {
|
||||||
uw=false;
|
uw = false;
|
||||||
//waves.setReverbEnabled(false);
|
//waves.setReverbEnabled(false);
|
||||||
waves.setDryFilter(new LowPassFilter(1, 1f));
|
waves.setDryFilter(new LowPassFilter(1, 1f));
|
||||||
//waves.setDryFilter(new LowPassFilter(1,1f));
|
//waves.setDryFilter(new LowPassFilter(1,1f));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user