X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fgraphics%2Fshaders%2Fcolor-visual-shader.frag;h=13be4df4cb3135ce9ab42dba2c1aa25973b0f7dd;hp=74e8f581662bd673fb03fd316ca8f9ca2ec7e6ea;hb=c2c2513ca81ea0db5a9ccdd99339a9b0ca77bd88;hpb=fa3f750c6878eb126034d7958458dc3a1f67924f diff --git a/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag b/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag index 74e8f58..13be4df 100644 --- a/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag +++ b/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag @@ -23,6 +23,7 @@ uniform lowp vec3 mixColor; uniform mediump float borderlineWidth; uniform mediump float borderlineOffset; uniform lowp vec4 borderlineColor; +uniform lowp vec4 uActorColor; #endif #if IS_REQUIRED_BLUR uniform mediump float blurRadius; @@ -121,28 +122,54 @@ lowp vec4 convertBorderlineColor(lowp vec4 textureColor) { // potential is inside borderline range. borderlineOpacity = smoothstep(gMinInlinePotential, gMaxInlinePotential, potential); + + // Muliply borderlineWidth to resolve very thin borderline + borderlineOpacity *= min(1.0, borderlineWidth); } - //calculate inside of borderline when outilneColor.a < 1.0 - if(borderlineColor.a < 1.0) + lowp vec3 borderlineColorRGB = borderlineColor.rgb * uActorColor.rgb; + lowp float borderlineColorAlpha = borderlineColor.a * uActorColor.a; + // NOTE : color-visual is always not preMultiplied. + + // Calculate inside of borderline when alpha is between (0.0 1.0). So we need to apply texture color. + // If borderlineOpacity is exactly 0.0, we always use whole texture color. In this case, we don't need to run below code. + // But if borderlineOpacity > 0.0 and borderlineColor.a == 0.0, we need to apply tCornerRadius. + if(borderlineOpacity > 0.0 && borderlineColor.a * borderlineOpacity < 1.0) { mediump float tCornerRadius = -gCenterPosition; mediump float MaxTexturelinePotential = tCornerRadius + gPotentialRange; mediump float MinTexturelinePotential = tCornerRadius - gPotentialRange; if(potential > MaxTexturelinePotential) { - // potential is out of texture range. use borderline color instead of texture - textureColor = vec4(borderlineColor.xyz, 0.0); + // potential is out of texture range. + textureColor = vec4(0.0); } - else if(potential > MinTexturelinePotential) + else { - // potential is in texture range - textureColor = mix(textureColor, vec4(borderlineColor.xyz, 0.0), smoothstep(MinTexturelinePotential, MaxTexturelinePotential, potential)); + // potential is in texture range. + lowp float textureAlphaScale = mix(1.0, 0.0, smoothstep(MinTexturelinePotential, MaxTexturelinePotential, potential)); + textureColor.a *= textureAlphaScale; + textureColor.rgb *= textureColor.a; } - borderlineOpacity *= borderlineColor.a; - return mix(textureColor, vec4(borderlineColor.xyz, 1.0), borderlineOpacity); + + // NOTE : color-visual is always not preMultiplied. + borderlineColorAlpha *= borderlineOpacity; + borderlineColorRGB *= borderlineColorAlpha; + // We use pre-multiplied color to reduce operations. + // In here, textureColor and borderlineColorRGB is pre-multiplied color now. + + // Manual blend operation with premultiplied colors. + // Final alpha = borderlineColorAlpha + (1.0 - borderlineColorAlpha) * textureColor.a. + // (Final rgb * alpha) = borderlineColorRGB + (1.0 - borderlineColorAlpha) * textureColor.rgb + // If preMultipliedAlpha == 1.0, just return vec4(rgb*alpha, alpha) + // Else, return vec4((rgb*alpha) / alpha, alpha) + + lowp float finalAlpha = mix(textureColor.a, 1.0, borderlineColorAlpha); + lowp vec3 finalMultipliedRGB = borderlineColorRGB + (1.0 - borderlineColorAlpha) * textureColor.rgb; + // TODO : Need to find some way without division + return vec4(finalMultipliedRGB / finalAlpha, finalAlpha); } - return mix(textureColor, borderlineColor, borderlineOpacity); + return mix(textureColor, vec4(borderlineColorRGB, borderlineColorAlpha), borderlineOpacity); } #endif @@ -239,13 +266,13 @@ mediump float calculateBlurOpacity() void main() { - lowp vec4 targetColor = vec4(mixColor, 1.0); + lowp vec4 targetColor = vec4(mixColor, 1.0) * uColor; #if IS_REQUIRED_BLUR || IS_REQUIRED_ROUNDED_CORNER || IS_REQUIRED_BORDERLINE // skip most potential calculate for performance if(abs(vPosition.x) < vOptRectSize.x && abs(vPosition.y) < vOptRectSize.y) { - OUT_COLOR = targetColor * uColor; + OUT_COLOR = targetColor; return; } PreprocessPotential(); @@ -254,7 +281,7 @@ void main() #if !IS_REQUIRED_BLUR && IS_REQUIRED_BORDERLINE targetColor = convertBorderlineColor(targetColor); #endif - OUT_COLOR = targetColor * uColor; + OUT_COLOR = targetColor; #if IS_REQUIRED_BLUR mediump float opacity = calculateBlurOpacity();