Problems desabling WaterFilter in init

Hello all,



Every time I start my game with water disabled I get





If I leave it enabled I get a good image

Photobucket



This is the code:

[java]import com.jme3.app.SimpleApplication;

import com.jme3.light.DirectionalLight;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.Vector3f;

import com.jme3.post.FilterPostProcessor;

import com.jme3.renderer.queue.RenderQueue.ShadowMode;

import com.jme3.scene.Node;

import com.jme3.scene.Spatial;

import com.jme3.terrain.geomipmap.TerrainQuad;

import com.jme3.terrain.heightmap.AbstractHeightMap;

import com.jme3.terrain.heightmap.ImageBasedHeightMap;

import com.jme3.texture.Texture;

import com.jme3.texture.Texture.WrapMode;

import com.jme3.util.SkyFactory;

import com.jme3.water.WaterFilter;



public class MyWaterLake extends SimpleApplication{

private WaterFilter water;



public static void main(String[] args) {



MyWaterLake app = new MyWaterLake();

app.start();

}



public void simpleInitApp() {

initCamera();

initSky();

Node scene = initScene();

createTerrain(scene);

Vector3f lightDir = new Vector3f(-0.37352666f, -0.50444174f, -0.7784704f);

initSun(scene, lightDir);

initWaterLake(lightDir);

water.setEnabled(false);

}



private void initWaterLake(Vector3f lightDir){

ColorRGBA shallowWaterColor = new ColorRGBA(0.0078f, 0.3176f, 0.5f, 1.0f);

ColorRGBA deepWaterColor = new ColorRGBA(0.0039f, 0.00196f, 0.145f, 1.0f);

Vector3f colorExtinction = new Vector3f(5.0f, 20.0f, 30.0f);



FilterPostProcessor fpp = new FilterPostProcessor(assetManager);

water = new WaterFilter(rootNode, lightDir);

water.setWaterHeight(-10);



// underwater color

water.setDeepWaterColor(deepWaterColor);

water.setWaterColor(shallowWaterColor);

water.setColorExtinction(colorExtinction); // refraction color extintion

water.setWaterTransparency(0.1f);

// wave stuff

water.setUseFoam(false);

water.setUseRipples(true);

water.setMaxAmplitude(0.3f);

water.setWaveScale(0.008f);

water.setSpeed(0.7f);

water.setShoreHardness(0.8f); // changed from 0.6 to 0.8 so water integrates better with terrain

water.setRefractionConstant(0.01f); // changed from 0.2 to 0.01 underwater sky woobles more

water.setShininess(0.3f);

water.setSunScale(1.0f);

fpp.addFilter(water);

viewPort.addProcessor(fpp);

}



private void initSun(Spatial scene, Vector3f lightDir){

DirectionalLight sun = new DirectionalLight();

sun.setDirection(lightDir);

sun.setColor(ColorRGBA.White.clone().multLocal(2));

scene.addLight(sun);

}



private Node initScene(){

Node mainScene = new Node(“Main Scene”);

rootNode.attachChild(mainScene);

return mainScene;

}



TerrainQuad terrain;

Material matRock;

private void createTerrain(Node rootNode) {

matRock = new Material(assetManager, “Common/MatDefs/Terrain/TerrainLighting.j3md”);

matRock.setBoolean(“useTriPlanarMapping”, false);

matRock.setBoolean(“WardIso”, true);

matRock.setTexture(“AlphaMap”, assetManager.loadTexture(“Textures/Terrain/splat/alphamap.png”));

Texture heightMapImage = assetManager.loadTexture(“Textures/Terrain/splat/mountains512.png”);

Texture grass = assetManager.loadTexture(“Textures/Terrain/splat/grass.jpg”);

grass.setWrap(WrapMode.Repeat);

matRock.setTexture(“DiffuseMap”, grass);

matRock.setFloat(“DiffuseMap_0_scale”, 64);

Texture dirt = assetManager.loadTexture(“Textures/Terrain/splat/dirt.jpg”);

dirt.setWrap(WrapMode.Repeat);

matRock.setTexture(“DiffuseMap_1”, dirt);

matRock.setFloat(“DiffuseMap_1_scale”, 16);

Texture rock = assetManager.loadTexture(“Textures/Terrain/splat/road.jpg”);

rock.setWrap(WrapMode.Repeat);

matRock.setTexture(“DiffuseMap_2”, rock);

matRock.setFloat(“DiffuseMap_2_scale”, 128);

Texture normalMap0 = assetManager.loadTexture(“Textures/Terrain/splat/grass_normal.jpg”);

normalMap0.setWrap(WrapMode.Repeat);

Texture normalMap1 = assetManager.loadTexture(“Textures/Terrain/splat/dirt_normal.png”);

normalMap1.setWrap(WrapMode.Repeat);

Texture normalMap2 = assetManager.loadTexture(“Textures/Terrain/splat/road_normal.png”);

normalMap2.setWrap(WrapMode.Repeat);

matRock.setTexture(“NormalMap”, normalMap0);

matRock.setTexture(“NormalMap_1”, normalMap2);

matRock.setTexture(“NormalMap_2”, normalMap2);



AbstractHeightMap heightmap = null;

try {

heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f);

heightmap.load();

} catch (Exception e) {

e.printStackTrace();

}

terrain = new TerrainQuad(“terrain”, 65, 513, heightmap.getHeightMap());

terrain.setMaterial(matRock);

terrain.setLocalScale(new Vector3f(5, 5, 5));

terrain.setLocalTranslation(new Vector3f(0, -30, 0));

terrain.setLocked(false); // unlock it so we can edit the height



terrain.setShadowMode(ShadowMode.Receive);

rootNode.attachChild(terrain);



}



