@Override
    protected void initFilter(AssetManager manager, RenderManager renderManager, ViewPort vp, int w, int h) {
        rootScene = vp.getScenes().get(0);

        if (reflectionScene == null) {
            reflectionScene = rootScene;
            DirectionalLight directionalLight = findLight((Node) reflectionScene);
            if (directionalLight != null && useDirectionLightFromScene()) {
                lightDirection = directionalLight.getDirection();
            }
        }

        this.renderManager = renderManager;
        this.viewPort = vp;
        reflectionPass = new Pass();
        reflectionPass.init(renderManager.getRenderer(), reflectionMapSize, reflectionMapSize, Format.RGBA8, Format.Depth);
        reflectionCam = new Camera(reflectionMapSize, reflectionMapSize);
        reflectionView = new ViewPort("reflectionView", reflectionCam);
        reflectionView.setClearFlags(true, true, true);
        reflectionView.attachScene(reflectionScene);
        reflectionView.setOutputFrameBuffer(reflectionPass.getRenderFrameBuffer());
        plane = new Plane(Vector3f.UNIT_Y, new Vector3f(0, waterHeight, 0).dot(Vector3f.UNIT_Y));
        reflectionProcessor = new ReflectionProcessor(reflectionCam, reflectionPass.getRenderFrameBuffer(), plane);
        reflectionProcessor.setReflectionClipPlane(plane);
        reflectionView.addProcessor(reflectionProcessor);

        if (normalTexture == null) {
            normalTexture = (Texture2D) manager.loadTexture(DEFAULT_NORMAL_MAP);
            normalTexture.setWrap(WrapMode.Repeat);
        }

        if (foamTexture == null) {
            foamTexture = (Texture2D) manager.loadTexture(DEFAULT_FOAM);
            foamTexture.setWrap(WrapMode.Repeat);
        }

        if (causticsTexture == null) {
            causticsTexture = (Texture2D) manager.loadTexture(DEFAULT_CAUSTICS);
            causticsTexture.setWrap(WrapMode.Repeat);
        }

        if (heightTexture == null) {
            heightTexture = (Texture2D) manager.loadTexture(DEFAULT_HEIGHT_MAP);
            heightTexture.setWrap(WrapMode.Repeat);
        }

        material = new Material(manager, "Common/MatDefs/Water/Water.j3md");
        material.setTexture("HeightMap", heightTexture);
        material.setTexture("CausticsMap", causticsTexture);
        material.setTexture("FoamMap", foamTexture);
        material.setTexture("NormalMap", normalTexture);
        material.setTexture("ReflectionMap", reflectionPass.getRenderedTexture());

        material.setFloat("WaterTransparency", waterTransparency);
        material.setFloat("NormalScale", normalScale);
        material.setFloat("R0", refractionConstant);
        material.setFloat("MaxAmplitude", maxAmplitude);
        material.setVector3("LightDir", lightDirection);
        material.setColor("LightColor", lightColor);
        material.setFloat("ShoreHardness", shoreHardness);
        material.setFloat("RefractionStrength", refractionStrength);
        material.setFloat("WaveScale", waveScale);
        material.setVector3("FoamExistence", foamExistence);
        material.setFloat("SunScale", sunScale);
        material.setVector3("ColorExtinction", colorExtinction);
        material.setFloat("Shininess", shininess);
        material.setColor("WaterColor", waterColor);
        material.setColor("DeepWaterColor", deepWaterColor);
        material.setVector2("WindDirection", windDirection);
        material.setFloat("FoamHardness", foamHardness);
        material.setBoolean("UseRipples", useRipples);
        material.setBoolean("UseHQShoreline", useHQShoreline);
        material.setBoolean("UseSpecular", useSpecular);
        material.setBoolean("UseFoam", useFoam);
        material.setBoolean("UseCaustics", useCaustics);
        material.setBoolean("UseRefraction", useRefraction);
        material.setFloat("ReflectionDisplace", reflectionDisplace);
        material.setFloat("FoamIntensity", foamIntensity);
        material.setFloat("UnderWaterFogDistance", underWaterFogDistance);
        material.setFloat("CausticsIntensity", causticsIntensity);
        if (center != null) {
            material.setVector3("Center", center);
            material.setFloat("Radius", radius * radius);
            material.setBoolean("SquareArea", shapeType == AreaShape.Square);
        }
        material.setFloat("WaterHeight", waterHeight);
    }
@return true to try using directional light from a scene
jme3-effects/src/main/java/com/jme3/water/WaterFilter.java