Adjusted TestPostWater to gamma correction

experimental
Nehon 11 years ago
parent 200c875ba2
commit 95f215c180
  1. 110
      jme3-examples/src/main/java/jme3test/water/TestPostWater.java

@ -8,6 +8,7 @@ import com.jme3.effect.ParticleMesh;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.material.RenderState.BlendMode;
@ -18,6 +19,7 @@ import com.jme3.math.Vector3f;
import com.jme3.post.FilterPostProcessor;
import com.jme3.post.filters.BloomFilter;
import com.jme3.post.filters.DepthOfFieldFilter;
import com.jme3.post.filters.FXAAFilter;
import com.jme3.post.filters.LightScatteringFilter;
import com.jme3.renderer.Camera;
import com.jme3.renderer.queue.RenderQueue.Bucket;
@ -70,13 +72,12 @@ public class TestPostWater extends SimpleApplication {
createTerrain(mainScene);
DirectionalLight sun = new DirectionalLight();
sun.setDirection(lightDir);
sun.setColor(ColorRGBA.White.clone().multLocal(1.7f));
sun.setColor(ColorRGBA.White.clone().multLocal(1f));
mainScene.addLight(sun);
DirectionalLight l = new DirectionalLight();
l.setDirection(Vector3f.UNIT_Y.mult(-1));
l.setColor(ColorRGBA.White.clone().multLocal(0.3f));
// mainScene.addLight(l);
AmbientLight al = new AmbientLight();
al.setColor(new ColorRGBA(0.1f, 0.1f, 0.1f, 1.0f));
mainScene.addLight(al);
flyCam.setMoveSpeed(50);
@ -97,49 +98,52 @@ public class TestPostWater extends SimpleApplication {
mainScene.attachChild(sky);
cam.setFrustumFar(4000);
//cam.setFrustumNear(100);
//private FilterPostProcessor fpp;
//Water Filter
water = new WaterFilter(rootNode, lightDir);
water.setWaterColor(new ColorRGBA().setAsSrgb(0.0078f, 0.3176f, 0.5f, 1.0f));
water.setDeepWaterColor(new ColorRGBA().setAsSrgb(0.0039f, 0.00196f, 0.145f, 1.0f));
water.setUnderWaterFogDistance(80);
water.setWaterTransparency(0.12f);
water.setFoamIntensity(0.4f);
water.setFoamHardness(0.3f);
water.setFoamExistence(new Vector3f(0.8f, 8f, 1f));
water.setReflectionDisplace(50);
water.setRefractionConstant(0.25f);
water.setColorExtinction(new Vector3f(30, 50, 70));
water.setCausticsIntensity(0.4f);
water.setWaveScale(0.003f);
water.setMaxAmplitude(2f);
water.setFoamTexture((Texture2D) assetManager.loadTexture("Common/MatDefs/Water/Textures/foam2.jpg"));
water.setRefractionStrength(0.2f);
water.setWaterHeight(initialWaterHeight);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
fpp.addFilter(water);
//Bloom Filter
BloomFilter bloom = new BloomFilter();
//bloom.getE
bloom.setExposurePower(55);
bloom.setBloomIntensity(1.0f);
fpp.addFilter(bloom);
//Light Scattering Filter
LightScatteringFilter lsf = new LightScatteringFilter(lightDir.mult(-300));
lsf.setLightDensity(1.0f);
fpp.addFilter(lsf);
lsf.setLightDensity(0.5f);
//Depth of field Filter
DepthOfFieldFilter dof = new DepthOfFieldFilter();
dof.setFocusDistance(0);
dof.setFocusRange(100);
fpp.addFilter(dof);
//
// fpp.addFilter(new TranslucentBucketFilter());
//
// fpp.setNumSamples(4);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
water.setWaveScale(0.003f);
water.setMaxAmplitude(2f);
water.setFoamExistence(new Vector3f(1f, 4, 0.5f));
water.setFoamTexture((Texture2D) assetManager.loadTexture("Common/MatDefs/Water/Textures/foam2.jpg"));
//water.setNormalScale(0.5f);
fpp.addFilter(water);
fpp.addFilter(bloom);
fpp.addFilter(dof);
fpp.addFilter(lsf);
fpp.addFilter(new FXAAFilter());
//water.setRefractionConstant(0.25f);
water.setRefractionStrength(0.2f);
//water.setFoamHardness(0.6f);
// fpp.addFilter(new GammaCorrectionFilter());
// fpp.addFilter(new TranslucentBucketFilter());
// fpp.setNumSamples(4);
water.setWaterHeight(initialWaterHeight);
uw = cam.getLocation().y < waterHeight;
waves = new AudioNode(assetManager, "Sound/Environment/Ocean Waves.ogg", false);
@ -184,7 +188,7 @@ public class TestPostWater extends SimpleApplication {
inputManager.addMapping("upRM", new KeyTrigger(KeyInput.KEY_PGUP));
inputManager.addMapping("downRM", new KeyTrigger(KeyInput.KEY_PGDN));
// createBox();
// createFire();
// createFire();
}
Geometry box;
@ -234,9 +238,9 @@ public class TestPostWater extends SimpleApplication {
fire.setLowLife(0.5f);
fire.setHighLife(1.5f);
fire.getParticleInfluencer().setVelocityVariation(0.3f);
fire.setLocalTranslation(-350, 40, 430);
fire.setLocalTranslation(-600, 50, 300);
fire.setQueueBucket(Bucket.Transparent);
fire.setQueueBucket(Bucket.Translucent);
rootNode.attachChild(fire);
}
@ -296,21 +300,21 @@ public class TestPostWater extends SimpleApplication {
@Override
public void simpleUpdate(float tpf) {
super.simpleUpdate(tpf);
// // box.updateGeometricState();
// time += tpf;
// waterHeight = (float) Math.cos(((time * 0.6f) % FastMath.TWO_PI)) * 1.5f;
// water.setWaterHeight(initialWaterHeight + waterHeight);
// if (water.isUnderWater() && !uw) {
//
// waves.setDryFilter(new LowPassFilter(0.5f, 0.1f));
// uw = true;
// }
// if (!water.isUnderWater() && uw) {
// uw = false;
// //waves.setReverbEnabled(false);
// waves.setDryFilter(new LowPassFilter(1, 1f));
// //waves.setDryFilter(new LowPassFilter(1,1f));
//
// }
// box.updateGeometricState();
time += tpf;
waterHeight = (float) Math.cos(((time * 0.6f) % FastMath.TWO_PI)) * 1.5f;
water.setWaterHeight(initialWaterHeight + waterHeight);
if (water.isUnderWater() && !uw) {
waves.setDryFilter(new LowPassFilter(0.5f, 0.1f));
uw = true;
}
if (!water.isUnderWater() && uw) {
uw = false;
//waves.setReverbEnabled(false);
waves.setDryFilter(new LowPassFilter(1, 1f));
//waves.setDryFilter(new LowPassFilter(1,1f));
}
}
}

Loading…
Cancel
Save