Просмотр исходного кода

Revert "Modularize PBRLighting"

Riccardo Balbo 1 год назад
Родитель
Сommit
35532e063d

+ 338 - 65
jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.frag

@@ -1,94 +1,367 @@
 #import "Common/ShaderLib/GLSLCompat.glsllib"
+#import "Common/ShaderLib/PBR.glsllib"
+#import "Common/ShaderLib/Parallax.glsllib"
+#import "Common/ShaderLib/Lighting.glsllib"
 
 varying vec2 texCoord;
-vec2 newTexCoord; 
 #ifdef SEPARATE_TEXCOORD
-    varying vec2 texCoord2;
+  varying vec2 texCoord2;
 #endif
 
-#ifdef DISCARD_ALPHA
-    uniform float m_AlphaDiscardThreshold;
+varying vec4 Color;
+
+uniform vec4 g_LightData[NB_LIGHTS];
+uniform vec3 g_CameraPosition;
+uniform vec4 g_AmbientLightColor;
+
+uniform float m_Roughness;
+uniform float m_Metallic;
+
+varying vec3 wPosition;    
+
+
+#if NB_PROBES >= 1
+  uniform samplerCube g_PrefEnvMap;
+  uniform vec3 g_ShCoeffs[9];
+  uniform mat4 g_LightProbeData;
+#endif
+#if NB_PROBES >= 2
+  uniform samplerCube g_PrefEnvMap2;
+  uniform vec3 g_ShCoeffs2[9];
+  uniform mat4 g_LightProbeData2;
+#endif
+#if NB_PROBES == 3
+  uniform samplerCube g_PrefEnvMap3;
+  uniform vec3 g_ShCoeffs3[9];
+  uniform mat4 g_LightProbeData3;
 #endif
 
-#ifdef DEBUG_VALUES_MODE
-    uniform int m_DebugValuesMode;
+#ifdef BASECOLORMAP
+  uniform sampler2D m_BaseColorMap;
 #endif
 
-varying vec3 wPosition;
-varying vec3 wNormal;
-varying vec4 wTangent;
+#ifdef USE_PACKED_MR
+  uniform sampler2D m_MetallicRoughnessMap;
+#else
+    #ifdef METALLICMAP
+      uniform sampler2D m_MetallicMap;
+    #endif
+    #ifdef ROUGHNESSMAP
+      uniform sampler2D m_RoughnessMap;
+    #endif
+#endif
 
+#ifdef EMISSIVE
+  uniform vec4 m_Emissive;
+#endif
+#ifdef EMISSIVEMAP
+  uniform sampler2D m_EmissiveMap;
+#endif
+#if defined(EMISSIVE) || defined(EMISSIVEMAP)
+    uniform float m_EmissivePower;
+    uniform float m_EmissiveIntensity;
+#endif 
 
-#import "Common/ShaderLib/PBRLightingParamsReader.glsllib"
-#import "Common/ShaderLib/PBRLighting.glsllib"
-// It is important that these 2 glsllibs are referenced AFTER the other variables above have been declared. 
-// The above variables are declared here (rather than in a glsllib) to reduce redundancy, since these variables are likely to be used by more than one glsllib.
-// Only lighting variables are declared in PBRLighting.glsllib, and only basic PBR material params are declared in PBRLightingParamsReader.glsllib.
-// This allows jme developers to create a fork of this shader and make their own changes before reading the base PBR parameters or before the final lighting calculation.
-// For example, you can move texCoords based on g_Time before texReads for a simple moving water/lava effect, or blend values like albedo/roughness after the param reads
-// but before final lighting calculations to do things like dynamic texture splatting.
+#ifdef SPECGLOSSPIPELINE
 
-vec4 albedo = vec4(1.0);
-float alpha = 1.0;
+  uniform vec4 m_Specular;
+  uniform float m_Glossiness;
+  #ifdef USE_PACKED_SG
+    uniform sampler2D m_SpecularGlossinessMap;
+  #else
+    uniform sampler2D m_SpecularMap;
+    uniform sampler2D m_GlossinessMap;
+  #endif
+#endif
 
-vec4 emissive = vec4(0.0);
+#ifdef PARALLAXMAP
+  uniform sampler2D m_ParallaxMap;  
+#endif
+#if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP)))
+    uniform float m_ParallaxHeight;
+#endif
 
-vec3 ao = vec3(1.0);
-vec3 lightMapColor = vec3(0.0);
+#ifdef LIGHTMAP
+  uniform sampler2D m_LightMap;
+#endif
 
-float indoorSunLightExposure = 1.0;
+#ifdef AO_STRENGTH
+  uniform float m_AoStrength;
+#endif
+  
+#if defined(NORMALMAP) || defined(PARALLAXMAP)
+  uniform sampler2D m_NormalMap;   
+  varying vec4 wTangent;
+#endif
+#ifdef NORMALSCALE
+  uniform float m_NormalScale;
+#endif
+varying vec3 wNormal;
 
