Browse Source

Fixed LightProbe selection according to distance and bounds

Nehon 10 years ago
parent
commit
b5c946ef02

+ 8 - 0
jme3-core/src/main/java/com/jme3/light/LightProbe.java

@@ -221,6 +221,7 @@ public class LightProbe extends Light implements Savable {
      */
     public void setPosition(Vector3f position) {
         this.position.set(position);
+        getBounds().setCenter(position);
     }
 
     @Override
@@ -248,4 +249,11 @@ public class LightProbe extends Light implements Savable {
         return Type.Probe;
     }
 
+    @Override
+    public String toString() {
+        return "Light Probe : " + position ;
+    }
+    
+    
+
 }

+ 3 - 12
jme3-core/src/main/java/com/jme3/material/Material.java

@@ -839,27 +839,18 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
                         break;
                     case Probe:
                         
-                        //There should be a better way to handle these texture units
-                        //for now they are removed and reassign on every frame which is a waste.                        
-                        if (irrUnit != -1) {
-                            lightProbeIrrMap.clearValue();
-                            lightProbePemMap.clearValue();
-                            removeTexUnit(irrUnit);
-                            removeTexUnit(pemUnit);
-                            irrUnit = -1;
-                            pemUnit = -1;
-                        }
                         endIndex++;
                         LightProbe probe = (LightProbe)l;
                         BoundingSphere s = (BoundingSphere)probe.getBounds();
                         tmpVec.set(probe.getPosition().x, probe.getPosition().y, probe.getPosition().z, 1f/s.getRadius());
-                        lightProbeData.setValue(VarType.Vector4, tmpVec);
+                        lightProbeData.setValue(VarType.Vector4, tmpVec);                        
+                        //assigning new texture indexes if they have never been assigned.
                         if( irrUnit == -1 ){
                             irrUnit = nextTexUnit++;
                             pemUnit = nextTexUnit++;
                         }
                         rm.getRenderer().setTexture(irrUnit, probe.getIrradianceMap());
-                        lightProbeIrrMap.setValue(VarType.Int, irrUnit);
+                        lightProbeIrrMap.setValue(VarType.Int, irrUnit);                        
                         rm.getRenderer().setTexture(pemUnit, probe.getPrefilteredEnvMap());
                         lightProbePemMap.setValue(VarType.Int, pemUnit);
                         break;