/** * sets the reflection clipping plane offset * set a nagetive value to lower the clipping plane for relection texture rendering. * @param reflectionClippingOffset */ public void setReflectionClippingOffset(float reflectionClippingOffset) { this.reflectionClippingOffset = reflectionClippingOffset; updateClipPlanes(); }
public void onAction(String name, boolean isPressed, float tpf) { if(isPressed){ if(water.isUseHQShoreline()){ water.setUseHQShoreline(false); }else{ water.setUseHQShoreline(true); } } } }, "HQ");
public void onAnalog(String name, float value, float tpf) { if (name.equals("transparencyUp")) { processor.setWaterTransparency(processor.getWaterTransparency()+0.001f); System.out.println("Water transparency : "+processor.getWaterTransparency()); } if (name.equals("transparencyDown")) { processor.setWaterTransparency(processor.getWaterTransparency()-0.001f); System.out.println("Water transparency : "+processor.getWaterTransparency()); } if (name.equals("depthUp")) { processor.setWaterDepth(processor.getWaterDepth()+0.001f); System.out.println("Water depth : "+processor.getWaterDepth()); } if (name.equals("depthDown")) { processor.setWaterDepth(processor.getWaterDepth()-0.001f); System.out.println("Water depth : "+processor.getWaterDepth()); } } };
public void initialize(RenderManager rm, ViewPort vp) { this.rm = rm; this.vp = vp; loadTextures(manager); createTextures(); applyTextures(material); createPreViews(); material.setVector2("FrustumNearFar", new Vector2f(vp.getCamera().getFrustumNear(), vp.getCamera().getFrustumFar())); if (debug) { dispRefraction = new Picture("dispRefraction"); dispRefraction.setTexture(manager, refractionTexture, false); dispReflection = new Picture("dispRefraction"); dispReflection.setTexture(manager, reflectionTexture, false); dispDepth = new Picture("depthTexture"); dispDepth.setTexture(manager, depthTexture, false); } }
reflectionView.addProcessor(new ReflectionProcessor(reflectionCam, reflectionBuffer, reflectionClipPlane)); refractionView.addProcessor(new RefractionProcessor());
public void onAction(String name, boolean isPressed, float tpf) { if (isPressed) { if (name.equals("foam1")) { water.setFoamTexture((Texture2D) assetManager.loadTexture("Common/MatDefs/Water/Textures/foam.jpg")); } if (name.equals("foam2")) { water.setFoamTexture((Texture2D) assetManager.loadTexture("Common/MatDefs/Water/Textures/foam2.jpg")); } if (name.equals("foam3")) { 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", "upRM", "downRM");
@Override public void simpleInitApp() { initInput(); initScene(); //create processor waterProcessor = new SimpleWaterProcessor(assetManager); waterProcessor.setReflectionScene(sceneNode); waterProcessor.setDebug(true); viewPort.addProcessor(waterProcessor); waterProcessor.setLightPosition(lightPos); //create water quad //waterPlane = waterProcessor.createWaterGeometry(100, 100); waterPlane=(Spatial) assetManager.loadModel("Models/WaterTest/WaterTest.mesh.xml"); waterPlane.setMaterial(waterProcessor.getMaterial()); waterPlane.setLocalScale(40); waterPlane.setLocalTranslation(-5, 0, 5); rootNode.attachChild(waterPlane); }
public void postFrame(FrameBuffer out) { if (debug) { displayMap(rm.getRenderer(), dispRefraction, 64); displayMap(rm.getRenderer(), dispReflection, 256); displayMap(rm.getRenderer(), dispDepth, 448); } }
private DirectionalLight findLight(Node node) { for (Light light : node.getWorldLightList()) { if (light instanceof DirectionalLight) { return (DirectionalLight) light; } } for (Spatial child : node.getChildren()) { if (child instanceof Node) { return findLight((Node) child); } } return null; }
/** * Sets the height of the water plane * default is 0.0 * @param waterHeight */ public void setWaterHeight(float waterHeight) { this.waterHeight = waterHeight; this.plane = new Plane(Vector3f.UNIT_Y, waterHeight); if (material != null) { material.setFloat("WaterHeight", waterHeight); } if (reflectionProcessor != null) { reflectionProcessor.setReflectionClipPlane(plane); } }
/** * Sets the size of the reflection map * default is 512, the higher, the better quality, but the slower the effect. * @param reflectionMapSize */ public void setReflectionMapSize(int reflectionMapSize) { this.reflectionMapSize = reflectionMapSize; //if reflection pass is already initialized we must update it if(reflectionPass != null){ reflectionPass.init(renderManager.getRenderer(), reflectionMapSize, reflectionMapSize, Format.RGBA8, Format.Depth); reflectionCam.resize(reflectionMapSize, reflectionMapSize, true); reflectionProcessor.setReflectionBuffer(reflectionPass.getRenderFrameBuffer()); material.setTexture("ReflectionMap", reflectionPass.getRenderedTexture()); } }
@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)); } } }
public void postQueue(RenderQueue rq) { Camera sceneCam = rm.getCurrentCamera(); //update refraction cam refractionCam.setLocation(sceneCam.getLocation()); refractionCam.setRotation(sceneCam.getRotation()); refractionCam.setFrustum(sceneCam.getFrustumNear(), sceneCam.getFrustumFar(), sceneCam.getFrustumLeft(), sceneCam.getFrustumRight(), sceneCam.getFrustumTop(), sceneCam.getFrustumBottom()); refractionCam.setParallelProjection(sceneCam.isParallelProjection()); //update reflection cam WaterUtils.updateReflectionCam(reflectionCam, plane, sceneCam); //Rendering reflection and refraction rm.renderViewPort(reflectionView, savedTpf); rm.renderViewPort(refractionView, savedTpf); rm.getRenderer().setFrameBuffer(vp.getOutputFrameBuffer()); rm.setCamera(sceneCam, false); }
/** * Sets the scene to render in the reflection map. * * @param reflectionScene the refraction scene. */ public void setReflectionScene(final Spatial reflectionScene) { final Spatial currentScene = getReflectionScene(); if (reflectionView != null) { reflectionView.detachScene(currentScene == null? rootScene : currentScene); } this.reflectionScene = reflectionScene; if (reflectionView != null) { reflectionView.attachScene(reflectionScene == null? rootScene : reflectionScene); } }
public void onAction(String name, boolean value, float tpf) { if (name.equals("use_water") && value) { if (!useWater) { useWater = true; waterPlane.setMaterial(waterProcessor.getMaterial()); } else { useWater = false; waterPlane.setMaterial(mat); } } else if (name.equals("lightup") && value) { lightPos.y++; } else if (name.equals("lightdown") && value) { lightPos.y--; } else if (name.equals("lightleft") && value) { lightPos.x--; } else if (name.equals("lightright") && value) { lightPos.x++; } else if (name.equals("lightforward") && value) { lightPos.z--; } else if (name.equals("lightback") && value) { lightPos.z++; } } }
@Override public void simpleUpdate(float tpf) { fpsText.setText("Light Position: "+lightPos.toString()+" Change Light position with [U], [H], [J], [K] and [T], [G] Turn off water with [O]"); lightSphere.setLocalTranslation(lightPos); waterProcessor.setLightPosition(lightPos); }
/** * Sets the refraction clipping plane offset * set a positive value to raise the clipping plane for refraction texture rendering * @param refractionClippingOffset */ public void setRefractionClippingOffset(float refractionClippingOffset) { this.refractionClippingOffset = refractionClippingOffset; updateClipPlanes(); }
/** * Set the water plane using an origin (location) and a normal (reflection direction). * @param origin Set to 0,-6,0 if your water quad is at that location for correct reflection * @param normal Set to 0,1,0 (Vector3f.UNIT_Y) for normal planar water */ public void setPlane(Vector3f origin, Vector3f normal) { this.plane.setOriginNormal(origin, normal); updateClipPlanes(); }
/** * Set the water plane for this processor. * @param plane */ public void setPlane(Plane plane) { this.plane.setConstant(plane.getConstant()); this.plane.setNormal(plane.getNormal()); updateClipPlanes(); }
/** * Creates a SimpleWaterProcessor * @param manager the asset manager */ public SimpleWaterProcessor(AssetManager manager) { this.manager = manager; material = new Material(manager, "Common/MatDefs/Water/SimpleWater.j3md"); material.setFloat("waterDepth", waterDepth); material.setFloat("waterTransparency", waterTransparency / 10); material.setColor("waterColor", ColorRGBA.White); material.setVector3("lightPos", new Vector3f(1, -1, 1)); material.setFloat("distortionScale", distortionScale); material.setFloat("distortionMix", distortionMix); material.setFloat("texScale", texScale); updateClipPlanes(); }