-//metallic pipeline vars:
-float Metallic = 0.0;
-float Roughness = 0.0;
+// Specular-AA
+#ifdef SPECULAR_AA_SCREEN_SPACE_VARIANCE
+  uniform float m_SpecularAASigma;
+#endif
+#ifdef SPECULAR_AA_THRESHOLD
+  uniform float m_SpecularAAKappa;
+#endif
 
-//spec gloss pipeline vars:
-vec4 specularColor;
-float glossiness;
+#ifdef DISCARD_ALPHA
+  uniform float m_AlphaDiscardThreshold;
+#endif
 
 void main(){
-    
-    vec3 norm = normalize(wNormal);
-    vec3 normal = norm;
+    vec2 newTexCoord;
     vec3 viewDir = normalize(g_CameraPosition - wPosition);
 
-    // Note: These are intentionally not surrounded by ifDefs relating to normal and parallax maps being defined, because
-    // other .glsllibs may require normal or parallax mapping even if the base model does not have those maps
-    vec3 tan = normalize(wTangent.xyz);
-    mat3 tbnMat = mat3(tan, wTangent.w * cross( (norm), (tan)), norm); 
-    vec3 vViewDir =  viewDir * tbnMat;                                 
+    vec3 norm = normalize(wNormal);
+    #if defined(NORMALMAP) || defined(PARALLAXMAP)
+        vec3 tan = normalize(wTangent.xyz);
+        mat3 tbnMat = mat3(tan, wTangent.w * cross( (norm), (tan)), norm);
+    #endif
 
-    //base PBR params and tex reads:
-    readMatParamsAndTextures(tbnMat, vViewDir, albedo, Metallic, Roughness, specularColor, glossiness, lightMapColor, ao, indoorSunLightExposure, normal, emissive, alpha);
+    #if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP)))
+       vec3 vViewDir =  viewDir * tbnMat;  
+       #ifdef STEEP_PARALLAX
+           #ifdef NORMALMAP_PARALLAX
+               //parallax map is stored in the alpha channel of the normal map         
+               newTexCoord = steepParallaxOffset(m_NormalMap, vViewDir, texCoord, m_ParallaxHeight);
+           #else
+               //parallax map is a texture
+               newTexCoord = steepParallaxOffset(m_ParallaxMap, vViewDir, texCoord, m_ParallaxHeight);         
+           #endif
+       #else
+           #ifdef NORMALMAP_PARALLAX
+               //parallax map is stored in the alpha channel of the normal map         
+               newTexCoord = classicParallaxOffset(m_NormalMap, vViewDir, texCoord, m_ParallaxHeight);
+           #else
+               //parallax map is a texture
+               newTexCoord = classicParallaxOffset(m_ParallaxMap, vViewDir, texCoord, m_ParallaxHeight);
+           #endif
+       #endif
+    #else
+       newTexCoord = texCoord;    
+    #endif
     
-    // Lighting calculation:    
-    vec3 finalLightingValue = calculatePBRLighting(albedo, Metallic, Roughness, specularColor, glossiness, lightMapColor, ao, indoorSunLightExposure, normal, norm, viewDir);
-    gl_FragColor.rgb += finalLightingValue;
+    #ifdef BASECOLORMAP
+        vec4 albedo = texture2D(m_BaseColorMap, newTexCoord) * Color;
+    #else
+        vec4 albedo = Color;
+    #endif
 
-    //apply final emissive value after lighting
-    gl_FragColor += emissive;  //no need for #ifdef check because emissive will be 0,0,0,0 if emissive vars werent defined.
+    //ao in r channel, roughness in green channel, metallic in blue channel!
+    vec3 aoRoughnessMetallicValue = vec3(1.0, 1.0, 0.0);
+    #ifdef USE_PACKED_MR
+        aoRoughnessMetallicValue = texture2D(m_MetallicRoughnessMap, newTexCoord).rgb;
+        float Roughness = aoRoughnessMetallicValue.g * max(m_Roughness, 1e-4);
+        float Metallic = aoRoughnessMetallicValue.b * max(m_Metallic, 0.0);
+    #else
+        #ifdef ROUGHNESSMAP
+            float Roughness = texture2D(m_RoughnessMap, newTexCoord).r * max(m_Roughness, 1e-4);
+        #else
+            float Roughness =  max(m_Roughness, 1e-4);
+        #endif
+        #ifdef METALLICMAP
+            float Metallic = texture2D(m_MetallicMap, newTexCoord).r * max(m_Metallic, 0.0);
+        #else
+            float Metallic =  max(m_Metallic, 0.0);
+        #endif
+    #endif
+ 
+    float alpha = albedo.a;
 
-    gl_FragColor.a = alpha;
-   
-   //outputs the final value of the selected layer as a color for debug purposes. 
-    #ifdef DEBUG_VALUES_MODE
-        if(m_DebugValuesMode == 0){
-            gl_FragColor.rgb = vec3(albedo);
-        }
-        else if(m_DebugValuesMode == 1){
-            gl_FragColor.rgb = vec3(normal);
-        }
-        else if(m_DebugValuesMode == 2){
-            gl_FragColor.rgb = vec3(Roughness);
-        }
-        else if(m_DebugValuesMode == 3){
-            gl_FragColor.rgb = vec3(Metallic);
+    #ifdef DISCARD_ALPHA
+        if(alpha < m_AlphaDiscardThreshold){
+            discard;
         }
-        else if(m_DebugValuesMode == 4){
-            gl_FragColor.rgb = ao.rgb;
+    #endif
+ 
+    // ***********************
+    // Read from textures
+    // ***********************
+    #if defined(NORMALMAP)
+      vec4 normalHeight = texture2D(m_NormalMap, newTexCoord);
+      // Note we invert directx style normal maps to opengl style
+
+      #ifdef NORMALSCALE
+        vec3 normal = normalize((normalHeight.xyz * vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0)) * vec3(m_NormalScale, m_NormalScale, 1.0));
+      #else
+        vec3 normal = normalize((normalHeight.xyz * vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0)));
+      #endif
+      normal = normalize(tbnMat * normal);
+      //normal = normalize(normal * inverse(tbnMat));
+    #else
+      vec3 normal = norm;
+    #endif
+
+    #ifdef SPECGLOSSPIPELINE
+
+        #ifdef USE_PACKED_SG
+            vec4 specularColor = texture2D(m_SpecularGlossinessMap, newTexCoord);
+            float glossiness = specularColor.a * m_Glossiness;
+            specularColor *= m_Specular;
+        #else
+            #ifdef SPECULARMAP
+                vec4 specularColor = texture2D(m_SpecularMap, newTexCoord);
+            #else
+                vec4 specularColor = vec4(1.0);
+            #endif
+            #ifdef GLOSSINESSMAP
+                float glossiness = texture2D(m_GlossinessMap, newTexCoord).r * m_Glossiness;
+            #else
+                float glossiness = m_Glossiness;
+            #endif
+            specularColor *= m_Specular;
+        #endif
+        vec4 diffuseColor = albedo;// * (1.0 - max(max(specularColor.r, specularColor.g), specularColor.b));
+        Roughness = 1.0 - glossiness;
+        vec3 fZero = specularColor.xyz;
+    #else
+        float specular = 0.5;
+        float nonMetalSpec = 0.08 * specular;
+        vec4 specularColor = (nonMetalSpec - nonMetalSpec * Metallic) + albedo * Metallic;
+        vec4 diffuseColor = albedo - albedo * Metallic;
+        vec3 fZero = vec3(specular);
+    #endif
+
+    gl_FragColor.rgb = vec3(0.0);
+    vec3 ao = vec3(1.0);
+
+    #ifdef LIGHTMAP
+       vec3 lightMapColor;
+       #ifdef SEPARATE_TEXCOORD
+          lightMapColor = texture2D(m_LightMap, texCoord2).rgb;
+       #else
+          lightMapColor = texture2D(m_LightMap, texCoord).rgb;
+       #endif
+       #ifdef AO_MAP
+         lightMapColor.gb = lightMapColor.rr;
+         ao = lightMapColor;
+       #else
+         gl_FragColor.rgb += diffuseColor.rgb * lightMapColor;
+       #endif
+       specularColor.rgb *= lightMapColor;
+    #endif
+
+    #if defined(AO_PACKED_IN_MR_MAP) && defined(USE_PACKED_MR)
+       ao = aoRoughnessMetallicValue.rrr;
+    #endif
+
+    #ifdef AO_STRENGTH
+       ao = 1.0 + m_AoStrength * (ao - 1.0);
+       // sanity check
+       ao = clamp(ao, 0.0, 1.0);
+    #endif
+
+    #ifdef SPECULAR_AA
+        float sigma = 1.0;
+        float kappa = 0.18;
+        #ifdef SPECULAR_AA_SCREEN_SPACE_VARIANCE
+            sigma = m_SpecularAASigma;
+        #endif
+        #ifdef SPECULAR_AA_THRESHOLD
+            kappa = m_SpecularAAKappa;
+        #endif
+    #endif
+    float ndotv = max( dot( normal, viewDir ),0.0);
+    for( int i = 0;i < NB_LIGHTS; i+=3){
+        vec4 lightColor = g_LightData[i];
+        vec4 lightData1 = g_LightData[i+1];                
+        vec4 lightDir;
+        vec3 lightVec;            
+        lightComputeDir(wPosition, lightColor.w, lightData1, lightDir, lightVec);
+
+        float fallOff = 1.0;
+        #if __VERSION__ >= 110
+            // allow use of control flow
+        if(lightColor.w > 1.0){
+        #endif
+            fallOff =  computeSpotFalloff(g_LightData[i+2], lightVec);
+        #if __VERSION__ >= 110
         }
-        else if(m_DebugValuesMode == 5){
-            gl_FragColor.rgb = vec3(emissive.rgb);          
-        }        
-    #endif   
+        #endif
+        //point light attenuation
+        fallOff *= lightDir.w;
+
+        lightDir.xyz = normalize(lightDir.xyz);            
+        vec3 directDiffuse;
+        vec3 directSpecular;
+
+        #ifdef SPECULAR_AA
+            float hdotv = PBR_ComputeDirectLightWithSpecularAA(
+                                normal, lightDir.xyz, viewDir,
+                                lightColor.rgb, fZero, Roughness, sigma, kappa, ndotv,
+                                directDiffuse,  directSpecular);
+        #else
+            float hdotv = PBR_ComputeDirectLight(
+                                normal, lightDir.xyz, viewDir,
+                                lightColor.rgb, fZero, Roughness, ndotv,
+                                directDiffuse,  directSpecular);
+        #endif
+
+        vec3 directLighting = diffuseColor.rgb *directDiffuse + directSpecular;
+        
+        gl_FragColor.rgb += directLighting * fallOff;
+    }
+
+    #if NB_PROBES >= 1
+        vec3 color1 = vec3(0.0);
+        vec3 color2 = vec3(0.0);
+        vec3 color3 = vec3(0.0);
+        float weight1 = 1.0;
+        float weight2 = 0.0;
+        float weight3 = 0.0;
+
+        float ndf = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData, g_ShCoeffs, g_PrefEnvMap, color1);
+        #if NB_PROBES >= 2
+            float ndf2 = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData2, g_ShCoeffs2, g_PrefEnvMap2, color2);
+        #endif
+        #if NB_PROBES == 3
+            float ndf3 = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData3, g_ShCoeffs3, g_PrefEnvMap3, color3);
+        #endif
+
+        #if NB_PROBES >= 2
+            float invNdf =  max(1.0 - ndf,0.0);
+            float invNdf2 =  max(1.0 - ndf2,0.0);
+            float sumNdf = ndf + ndf2;
+            float sumInvNdf = invNdf + invNdf2;
+            #if NB_PROBES == 3
+                float invNdf3 = max(1.0 - ndf3,0.0);
+                sumNdf += ndf3;
+                sumInvNdf += invNdf3;
+                weight3 =  ((1.0 - (ndf3 / sumNdf)) / (NB_PROBES - 1)) *  (invNdf3 / sumInvNdf);
+            #endif
+
+            weight1 = ((1.0 - (ndf / sumNdf)) / (NB_PROBES - 1)) *  (invNdf / sumInvNdf);
+            weight2 = ((1.0 - (ndf2 / sumNdf)) / (NB_PROBES - 1)) *  (invNdf2 / sumInvNdf);
+
+            float weightSum = weight1 + weight2 + weight3;
+
+            weight1 /= weightSum;
+            weight2 /= weightSum;
+            weight3 /= weightSum;
+        #endif
+
+        #ifdef USE_AMBIENT_LIGHT
+            color1.rgb *= g_AmbientLightColor.rgb;
+            color2.rgb *= g_AmbientLightColor.rgb;
+            color3.rgb *= g_AmbientLightColor.rgb;
+        #endif
+        gl_FragColor.rgb += color1 * clamp(weight1,0.0,1.0) + color2 * clamp(weight2,0.0,1.0) + color3 * clamp(weight3,0.0,1.0);
+
+    #endif
+
+    #if defined(EMISSIVE) || defined (EMISSIVEMAP)
+        #ifdef EMISSIVEMAP
+            vec4 emissive = texture2D(m_EmissiveMap, newTexCoord);
+            #ifdef EMISSIVE
+                emissive *= m_Emissive;
+            #endif
+        #else
+            vec4 emissive = m_Emissive;
+        #endif
+        gl_FragColor += emissive * pow(emissive.a, m_EmissivePower) * m_EmissiveIntensity;
+    #endif
+    gl_FragColor.a = alpha;
+   
 }

