From 25a048bee3efc9f047e5cd91d6e438eb9245c18c Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Thu, 7 Mar 2024 15:21:03 +0900 Subject: [PATCH] Let we use legacy rounded blur algorithm for gles2.0 + remove GL keyword Since low spec device also want to use rounded blur color visual, let we make them use some old legacy code, which required low calculation. Change-Id: I50ad32c09da384e9ddc8a18423e67681f8824a5c Signed-off-by: Eunki, Hong --- .../src/dali-toolkit/utc-Dali-Visual.cpp | 53 ++++++++++++++++++---- .../shaders/default-physically-based-shader.frag | 8 ++-- .../shaders/default-physically-based-shader.vert | 24 +++++----- .../graphics/shaders/shadow-map-shader.vert | 14 +++--- .../model-components/model-primitive-impl.cpp | 2 +- dali-scene3d/public-api/loader/shader-manager.cpp | 2 +- dali-scene3d/public-api/loader/shader-option.cpp | 2 +- dali-scene3d/public-api/loader/shader-option.h | 2 +- .../graphics/shaders/color-visual-shader.frag | 18 +++++++- .../internal/visuals/color/color-visual.cpp | 12 ++--- 10 files changed, 92 insertions(+), 45 deletions(-) diff --git a/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp b/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp index 2e829f1..5f7d114 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-Visual.cpp @@ -141,7 +141,6 @@ bool DaliTestCheckMaps(const Property::Map& fontStyleMapGet, const Property::Map return true; } - void TestShaderCodeContainSubstrings(Control control, std::vector> substringCheckList, const char* location) { Renderer renderer = control.GetRendererAt(0); @@ -150,6 +149,17 @@ void TestShaderCodeContainSubstrings(Control control, std::vectorFind("vertex"); // vertex key name from shader-impl.cpp + std::string vertexShader; + DALI_TEST_CHECK(vertex->Get(vertexShader)); + for(const auto& checkPair : substringCheckList) + { + const auto& keyword = checkPair.first; + const auto& expect = checkPair.second; + tet_printf("check [%s] %s exist in vertex shader\n", keyword.c_str(), expect ? "is" : "is not"); + DALI_TEST_EQUALS((vertexShader.find(keyword.c_str()) != std::string::npos), expect, location); + } + Property::Value* fragment = map->Find("fragment"); // fragment key name from shader-impl.cpp DALI_TEST_CHECK(fragment); std::string fragmentShader; @@ -161,6 +171,15 @@ void TestShaderCodeContainSubstrings(Control control, std::vector>> substringCheckList, const char* location) +{ + Renderer renderer = control.GetRendererAt(0); + Shader shader = renderer.GetShader(); + Property::Value value = shader.GetProperty(Shader::Property::PROGRAM); + Property::Map* map = value.GetMap(); + DALI_TEST_CHECK(map); Property::Value* vertex = map->Find("vertex"); // vertex key name from shader-impl.cpp std::string vertexShader; @@ -168,10 +187,22 @@ void TestShaderCodeContainSubstrings(Control control, std::vectorFind("fragment"); // fragment key name from shader-impl.cpp + DALI_TEST_CHECK(fragment); + std::string fragmentShader; + DALI_TEST_CHECK(fragment->Get(fragmentShader)); + for(const auto& checkPair : substringCheckList) + { + const auto& keyword = checkPair.first; + const auto& expect = checkPair.second.second; + tet_printf("check [%s] %s exist in fragment shader\n", keyword.c_str(), expect ? "is" : "is not"); + DALI_TEST_EQUALS((fragmentShader.find(keyword.c_str()) != std::string::npos), expect, location); + } } } //namespace @@ -6545,12 +6576,13 @@ int UtcDaliVisualUpdatePropertyChangeShader05(void) DALI_TEST_CHECK(cornerRadiusValue); DALI_TEST_EQUALS(cornerRadiusValue->Get(), targetCornerRadius, TEST_LOCATION); - TestShaderCodeContainSubstrings( + TestShaderCodeContainSubstringsForEachShader( dummyControl, { - {"#define IS_REQUIRED_BLUR", true}, - {"#define IS_REQUIRED_BORDERLINE", false}, // Note : We ignore borderline when blur radius occured - {"#define IS_REQUIRED_ROUNDED_CORNER", false}, // Note : low spec shader doesn't support rounded blur + {"#define IS_REQUIRED_BLUR", {true, true}}, + {"#define IS_REQUIRED_BORDERLINE", {false, false}}, // Note : We ignore borderline when blur radius occured + {"#define IS_REQUIRED_ROUNDED_CORNER", {true, true}}, + {"#define SL_VERSION_LOW", {false, true}}, }, TEST_LOCATION); @@ -6585,12 +6617,13 @@ int UtcDaliVisualUpdatePropertyChangeShader05(void) DALI_TEST_CHECK(cornerRadiusValue); DALI_TEST_EQUALS(cornerRadiusValue->Get(), Vector4::ZERO, TEST_LOCATION); - TestShaderCodeContainSubstrings( + TestShaderCodeContainSubstringsForEachShader( dummyControl, { - {"#define IS_REQUIRED_BLUR", true}, // Note : mAlwaysUsingBlurRadius is true. - {"#define IS_REQUIRED_BORDERLINE", false}, // Note : We ignore borderline when blur radius occured - {"#define IS_REQUIRED_ROUNDED_CORNER", false}, // Note : mAlwaysUsingCornerRadius is true. + {"#define IS_REQUIRED_BLUR", {true, true}}, // Note : mAlwaysUsingBlurRadius is true. + {"#define IS_REQUIRED_BORDERLINE", {false, false}}, // Note : We ignore borderline when blur radius occured + {"#define IS_REQUIRED_ROUNDED_CORNER", {true, true}}, // Note : mAlwaysUsingCornerRadius is true. + {"#define SL_VERSION_LOW", {false, true}}, }, TEST_LOCATION); diff --git a/dali-scene3d/internal/graphics/shaders/default-physically-based-shader.frag b/dali-scene3d/internal/graphics/shaders/default-physically-based-shader.frag index a7efc27..3b0eb21 100644 --- a/dali-scene3d/internal/graphics/shaders/default-physically-based-shader.frag +++ b/dali-scene3d/internal/graphics/shaders/default-physically-based-shader.frag @@ -96,7 +96,7 @@ uniform mediump vec3 uLightColor[MAX_LIGHTS]; // For Shadow Map uniform lowp int uIsShadowEnabled; uniform sampler2D sShadowMap; -#ifdef GLSL_VERSION_1_0 +#ifdef SL_VERSION_LOW uniform int uShadowMapWidth; uniform int uShadowMapHeight; #endif @@ -241,7 +241,7 @@ void main() // Specular Light // uMaxLOD that means mipmap level of specular texture is used for bluring of reflection of specular following roughness. float lod = perceptualRoughness * (uMaxLOD - 1.0); -#ifdef GLSL_VERSION_1_0 +#ifdef SL_VERSION_LOW // glsl 1.0 doesn't support textureLod. Let we just use textureCube instead. lowp vec3 specularLight = linear(textureCube(sSpecularEnvSampler, reflection * uYDirection).rgb); #else @@ -251,7 +251,7 @@ void main() // Diffuse Light lowp vec3 diffuseColor = mix(baseColor.rgb, vec3(0), metallic); -#ifdef GLSL_VERSION_1_0 +#ifdef SL_VERSION_LOW lowp vec3 irradiance = linear(textureCube(sDiffuseEnvSampler, n * uYDirection).rgb); #else lowp vec3 irradiance = linear(TEXTURE(sDiffuseEnvSampler, n * uYDirection).rgb); @@ -305,7 +305,7 @@ void main() mediump float exposureFactor = 0.0; if(uEnableShadowSoftFiltering > 0) { -#ifdef GLSL_VERSION_1_0 +#ifdef SL_VERSION_LOW ivec2 texSize = ivec2(uShadowMapWidth, uShadowMapHeight); #else ivec2 texSize = textureSize(sShadowMap, 0); diff --git a/dali-scene3d/internal/graphics/shaders/default-physically-based-shader.vert b/dali-scene3d/internal/graphics/shaders/default-physically-based-shader.vert index 25e615d..83be657 100644 --- a/dali-scene3d/internal/graphics/shaders/default-physically-based-shader.vert +++ b/dali-scene3d/internal/graphics/shaders/default-physically-based-shader.vert @@ -30,7 +30,7 @@ INPUT vec3 aTangent; INPUT vec4 aVertexColor; -#ifdef GLSL_VERSION_1_0 +#ifdef SL_VERSION_LOW INPUT float aVertexID; #endif @@ -42,7 +42,7 @@ ADD_EXTRA_SKINNING_ATTRIBUTES #ifdef MORPH uniform highp sampler2D sBlendShapeGeometry; -#ifdef GLSL_VERSION_1_0 +#ifdef SL_VERSION_LOW uniform int uBlendShapeGeometryWidth; uniform int uBlendShapeGeometryHeight; #endif @@ -60,7 +60,7 @@ uniform mat4 uProjection; #ifdef SKINNING -#ifdef GLSL_VERSION_1_0 +#ifdef SL_VERSION_LOW #define MAX_BONES 80 uniform mat4 uBone[MAX_BONES]; #else @@ -98,7 +98,7 @@ void main() highp vec3 tangent = aTangent.xyz; #ifdef MORPH -#ifdef GLSL_VERSION_1_0 +#ifdef SL_VERSION_LOW int width = uBlendShapeGeometryWidth; #else int width = textureSize( sBlendShapeGeometry, 0 ).x; @@ -106,7 +106,7 @@ void main() highp int blendShapeBufferOffset = 0; -#ifdef GLSL_VERSION_1_0 +#ifdef SL_VERSION_LOW highp float blendShapeWidth = float(uBlendShapeGeometryWidth); highp float blendShapeHeight = float(uBlendShapeGeometryHeight); highp float invertBlendShapeWidth = 1.0 / blendShapeWidth; @@ -123,7 +123,7 @@ void main() #ifdef MORPH_POSITION // Calculate the index to retrieve the geometry from the texture. -#ifdef GLSL_VERSION_1_0 +#ifdef SL_VERSION_LOW vertexId = int(floor(aVertexID + 0.5)) + blendShapeBufferOffset; y = vertexId / width; x = vertexId - y * width; @@ -142,7 +142,7 @@ void main() highp float unnormalizeFactor = uBlendShapeUnnormalizeFactor[index]; #endif -#ifdef GLSL_VERSION_1_0 +#ifdef SL_VERSION_LOW highp float floatX = float(x) + 0.5; highp float floatY = float(y) + 0.5; diff = weight * unnormalizeFactor * ( texture2D( sBlendShapeGeometry, vec2(floatX * invertBlendShapeWidth, floatY * invertBlendShapeHeight) ).xyz - 0.5 ); @@ -158,7 +158,7 @@ void main() #ifdef MORPH_NORMAL // Calculate the index to retrieve the normal from the texture. -#ifdef GLSL_VERSION_1_0 +#ifdef SL_VERSION_LOW vertexId = int(floor(aVertexID + 0.5)) + blendShapeBufferOffset; y = vertexId / width; x = vertexId - y * width; @@ -171,7 +171,7 @@ void main() // Retrieves the blend shape normal from the texture, unnormalizes it and multiply by the weight. if(0.0 != weight) { -#ifdef GLSL_VERSION_1_0 +#ifdef SL_VERSION_LOW highp float floatX = float(x) + 0.5; highp float floatY = float(y) + 0.5; diff = weight * 2.0 * ( texture2D( sBlendShapeGeometry, vec2(floatX * invertBlendShapeWidth, floatY * invertBlendShapeHeight) ).xyz - 0.5 ); @@ -187,7 +187,7 @@ void main() #ifdef MORPH_TANGENT // Calculate the index to retrieve the tangent from the texture. -#ifdef GLSL_VERSION_1_0 +#ifdef SL_VERSION_LOW vertexId = int(floor(aVertexID + 0.5)) + blendShapeBufferOffset; y = vertexId / width; x = vertexId - y * width; @@ -200,7 +200,7 @@ void main() // Retrieves the blend shape tangent from the texture, unnormalizes it and multiply by the weight. if(0.0 != weight) { -#ifdef GLSL_VERSION_1_0 +#ifdef SL_VERSION_LOW highp float floatX = float(x) + 0.5; highp float floatY = float(y) + 0.5; diff = weight * 2.0 * ( texture2D( sBlendShapeGeometry, vec2(floatX * invertBlendShapeWidth, floatY * invertBlendShapeHeight) ).xyz - 0.5 ); @@ -240,7 +240,7 @@ void main() highp vec4 positionV = uViewMatrix * positionW; -#ifdef GLSL_VERSION_1_0 +#ifdef SL_VERSION_LOW highp vec3 i0 = uViewMatrix[0].xyz; highp vec3 i1 = uViewMatrix[1].xyz; highp vec3 i2 = uViewMatrix[2].xyz; diff --git a/dali-scene3d/internal/graphics/shaders/shadow-map-shader.vert b/dali-scene3d/internal/graphics/shaders/shadow-map-shader.vert index f724b92..c0a873d 100644 --- a/dali-scene3d/internal/graphics/shaders/shadow-map-shader.vert +++ b/dali-scene3d/internal/graphics/shaders/shadow-map-shader.vert @@ -8,7 +8,7 @@ INPUT vec3 aPosition; INPUT vec2 aTexCoord; INPUT vec4 aVertexColor; -#ifdef GLSL_VERSION_1_0 +#ifdef SL_VERSION_LOW INPUT float aVertexID; #endif @@ -20,7 +20,7 @@ ADD_EXTRA_SKINNING_ATTRIBUTES; #ifdef MORPH uniform highp sampler2D sBlendShapeGeometry; -#ifdef GLSL_VERSION_1_0 +#ifdef SL_VERSION_LOW uniform int uBlendShapeGeometryWidth; uniform int uBlendShapeGeometryHeight; #endif @@ -35,7 +35,7 @@ uniform highp mat4 uProjection; #ifdef SKINNING -#ifdef GLSL_VERSION_1_0 +#ifdef SL_VERSION_LOW #define MAX_BONES 80 uniform mat4 uBone[MAX_BONES]; #else @@ -69,7 +69,7 @@ void main() #ifdef MORPH -#ifdef GLSL_VERSION_1_0 +#ifdef SL_VERSION_LOW int width = uBlendShapeGeometryWidth; #else int width = textureSize( sBlendShapeGeometry, 0 ).x; @@ -77,7 +77,7 @@ void main() highp int blendShapeBufferOffset = 0; -#ifdef GLSL_VERSION_1_0 +#ifdef SL_VERSION_LOW highp float blendShapeWidth = float(uBlendShapeGeometryWidth); highp float blendShapeHeight = float(uBlendShapeGeometryHeight); highp float invertBlendShapeWidth = 1.0 / blendShapeWidth; @@ -94,7 +94,7 @@ void main() #ifdef MORPH_POSITION // Calculate the index to retrieve the geometry from the texture. -#ifdef GLSL_VERSION_1_0 +#ifdef SL_VERSION_LOW vertexId = int(floor(aVertexID + 0.5)) + blendShapeBufferOffset; y = vertexId / width; x = vertexId - y * width; @@ -113,7 +113,7 @@ void main() highp float unnormalizeFactor = uBlendShapeUnnormalizeFactor[index]; #endif -#ifdef GLSL_VERSION_1_0 +#ifdef SL_VERSION_LOW highp float floatX = float(x) + 0.5; highp float floatY = float(y) + 0.5; diff = weight * unnormalizeFactor * ( texture2D( sBlendShapeGeometry, vec2(floatX * invertBlendShapeWidth, floatY * invertBlendShapeHeight) ).xyz - 0.5 ); diff --git a/dali-scene3d/internal/model-components/model-primitive-impl.cpp b/dali-scene3d/internal/model-components/model-primitive-impl.cpp index ce348d5..844f0b9 100644 --- a/dali-scene3d/internal/model-components/model-primitive-impl.cpp +++ b/dali-scene3d/internal/model-components/model-primitive-impl.cpp @@ -349,7 +349,7 @@ void ModelPrimitive::ApplyMaterialToRenderer(MaterialModifyObserver::ModifyFlag } if(DALI_UNLIKELY(Dali::Shader::GetShaderLanguageVersion() < MINIMUM_SHADER_VERSION_SUPPORT_TEXTURE_TEXEL_AND_SIZE)) { - shaderOption.AddOption(Scene3D::Loader::ShaderOption::Type::GLSL_VERSION_1_0); + shaderOption.AddOption(Scene3D::Loader::ShaderOption::Type::SL_VERSION_LOW); } Shader newShader = mShaderManager->ProduceShader(shaderOption); diff --git a/dali-scene3d/public-api/loader/shader-manager.cpp b/dali-scene3d/public-api/loader/shader-manager.cpp index 2969443..776092c 100644 --- a/dali-scene3d/public-api/loader/shader-manager.cpp +++ b/dali-scene3d/public-api/loader/shader-manager.cpp @@ -171,7 +171,7 @@ ShaderOption MakeOption(const MaterialDefinition& materialDef, const MeshDefinit } if(DALI_UNLIKELY(Dali::Shader::GetShaderLanguageVersion() < MINIMUM_SHADER_VERSION_SUPPORT_TEXTURE_TEXEL_AND_SIZE)) { - option.AddOption(ShaderOption::Type::GLSL_VERSION_1_0); + option.AddOption(ShaderOption::Type::SL_VERSION_LOW); } return option; diff --git a/dali-scene3d/public-api/loader/shader-option.cpp b/dali-scene3d/public-api/loader/shader-option.cpp index 859b65c..79cac28 100644 --- a/dali-scene3d/public-api/loader/shader-option.cpp +++ b/dali-scene3d/public-api/loader/shader-option.cpp @@ -49,7 +49,7 @@ static constexpr std::string_view OPTION_KEYWORD[] = "MORPH_NORMAL", "MORPH_TANGENT", "MORPH_VERSION_2_0", - "GLSL_VERSION_1_0", + "SL_VERSION_LOW", }; static constexpr uint32_t NUMBER_OF_OPTIONS = sizeof(OPTION_KEYWORD) / sizeof(OPTION_KEYWORD[0]); static const char* ADD_EXTRA_SKINNING_ATTRIBUTES{"ADD_EXTRA_SKINNING_ATTRIBUTES"}; diff --git a/dali-scene3d/public-api/loader/shader-option.h b/dali-scene3d/public-api/loader/shader-option.h index 65431db..47be344 100644 --- a/dali-scene3d/public-api/loader/shader-option.h +++ b/dali-scene3d/public-api/loader/shader-option.h @@ -52,7 +52,7 @@ public: MORPH_NORMAL, // 10000 MORPH_TANGENT, // 20000 MORPH_VERSION_2_0, // 40000 - GLSL_VERSION_1_0, // 80000 + SL_VERSION_LOW, // 80000 }; struct MacroDefinition diff --git a/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag b/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag index 04bb468..735f96b 100644 --- a/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag +++ b/dali-toolkit/internal/graphics/shaders/color-visual-shader.frag @@ -191,6 +191,19 @@ mediump float calculateCornerOpacity() #endif #ifdef IS_REQUIRED_BLUR +#ifdef SL_VERSION_LOW +// Legacy code for low version glsl +mediump float calculateBlurOpacity() +{ + highp float potential = gPotential; + + highp float alias = min(gRadius, vAliasMargin); + highp float potentialMin = gMinOutlinePotential - blurRadius - alias; + highp float potentialMax = gMaxOutlinePotential + blurRadius + alias; + + return 1.0 - smoothstep(potentialMin, potentialMax, potential); +} +#else mediump float calculateBlurOpacity() { // Don't use borderline! @@ -206,7 +219,7 @@ mediump float calculateBlurOpacity() v = v + cy; highp float potential = 0.0; - highp float alias = min(gRadius, 1.0); + highp float alias = min(gRadius, vAliasMargin); highp float potentialMin = cy + gRadius - blurRadius - alias; highp float potentialMax = cy + gRadius + blurRadius + alias; @@ -223,7 +236,7 @@ mediump float calculateBlurOpacity() potential = v.y; // for anti-alias when blurRaidus = 0.0 - highp float heuristicBaselineScale = max(1.0 , cr * (cr + cy)); + highp float heuristicBaselineScale = max(vAliasMargin , cr * (cr + cy)); highp float potentialDiff = min(alias, diffFromBaseline / heuristicBaselineScale); potentialMin += potentialDiff; potentialMax -= potentialDiff; @@ -258,6 +271,7 @@ mediump float calculateBlurOpacity() return 1.0 - smoothstep(potentialMin, potentialMax, potential); } #endif +#endif void main() { diff --git a/dali-toolkit/internal/visuals/color/color-visual.cpp b/dali-toolkit/internal/visuals/color/color-visual.cpp index ef61a6b..cb20865 100644 --- a/dali-toolkit/internal/visuals/color/color-visual.cpp +++ b/dali-toolkit/internal/visuals/color/color-visual.cpp @@ -242,12 +242,6 @@ Shader ColorVisual::GenerateShader() const // If we use blur, just ignore borderline borderline = false; shaderTypeFlag |= ColorVisualRequireFlag::BLUR; - - // If shader version doesn't support blur with corner radius, ignore corner radius - if(DALI_UNLIKELY(Dali::Shader::GetShaderLanguageVersion() < MINIMUM_SHADER_VERSION_SUPPORT_ROUNDED_BLUR)) - { - roundedCorner = false; - } } if(roundedCorner) { @@ -273,6 +267,12 @@ Shader ColorVisual::GenerateShader() const { vertexShaderPrefixList += "#define IS_REQUIRED_BLUR\n"; fragmentShaderPrefixList += "#define IS_REQUIRED_BLUR\n"; + + // If shader version doesn't support latest blur with corner radius, Let we use legacy code. + if(DALI_UNLIKELY(Dali::Shader::GetShaderLanguageVersion() < MINIMUM_SHADER_VERSION_SUPPORT_ROUNDED_BLUR)) + { + fragmentShaderPrefixList += "#define SL_VERSION_LOW\n"; + } } if(borderline) { -- 2.7.4