X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fgraphics%2Fshaders%2Fimage-visual-shader.frag;h=bad5500fd12faf9c021f0c32b638ae45cea1c16a;hb=25546b374e49d9454f4ce0004525a31b398f29a0;hp=37f080f2553d8a998ed58f9482e82ffac59d6542;hpb=d4caad077f67fbd78285cb549cda85da1e248620;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/graphics/shaders/image-visual-shader.frag b/dali-toolkit/internal/graphics/shaders/image-visual-shader.frag index 37f080f..bad5500 100644 --- a/dali-toolkit/internal/graphics/shaders/image-visual-shader.frag +++ b/dali-toolkit/internal/graphics/shaders/image-visual-shader.frag @@ -1,45 +1,47 @@ -#ifndef IS_REQUIRED_ROUNDED_CORNER -#define IS_REQUIRED_ROUNDED_CORNER 0 -#endif -#ifndef IS_REQUIRED_BORDERLINE -#define IS_REQUIRED_BORDERLINE 0 -#endif -#ifndef ATLAS_DEFAULT_WARP -#define ATLAS_DEFAULT_WARP 0 -#endif -#ifndef ATLAS_CUSTOM_WARP -#define ATLAS_CUSTOM_WARP 0 -#endif - INPUT mediump vec2 vTexCoord; -#if IS_REQUIRED_ROUNDED_CORNER || IS_REQUIRED_BORDERLINE +#if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) INPUT mediump vec2 vPosition; INPUT mediump vec2 vRectSize; INPUT mediump vec2 vOptRectSize; -#if IS_REQUIRED_ROUNDED_CORNER +#ifdef IS_REQUIRED_ROUNDED_CORNER INPUT mediump vec4 vCornerRadius; #endif #endif uniform sampler2D sTexture; -#if ATLAS_DEFAULT_WARP +#if defined(IS_REQUIRED_YUV_TO_RGB) || defined(IS_REQUIRED_UNIFIED_YUV_AND_RGB) +uniform sampler2D sTextureU; +uniform sampler2D sTextureV; +#endif + +#ifdef IS_REQUIRED_ALPHA_MASKING +uniform sampler2D sMaskTexture; +INPUT mediump vec2 vMaskTexCoord; +#endif + +#ifdef ATLAS_DEFAULT_WARP uniform mediump vec4 uAtlasRect; -#elif ATLAS_CUSTOM_WARP +#elif defined(ATLAS_CUSTOM_WARP) // WrapMode -- 0: CLAMP; 1: REPEAT; 2: REFLECT; uniform lowp vec2 wrapMode; #endif +#if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) +// Be used when we calculate anti-alias range near 1 pixel. +uniform highp vec3 uScale; +#endif + uniform lowp vec4 uColor; uniform lowp vec3 mixColor; uniform lowp float preMultipliedAlpha; -#if IS_REQUIRED_BORDERLINE +#ifdef IS_REQUIRED_BORDERLINE uniform mediump float borderlineWidth; uniform mediump float borderlineOffset; uniform lowp vec4 borderlineColor; uniform lowp vec4 uActorColor; #endif -#if ATLAS_CUSTOM_WARP +#ifdef ATLAS_CUSTOM_WARP mediump float wrapCoordinate( mediump vec2 range, mediump float coordinate, lowp float wrap ) { mediump float coord; @@ -51,7 +53,7 @@ mediump float wrapCoordinate( mediump vec2 range, mediump float coordinate, lowp } #endif -#if IS_REQUIRED_ROUNDED_CORNER || IS_REQUIRED_BORDERLINE +#if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) // Global values both rounded corner and borderline use // radius of rounded corner on this quadrant @@ -75,7 +77,7 @@ mediump float gMinInlinePotential = 0.0; void calculateCornerRadius() { -#if IS_REQUIRED_ROUNDED_CORNER +#ifdef IS_REQUIRED_ROUNDED_CORNER gRadius = mix( mix(vCornerRadius.x, vCornerRadius.y, sign(vPosition.x) * 0.5 + 0.5), @@ -89,7 +91,7 @@ void calculatePosition() { gFragmentPosition = abs(vPosition) - vRectSize; gCenterPosition = -gRadius; -#if IS_REQUIRED_BORDERLINE +#ifdef IS_REQUIRED_BORDERLINE gCenterPosition += borderlineWidth * (clamp(borderlineOffset, -1.0, 1.0) + 1.0) * 0.5; #endif gDiff = gFragmentPosition - gCenterPosition; @@ -102,12 +104,15 @@ 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 IS_REQUIRED_BORDERLINE +#ifdef IS_REQUIRED_BORDERLINE gMaxInlinePotential = gMaxOutlinePotential - borderlineWidth; gMinInlinePotential = gMinOutlinePotential - borderlineWidth; #else @@ -116,8 +121,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() @@ -130,7 +135,7 @@ void PreprocessPotential() } #endif -#if IS_REQUIRED_BORDERLINE +#ifdef IS_REQUIRED_BORDERLINE lowp vec4 convertBorderlineColor(lowp vec4 textureColor) { mediump float potential = gPotential; @@ -145,7 +150,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; @@ -157,7 +162,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) @@ -193,7 +198,7 @@ lowp vec4 convertBorderlineColor(lowp vec4 textureColor) } #endif -#if IS_REQUIRED_ROUNDED_CORNER +#ifdef IS_REQUIRED_ROUNDED_CORNER mediump float calculateCornerOpacity() { mediump float potential = gPotential; @@ -215,37 +220,76 @@ mediump float calculateCornerOpacity() } #endif +#if defined(IS_REQUIRED_YUV_TO_RGB) || defined(IS_REQUIRED_UNIFIED_YUV_AND_RGB) +lowp vec4 ConvertYuvToRgba(mediump vec2 texCoord) +{ +#ifdef IS_REQUIRED_UNIFIED_YUV_AND_RGB + // Special case when shader use YUV but actual textures are not YUV format. + // In this case, just resturn sTexture. + if(textureSize(sTextureU, 0) != textureSize(sTextureV, 0)) + { + return texture(sTexture, texCoord); + } +#endif + + lowp float y = texture(sTexture, texCoord).r; + lowp float u = texture(sTextureU, texCoord).r - 0.5; + lowp float v = texture(sTextureV, texCoord).r - 0.5; + lowp vec4 rgba; + rgba.r = y + (1.403 * v); + rgba.g = y - (0.344 * u) - (0.714 * v); + rgba.b = y + (1.770 * u); + rgba.a = 1.0; + return rgba; +} +#endif + void main() { -#if ATLAS_DEFAULT_WARP +#ifdef ATLAS_DEFAULT_WARP mediump vec2 texCoord = clamp( mix( uAtlasRect.xy, uAtlasRect.zw, vTexCoord ), uAtlasRect.xy, uAtlasRect.zw ); -#elif ATLAS_CUSTOM_WARP +#elif defined(ATLAS_CUSTOM_WARP) mediump vec2 texCoord = vec2( wrapCoordinate( uAtlasRect.xz, vTexCoord.x, wrapMode.x ), wrapCoordinate( uAtlasRect.yw, vTexCoord.y, wrapMode.y ) ); #else mediump vec2 texCoord = vTexCoord; #endif +#if defined(IS_REQUIRED_YUV_TO_RGB) || defined(IS_REQUIRED_UNIFIED_YUV_AND_RGB) + lowp vec4 textureColor = ConvertYuvToRgba(texCoord) * vec4( mixColor, 1.0 ) * uColor; +#else lowp vec4 textureColor = TEXTURE( sTexture, texCoord ) * vec4( mixColor, 1.0 ) * uColor; +#endif -#if IS_REQUIRED_ROUNDED_CORNER || IS_REQUIRED_BORDERLINE +#ifdef IS_REQUIRED_ALPHA_MASKING + mediump float maskAlpha = TEXTURE(sMaskTexture, vMaskTexCoord).a; + textureColor.a *= maskAlpha; + textureColor.rgb *= mix(1.0, maskAlpha, preMultipliedAlpha); +#endif + +#if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) // skip most potential calculate for performance if(abs(vPosition.x) < vOptRectSize.x && abs(vPosition.y) < vOptRectSize.y) { OUT_COLOR = textureColor; - return; } - PreprocessPotential(); + else + { + PreprocessPotential(); #endif -#if IS_REQUIRED_BORDERLINE - textureColor = convertBorderlineColor(textureColor); +#ifdef IS_REQUIRED_BORDERLINE + textureColor = convertBorderlineColor(textureColor); #endif - OUT_COLOR = textureColor; + OUT_COLOR = textureColor; -#if IS_REQUIRED_ROUNDED_CORNER - mediump float opacity = calculateCornerOpacity(); - OUT_COLOR.a *= opacity; - OUT_COLOR.rgb *= mix(1.0, opacity, preMultipliedAlpha); +#ifdef IS_REQUIRED_ROUNDED_CORNER + mediump float opacity = calculateCornerOpacity(); + OUT_COLOR.a *= opacity; + OUT_COLOR.rgb *= mix(1.0, opacity, preMultipliedAlpha); +#endif + +#if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) + } #endif }