From: Eunki, Hong Date: Thu, 8 Dec 2022 09:53:01 +0000 (+0900) Subject: [Tizen] Fix Scene3D shader cache miss X-Git-Tag: accepted/tizen/7.0/unified/20221212.015720^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cae8c5dee904d34aaad8343d33c54e152d80f6b4;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git [Tizen] Fix Scene3D shader cache miss Change-Id: I53858118dc98ae16ede4d48bd234ebc24e112933 Signed-off-by: Eunki, Hong --- 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 2dfc47b558..3556ec3d10 100644 --- a/dali-scene3d/internal/graphics/shaders/default-physically-based-shader.frag +++ b/dali-scene3d/internal/graphics/shaders/default-physically-based-shader.frag @@ -89,7 +89,9 @@ uniform lowp float uAlphaThreshold; // TODO: Multiple texture coordinate will be supported. in lowp vec2 vUV; in lowp mat3 vTBN; +#ifdef COLOR_ATTRIBUTE in lowp vec4 vColor; +#endif in highp vec3 vPositionToCamera; out vec4 FragColor; @@ -119,7 +121,11 @@ void main() lowp vec4 baseColor = texture(sAlbedoAlpha, vUV); baseColor = vec4(linear(baseColor.rgb), baseColor.w) * uColorFactor; #else // BASECOLOR_TEX +#ifdef COLOR_ATTRIBUTE lowp vec4 baseColor = vColor * uColorFactor; +#else // COLOR_ATTRIBUTE + lowp vec4 baseColor = uColorFactor; +#endif // COLOR_ATTRIBUTE #endif // BASECOLOR_TEX #ifdef METALLIC_ROUGHNESS_TEX @@ -134,7 +140,11 @@ void main() #endif // NORMAL_TEX #else // THREE_TEX vec4 albedoMetal = texture(sAlbedoMetal, vUV); +#ifdef COLOR_ATTRIBUTE lowp vec4 baseColor = vec4(linear(albedoMetal.rgb), 1.0) * vColor * uColorFactor; +#else // COLOR_ATTRIBUTE + lowp vec4 baseColor = vec4(linear(albedoMetal.rgb), 1.0) * uColorFactor; +#endif // COLOR_ATTRIBUTE metallic = albedoMetal.METALLIC * metallic; 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 ea4fd32fa8..332e417768 100644 --- a/dali-scene3d/internal/graphics/shaders/default-physically-based-shader.vert +++ b/dali-scene3d/internal/graphics/shaders/default-physically-based-shader.vert @@ -20,13 +20,16 @@ in vec4 aTangent; in vec3 aTangent; #endif +#ifdef COLOR_ATTRIBUTE in vec4 aVertexColor; +uniform lowp float uHasVertexColor; +#endif #ifdef MORPH uniform highp sampler2D sBlendShapeGeometry; #endif -out vec2 vUV; +out lowp vec2 vUV; out lowp mat3 vTBN; out lowp vec4 vColor; out highp vec3 vPositionToCamera; @@ -35,7 +38,6 @@ uniform highp mat4 uViewMatrix; uniform mat3 uNormalMatrix; uniform mat4 uModelMatrix; uniform mat4 uProjection; -uniform lowp float uHasVertexColor; #ifdef SKINNING in vec4 aJoints; @@ -160,7 +162,9 @@ void main() vUV = aTexCoord; #endif +#ifdef COLOR_ATTRIBUTE vColor = mix(vec4(1.0f), aVertexColor, uHasVertexColor); +#endif gl_Position = uProjection * positionV; } diff --git a/dali-scene3d/public-api/loader/shader-definition-factory.cpp b/dali-scene3d/public-api/loader/shader-definition-factory.cpp index 37638b5a99..2e92362ade 100644 --- a/dali-scene3d/public-api/loader/shader-definition-factory.cpp +++ b/dali-scene3d/public-api/loader/shader-definition-factory.cpp @@ -81,6 +81,22 @@ uint64_t HashNode(const NodeDefinition& nodeDef, const MaterialDefinition& mater materialDef.CheckTextures(MaterialDefinition::NORMAL)) { hash.Add("3TEX"); + + // For the glTF, each of basecolor, metallic_roughness, normal texture is not essential. + if(materialDef.CheckTextures(MaterialDefinition::ALBEDO)) + { + hash.Add("BCTEX"); + } + + if(materialDef.CheckTextures(MaterialDefinition::METALLIC | MaterialDefinition::ROUGHNESS)) + { + hash.Add("MRTEX"); + } + + if(materialDef.CheckTextures(MaterialDefinition::NORMAL)) + { + hash.Add("NTEX"); + } } if(materialDef.GetAlphaCutoff() > 0.f) @@ -160,6 +176,16 @@ uint64_t HashNode(const NodeDefinition& nodeDef, const MaterialDefinition& mater } } + if(meshDef.mColors.IsDefined()) + { + hash.Add("COLATT"); + } + + if(meshDef.mTangentType == Property::VECTOR4) + { + hash.Add("V4TAN"); + } + return hash; } } // namespace @@ -323,6 +349,11 @@ Index ShaderDefinitionFactory::ProduceShader(const NodeDefinition& nodeDef) } } + if(meshDef.mColors.IsDefined()) + { + shaderDef.mDefines.push_back("COLOR_ATTRIBUTE"); + } + if(meshDef.mTangentType == Property::VECTOR4) { shaderDef.mDefines.push_back("VEC4_TANGENT");