+ 0 - 18
jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.j3md

@@ -132,20 +132,6 @@ MaterialDef PBR Lighting {
         Boolean UseVertexColor
 
         Boolean BackfaceShadows : false
-
-        Boolean UseVertexColorsAsSunIntensity
-        Float StaticSunIntensity
-        Boolean BrightenIndoorShadows
-    
-        Int DebugValuesMode
-            // debugs the final value of the selected layer as a color output:         
-            // Layers:
-            //   0 - albedo (unshaded)
-            //   1 - normals
-            //   2 - roughness
-            //   3 - metallic
-            //   4 - ao
-            //   5 - emissive
     }
 
     Technique {
@@ -196,10 +182,6 @@ MaterialDef PBR Lighting {
             NUM_MORPH_TARGETS: NumberOfMorphTargets
             NUM_TARGETS_BUFFERS: NumberOfTargetsBuffers
             HORIZON_FADE: HorizonFade
-            USE_VERTEX_COLORS_AS_SUN_INTENSITY : UseVertexColorsAsSunIntensity
-            STATIC_SUN_INTENSITY : StaticSunIntensity
-            BRIGHTEN_INDOOR_SHADOWS : BrightenIndoorShadows
-            DEBUG_VALUES_MODE : DebugValuesMode
         }
     }
 

