X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-scene3d%2Finternal%2Fgraphics%2Fshaders%2Fdefault-physically-based-shader.frag;h=47bb8316f1a8a14c06568a286701edb13a922a28;hb=HEAD;hp=a7efc275aca69393d6fc35d53a5979f2341b52fc;hpb=875eeb04d30b584d7c2c7f12754013ffee0bf083;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-scene3d/internal/graphics/shaders/default-physically-based-shader.frag b/dali-scene3d/internal/graphics/shaders/default-physically-based-shader.frag index a7efc27..a9e704b 100644 --- a/dali-scene3d/internal/graphics/shaders/default-physically-based-shader.frag +++ b/dali-scene3d/internal/graphics/shaders/default-physically-based-shader.frag @@ -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 @@ -135,6 +136,8 @@ const float kPcfTheta = 2.0 * kPi * kInvSampleCount; const float kSinPcfTheta = sin(kPcfTheta); const float kCosPcfTheta = cos(kPcfTheta); + +uniform mediump int uShadowLightIndex; uniform lowp int uEnableShadowSoftFiltering; uniform mediump float uShadowIntensity; uniform highp float uShadowBias; @@ -241,7 +244,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 +254,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); @@ -279,7 +282,7 @@ void main() for(int i = 0; i < uLightCount; ++i) { highp vec3 l = normalize(-uLightDirection[i]); // Vector from surface point to light - highp vec3 h = normalize(l+v); // Half vector between both l and v + 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); @@ -300,12 +303,15 @@ void main() } } - if(float(uIsShadowEnabled) * uShadowIntensity > 0.0) + if(float(uIsShadowReceiving) * float(uIsShadowEnabled) * uShadowIntensity > 0.0) { mediump float exposureFactor = 0.0; + + highp vec3 l = normalize(-uLightDirection[uShadowLightIndex]); + highp float NdotL = dot(n, l); if(uEnableShadowSoftFiltering > 0) { -#ifdef GLSL_VERSION_1_0 +#ifdef SL_VERSION_LOW ivec2 texSize = ivec2(uShadowMapWidth, uShadowMapHeight); #else ivec2 texSize = textureSize(sShadowMap, 0); @@ -320,12 +326,20 @@ void main() exposureFactor += (depthValue < positionFromLightView.z - uShadowBias) ? 0.0 : 1.0; } exposureFactor *= kInvSampleCount; + + // Blend filtered shadow and shadow from fragment normal to allow soft filtering nearby where the NdotL is zero. + highp float shadowFactor = clamp((NdotL + 0.5) * 2.0, 0.0f, 1.0); + exposureFactor = mix(0.0, exposureFactor, shadowFactor); } else { - mediump float depthValue = TEXTURE(sShadowMap, positionFromLightView.xy).r; - exposureFactor = (depthValue < positionFromLightView.z - uShadowBias) ? 0.0 : 1.0; + if(NdotL > 0.0) + { + mediump float depthValue = TEXTURE(sShadowMap, positionFromLightView.xy).r; + exposureFactor = (depthValue < positionFromLightView.z - uShadowBias) ? 0.0 : 1.0; + } } + color *= (1.0 - (1.0 - exposureFactor) * uShadowIntensity); }