private void initSky(){

rootNode.attachChild(SkyFactory.createSky(assetManager, “Textures/Sky/Bright/BrightSky.dds”, false));

}



private void initCamera() {

getCamera().setLocation(new Vector3f(0, 10, -10));

getCamera().lookAtDirection(new Vector3f(0, -1.5f, -1).normalizeLocal(), Vector3f.UNIT_Y);

getFlyByCamera().setMoveSpeed(400);

}

}[/java]



This is the code for a minimal working example but the even stranger thing is that if I start the program showing the water and then disable it, it works fine.

How do you “disable”? Do you add the empty post processor still?

It’s the

[java]water.setEnabled(false);[/java]



In the simpleInitApp().



So I think I’m adding a fully built filter, just set to disable.

I guess he means this one

FilterPostProcessor fpp = new FilterPostProcessor(assetManager);

Oh, does a disabled Filter count as empty?



I create the WaterFilter, add it to the post processor and then disable the filter.

…creating an empty post processor… like I said in the post you ignored, do the inverse of what you do to add the water, remove the processor.

I didn’t ignore your post, I just didn’t understand what you meant since I didn’t know that a Post Processor with a disabled Filter is equal to an empty PostProcessor since when you turn it off it works just fine.

I told you directly I didn’t understand, in that thread ("I think this is what you suggested but I’m not sure, can you confirm? "). When you answered “Your WaterFilter variable is null” i also didn’t understand. Since I indeed tried to remove the filter in the example of code I just showed so I assumed I wasn’t doing what you suggested.



I know you’re probably gonna ignore me from now on and I’m really sorry about that because I really value your input.

Just want you to know the only reason seem to ignore you is that I don’t know enough to understand what you are saying.

thats your interpretation of “the post you ignored”? my intention in “reminding” you is to hint at the fact that you might want to read back on answers people already gave to you as some information might become clearer after you gained other knowledge. else it can become frustrating quickly on the other side having to repeat things all the time.

Yes, that was my interpretation as ‘ignored’ usually has a bad connotation.

Happy to be wrong.



Anyway, it’s working fine now that I’m add and removing the whole PostProcessor.



So the setEnable(false) is for the case when there are several filters and we want to switch between them.

And it worked after I initialized it with an enabled filter because there are things that are only done in the init phase?

Just to learn a bit about the inside working of the engine as I make mistakes.

setEnable mainly allows disabling filters temporarily w/o changing the order, yes. It didn’t work as nothing was processing your scene in the empty filterPostProcessor, hence there was no output. I guess an empty PostProcessor could be handled a bit more graceful @nehon?