+ 12 - 13
jme3-core/src/main/resources/Common/MatDefs/Light/PBRLighting.vert

@@ -18,27 +18,23 @@ attribute vec3 inPosition;
 attribute vec2 inTexCoord;
 attribute vec3 inNormal;
 
-#if defined (VERTEX_COLOR) || defined(USE_VERTEX_COLORS_AS_SUN_INTENSITY)
-    attribute vec4 inColor;
-#endif
-
-#if defined(USE_VERTEX_COLORS_AS_SUN_INTENSITY)
-    varying vec4 vertColors;
+#ifdef VERTEX_COLOR
+  attribute vec4 inColor;
 #endif
 
 varying vec3 wNormal;
 varying vec3 wPosition;
-
-attribute vec4 inTangent;
-varying vec4 wTangent;
+#if defined(NORMALMAP) || defined(PARALLAXMAP)
+    attribute vec4 inTangent;
+    varying vec4 wTangent;
+#endif
 
 void main(){
     vec4 modelSpacePos = vec4(inPosition, 1.0);
     vec3 modelSpaceNorm = inNormal;
-    vec3 modelSpaceTan  = inTangent.xyz;
 
-    #ifdef USE_VERTEX_COLORS_AS_SUN_INTENSITY
-        vertColors = inColor;
+    #if  ( defined(NORMALMAP) || defined(PARALLAXMAP)) && !defined(VERTEX_LIGHTING)
+         vec3 modelSpaceTan  = inTangent.xyz;
     #endif
 
     #ifdef NUM_MORPH_TARGETS
@@ -65,7 +61,10 @@ void main(){
 
     wPosition = TransformWorld(modelSpacePos).xyz;
     wNormal  = TransformWorldNormal(modelSpaceNorm);
-    wTangent = vec4(TransformWorldNormal(modelSpaceTan),inTangent.w);
+
+    #if defined(NORMALMAP) || defined(PARALLAXMAP)
+      wTangent = vec4(TransformWorldNormal(modelSpaceTan),inTangent.w);
+    #endif
 
     Color = m_BaseColor;
     

+ 0 - 184
jme3-core/src/main/resources/Common/ShaderLib/PBRLighting.glsllib

@@ -1,184 +0,0 @@
-#import "Common/ShaderLib/Lighting.glsllib"
-#import "Common/ShaderLib/PBR.glsllib"
-
-//declare PBR Lighting vars
-uniform vec4 g_LightData[NB_LIGHTS];
-uniform vec3 g_CameraPosition;
-uniform vec4 g_AmbientLightColor;
-
-#if NB_PROBES >= 1
-    uniform samplerCube g_PrefEnvMap;
-    uniform vec3 g_ShCoeffs[9];
-    uniform mat4 g_LightProbeData;
-#endif
-#if NB_PROBES >= 2
-    uniform samplerCube g_PrefEnvMap2;
-    uniform vec3 g_ShCoeffs2[9];
-    uniform mat4 g_LightProbeData2;
-#endif
-#if NB_PROBES == 3
-    uniform samplerCube g_PrefEnvMap3;
-    uniform vec3 g_ShCoeffs3[9];
-    uniform mat4 g_LightProbeData3;
-#endif
-
-// Specular-AA
-#ifdef SPECULAR_AA_SCREEN_SPACE_VARIANCE
-    uniform float m_SpecularAASigma;
-#endif
-#ifdef SPECULAR_AA_THRESHOLD
-    uniform float m_SpecularAAKappa;
-#endif
-
-vec3 calculatePBRLighting(in vec4 albedo, in float Metallic, in float Roughness, in vec4 specularColor, in float glossiness, in vec3 lightMapColor, in vec3 ao, in float indoorSunLightExposure, in vec3 normal, in vec3 norm, in vec3 viewDir){
-    vec3 finalLightingValue;
-    
-    #ifdef SPECGLOSSPIPELINE
-        vec4 diffuseColor = albedo;// * (1.0 - max(max(specularColor.r, specularColor.g), specularColor.b));
-        Roughness = 1.0 - glossiness;
-        vec3 fZero = specularColor.xyz;
-    #else
-        float specular = 0.5;
-        float nonMetalSpec = 0.08 * specular;
-        specularColor = (nonMetalSpec - nonMetalSpec * Metallic) + albedo * Metallic;
-        vec4 diffuseColor = albedo - albedo * Metallic;
-        vec3 fZero = vec3(specular);
-    #endif
-
-    #ifdef LIGHTMAP
-        #if !defined(AO_MAP)
-            finalLightingValue.rgb += diffuseColor.rgb * lightMapColor;
-        #endif
-        specularColor.rgb *= lightMapColor;
-    #endif
-    
-    #ifdef SPECULAR_AA
-        float sigma = 1.0;
-        float kappa = 0.18;
-        #ifdef SPECULAR_AA_SCREEN_SPACE_VARIANCE
-            sigma = m_SpecularAASigma;
-        #endif
-        #ifdef SPECULAR_AA_THRESHOLD
-            kappa = m_SpecularAAKappa;
-        #endif
-    #endif
-    
-    float finalLightingScale = 1.0; 
-    float brightestPointLight = 1.0;
-    
-    float ndotv = max( dot( normal, viewDir ),0.0);
-    for( int i = 0;i < NB_LIGHTS; i+=3){
-        vec4 lightColor = g_LightData[i];
-        vec4 lightData1 = g_LightData[i+1];                
-        vec4 lightDir;
-        vec3 lightVec;            
-        lightComputeDir(wPosition, lightColor.w, lightData1, lightDir, lightVec);
-
-        float fallOff = 1.0;
-        #if __VERSION__ >= 110
-            // allow use of control flow
-        if(lightColor.w > 1.0){
-        #endif
-            fallOff =  computeSpotFalloff(g_LightData[i+2], lightVec);
-        #if __VERSION__ >= 110
-        }
-        #endif
-        //point light attenuation
-        fallOff *= lightDir.w;
-
-        lightDir.xyz = normalize(lightDir.xyz);            
-        vec3 directDiffuse;
-        vec3 directSpecular;
-
-        #ifdef SPECULAR_AA
-            float hdotv = PBR_ComputeDirectLightWithSpecularAA(
-                                normal, lightDir.xyz, viewDir,
-                                lightColor.rgb, fZero, Roughness, sigma, kappa, ndotv,
-                                directDiffuse,  directSpecular);
-        #else
-            float hdotv = PBR_ComputeDirectLight(
-                                normal, lightDir.xyz, viewDir,
-                                lightColor.rgb, fZero, Roughness, ndotv,
-                                directDiffuse,  directSpecular);
-        #endif
-
-        vec3 directLighting = diffuseColor.rgb *directDiffuse + directSpecular;
-        
-        #if defined(USE_VERTEX_COLORS_AS_SUN_INTENSITY) || defined(STATIC_SUN_INTENSITY)         
-            if(fallOff == 1.0){
-                directLighting.rgb *= indoorSunLightExposure;//  used to scale down how intense just the sun is indoors, and so the ambientLighting can be scaled back up indoors based on nearest pointlight intensity (ambient and direct light are 1.0 fallOff)                
-            }
-            else{
-                brightestPointLight = max(fallOff, brightestPointLight);
-            }
-        #endif
-        
-        finalLightingValue.rgb += directLighting * fallOff;
-    }
-    
-    float minVertLighting;
-    #ifdef BRIGHTEN_INDOOR_SHADOWS
-        minVertLighting = 0.0833; //enable this when using shadows, in order to brighten indoor areas (which are naturally covered from the DL shadows) so that indoor areas are not way too dark when using IndoorLighting with shadows compared to when shadows are off
-    #else
-        minVertLighting = 0.0533;
-    #endif
-    
-    finalLightingScale = max(finalLightingScale, brightestPointLight);    
-    finalLightingScale = max(finalLightingScale, minVertLighting); //essentially just the vertColors.r (aka indoor light exposure) multiplied by the time of day scale.   
-
-    #if NB_PROBES >= 1
-        vec3 color1 = vec3(0.0);
-        vec3 color2 = vec3(0.0);
-        vec3 color3 = vec3(0.0);
-        float weight1 = 1.0;
-        float weight2 = 0.0;
-        float weight3 = 0.0;
-
-        float ndf = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData, g_ShCoeffs, g_PrefEnvMap, color1);
-        #if NB_PROBES >= 2
-            float ndf2 = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData2, g_ShCoeffs2, g_PrefEnvMap2, color2);
-        #endif
-        #if NB_PROBES == 3
-            float ndf3 = renderProbe(viewDir, wPosition, normal, norm, Roughness, diffuseColor, specularColor, ndotv, ao, g_LightProbeData3, g_ShCoeffs3, g_PrefEnvMap3, color3);
-        #endif
-
-        #if NB_PROBES >= 2
-            float invNdf =  max(1.0 - ndf,0.0);
-            float invNdf2 =  max(1.0 - ndf2,0.0);
-            float sumNdf = ndf + ndf2;
-            float sumInvNdf = invNdf + invNdf2;
-            #if NB_PROBES == 3
-                float invNdf3 = max(1.0 - ndf3,0.0);
-                sumNdf += ndf3;
-                sumInvNdf += invNdf3;
-                weight3 =  ((1.0 - (ndf3 / sumNdf)) / (NB_PROBES - 1)) *  (invNdf3 / sumInvNdf);
-            #endif
-
-            weight1 = ((1.0 - (ndf / sumNdf)) / (NB_PROBES - 1)) *  (invNdf / sumInvNdf);
-            weight2 = ((1.0 - (ndf2 / sumNdf)) / (NB_PROBES - 1)) *  (invNdf2 / sumInvNdf);
-
-            float weightSum = weight1 + weight2 + weight3;
-
-            weight1 /= weightSum;
-            weight2 /= weightSum;
-            weight3 /= weightSum;
-        #endif
-
-        #ifdef USE_AMBIENT_LIGHT
-            color1.rgb *= g_AmbientLightColor.rgb;
-            color2.rgb *= g_AmbientLightColor.rgb;
-            color3.rgb *= g_AmbientLightColor.rgb;
-        #endif
-        
-                // multiply probes by the finalLightingScale, as determined by pixel's 
-        // sunlightExposure and adjusted for nearby point/spot lights
-        color1.rgb *= finalLightingScale;
-        color2.rgb *= finalLightingScale;
-        color3.rgb *= finalLightingScale;
-        
-        finalLightingValue.rgb += color1 * clamp(weight1,0.0,1.0) + color2 * clamp(weight2,0.0,1.0) + color3 * clamp(weight3,0.0,1.0);
-
-    #endif
-    
-    return finalLightingValue;
-}

