From 1185d2099b4a5230019453f1a60579167818ad52 Mon Sep 17 00:00:00 2001 From: pspeed42 Date: Tue, 12 Aug 2014 03:13:16 -0400 Subject: [PATCH] Avoid some teeny-tiny per frame allocations by only creating a new Plane() and setting the water height uniform when the water height changes. Also got rid of the redundant dot() product and Vector3f allocation in the process. --- .../src/main/java/com/jme3/water/WaterFilter.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/jme3-effects/src/main/java/com/jme3/water/WaterFilter.java b/jme3-effects/src/main/java/com/jme3/water/WaterFilter.java index 14c9b4f2f..211dc9f8e 100644 --- a/jme3-effects/src/main/java/com/jme3/water/WaterFilter.java +++ b/jme3-effects/src/main/java/com/jme3/water/WaterFilter.java @@ -152,11 +152,11 @@ public class WaterFilter extends Filter { biasMatrix.mult(sceneCam.getViewProjectionMatrix(), textureProjMatrix); material.setMatrix4("TextureProjMatrix", textureProjMatrix); material.setVector3("CameraPosition", sceneCam.getLocation()); - material.setFloat("WaterHeight", waterHeight); + //material.setFloat("WaterHeight", waterHeight); //update reflection cam - plane = new Plane(Vector3f.UNIT_Y, new Vector3f(0, waterHeight, 0).dot(Vector3f.UNIT_Y)); - reflectionProcessor.setReflectionClipPlane(plane); + //plane = new Plane(Vector3f.UNIT_Y, new Vector3f(0, waterHeight, 0).dot(Vector3f.UNIT_Y)); + //reflectionProcessor.setReflectionClipPlane(plane); WaterUtils.updateReflectionCam(reflectionCam, plane, sceneCam); @@ -393,6 +393,13 @@ public class WaterFilter extends Filter { */ 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); + } } /**