#include <dali/integration-api/debug.h>
// INTERNAL INCLUDES
+#include <dali-scene3d/internal/light/light-impl.h>
#include <dali-scene3d/internal/model-components/material-impl.h>
+#include <dali-scene3d/internal/model-components/model-node-impl.h>
#include <dali-scene3d/internal/model-components/model-primitive-impl.h>
#include <dali-scene3d/public-api/loader/renderer-state.h>
#include <dali-scene3d/public-api/loader/utils.h>
-#include <dali-scene3d/internal/light/light-impl.h>
namespace Dali
{
reflector.Reflect(ResourceType::Material, mMaterialIdx);
}
+// How many shader managers are there?!
void ModelRenderable::OnCreate(const NodeDefinition& nodeDefinition, NodeDefinition::CreateParams& params, ModelNode& node) const
{
DALI_ASSERT_DEBUG(mMeshIdx != INVALID_INDEX);
- Renderable::OnCreate(nodeDefinition, params, node);
+ ShaderOption::HashType shaderOptionHash{0u};
+ if(mShaderIdx == INVALID_INDEX)
+ {
+ ShaderOption option = params.mShaderManager->ProduceShaderOption(params.mResources.mMaterials[mMaterialIdx].first,
+ params.mResources.mMeshes[mMeshIdx].first);
+ shaderOptionHash = option.GetOptionHash();
+ Shader shader = params.mShaderManager->ProduceShader(option);
+
+ static Geometry defaultGeometry = Geometry::New();
+ Renderer renderer = Renderer::New(defaultGeometry, shader);
+
+ RendererState::Apply(params.mShaderManager->GetRendererState(params.mResources.mMaterials[mMaterialIdx].first), renderer);
+ Internal::GetImplementation(node).UpdateShader(params.mShaderManager);
+ node.AddRenderer(renderer);
+ }
+ else
+ {
+ Renderable::OnCreate(nodeDefinition, params, node);
+ }
auto& resources = params.mResources;
auto& mesh = resources.mMeshes[mMeshIdx];
{
mesh.first.mModelPrimitive = ModelPrimitive::New();
- auto primitive = mesh.first.mModelPrimitive;
- GetImplementation(primitive).SetRenderer(renderer);
+ auto& primitive = GetImplementation(mesh.first.mModelPrimitive);
+ primitive.SetRenderer(renderer);
Index envIndex = resources.mMaterials[mMaterialIdx].first.mEnvironmentIdx;
uint32_t specularMipmap = resources.mEnvironmentMaps[envIndex].second.mSpecularMipmapLevels;
- GetImplementation(primitive).SetImageBasedLightTexture(resources.mEnvironmentMaps[envIndex].second.mDiffuse,
- resources.mEnvironmentMaps[envIndex].second.mSpecular,
- resources.mEnvironmentMaps[envIndex].first.mIblIntensity,
- specularMipmap);
+ primitive.SetImageBasedLightTexture(resources.mEnvironmentMaps[envIndex].second.mDiffuse,
+ resources.mEnvironmentMaps[envIndex].second.mSpecular,
+ resources.mEnvironmentMaps[envIndex].first.mIblIntensity,
+ specularMipmap);
bool hasPositions = false;
bool hasNormals = false;
bool hasTangents = false;
mesh.first.RetrieveBlendShapeComponents(hasPositions, hasNormals, hasTangents);
- GetImplementation(primitive).SetBlendShapeOptions(hasPositions, hasNormals, hasTangents);
- GetImplementation(primitive).SetBlendShapeGeometry(mesh.second.blendShapeGeometry);
- GetImplementation(primitive).SetSkinned(mesh.first.IsSkinned());
+ primitive.SetBlendShapeOptions(hasPositions, hasNormals, hasTangents, mesh.first.mBlendShapeVersion);
+ primitive.SetBlendShapeGeometry(mesh.second.blendShapeGeometry);
+ primitive.SetSkinned(mesh.first.IsSkinned(), mesh.first.GetNumberOfJointSets());
+ primitive.SetVertexColor(mesh.first.HasVertexColor());
}
auto shader = renderer.GetShader();
renderer.RegisterProperty(IBL_INTENSITY_STRING.data(), resources.mEnvironmentMaps[envIndex].first.mIblIntensity);
renderer.RegisterProperty(IBL_Y_DIRECTION.data(), resources.mEnvironmentMaps[envIndex].first.mYDirection);
- std::string lightCountPropertyName(Scene3D::Internal::Light::GetLightCountUniformName());
- renderer.RegisterProperty(lightCountPropertyName, 0);
-
- uint32_t maxLightCount = Scene3D::Internal::Light::GetMaximumEnabledLightCount();
- for(uint32_t i = 0; i < maxLightCount; ++i)
- {
- std::string lightDirectionPropertyName(Scene3D::Internal::Light::GetLightDirectionUniformName());
- lightDirectionPropertyName += "[" + std::to_string(i) + "]";
- renderer.RegisterProperty(lightDirectionPropertyName, Vector3::ZAXIS);
-
- std::string lightColorPropertyName(Scene3D::Internal::Light::GetLightColorUniformName());
- lightColorPropertyName += "[" + std::to_string(i) + "]";
- renderer.RegisterProperty(lightColorPropertyName, Vector3(Color::WHITE));
- }
-
node.SetProperty(Actor::Property::COLOR, mColor);
+ // If user uses customshader, the properties of the shader could not be changed by Material.
+ if(mShaderIdx == INVALID_INDEX)
{
matDef.mMaterial = Material::New();
auto material = matDef.mMaterial;
material.SetProperty(Scene3D::Material::Property::ALPHA_CUTOFF, matDef.GetAlphaCutoff());
material.SetProperty(Scene3D::Material::Property::DOUBLE_SIDED, matDef.mDoubleSided);
material.SetProperty(Scene3D::Material::Property::IOR, matDef.mIor);
+
+ // This _should_ keep the same shader as generated at the top of the method.
GetImplementation(mesh.first.mModelPrimitive).SetMaterial(material, false);
GetImplementation(material).ResetFlag();
}
- node.AddModelPrimitive(mesh.first.mModelPrimitive);
+ Internal::GetImplementation(node).AddModelPrimitive(mesh.first.mModelPrimitive, shaderOptionHash);
}
void ArcRenderable::OnCreate(const NodeDefinition& nodeDefinition, NodeDefinition::CreateParams& params, ModelNode& node) const