From 4350a6c2ac0a60a3e80038388c0d009edbabe585 Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Mon, 20 Nov 2023 13:41:03 +0900 Subject: [PATCH] Let Anti-Alias consider scale factor Some days ago, we assume that the view which is smaller than 100x100 doesn't use the range of anti-alias as 1.0. (See https://review.tizen.org/gerrit/c/platform/core/uifw/dali-toolkit/+/279801) But it make some visual defect when we use 56x56 size of view and scale it up. Basically, the problem of these issues comes due to visuald don't know the scale value. So let we get actor's scale value as default shader property, and then use it as anti-alias calculation parameter. Change-Id: I64b32049919cd79c9dda7fcf7c9c256e5b5a6078 Signed-off-by: Eunki, Hong --- .../dali-toolkit-test-utils/test-gl-abstraction.cpp | 1 + .../dali-toolkit-test-utils/test-graphics-reflection.cpp | 1 + .../internal/graphics/shaders/color-visual-shader.frag | 16 +++++++++++----- .../graphics/shaders/gradient-visual-shader.frag | 15 +++++++++++---- .../internal/graphics/shaders/image-visual-shader.frag | 15 +++++++++++---- 5 files changed, 35 insertions(+), 13 deletions(-) diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-gl-abstraction.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-gl-abstraction.cpp index 38169a2..b861c66 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-gl-abstraction.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-gl-abstraction.cpp @@ -166,6 +166,7 @@ void TestGlAbstraction::Initialize() {"uMvpMatrix", GL_FLOAT_MAT4, 1}, {"uNormalMatrix", GL_FLOAT_MAT4, 1}, {"uProjection", GL_FLOAT_MAT4, 1}, + {"uScale", GL_FLOAT_VEC3, 1}, {"uSize", GL_FLOAT_VEC3, 1}, {"uViewMatrix", GL_FLOAT_MAT4, 1}, {"uLightCameraProjectionMatrix", GL_FLOAT_MAT4, 1}, diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-graphics-reflection.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-graphics-reflection.cpp index 7b3e6c8..3998fde 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-graphics-reflection.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-graphics-reflection.cpp @@ -54,6 +54,7 @@ static const std::vector UNIFORMS = UniformData("uMvpMatrix", Property::Type::MATRIX), UniformData("uNormalMatrix", Property::Type::MATRIX3), UniformData("uProjection", Property::Type::MATRIX), + UniformData("uScale", Property::Type::VECTOR3), UniformData("uSize", Property::Type::VECTOR3), UniformData("uViewMatrix", Property::Type::MATRIX), UniformData("uLightCameraProjectionMatrix", Property::Type::MATRIX), diff --git a/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag b/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag index 662121e..f1b51bb 100644 --- a/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag +++ b/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag @@ -7,6 +7,11 @@ 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 @@ -18,7 +23,6 @@ uniform lowp vec4 borderlineColor; uniform lowp vec4 uActorColor; #endif - #if defined(IS_REQUIRED_ROUNDED_CORNER) || defined(IS_REQUIRED_BORDERLINE) || defined(IS_REQUIRED_BLUR) // Global values both rounded corner and borderline use @@ -71,8 +75,10 @@ void calculatePotential() void setupMinMaxPotential() { - // Set soft anti-alias range at most 2% of visual size - gPotentialRange = min(1.0, max(vRectSize.x, vRectSize.y) * 0.02); + // 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; @@ -89,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() diff --git a/dali-toolkit/internal/graphics/shaders/gradient-visual-shader.frag b/dali-toolkit/internal/graphics/shaders/gradient-visual-shader.frag index 5104f6b..c2b9c5d 100644 --- a/dali-toolkit/internal/graphics/shaders/gradient-visual-shader.frag +++ b/dali-toolkit/internal/graphics/shaders/gradient-visual-shader.frag @@ -11,6 +11,11 @@ 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; @@ -72,8 +77,10 @@ void calculatePotential() void setupMinMaxPotential() { - // Set soft anti-alias range at most 2% of visual size - gPotentialRange = min(1.0, max(vRectSize.x, vRectSize.y) * 0.02); + // 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; @@ -87,8 +94,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() diff --git a/dali-toolkit/internal/graphics/shaders/image-visual-shader.frag b/dali-toolkit/internal/graphics/shaders/image-visual-shader.frag index c2c17e5..bad5500 100644 --- a/dali-toolkit/internal/graphics/shaders/image-visual-shader.frag +++ b/dali-toolkit/internal/graphics/shaders/image-visual-shader.frag @@ -26,6 +26,11 @@ 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; @@ -99,8 +104,10 @@ void calculatePotential() void setupMinMaxPotential() { - // Set soft anti-alias range at most 2% of visual size - gPotentialRange = min(1.0, max(vRectSize.x, vRectSize.y) * 0.02); + // 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; @@ -114,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() -- 2.7.4