X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fgraphics%2Fshaders%2Fcolor-visual-shader.frag;h=f1b51bbb6faa0582e455572e3352f517c559732c;hb=25546b374e49d9454f4ce0004525a31b398f29a0;hp=db23361502a9fe97deeab0635e7a4d777b538ddc;hpb=45ad62cd772319bc585a48c868b31892881374bb;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag b/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag index db23361..f1b51bb 100644 --- a/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag +++ b/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag @@ -7,18 +7,21 @@ INPUT mediump vec4 vCornerRadius; #endif #endif +#if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) || defined(IS_REQUIRED_BLUR) +// Be used when we calculate anti-alias range near 1 pixel. +uniform highp vec3 uScale; +#endif + uniform lowp vec4 uColor; uniform lowp vec3 mixColor; -#if !defined(IS_REQUIRED_BLUR) && defined(IS_REQUIRED_BORDERLINE) +#ifdef IS_REQUIRED_BLUR +uniform mediump float blurRadius; +#elif defined(IS_REQUIRED_BORDERLINE) uniform mediump float borderlineWidth; uniform mediump float borderlineOffset; uniform lowp vec4 borderlineColor; uniform lowp vec4 uActorColor; #endif -#ifdef IS_REQUIRED_BLUR -uniform mediump float blurRadius; -#endif - #if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) || defined(IS_REQUIRED_BLUR) // Global values both rounded corner and borderline use @@ -58,7 +61,8 @@ void calculatePosition() { gFragmentPosition = abs(vPosition) - vRectSize; gCenterPosition = -gRadius; -#if !defined(IS_REQUIRED_BLUR) && defined(IS_REQUIRED_BORDERLINE) +#ifdef IS_REQUIRED_BLUR +#elif defined(IS_REQUIRED_BORDERLINE) gCenterPosition += borderlineWidth * (clamp(borderlineOffset, -1.0, 1.0) + 1.0) * 0.5; #endif gDiff = gFragmentPosition - gCenterPosition; @@ -71,12 +75,18 @@ void calculatePotential() void setupMinMaxPotential() { - gPotentialRange = 1.0; + // Set soft anti-alias range at most 10% of visual size. + // The range should be inverse proportion with scale of view. + // To avoid divid-by-zero, let we allow minimum scale value is 0.001 (0.1%) + gPotentialRange = min(1.0, max(vRectSize.x, vRectSize.y) * 0.2) / max(0.001, max(uScale.x, uScale.y)); gMaxOutlinePotential = gRadius + gPotentialRange; gMinOutlinePotential = gRadius - gPotentialRange; -#if !defined(IS_REQUIRED_BLUR) && defined(IS_REQUIRED_BORDERLINE) +#ifdef IS_REQUIRED_BLUR + gMaxInlinePotential = gMaxOutlinePotential; + gMinInlinePotential = gMinOutlinePotential; +#elif defined(IS_REQUIRED_BORDERLINE) gMaxInlinePotential = gMaxOutlinePotential - borderlineWidth; gMinInlinePotential = gMinOutlinePotential - borderlineWidth; #else @@ -85,8 +95,8 @@ void setupMinMaxPotential() #endif // reduce defect near edge of rounded corner. - gMaxOutlinePotential += clamp(-min(gDiff.x, gDiff.y)/ max(1.0, gRadius) , 0.0, 1.0); - gMinOutlinePotential += clamp(-min(gDiff.x, gDiff.y)/ max(1.0, gRadius) , 0.0, 1.0); + gMaxOutlinePotential += clamp(-min(gDiff.x, gDiff.y) / max(1.0, gRadius), 0.0, 1.0); + gMinOutlinePotential += clamp(-min(gDiff.x, gDiff.y) / max(1.0, gRadius), 0.0, 1.0); } void PreprocessPotential() @@ -99,7 +109,8 @@ void PreprocessPotential() } #endif -#if !defined(IS_REQUIRED_BLUR) && defined(IS_REQUIRED_BORDERLINE) +#ifdef IS_REQUIRED_BLUR +#elif defined(IS_REQUIRED_BORDERLINE) lowp vec4 convertBorderlineColor(lowp vec4 textureColor) { mediump float potential = gPotential; @@ -114,7 +125,7 @@ lowp vec4 convertBorderlineColor(lowp vec4 textureColor) borderlineOpacity = smoothstep(gMinInlinePotential, gMaxInlinePotential, potential); // Muliply borderlineWidth to resolve very thin borderline - borderlineOpacity *= min(1.0, borderlineWidth); + borderlineOpacity *= min(1.0, borderlineWidth / gPotentialRange); } lowp vec3 borderlineColorRGB = borderlineColor.rgb * uActorColor.rgb; @@ -126,7 +137,7 @@ lowp vec4 convertBorderlineColor(lowp vec4 textureColor) // 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 tCornerRadius = -gCenterPosition + gPotentialRange; mediump float MaxTexturelinePotential = tCornerRadius + gPotentialRange; mediump float MinTexturelinePotential = tCornerRadius - gPotentialRange; if(potential > MaxTexturelinePotential) @@ -163,7 +174,8 @@ lowp vec4 convertBorderlineColor(lowp vec4 textureColor) } #endif -#if !defined(IS_REQUIRED_BLUR) && defined(IS_REQUIRED_ROUNDED_CORNER) +#ifdef IS_REQUIRED_BLUR +#elif defined(IS_REQUIRED_ROUNDED_CORNER) mediump float calculateCornerOpacity() { mediump float potential = gPotential; @@ -269,7 +281,8 @@ void main() PreprocessPotential(); #endif -#if !defined(IS_REQUIRED_BLUR) && defined(IS_REQUIRED_BORDERLINE) +#ifdef IS_REQUIRED_BLUR +#elif defined(IS_REQUIRED_BORDERLINE) targetColor = convertBorderlineColor(targetColor); #endif OUT_COLOR = targetColor;