+ 0 - 205
jme3-core/src/main/resources/Common/ShaderLib/PBRLightingParamsReader.glsllib

@@ -1,205 +0,0 @@
-#import "Common/ShaderLib/Parallax.glsllib"
-
-varying vec4 Color;
-
-#ifdef BASECOLORMAP
-    uniform sampler2D m_BaseColorMap;
-#endif
-
-#ifdef USE_PACKED_MR
-    uniform sampler2D m_MetallicRoughnessMap;
-#else
-    #ifdef METALLICMAP
-        uniform sampler2D m_MetallicMap;
-    #endif
-    #ifdef ROUGHNESSMAP
-        uniform sampler2D m_RoughnessMap;
-    #endif
-#endif
-
-#ifdef EMISSIVE
-    uniform vec4 m_Emissive;
-#endif
-#ifdef EMISSIVEMAP
-    uniform sampler2D m_EmissiveMap;
-#endif
-#if defined(EMISSIVE) || defined(EMISSIVEMAP)
-    uniform float m_EmissivePower;
-    uniform float m_EmissiveIntensity;
-#endif 
-
-uniform float m_Roughness;
-uniform float m_Metallic;
-
-#ifdef SPECGLOSSPIPELINE
-    uniform vec4 m_Specular;
-    uniform float m_Glossiness;
-    #ifdef USE_PACKED_SG
-        uniform sampler2D m_SpecularGlossinessMap;
-    #else
-        uniform sampler2D m_SpecularMap;
-        uniform sampler2D m_GlossinessMap;
-    #endif
-#endif
-
-#ifdef PARALLAXMAP
-    uniform sampler2D m_ParallaxMap;  
-#endif
-#if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP)))
-    uniform float m_ParallaxHeight;
-#endif
-
-#ifdef LIGHTMAP
-    uniform sampler2D m_LightMap;
-#endif
-
-#ifdef AO_STRENGTH
-    uniform float m_AoStrength;
-#endif
-  
-#if defined(NORMALMAP) || defined(PARALLAXMAP)
-    uniform sampler2D m_NormalMap;       
-#endif
-#ifdef NORMALSCALE
-    uniform float m_NormalScale;
-#endif
-
-#if defined(USE_VERTEX_COLORS_AS_SUN_INTENSITY)
-    varying vec4 vertColors;
-#endif
-#ifdef STATIC_SUN_INTENSITY
-    uniform float m_StaticSunIntensity;
-#endif
-
-void readMatParamsAndTextures(in mat3 tbnMat, in vec3 vViewDir, inout vec4 albedo, inout float Metallic, inout float Roughness, inout vec4 SpecularColor, inout float glossiness, inout vec3 lightMapColor, inout vec3 ao, inout float indoorSunLightExposure, inout vec3 normal, inout vec4 emissive, inout float alpha){
-    #if (defined(PARALLAXMAP) || (defined(NORMALMAP_PARALLAX) && defined(NORMALMAP)))
-        #ifdef STEEP_PARALLAX
-            #ifdef NORMALMAP_PARALLAX
-                //parallax map is stored in the alpha channel of the normal map         
-                newTexCoord = steepParallaxOffset(m_NormalMap, vViewDir, texCoord, m_ParallaxHeight);
-            #else
-                //parallax map is a texture
-                newTexCoord = steepParallaxOffset(m_ParallaxMap, vViewDir, texCoord, m_ParallaxHeight);         
-            #endif
-        #else
-            #ifdef NORMALMAP_PARALLAX
-                //parallax map is stored in the alpha channel of the normal map         
-                newTexCoord = classicParallaxOffset(m_NormalMap, vViewDir, texCoord, m_ParallaxHeight);
-            #else
-               //parallax map is a texture
-               newTexCoord = classicParallaxOffset(m_ParallaxMap, vViewDir, texCoord, m_ParallaxHeight);
-           #endif
-       #endif
-    #else
-       newTexCoord = texCoord;    
-    #endif
-    
-    #ifdef BASECOLORMAP
-        albedo = texture2D(m_BaseColorMap, newTexCoord) * Color;
-    #else
-        albedo = Color;
-    #endif
-    
-    alpha = albedo.a;
-
-    #ifdef DISCARD_ALPHA
-        if(alpha < m_AlphaDiscardThreshold){
-            discard;
-        }
-    #endif
-
-    //ao in r channel, roughness in green channel, metallic in blue channel!
-    vec3 aoRoughnessMetallicValue = vec3(1.0, 1.0, 0.0);
-    #ifdef USE_PACKED_MR
-        aoRoughnessMetallicValue = texture2D(m_MetallicRoughnessMap, newTexCoord).rgb;
-        Roughness = aoRoughnessMetallicValue.g * max(m_Roughness, 1e-4);
-        Metallic = aoRoughnessMetallicValue.b * max(m_Metallic, 0.0);
-    #else
-        #ifdef ROUGHNESSMAP
-            Roughness = texture2D(m_RoughnessMap, newTexCoord).r * max(m_Roughness, 1e-4);
-        #else
-            Roughness =  max(m_Roughness, 1e-4);
-        #endif
-        #ifdef METALLICMAP
-            Metallic = texture2D(m_MetallicMap, newTexCoord).r * max(m_Metallic, 0.0);
-        #else
-            Metallic =  max(m_Metallic, 0.0);
-        #endif
-    #endif
- 
-    #if defined(NORMALMAP)
-        vec4 normalHeight = texture2D(m_NormalMap, newTexCoord);
-        // Note we invert directx style normal maps to opengl style
-        #ifdef NORMALSCALE
-            normal = normalize((normalHeight.xyz * vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0)) * vec3(m_NormalScale, m_NormalScale, 1.0));
-        #else
-            normal = normalize((normalHeight.xyz * vec3(2.0, NORMAL_TYPE * 2.0, 2.0) - vec3(1.0, NORMAL_TYPE * 1.0, 1.0)));
-        #endif
-        normal = normalize(tbnMat * normal);
-        //normal = normalize(normal * inverse(tbnMat));
-    #endif
-    
-    //spec gloss tex reads:
-    
-    #ifdef SPECGLOSSPIPELINE
-        #ifdef USE_PACKED_SG
-            specularColor = texture2D(m_SpecularGlossinessMap, newTexCoord);
-            glossiness = specularColor.a * m_Glossiness;
-            specularColor *= m_Specular;
-        #else
-            #ifdef SPECULARMAP
-                specularColor = texture2D(m_SpecularMap, newTexCoord);
-            #else
-                specularColor = vec4(1.0);
-            #endif
-            #ifdef GLOSSINESSMAP
-                glossiness = texture2D(m_GlossinesMap, newTexCoord).r * m_Glossiness;
-            #else
-                glossiness = m_Glossiness;
-            #endif
-            specularColor *= m_Specular;
-        #endif
-    #endif
-    
-    
-    #ifdef LIGHTMAP
-        #ifdef SEPARATE_TEXCOORD
-            lightMapColor = texture2D(m_LightMap, texCoord2).rgb;
-        #else
-            lightMapColor = texture2D(m_LightMap, texCoord).rgb;
-        #endif       
-        
-        #ifdef AO_MAP
-            lightMapColor.gb = lightMapColor.rr; 
-            ao = lightMapColor;
-        #endif
-    #endif
-    
-    #if defined(AO_PACKED_IN_MR_MAP) && defined(USE_PACKED_MR) 
-        ao = aoRoughnessMetallicValue.rrr; //note that this will override the AO value if it was previously read from a lightMap that is being used as AO_Map above. so don't try to use an AO map packed in metallic roughness while also using lightmap as ao map
-    #endif
-
-    #ifdef AO_STRENGTH
-        ao = 1.0 + m_AoStrength * (ao - 1.0);
-        // sanity check
-        ao = clamp(ao, 0.0, 1.0);
-    #endif
-    
-    #if defined(EMISSIVE) || defined (EMISSIVEMAP)
-        #ifdef EMISSIVEMAP
-            emissive = texture2D(m_EmissiveMap, newTexCoord);
-            #ifdef EMISSIVE
-            emissive *= m_Emissive;
-            #endif
-        #endif
-        emissive = emissive * pow(emissive.a, m_EmissivePower) * m_EmissiveIntensity;
-    #endif
-    
-    #ifdef STATIC_SUN_INTENSITY
-        indoorSunLightExposure = m_StaticSunIntensity; //single float value to indicate percentage of sunlight hitting the model (only suitable for small models or models with equal sunlight exposure accross the entire model
-    #endif
-    #ifdef USE_VERTEX_COLORS_AS_SUN_INTENSITY
-        indoorSunLightExposure = vertColors.r * indoorSunLightExposure;    // use red channel of vertexColors for non-uniform sunlighting accross a single model
-    #endif 
-    
-}