From: Eunki, Hong Date: Tue, 26 Apr 2022 05:03:06 +0000 (+0900) Subject: [Tizen] CornerRadius valid to clip children X-Git-Tag: accepted/tizen/6.0/unified/20220513.142023^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F01%2F274301%2F1;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git [Tizen] CornerRadius valid to clip children Make able to use CornerRadius clip children. Note : It use stencil buffer. So Edge of rounded corner will show some alias. Change-Id: Id077a6a4226547e8ead3b953a8d8650ec5a4e733 Signed-off-by: Eunki, Hong --- diff --git a/dali-toolkit/devel-api/visuals/visual-properties-devel.h b/dali-toolkit/devel-api/visuals/visual-properties-devel.h index 99e3837..b449034 100644 --- a/dali-toolkit/devel-api/visuals/visual-properties-devel.h +++ b/dali-toolkit/devel-api/visuals/visual-properties-devel.h @@ -74,6 +74,7 @@ enum Type /** * @brief The radius for the rounded corners of the visual * @details Name "cornerRadius", type Property::FLOAT. + * @note Their may exist some alias when you use it as ClippingMode::CLIP_CHILDREN. * @note Optional. */ CORNER_RADIUS = OPACITY + 2, diff --git a/dali-toolkit/internal/visuals/color/color-visual.cpp b/dali-toolkit/internal/visuals/color/color-visual.cpp index 4fae268..3a67c29 100644 --- a/dali-toolkit/internal/visuals/color/color-visual.cpp +++ b/dali-toolkit/internal/visuals/color/color-visual.cpp @@ -126,9 +126,16 @@ const char* FRAGMENT_SHADER_ROUNDED_CORNER = DALI_COMPOSE_SHADER( \n void main()\n {\n - mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;\n + mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;\n + if(dist > 1.0)\n + {\n + discard;\n + }\n + else\n + {\n gl_FragColor = uColor * vec4( mixColor, 1.0 );\n gl_FragColor.a *= 1.0 - smoothstep( -1.0, 1.0, dist );\n + }\n }\n ); diff --git a/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp b/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp index 462a6c0..497dccd 100644 --- a/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp +++ b/dali-toolkit/internal/visuals/gradient/gradient-visual.cpp @@ -274,8 +274,15 @@ DALI_COMPOSE_SHADER( void main()\n {\n mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;\n - gl_FragColor = texture2D( sTexture, vec2( vTexCoord.y, 0.5 ) ) * vec4(mixColor, 1.0) * uColor;\n - gl_FragColor *= 1.0 - smoothstep( -1.0, 1.0, dist );\n + if(dist > 1.0)\n + {\n + discard;\n + }\n + else\n + {\n + gl_FragColor = texture2D( sTexture, vec2( vTexCoord.y, 0.5 ) ) * vec4(mixColor, 1.0) * uColor;\n + gl_FragColor *= 1.0 - smoothstep( -1.0, 1.0, dist );\n + }\n }\n ), @@ -292,8 +299,15 @@ DALI_COMPOSE_SHADER( void main()\n {\n mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;\n - gl_FragColor = texture2D( sTexture, vec2( length(vTexCoord), 0.5 ) ) * vec4(mixColor, 1.0) * uColor;\n - gl_FragColor *= 1.0 - smoothstep( -1.0, 1.0, dist );\n + if(dist > 1.0)\n + {\n + discard;\n + }\n + else\n + {\n + gl_FragColor = texture2D( sTexture, vec2( length(vTexCoord), 0.5 ) ) * vec4(mixColor, 1.0) * uColor;\n + gl_FragColor *= 1.0 - smoothstep( -1.0, 1.0, dist );\n + }\n }\n ) }; diff --git a/dali-toolkit/internal/visuals/image-visual-shader-factory.cpp b/dali-toolkit/internal/visuals/image-visual-shader-factory.cpp index 45d0e3f..49d1b5c 100644 --- a/dali-toolkit/internal/visuals/image-visual-shader-factory.cpp +++ b/dali-toolkit/internal/visuals/image-visual-shader-factory.cpp @@ -174,10 +174,17 @@ const char* FRAGMENT_SHADER_ROUNDED_CORNER = DALI_COMPOSE_SHADER( void main()\n {\n mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - vCornerRadius;\n - mediump float opacity = 1.0 - smoothstep( -1.0, 1.0, dist );\n - gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * vec4( mixColor, 1.0 );\n - gl_FragColor.a *= opacity;\n - gl_FragColor.rgb *= mix( 1.0, opacity, preMultipliedAlpha );\n + if(dist > 1.0)\n + {\n + discard;\n + }\n + else\n + {\n + mediump float opacity = 1.0 - smoothstep( -1.0, 1.0, dist );\n + gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * vec4( mixColor, 1.0 );\n + gl_FragColor.a *= opacity;\n + gl_FragColor.rgb *= mix( 1.0, opacity, preMultipliedAlpha );\n + }\n }\n );