[dali_2.3.24] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / internal / graphics / shaders / default-physically-based-shader.frag
index 78af54c..47bb831 100644 (file)
@@ -96,7 +96,8 @@ uniform mediump vec3 uLightColor[MAX_LIGHTS];
 // For Shadow Map
 uniform lowp int uIsShadowEnabled;
 uniform sampler2D sShadowMap;
-#ifdef GLSL_VERSION_1_0
+uniform lowp int uIsShadowReceiving;
+#ifdef SL_VERSION_LOW
 uniform int uShadowMapWidth;
 uniform int uShadowMapHeight;
 #endif
@@ -241,7 +242,7 @@ void main()
   // Specular Light
   // uMaxLOD that means mipmap level of specular texture is used for bluring of reflection of specular following roughness.
   float lod = perceptualRoughness * (uMaxLOD - 1.0);
-#ifdef GLSL_VERSION_1_0
+#ifdef SL_VERSION_LOW
   // glsl 1.0 doesn't support textureLod. Let we just use textureCube instead.
   lowp vec3 specularLight = linear(textureCube(sSpecularEnvSampler, reflection * uYDirection).rgb);
 #else
@@ -251,7 +252,7 @@ void main()
 
   // Diffuse Light
   lowp vec3 diffuseColor = mix(baseColor.rgb, vec3(0), metallic);
-#ifdef GLSL_VERSION_1_0
+#ifdef SL_VERSION_LOW
   lowp vec3 irradiance = linear(textureCube(sDiffuseEnvSampler, n * uYDirection).rgb);
 #else
   lowp vec3 irradiance = linear(TEXTURE(sDiffuseEnvSampler, n * uYDirection).rgb);
@@ -268,44 +269,44 @@ void main()
   if(uLightCount > 0)
   {
     // Compute reflectance.
-    lowp float reflectance = max(max(f0.r, f0.g), f0.b);
-    lowp float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
-    lowp float r = perceptualRoughness * perceptualRoughness;
-    lowp float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));
-    mediump float roughnessSq = r * r;
-    lowp vec3 diffuseColorPunctual = baseColor.rgb * (vec3(1.0) - f0);
+    highp float reflectance = max(max(f0.r, f0.g), f0.b);
+    highp float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
+    highp float r = perceptualRoughness * perceptualRoughness;
+    highp float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));
+    highp float roughnessSq = r * r;
+    highp vec3 diffuseColorPunctual = baseColor.rgb * (vec3(1.0) - f0);
     diffuseColorPunctual *= ( 1.0 - metallic );
 
     for(int i = 0; i < uLightCount; ++i)
     {
       highp vec3 l = normalize(-uLightDirection[i]); // Vector from surface point to light
-      mediump vec3 h = normalize(l+v);               // Half vector between both l and v
-      mediump float VdotH = dot(v, h);
-      lowp vec3 specularReflection = f0 + (reflectance90 - f0) * pow(clamp(1.0 - VdotH, 0.0, 1.0), 5.0);
+      highp vec3 h = normalize(l+v);               // Half vector between both l and v
+      highp float VdotH = dot(v, h);
+      highp vec3 specularReflection = f0 + (reflectance90 - f0) * pow(clamp(1.0 - VdotH, 0.0, 1.0), 5.0);
 
-      mediump float NdotL = clamp(dot(n, l), 0.001, 1.0);
-      lowp float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));
-      lowp float geometricOcclusion = attenuationL * attenuationV;
+      highp float NdotL = clamp(dot(n, l), 0.001, 1.0);
+      highp float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));
+      highp float geometricOcclusion = attenuationL * attenuationV;
 
       highp float NdotH = dot(n, h);
       highp float f = (NdotH * roughnessSq - NdotH) * NdotH + 1.0;
-      lowp float microfacetDistribution = roughnessSq / (M_PI * f * f);;
+      highp float microfacetDistribution = roughnessSq / (M_PI * f * f);;
 
       // Calculation of analytical lighting contribution
-      lowp vec3 diffuseContrib = ( 1.0 - specularReflection ) * ( diffuseColorPunctual / M_PI );
-      lowp vec3 specContrib = specularReflection * geometricOcclusion * microfacetDistribution / ( 4.0 * NdotL * NdotV );
+      highp vec3 diffuseContrib = ( 1.0 - specularReflection ) * ( diffuseColorPunctual / M_PI );
+      highp vec3 specContrib = specularReflection * geometricOcclusion * microfacetDistribution / ( 4.0 * NdotL * NdotV );
 
       // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)
       color += NdotL * uLightColor[i] * (diffuseContrib + specContrib);
     }
   }
 
-  if(float(uIsShadowEnabled) * uShadowIntensity > 0.0)
+  if(float(uIsShadowReceiving) * float(uIsShadowEnabled) * uShadowIntensity > 0.0)
   {
     mediump float exposureFactor = 0.0;
     if(uEnableShadowSoftFiltering > 0)
     {
-#ifdef GLSL_VERSION_1_0
+#ifdef SL_VERSION_LOW
       ivec2 texSize = ivec2(uShadowMapWidth, uShadowMapHeight);
 #else
       ivec2 texSize = textureSize(sShadowMap, 0);