Browse Source

Fix compile errors in PBR shaders on GLES. Fix mismatches in PBR techniques where IBL compile define would be present for pixel shader but not vertex shader (causes shader linking error)

Lasse Öörni 9 years ago
parent
commit
06b0dbba76

+ 2 - 2
bin/CoreData/Shaders/GLSL/BRDF.glsl

@@ -78,7 +78,7 @@
     float GGXDistribution(float NdotH, float roughness)
     {
         float rough2 = roughness * roughness;
-        float tmp =  (NdotH * rough2 - NdotH) * NdotH + 1;
+        float tmp =  (NdotH * rough2 - NdotH) * NdotH + 1.0;
         return rough2 / (tmp * tmp);
     }
 
@@ -109,7 +109,7 @@
     // VdotH        = the camera view direction dot with the half vector
     vec3 BurleyDiffuse(vec3 diffuseColor, float roughness, float NdotV, float NdotL, float VdotH)
     {
-        float energyBias = mix(roughness, 0, 0.5);
+        float energyBias = mix(roughness, 0.0, 0.5);
         float energyFactor = mix(roughness, 1.0, 1.0 / 1.51);
         float fd90 = energyBias + 2.0 * VdotH * VdotH * roughness;
         float f0 = 1.0;

+ 11 - 2
bin/CoreData/Shaders/GLSL/IBL.glsl

@@ -269,8 +269,17 @@
         //float GlossBias = 5.0;
         float mipSelect = roughness * 9.0; //exp2(GlossScale * roughness * roughness + GlossBias) - exp2(GlossBias);
 
-        vec3 cube = textureLod(sZoneCubeMap, reflectVec, mipSelect).rgb;
-        vec3 cubeD = textureLod(sZoneCubeMap, wsNormal, 9.0).rgb;
+        // OpenGL ES does not support textureLod without extensions and does not have the sZoneCubeMap sampler,
+        // so for now, sample without explicit LOD, and from the environment sampler, where the zone texture will be put
+        // on mobile hardware
+        #ifndef GL_ES
+            vec3 cube = textureLod(sZoneCubeMap, reflectVec, mipSelect).rgb;
+            vec3 cubeD = textureLod(sZoneCubeMap, wsNormal, 9.0).rgb;
+        #else
+            vec3 cube = textureCube(sEnvCubeMap, reflectVec).rgb;
+            vec3 cubeD = textureCube(sEnvCubeMap, wsNormal).rgb;
+        #endif
+
         // Fake the HDR texture
         float brightness = clamp(cAmbientColor.a, 0.0, 1.0);
         float darknessCutoff = clamp((cAmbientColor.a - 1.0) * 0.1, 0.0, 0.25);

+ 1 - 1
bin/CoreData/Shaders/GLSL/Lighting.glsl

@@ -133,7 +133,7 @@ float GetAtten(vec3 normal, vec3 worldPos, out vec3 lightDir)
     #else
         vec3 lightVec = (cLightPosPS.xyz - worldPos) * cLightPosPS.w;
         float lightDist = length(lightVec);
-        float falloff = pow(clamp(1 - pow(lightDist / 1, 4), 0.0, 1.0),2) / (pow(lightDist, 2.0) + 1.0);
+        float falloff = pow(clamp(1.0 - pow(lightDist / 1.0, 4.0), 0.0, 1.0), 2.0) / (pow(lightDist, 2.0) + 1.0);
 
         lightDir = lightVec / vec3(lightDist, lightDist, lightDist);
         return clamp(dot(normal, lightDir), 0.0, 1.0) * falloff;

+ 1 - 1
bin/CoreData/Shaders/GLSL/PBRLitSolid.glsl

@@ -206,7 +206,7 @@ void PS()
         gl_FragData[0] = vec4(specColor, spareData.r);
         gl_FragData[1] = vec4(diffColor.rgb, spareData.g);
         gl_FragData[2] = vec4(normal * roughness, spareData.b);
-        gl_FragData[3] = vec4(EncodeDepth(vWorldPos.w), 0);
+        gl_FragData[3] = vec4(EncodeDepth(vWorldPos.w), 0.0);
     #else
         // Ambient & per-vertex lighting
         vec3 finalColor = vVertexLight * diffColor.rgb;

+ 1 - 1
bin/CoreData/Shaders/HLSL/Lighting.hlsl

@@ -144,7 +144,7 @@ float GetAtten(float3 normal, float3 worldPos, out float3 lightDir)
     #else
         float3 lightVec = (cLightPosPS.xyz - worldPos) * cLightPosPS.w;
         float lightDist = length(lightVec);
-        float falloff = pow(saturate(1 - pow(lightDist / 1, 4)),2) / (pow(lightDist, 2.0) + 1.0);
+        float falloff = pow(saturate(1.0 - pow(lightDist / 1.0, 4.0)), 2.0) / (pow(lightDist, 2.0) + 1.0);
 
         lightDir = lightVec / lightDist;
         return saturate(dot(normal, lightDir)) * falloff;

+ 1 - 1
bin/CoreData/Techniques/PBR/PBRMetallicRoughDiffNormalSpecEmissiveAlpha.xml

@@ -1,4 +1,4 @@
-<technique vs="PBRLitSolid" ps="PBRLitSolid" psdefines="DIFFMAP NORMALMAP EMISSIVEMAP PBR IBL METALLIC ROUGHNESS">
+<technique vs="PBRLitSolid" ps="PBRLitSolid" vsdefines="IBL" psdefines="DIFFMAP NORMALMAP EMISSIVEMAP PBR IBL METALLIC ROUGHNESS">
     <pass name="alpha" depthwrite="false" blend="alpha" />
     <pass name="litalpha" depthwrite="false" blend="addalpha" />
     <pass name="shadow" vs="Shadow" ps="Shadow" />

+ 1 - 1
bin/CoreData/Techniques/PBR/PBRMetallicRoughDiffSpec.xml

@@ -1,4 +1,4 @@
-<technique vs="PBRLitSolid" ps="PBRLitSolid" psdefines="DIFFMAP PBR IBL METALLIC ROUGHNESS">
+<technique vs="PBRLitSolid" ps="PBRLitSolid" vsdefines="IBL" psdefines="DIFFMAP PBR IBL METALLIC ROUGHNESS">
     <pass name="base"/>
     <pass name="light" depthtest="equal" depthwrite="false" blend="add" />
     <pass name="material" psdefines="MATERIAL" depthtest="equal" depthwrite="false" />

+ 1 - 1
bin/CoreData/Techniques/PBR/PBRMetallicRoughDiffSpecAlpha.xml

@@ -1,4 +1,4 @@
-<technique vs="PBRLitSolid" ps="PBRLitSolid" psdefines="DIFFMAP PBR IBL METALLIC ROUGHNESS">
+<technique vs="PBRLitSolid" ps="PBRLitSolid" vsdefines="IBL" psdefines="DIFFMAP PBR IBL METALLIC ROUGHNESS">
     <pass name="alpha" depthwrite="false" blend="alpha" />
     <pass name="litalpha" depthwrite="false" blend="addalpha" />
     <pass name="shadow" vs="Shadow" ps="Shadow" />

+ 1 - 1
bin/CoreData/Techniques/PBR/PBRNoTextureAlpha.xml

@@ -1,4 +1,4 @@
-<technique vs="PBRLitSolid" ps="PBRLitSolid" vsdefines="NOUV" psdefines="PBR IBL">
+<technique vs="PBRLitSolid" ps="PBRLitSolid" vsdefines="NOUV IBL" psdefines="PBR IBL">
     <pass name="alpha"  depthwrite="false" blend="alpha" />
     <pass name="litalpha" depthwrite="false" blend="addalpha" />
     <pass name="shadow" vs="Shadow" ps="Shadow" />