#include <iostream>
#include <dali-scene3d/internal/model-components/model-primitive-impl.h>
+#include <dali-scene3d/public-api/common/scene-depth-index-ranges.h>
using namespace Dali;
using namespace Dali::Toolkit;
DALI_TEST_CHECK(GetImplementation(modelPrimitive).GetRenderer());
END_TEST;
+}
+
+int UtcDaliModelPrimitiveMaterialDepthIndex(void)
+{
+ ToolkitTestApplication application;
+
+ Scene3D::ModelPrimitive modelPrimitive = Scene3D::ModelPrimitive::New();
+
+ tet_printf("Check primitive don't have material initial time\n");
+
+ DALI_TEST_CHECK(!modelPrimitive.GetMaterial());
+
+ Dali::Geometry geometry = Dali::Geometry::New();
+ Dali::Scene3D::Material material = Dali::Scene3D::Material::New();
+
+ modelPrimitive.SetGeometry(geometry);
+ modelPrimitive.SetMaterial(material);
+ DALI_TEST_CHECK(material == modelPrimitive.GetMaterial());
+
+ DALI_TEST_CHECK(GetImplementation(modelPrimitive).GetRenderer());
+
+ Dali::Renderer renderer = GetImplementation(modelPrimitive).GetRenderer();
+ DALI_TEST_CHECK(renderer.GetProperty<int32_t>(Dali::Renderer::Property::DEPTH_INDEX) == Scene3D::DepthIndex::Ranges::SCENE);
+
+ material.SetProperty(Scene3D::Material::Property::DEPTH_INDEX, 50);
+ DALI_TEST_CHECK(renderer.GetProperty<int32_t>(Dali::Renderer::Property::DEPTH_INDEX) == 50);
+
+ END_TEST;
}
\ No newline at end of file
material.SetProperty(Scene3D::Material::Property::SPECULAR_COLOR_FACTOR, specularColorFactor);
DALI_TEST_EQUALS(specularColorFactor, material.GetProperty<Vector3>(Scene3D::Material::Property::SPECULAR_COLOR_FACTOR), TEST_LOCATION);
+ int32_t depthIndex = 50;
+ material.SetProperty(Scene3D::Material::Property::DEPTH_INDEX, depthIndex);
+ DALI_TEST_EQUALS(depthIndex, material.GetProperty<int32_t>(Scene3D::Material::Property::DEPTH_INDEX), TEST_LOCATION);
+
END_TEST;
}
DALI_TEST_CHECK(!material.GetSampler((Scene3D::Material::TextureType)100));
END_TEST;
-}
\ No newline at end of file
+}
DALI_TEST_CHECK(material2 == modelPrimitive.GetMaterial());
END_TEST;
-}
\ No newline at end of file
+}
}
break;
}
+ case Dali::Scene3D::Material::Property::DEPTH_INDEX:
+ {
+ int32_t depthIndex = 0;
+ if(propertyValue.Get(depthIndex) && mDepthIndex != depthIndex)
+ {
+ mDepthIndex = depthIndex;
+ mModifyFlag |= MaterialModifyObserver::ModifyFlag::PROPERTY;
+ }
+ break;
+ }
}
if(needToApply)
value = Vector3(mTextureInformations[TextureIndex::SPECULAR_COLOR].mFactor);
break;
}
+ case Dali::Scene3D::Material::Property::DEPTH_INDEX:
+ {
+ value = mDepthIndex;
+ break;
+ }
}
return value;
}
Scene3D::Loader::RendererState::Apply(mRendererState, renderer);
}
+void Material::SetRendererProperty(Dali::Renderer renderer)
+{
+ renderer.SetProperty(Dali::Renderer::Property::DEPTH_INDEX, mDepthIndex);
+}
+
uint32_t Material::GetShadowMapTextureOffset()
{
return OFFSET_FOR_SHADOW_MAP_TEXTURE;
#include <dali-scene3d/public-api/loader/shader-definition.h>
#include <dali-scene3d/public-api/loader/shader-option.h>
#include <dali-scene3d/public-api/model-components/material.h>
+#include <dali-scene3d/public-api/common/scene-depth-index-ranges.h>
namespace Dali
{
void SetRendererUniform(Dali::Renderer renderer);
/**
+ * @brief Sets property value to the Renderer.
+ *
+ * @param[in] renderer Renderer object.
+ */
+ void SetRendererProperty(Dali::Renderer renderer);
+
+ /**
* @brief Retrieves shadow map texture offset.
*
* @return shadow map texture offset.
uint32_t mMaterialFlag = std::numeric_limits<uint32_t>::max();
Scene3D::Loader::RendererState::Type mRendererState = Scene3D::Loader::RendererState::NONE;
+ int32_t mDepthIndex{Scene3D::DepthIndex::Ranges::SCENE};
+
bool mIsOpaque = true;
bool mIsMask = false;
bool mObserverNotifying; ///< True if observe is notify now. If then, we should not change the mObservers.
*/
enum ModifyFlag
{
- NONE = 0,
- TEXTURE = 1 << 0,
- SHADER = 1 << 1,
- UNIFORM = 1 << 2,
+ NONE = 0,
+ TEXTURE = 1 << 0,
+ SHADER = 1 << 1,
+ UNIFORM = 1 << 2,
+ PROPERTY = 1 << 3,
};
/**
uint32_t uniformFlag = (flag & static_cast<uint32_t>(MaterialModifyObserver::ModifyFlag::UNIFORM));
if(mIsMaterialChanged || uniformFlag == static_cast<uint32_t>(MaterialModifyObserver::ModifyFlag::UNIFORM))
{
- if(!mRenderer)
+ if(mRenderer)
{
- mNeedToSetRendererUniform = true;
+ UpdateRendererUniform();
}
- else
+ }
+
+ uint32_t propertyFlag = (flag & static_cast<uint32_t>(MaterialModifyObserver::ModifyFlag::PROPERTY));
+ if(mIsMaterialChanged || propertyFlag == static_cast<uint32_t>(MaterialModifyObserver::ModifyFlag::PROPERTY))
+ {
+ if(mRenderer)
{
- UpdateRendererUniform();
+ UpdateRendererProperty();
}
}
mIsMaterialChanged = false;
mRenderer = Renderer::New(mGeometry, mShader);
mRenderer.SetTextures(mTextureSet);
UpdateRendererUniform();
+ UpdateRendererProperty();
for(auto* observer : mObservers)
{
}
}
+void ModelPrimitive::UpdateRendererProperty()
+{
+ if(mMaterial)
+ {
+ GetImplementation(mMaterial).SetRendererProperty(mRenderer);
+ }
+}
+
} // namespace Internal
} // namespace Scene3D
void UpdateRendererUniform();
/**
+ * @brief Updates the property of renderer.
+ */
+ void UpdateRendererProperty();
+
+ /**
* @brief Creates a renderer.
*/
void CreateRenderer();
Scene3D::Loader::BlendShapes::Version mBlendShapeVersion = Scene3D::Loader::BlendShapes::Version::INVALID;
bool mIsMaterialChanged = false;
- bool mNeedToSetRendererUniform = false;
};
} // namespace Internal
--- /dev/null
+#ifndef DALI_SCENE3D_SCENE_DEPTH_INDEX_RANGES_H
+#define DALI_SCENE3D_SCENE_DEPTH_INDEX_RANGES_H
+
+/*
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+namespace Dali
+{
+namespace Scene3D
+{
+namespace DepthIndex
+{
+
+/**
+ * @brief Depth index ranges to define rendering order.
+ * @SINCE_2_3.3
+ */
+enum Ranges
+{
+ /**
+ * @brief Depth index range for 3D scene content.
+ * @details The range of the scene content is between [SCENE, SCENE + 999]
+ * @SINCE_2_3.3
+ */
+ SCENE = -2000,
+
+ /**
+ * @brief Depth index range for UI scene content.
+ * @details The range of the UI content is between [UI, UI + 999].
+ * Some of internally created Renderer of Toolkit::Control already has
+ * default depth index value.
+ * Developer can fix the default values for their design.
+ * @SINCE_2_3.3
+ */
+ UI = 0
+};
+
+} // namespace DepthIndex
+
+} // namespace Scene3D
+
+} // namespace Dali
+
+#endif // DALI_SCENE3D_SCENE_DEPTH_INDEX_RANGES_H
DOUBLE_SIDED,
/**
- *@brief Index of refraction (IOR) of the material surface
- *@details type Property::FLOAT
+ * @brief Index of refraction (IOR) of the material surface
+ * @details type Property::FLOAT
* @SINCE_2_2.22
*/
IOR,
SPECULAR_URL,
/**
- *@brief Property for the specular factor of the material surface.
- *@details Type Property::FLOAT.
+ * @brief Property for the specular factor of the material surface.
+ * @details Type Property::FLOAT.
* @SINCE_2_2.22
*/
SPECULAR_FACTOR,
SPECULAR_COLOR_URL,
/**
- *@brief Property for the specular color factor of the material surface.
- *@details Type Property::VECTOR3.
+ * @brief Property for the specular color factor of the material surface.
+ * @details Type Property::VECTOR3.
* @SINCE_2_2.22
*/
SPECULAR_COLOR_FACTOR,
+
+ /**
+ * @brief Property to define rendering order.
+ * @details Depth index is used to define rendering order. This property
+ * is compatible with Dali::Renderer::Property::DepthIndex. Basically,
+ * a Renderer that has smaller depth index is rendered earlier.
+ * In the ordinary DALI UI components has 0 as depth index by default.
+ * (For the case of Toolkit::Control, its renderer has depth index
+ * value between [-20, 20] as fallowing the renderer's purpose)
+ *
+ * In the Scene3D cases, the rendering order of each Renderer may need
+ * to be manually defined to match scene developer's intent.
+ * Scene3D::DepthIndex::Ranges could be used to adjust rendering order
+ * between 3D Scene content.
+ * Or it also could be used to manage UI component in 3D Scene independently.
+ *
+ * Changing the depth index only affects the rendering order, and does not
+ * mean that objects drawn later will be drawn on top. To compute final
+ * rendering order, whether the object is opaque or non-opaque takes precedence
+ * over the depth index. Changing the rendering order among translucent objects
+ * has a significant impact on the rendering results.
+ * @SINCE_2_3.3
+ */
+ DEPTH_INDEX,
};
};