From b19cf78f1600ffa505de264f465865d18063dd5d Mon Sep 17 00:00:00 2001 From: Heeyong Song Date: Tue, 14 Apr 2020 15:31:07 +0900 Subject: [PATCH] Fix corner radius shader of the ImageVisual It didn't work for premultiplied-alpha images. Change-Id: I69d612112cb0f1ef132979ce830c8466a639c6f7 --- dali-toolkit/internal/visuals/image-visual-shader-factory.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/dali-toolkit/internal/visuals/image-visual-shader-factory.cpp b/dali-toolkit/internal/visuals/image-visual-shader-factory.cpp index 7fe979f..d9f273c 100644 --- a/dali-toolkit/internal/visuals/image-visual-shader-factory.cpp +++ b/dali-toolkit/internal/visuals/image-visual-shader-factory.cpp @@ -1,5 +1,5 @@ - /* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -143,7 +143,7 @@ const char* VERTEX_SHADER_ROUNDED_CORNER = DALI_COMPOSE_SHADER( {\n vec2 visualSize = mix(uSize.xy*size, size, offsetSizeMode.zw ) + extraSize;\n vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy);\n - vRectSize = visualSize / 2.0 - cornerRadius;\n + vRectSize = visualSize * 0.5 - cornerRadius;\n vPosition = aPosition* visualSize;\n return vec4( vPosition + anchorPoint*visualSize + (visualOffset + origin)*uSize.xy, 0.0, 1.0 );\n }\n @@ -164,12 +164,15 @@ const char* FRAGMENT_SHADER_ROUNDED_CORNER = DALI_COMPOSE_SHADER( uniform lowp vec4 uColor;\n uniform lowp vec3 mixColor;\n uniform mediump float cornerRadius;\n + uniform lowp float preMultipliedAlpha;\n \n void main()\n {\n mediump float dist = length( max( abs( vPosition ), vRectSize ) - vRectSize ) - cornerRadius;\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 *= smoothstep( 1.0, -1.0, dist );\n + gl_FragColor.a *= opacity;\n + gl_FragColor.rgb *= mix( 1.0, opacity, preMultipliedAlpha );\n }\n ); -- 2.7.4