From c95c656a551a4bd6c37423a41599645d2bdd686e Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Fri, 10 Jun 2011 16:32:32 +0000 Subject: [PATCH] WaterFilter reflection is now correctly rendered when the up axis of the cam is not Y git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7567 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../src/core/com/jme3/post/FilterPostProcessor.java | 5 ++++- .../jme3/post/filters/TranslucentBucketFilter.java | 4 +++- .../src/desktop-fx/com/jme3/water/WaterFilter.java | 12 +++++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/engine/src/core/com/jme3/post/FilterPostProcessor.java b/engine/src/core/com/jme3/post/FilterPostProcessor.java index b9be95e60..e4bb26c55 100644 --- a/engine/src/core/com/jme3/post/FilterPostProcessor.java +++ b/engine/src/core/com/jme3/post/FilterPostProcessor.java @@ -194,7 +194,7 @@ public class FilterPostProcessor implements SceneProcessor, Savable { public void renderFilterChain(Renderer r, FrameBuffer sceneFb) { Texture2D tex = filterTexture; - FrameBuffer buff = null; + FrameBuffer buff = sceneFb; boolean msDepth = depthTexture != null && depthTexture.getImage().getMultiSamples() > 1; for (int i = 0; i < filters.size(); i++) { Filter filter = filters.get(i); @@ -260,6 +260,9 @@ public class FilterPostProcessor implements SceneProcessor, Savable { sceneBuffer = renderFrameBufferMS; } renderFilterChain(renderer, sceneBuffer); + renderManager.setCamera(viewPort.getCamera(), false); + + renderer.setFrameBuffer(outputBuffer); } diff --git a/engine/src/desktop-fx/com/jme3/post/filters/TranslucentBucketFilter.java b/engine/src/desktop-fx/com/jme3/post/filters/TranslucentBucketFilter.java index 8a16983ea..12016d485 100644 --- a/engine/src/desktop-fx/com/jme3/post/filters/TranslucentBucketFilter.java +++ b/engine/src/desktop-fx/com/jme3/post/filters/TranslucentBucketFilter.java @@ -49,7 +49,9 @@ public final class TranslucentBucketFilter extends Filter { @Override public void postFrame(RenderManager renderManager, ViewPort viewPort, FrameBuffer prevFilterBuffer, FrameBuffer sceneBuffer) { renderManager.setCamera(viewPort.getCamera(), false); - renderManager.getRenderer().copyFrameBuffer(prevFilterBuffer, sceneBuffer, false); + if(prevFilterBuffer != sceneBuffer){ + renderManager.getRenderer().copyFrameBuffer(prevFilterBuffer, sceneBuffer, false); + } renderManager.getRenderer().setFrameBuffer(sceneBuffer); viewPort.getQueue().renderQueue(RenderQueue.Bucket.Translucent, renderManager, viewPort.getCamera()); } diff --git a/engine/src/desktop-fx/com/jme3/water/WaterFilter.java b/engine/src/desktop-fx/com/jme3/water/WaterFilter.java index d5a8054a9..01b66ebae 100644 --- a/engine/src/desktop-fx/com/jme3/water/WaterFilter.java +++ b/engine/src/desktop-fx/com/jme3/water/WaterFilter.java @@ -53,6 +53,7 @@ import com.jme3.scene.Spatial; import com.jme3.texture.Image.Format; import com.jme3.texture.Texture.WrapMode; import com.jme3.texture.Texture2D; +import com.jme3.util.TempVars; import java.io.IOException; /** @@ -166,7 +167,16 @@ public class WaterFilter extends Filter { sceneCam.getFrustumRight(), sceneCam.getFrustumTop(), sceneCam.getFrustumBottom()); - reflectionCam.lookAt(targetLocation, Vector3f.UNIT_Y); + TempVars vars = TempVars.get(); + assert vars.lock(); + + vars.vect1.set(sceneCam.getLocation()).addLocal(sceneCam.getUp()); + float planeDistance = plane.pseudoDistance(vars.vect1); + vars.vect2.set(plane.getNormal()).multLocal(planeDistance * 2.0f); + vars.vect3.set(vars.vect1.subtractLocal(vars.vect2)).subtractLocal(loc).normalizeLocal().negateLocal(); + reflectionCam.lookAt(targetLocation, vars.vect3); + + assert vars.unlock(); if (inv) { reflectionCam.setAxes(reflectionCam.getLeft().negateLocal(), reflectionCam.getUp(), reflectionCam.getDirection().negateLocal()); }