Fix Scene3D shader cache miss
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / public-api / loader / shader-definition-factory.cpp
index 8a5b639..390284c 100644 (file)
@@ -81,6 +81,22 @@ uint64_t HashNode(const MaterialDefinition& materialDef, const MeshDefinition& m
      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)
@@ -128,6 +144,16 @@ uint64_t HashNode(const MaterialDefinition& materialDef, const MeshDefinition& m
     hash.Add("FLIP" /*_V*/);
   }
 
+  if(meshDef.mColors.IsDefined())
+  {
+    hash.Add("COLATT");
+  }
+
+  if(meshDef.mTangentType == Property::VECTOR4)
+  {
+    hash.Add("V4TAN");
+  }
+
   if(meshDef.HasBlendShapes())
   {
     bool hasPositions = false;
@@ -292,6 +318,16 @@ Index ShaderDefinitionFactory::ProduceShader(NodeDefinition::Renderable& rendera
       shaderDef.mDefines.push_back("FLIP_V");
     }
 
+    if(meshDef.mColors.IsDefined())
+    {
+      shaderDef.mDefines.push_back("COLOR_ATTRIBUTE");
+    }
+
+    if(meshDef.mTangentType == Property::VECTOR4)
+    {
+      shaderDef.mDefines.push_back("VEC4_TANGENT");
+    }
+
     if(meshDef.HasBlendShapes())
     {
       bool hasPositions = false;
@@ -325,11 +361,6 @@ Index ShaderDefinitionFactory::ProduceShader(NodeDefinition::Renderable& rendera
       }
     }
 
-    if(meshDef.mTangentType == Property::VECTOR4)
-    {
-      shaderDef.mDefines.push_back("VEC4_TANGENT");
-    }
-
     shaderDef.mUniforms["uMaxLOD"]     = 6.f;
     shaderDef.mUniforms["uCubeMatrix"] = Matrix::IDENTITY;