From 5926b0ec7eb3ab1b142923dc2417a20db862ee22 Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Wed, 22 Nov 2023 11:22:40 +0900 Subject: [PATCH] Append 1 pixel if corner radius is full-circle Their was some visual quality issue occured when we render perfect circle. The reason of issue was, the fragments for soft-anti-alias area was required. For resolve this issue greedly, let we just append vertex position margin, and render it applied as that margin value. TODO : Currently, we only consider fully-circle case. Let we need to calculate is there any similar defect need to be resolved for normal rect cases. Change-Id: Ib114c29b08806e21c3830b1dc65a8098b34ef060 Signed-off-by: Eunki, Hong --- .../graphics/shaders/color-visual-shader.frag | 11 ++------ .../graphics/shaders/color-visual-shader.vert | 33 ++++++++++++++++++++-- .../graphics/shaders/gradient-visual-shader.frag | 11 ++------ .../graphics/shaders/gradient-visual-shader.vert | 27 ++++++++++++++++-- .../graphics/shaders/image-visual-shader.frag | 11 ++------ .../graphics/shaders/image-visual-shader.vert | 33 +++++++++++++++++++--- 6 files changed, 89 insertions(+), 37 deletions(-) diff --git a/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag b/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag index f1b51bb..6c1fef6 100644 --- a/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag +++ b/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag @@ -2,16 +2,12 @@ INPUT mediump vec2 vPosition; INPUT mediump vec2 vRectSize; INPUT mediump vec2 vOptRectSize; +INPUT mediump float vAliasMargin; #ifdef IS_REQUIRED_ROUNDED_CORNER 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; #ifdef IS_REQUIRED_BLUR @@ -75,10 +71,7 @@ void calculatePotential() void setupMinMaxPotential() { - // 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)); + gPotentialRange = vAliasMargin; gMaxOutlinePotential = gRadius + gPotentialRange; gMinOutlinePotential = gRadius - gPotentialRange; diff --git a/dali-toolkit/internal/graphics/shaders/color-visual-shader.vert b/dali-toolkit/internal/graphics/shaders/color-visual-shader.vert index 29ad984..28c5646 100644 --- a/dali-toolkit/internal/graphics/shaders/color-visual-shader.vert +++ b/dali-toolkit/internal/graphics/shaders/color-visual-shader.vert @@ -3,6 +3,7 @@ INPUT mediump vec2 aPosition; OUTPUT mediump vec2 vPosition; OUTPUT mediump vec2 vRectSize; OUTPUT mediump vec2 vOptRectSize; +OUTPUT mediump float vAliasMargin; #ifdef IS_REQUIRED_ROUNDED_CORNER OUTPUT mediump vec4 vCornerRadius; #endif @@ -11,6 +12,11 @@ OUTPUT mediump vec4 vCornerRadius; uniform highp mat4 uMvpMatrix; uniform highp vec3 uSize; +#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 + //Visual size and offset uniform mediump vec2 offset; uniform highp vec2 size; @@ -37,31 +43,52 @@ vec4 ComputeVertexPosition() #if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) || defined(IS_REQUIRED_BLUR) vRectSize = visualSize * 0.5; vOptRectSize = vRectSize; + + // 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%) + vAliasMargin = min(1.0, max(visualSize.x, visualSize.y) * 0.1) / max(0.001, max(uScale.x, uScale.y)); + + mediump float vertexMargin = 0.0; #endif #ifdef IS_REQUIRED_ROUNDED_CORNER #ifdef IS_REQUIRED_BLUR + mediump float maxSize = max(visualSize.x, visualSize.y); mediump float minSize = min(visualSize.x, visualSize.y); #elif defined(IS_REQUIRED_BORDERLINE) + mediump float maxSize = max(visualSize.x, visualSize.y) + (1.0 + clamp(borderlineOffset, -1.0, 1.0)) * borderlineWidth; mediump float minSize = min(visualSize.x, visualSize.y) + (1.0 + clamp(borderlineOffset, -1.0, 1.0)) * borderlineWidth; #else + mediump float maxSize = max(visualSize.x, visualSize.y); mediump float minSize = min(visualSize.x, visualSize.y); #endif vCornerRadius = mix(cornerRadius * minSize, cornerRadius, cornerRadiusPolicy); vCornerRadius = min(vCornerRadius, minSize * 0.5); // Optimize fragment shader. 0.2929 ~= 1.0 - sqrt(0.5) mediump float maxRadius = max(max(vCornerRadius.x, vCornerRadius.y), max(vCornerRadius.z, vCornerRadius.w)); + mediump float minRadius = min(min(vCornerRadius.x, vCornerRadius.y), min(vCornerRadius.z, vCornerRadius.w)); vOptRectSize -= 0.2929 * maxRadius + 1.0; + + // Set vertex margin as vAliasMargin if we need to make some more fragments for alias. +#ifdef IS_REQUIRED_BLUR + // Let we always increase alias margin for blur case + vertexMargin = 2.0 * vAliasMargin; +#else + // Do not increase margin if the minRadius is small enough rather than maxSize. + // TODO : We should change the magic parameter, 0.49 + vertexMargin = 2.0 * vAliasMargin * smoothstep(maxSize * 0.49, maxSize * 0.5, minRadius); +#endif #endif #ifdef IS_REQUIRED_BLUR - vPosition = aPosition * (visualSize + 2.0 * blurRadius); + vPosition = aPosition * (visualSize + 2.0 * blurRadius + vertexMargin); vOptRectSize -= blurRadius + 1.0; #elif defined(IS_REQUIRED_BORDERLINE) - vPosition = aPosition * (visualSize + (1.0 + clamp(borderlineOffset, -1.0, 1.0))* borderlineWidth); + vPosition = aPosition * (visualSize + (1.0 + clamp(borderlineOffset, -1.0, 1.0))* borderlineWidth + vertexMargin); vOptRectSize -= (1.0 - clamp(borderlineOffset, -1.0, 1.0)) * 0.5 * borderlineWidth + 1.0; #elif defined(IS_REQUIRED_ROUNDED_CORNER) - vPosition = aPosition * visualSize; + vPosition = aPosition * (visualSize + vertexMargin); #else mediump vec2 vPosition = aPosition * visualSize; #endif diff --git a/dali-toolkit/internal/graphics/shaders/gradient-visual-shader.frag b/dali-toolkit/internal/graphics/shaders/gradient-visual-shader.frag index c2b9c5d..752ecdb 100644 --- a/dali-toolkit/internal/graphics/shaders/gradient-visual-shader.frag +++ b/dali-toolkit/internal/graphics/shaders/gradient-visual-shader.frag @@ -3,6 +3,7 @@ INPUT mediump vec2 vTexCoord; INPUT mediump vec2 vPosition; INPUT mediump vec2 vRectSize; INPUT mediump vec2 vOptRectSize; +INPUT mediump float vAliasMargin; #ifdef IS_REQUIRED_ROUNDED_CORNER INPUT mediump vec4 vCornerRadius; #endif @@ -11,11 +12,6 @@ INPUT mediump vec4 vCornerRadius; // scale factor to fit start and end position of gradient. uniform mediump float uTextureCoordinateScaleFactor; -#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 sampler2D sTexture; // sampler1D? uniform lowp vec4 uColor; uniform lowp vec3 mixColor; @@ -77,10 +73,7 @@ void calculatePotential() void setupMinMaxPotential() { - // 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)); + gPotentialRange = vAliasMargin; gMaxOutlinePotential = gRadius + gPotentialRange; gMinOutlinePotential = gRadius - gPotentialRange; diff --git a/dali-toolkit/internal/graphics/shaders/gradient-visual-shader.vert b/dali-toolkit/internal/graphics/shaders/gradient-visual-shader.vert index b2b0864..928fd1c 100644 --- a/dali-toolkit/internal/graphics/shaders/gradient-visual-shader.vert +++ b/dali-toolkit/internal/graphics/shaders/gradient-visual-shader.vert @@ -4,6 +4,7 @@ OUTPUT mediump vec2 vTexCoord; OUTPUT mediump vec2 vPosition; OUTPUT mediump vec2 vRectSize; OUTPUT mediump vec2 vOptRectSize; +OUTPUT mediump float vAliasMargin; #ifdef IS_REQUIRED_ROUNDED_CORNER OUTPUT mediump vec4 vCornerRadius; #endif @@ -13,6 +14,11 @@ uniform highp mat4 uMvpMatrix; uniform highp vec3 uSize; uniform mediump mat3 uAlignmentMatrix; +#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 + //Visual size and offset uniform mediump vec2 offset; uniform highp vec2 size; @@ -36,28 +42,43 @@ vec4 ComputeVertexPosition() #if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) vRectSize = visualSize * 0.5; vOptRectSize = vRectSize; + + // 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%) + vAliasMargin = min(1.0, max(visualSize.x, visualSize.y) * 0.1) / max(0.001, max(uScale.x, uScale.y)); + + mediump float vertexMargin = 0.0; #endif #ifdef IS_REQUIRED_ROUNDED_CORNER #ifdef IS_REQUIRED_BORDERLINE + mediump float maxSize = max(visualSize.x, visualSize.y) + (1.0 + clamp(borderlineOffset, -1.0, 1.0)) * borderlineWidth; mediump float minSize = min(visualSize.x, visualSize.y) + (1.0 + clamp(borderlineOffset, -1.0, 1.0)) * borderlineWidth; #else + mediump float maxSize = max(visualSize.x, visualSize.y); mediump float minSize = min(visualSize.x, visualSize.y); #endif vCornerRadius = mix(cornerRadius * minSize, cornerRadius, cornerRadiusPolicy); vCornerRadius = min(vCornerRadius, minSize * 0.5); // Optimize fragment shader. 0.2929 ~= 1.0 - sqrt(0.5) mediump float maxRadius = max(max(vCornerRadius.x, vCornerRadius.y), max(vCornerRadius.z, vCornerRadius.w)); + mediump float minRadius = min(min(vCornerRadius.x, vCornerRadius.y), min(vCornerRadius.z, vCornerRadius.w)); vOptRectSize -= 0.2929 * maxRadius + 1.0; + + // Set vertex margin as vAliasMargin if we need to make some more fragments for alias. + // Do not increase margin if the minRadius is small enough rather than maxSize. + // TODO : We should change the magic parameter, 0.49 + vertexMargin = 2.0 * vAliasMargin * smoothstep(maxSize * 0.49, maxSize * 0.5, minRadius); #endif mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); #ifdef IS_REQUIRED_BORDERLINE - vPosition = aPosition * (visualSize + (1.0 + clamp(borderlineOffset, -1.0, 1.0)) * borderlineWidth); - vertexPosition.xy *= (1.0 + (1.0 + clamp(borderlineOffset, -1.0, 1.0)) * borderlineWidth / visualSize); + vPosition = aPosition * (visualSize + (1.0 + clamp(borderlineOffset, -1.0, 1.0)) * borderlineWidth + vertexMargin); + vertexPosition.xy *= (1.0 + ((1.0 + clamp(borderlineOffset, -1.0, 1.0)) * borderlineWidth + vertexMargin) / visualSize); vOptRectSize -= (1.0 - clamp(borderlineOffset, -1.0, 1.0)) * 0.5 * borderlineWidth + 1.0; #elif defined(IS_REQUIRED_ROUNDED_CORNER) - vPosition = aPosition * visualSize; + vPosition = aPosition * (visualSize + vertexMargin); #else mediump vec2 vPosition = aPosition * visualSize; #endif diff --git a/dali-toolkit/internal/graphics/shaders/image-visual-shader.frag b/dali-toolkit/internal/graphics/shaders/image-visual-shader.frag index bad5500..98a7347 100644 --- a/dali-toolkit/internal/graphics/shaders/image-visual-shader.frag +++ b/dali-toolkit/internal/graphics/shaders/image-visual-shader.frag @@ -3,6 +3,7 @@ INPUT mediump vec2 vTexCoord; INPUT mediump vec2 vPosition; INPUT mediump vec2 vRectSize; INPUT mediump vec2 vOptRectSize; +INPUT mediump float vAliasMargin; #ifdef IS_REQUIRED_ROUNDED_CORNER INPUT mediump vec4 vCornerRadius; #endif @@ -26,11 +27,6 @@ uniform mediump vec4 uAtlasRect; 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; @@ -104,10 +100,7 @@ void calculatePotential() void setupMinMaxPotential() { - // 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)); + gPotentialRange = vAliasMargin; gMaxOutlinePotential = gRadius + gPotentialRange; gMinOutlinePotential = gRadius - gPotentialRange; diff --git a/dali-toolkit/internal/graphics/shaders/image-visual-shader.vert b/dali-toolkit/internal/graphics/shaders/image-visual-shader.vert index a1243ec..6109c29 100644 --- a/dali-toolkit/internal/graphics/shaders/image-visual-shader.vert +++ b/dali-toolkit/internal/graphics/shaders/image-visual-shader.vert @@ -4,6 +4,7 @@ OUTPUT mediump vec2 vTexCoord; OUTPUT mediump vec2 vPosition; OUTPUT mediump vec2 vRectSize; OUTPUT mediump vec2 vOptRectSize; +OUTPUT mediump float vAliasMargin; #ifdef IS_REQUIRED_ROUNDED_CORNER OUTPUT mediump vec4 vCornerRadius; #endif @@ -13,6 +14,11 @@ uniform highp mat4 uMvpMatrix; uniform highp vec3 uSize; uniform mediump vec4 pixelArea; +#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 + //Visual size and offset uniform mediump vec2 offset; uniform highp vec2 size; @@ -42,6 +48,13 @@ vec4 ComputeVertexPosition() #if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) vRectSize = visualSize * 0.5; vOptRectSize = vRectSize; + + // 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%) + vAliasMargin = min(1.0, max(visualSize.x, visualSize.y) * 0.1) / max(0.001, max(uScale.x, uScale.y)); + + mediump float vertexMargin = 0.0; #endif #ifdef IS_REQUIRED_BORDERLINE @@ -51,22 +64,30 @@ vec4 ComputeVertexPosition() #ifdef IS_REQUIRED_ROUNDED_CORNER #ifdef IS_REQUIRED_BORDERLINE + mediump float maxSize = max(visualSize.x, visualSize.y) + outerBorderlineSize; mediump float minSize = min(visualSize.x, visualSize.y) + outerBorderlineSize; #else + mediump float maxSize = max(visualSize.x, visualSize.y); mediump float minSize = min(visualSize.x, visualSize.y); #endif vCornerRadius = mix(cornerRadius * minSize, cornerRadius, cornerRadiusPolicy); vCornerRadius = min(vCornerRadius, minSize * 0.5); // Optimize fragment shader. 0.2929 ~= 1.0 - sqrt(0.5) mediump float maxRadius = max(max(vCornerRadius.x, vCornerRadius.y), max(vCornerRadius.z, vCornerRadius.w)); + mediump float minRadius = min(min(vCornerRadius.x, vCornerRadius.y), min(vCornerRadius.z, vCornerRadius.w)); vOptRectSize -= 0.2929 * maxRadius + 1.0; + + // Set vertex margin as vAliasMargin if we need to make some more fragments for alias. + // Do not increase margin if the minRadius is small enough rather than maxSize. + // TODO : We should change the magic parameter, 0.49 + vertexMargin = 2.0 * vAliasMargin * smoothstep(maxSize * 0.49, maxSize * 0.5, minRadius); #endif #ifdef IS_REQUIRED_BORDERLINE - vPosition = aPosition * (visualSize + outerBorderlineSize); + vPosition = aPosition * (visualSize + outerBorderlineSize + vertexMargin); vOptRectSize -= (borderlineWidth - outerBorderlineSize * 0.5) + 1.0; #elif defined(IS_REQUIRED_ROUNDED_CORNER) - vPosition = aPosition * visualSize; + vPosition = aPosition * (visualSize + vertexMargin); #else mediump vec2 vPosition = aPosition * visualSize; #endif @@ -81,13 +102,17 @@ vec4 ComputeVertexPosition() cropToMask); vMaskTexCoord = pixelArea.xy + pixelArea.zw * (vec2(0.5) + aPosition.xy #ifdef IS_REQUIRED_BORDERLINE - * (1.0 + outerBorderlineSize / visualSize) + * (1.0 + (outerBorderlineSize + vertexMargin) / visualSize) +#elif defined(IS_REQUIRED_ROUNDED_CORNER) + * (1.0 + vertexMargin / visualSize) #endif ); #endif vTexCoord = finalPixelArea.xy + finalPixelArea.zw * (vec2(0.5) + aPosition.xy #ifdef IS_REQUIRED_BORDERLINE - * (1.0 + outerBorderlineSize / visualSize) + * (1.0 + (outerBorderlineSize + vertexMargin) / visualSize) +#elif defined(IS_REQUIRED_ROUNDED_CORNER) + * (1.0 + vertexMargin / visualSize) #endif ); -- 2.7.4