Browse Source

Changed the way indirect lighting is toggled on or of, there was silly problems with previous commit.

Nehon 9 years ago
parent
commit
31d271d972

+ 7 - 6
jme3-core/src/main/java/com/jme3/material/Material.java

@@ -760,6 +760,7 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
         lightData.setVector4Length(numLights * 3);//8 lights * max 3
         lightData.setVector4Length(numLights * 3);//8 lights * max 3
         Uniform ambientColor = shader.getUniform("g_AmbientLightColor");
         Uniform ambientColor = shader.getUniform("g_AmbientLightColor");
         Uniform lightProbeData = shader.getUniform("g_LightProbeData");
         Uniform lightProbeData = shader.getUniform("g_LightProbeData");
+        lightProbeData.setVector4Length(1);
         Uniform lightProbeIrrMap = shader.getUniform("g_IrradianceMap");
         Uniform lightProbeIrrMap = shader.getUniform("g_IrradianceMap");
         Uniform lightProbePemMap = shader.getUniform("g_PrefEnvMap");
         Uniform lightProbePemMap = shader.getUniform("g_PrefEnvMap");
         
         
@@ -843,12 +844,11 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
                         break;
                         break;
                     case Probe:
                     case Probe:
                         useIBL = true;
                         useIBL = true;
-                        technique.setUseIndirectLighting(true);
                         endIndex++;
                         endIndex++;
                         LightProbe probe = (LightProbe)l;
                         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);                        
+                        BoundingSphere s = (BoundingSphere)probe.getBounds();                        
+                        lightProbeData.setVector4InArray(probe.getPosition().x, probe.getPosition().y, probe.getPosition().z, 1f/s.getRadius(), 0);
+                        
                         //assigning new texture indexes if they have never been assigned.
                         //assigning new texture indexes if they have never been assigned.
                         if( irrUnit == -1 ){
                         if( irrUnit == -1 ){
                             irrUnit = nextTexUnit++;
                             irrUnit = nextTexUnit++;
@@ -865,8 +865,9 @@ public class Material implements CloneableSmartAsset, Cloneable, Savable {
         }
         }
         vars.release();
         vars.release();
         
         
-        if(!useIBL ){ 
-            technique.setUseIndirectLighting(false);            
+        if(!useIBL ){            
+            //Disable IBL for this pass
+            lightProbeData.setVector4InArray(0,0,0,-1, 0);
         }
         }
         //Padding of unsued buffer space
         //Padding of unsued buffer space
         while(lightDataIndex < numLights * 3) {
         while(lightDataIndex < numLights * 3) {

+ 0 - 9
jme3-core/src/main/java/com/jme3/material/Technique.java

@@ -188,15 +188,6 @@ public class Technique /* implements Savable */ {
         }
         }
     }
     }
     
     
-    public void setUseIndirectLighting(boolean useIBL){
-        if(useIBL){
-            defines.set("INDIRECT_LIGHTING", VarType.Boolean, true);
-        }else{
-            defines.remove("INDIRECT_LIGHTING");
-        }
-        needReload = true;
-    }
-
     private void loadShader(AssetManager manager,EnumSet<Caps> rendererCaps) {
     private void loadShader(AssetManager manager,EnumSet<Caps> rendererCaps) {
         
         
         ShaderKey key = new ShaderKey(getAllDefines(),def.getShaderProgramLanguages(),def.getShaderProgramNames());
         ShaderKey key = new ShaderKey(getAllDefines(),def.getShaderProgramLanguages(),def.getShaderProgramNames());

+ 20 - 22
jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag

@@ -23,7 +23,7 @@ varying vec3 wPosition;
 //  uniform sampler2D m_IntegrateBRDF;
 //  uniform sampler2D m_IntegrateBRDF;
   uniform samplerCube g_PrefEnvMap;
   uniform samplerCube g_PrefEnvMap;
   uniform samplerCube g_IrradianceMap;
   uniform samplerCube g_IrradianceMap;
-  uniform vec4 g_ProbeData;
+  uniform vec4 g_LightProbeData;
 //#endif
 //#endif
 
 
 #ifdef BASECOLORMAP
 #ifdef BASECOLORMAP
@@ -202,28 +202,26 @@ void main(){
         gl_FragColor.rgb += directLighting * fallOff;
         gl_FragColor.rgb += directLighting * fallOff;
     }
     }
 
 
-    #ifdef INDIRECT_LIGHTING
-        vec3 rv = reflect(-viewDir.xyz, normal.xyz);
-        //prallax fix for spherical bounds.
-        rv = g_ProbeData.w * (wPosition - g_ProbeData.xyz) +rv;
-       
-         //horizon fade from http://marmosetco.tumblr.com/post/81245981087
-        float horiz = dot(rv, wNormal.xyz);
-        float horizFadePower= 1.0 - Roughness;
-        horiz = clamp( 1.0 + horizFadePower * horiz, 0.0, 1.0 );
-        horiz *= horiz;
-        
-        vec3 indirectDiffuse = vec3(0.0);
-        vec3 indirectSpecular = vec3(0.0);    
-        indirectDiffuse = textureCube(g_IrradianceMap, rv.xyz).rgb * albedo.rgb;
-        
-        indirectSpecular = ApproximateSpecularIBLPolynomial(g_PrefEnvMap, specularColor.rgb, Roughness, ndotv, rv.xyz);
-        indirectSpecular *= vec3(horiz);
+    vec3 rv = reflect(-viewDir.xyz, normal.xyz);
+    //prallax fix for spherical bounds.
+    rv = g_LightProbeData.w * (wPosition - g_LightProbeData.xyz) +rv;
 
 
-        vec3 indirectLighting =  indirectDiffuse + indirectSpecular;
-        
-        gl_FragColor.rgb = gl_FragColor.rgb + indirectLighting ;        
-    #endif
+     //horizon fade from http://marmosetco.tumblr.com/post/81245981087
+    float horiz = dot(rv, wNormal.xyz);
+    float horizFadePower= 1.0 - Roughness;
+    horiz = clamp( 1.0 + horizFadePower * horiz, 0.0, 1.0 );
+    horiz *= horiz;
+
+    vec3 indirectDiffuse = vec3(0.0);
+    vec3 indirectSpecular = vec3(0.0);    
+    indirectDiffuse = textureCube(g_IrradianceMap, rv.xyz).rgb * albedo.rgb;
+
+    indirectSpecular = ApproximateSpecularIBLPolynomial(g_PrefEnvMap, specularColor.rgb, Roughness, ndotv, rv.xyz);
+    indirectSpecular *= vec3(horiz);
+
+    vec3 indirectLighting =  indirectDiffuse + indirectSpecular;
+
+    gl_FragColor.rgb = gl_FragColor.rgb + indirectLighting * step( 0.0, g_LightProbeData.w);        
  
  
     #if defined(EMISSIVE) || defined (EMISSIVEMAP)
     #if defined(EMISSIVE) || defined (EMISSIVEMAP)
         #ifdef EMISSIVEMAP
         #ifdef EMISSIVEMAP