浏览代码

SinglePass now uses the TechniqueDef LightSpace.
The single pass material definition LightSpace has been set to View until we implement it in world space.

Nehon 10 年之前
父节点
当前提交
cecf355c70

+ 8 - 13
jme3-core/src/main/java/com/jme3/material/Material.java

@@ -788,9 +788,8 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
                         Vector3f dir = dl.getDirection();                        
                         Vector3f dir = dl.getDirection();                        
                         //Data directly sent in view space to avoid a matrix mult for each pixel
                         //Data directly sent in view space to avoid a matrix mult for each pixel
                         tmpVec.set(dir.getX(), dir.getY(), dir.getZ(), 0.0f);
                         tmpVec.set(dir.getX(), dir.getY(), dir.getZ(), 0.0f);
-                        rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);      
-//                        tmpVec.divideLocal(tmpVec.w);
-//                        tmpVec.normalizeLocal();
+                        transposeLightDataToSpace(technique.getDef().getLightSpace(), rm, tmpVec);                        
+
                         lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), -1, lightDataIndex);
                         lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), -1, lightDataIndex);
                         lightDataIndex++;
                         lightDataIndex++;
                         //PADDING
                         //PADDING
@@ -802,8 +801,8 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
                         Vector3f pos = pl.getPosition();
                         Vector3f pos = pl.getPosition();
                         float invRadius = pl.getInvRadius();
                         float invRadius = pl.getInvRadius();
                         tmpVec.set(pos.getX(), pos.getY(), pos.getZ(), 1.0f);
                         tmpVec.set(pos.getX(), pos.getY(), pos.getZ(), 1.0f);
-                        rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);    
-                        //tmpVec.divideLocal(tmpVec.w);
+                        transposeLightDataToSpace(technique.getDef().getLightSpace(), rm, tmpVec);                        
+                        
                         lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRadius, lightDataIndex);
                         lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRadius, lightDataIndex);
                         lightDataIndex++;
                         lightDataIndex++;
                         //PADDING
                         //PADDING
@@ -817,17 +816,13 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
                         float invRange = sl.getInvSpotRange();
                         float invRange = sl.getInvSpotRange();
                         float spotAngleCos = sl.getPackedAngleCos();
                         float spotAngleCos = sl.getPackedAngleCos();
                         tmpVec.set(pos2.getX(), pos2.getY(), pos2.getZ(),  1.0f);
                         tmpVec.set(pos2.getX(), pos2.getY(), pos2.getZ(),  1.0f);
-                        rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);   
-                       // tmpVec.divideLocal(tmpVec.w);
+                        transposeLightDataToSpace(technique.getDef().getLightSpace(), rm, tmpVec);                        
+                       
                         lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRange, lightDataIndex);
                         lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), invRange, lightDataIndex);
                         lightDataIndex++;
                         lightDataIndex++;
                         
                         
-                        //We transform the spot direction in view space here to save 5 varying later in the lighting shader
-                        //one vec4 less and a vec4 that becomes a vec3
-                        //the downside is that spotAngleCos decoding happens now in the frag shader.
                         tmpVec.set(dir2.getX(), dir2.getY(), dir2.getZ(),  0.0f);
                         tmpVec.set(dir2.getX(), dir2.getY(), dir2.getZ(),  0.0f);
-                        rm.getCurrentCamera().getViewMatrix().mult(tmpVec, tmpVec);                           
-                        tmpVec.normalizeLocal();
+                        transposeLightDataToSpace(technique.getDef().getLightSpace(), rm, tmpVec);                        
                         lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), spotAngleCos, lightDataIndex);
                         lightData.setVector4InArray(tmpVec.getX(), tmpVec.getY(), tmpVec.getZ(), spotAngleCos, lightDataIndex);
                         lightDataIndex++;
                         lightDataIndex++;
                         break;                    
                         break;                    
@@ -956,7 +951,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
     
     
     private void transposeLightDataToSpace(TechniqueDef.LightSpace space, RenderManager rm, Vector4f store){
     private void transposeLightDataToSpace(TechniqueDef.LightSpace space, RenderManager rm, Vector4f store){
         if(space == TechniqueDef.LightSpace.View){          
         if(space == TechniqueDef.LightSpace.View){          
-            rm.getCurrentCamera().getViewMatrix().mult(store, store);            
+            rm.getCurrentCamera().getViewMatrix().mult(store, store);        
         }
         }
     };
     };
 
 

+ 1 - 0
jme3-core/src/main/resources/Common/MatDefs/Light/Lighting.j3md

@@ -117,6 +117,7 @@ MaterialDef Phong Lighting {
 
 
  Technique {
  Technique {
         LightMode SinglePass
         LightMode SinglePass
+        LightSpace View
         
         
         VertexShader GLSL100:   Common/MatDefs/Light/SPLighting.vert
         VertexShader GLSL100:   Common/MatDefs/Light/SPLighting.vert
         FragmentShader GLSL100: Common/MatDefs/Light/SPLighting.frag
         FragmentShader GLSL100: Common/MatDefs/Light/SPLighting.frag