1 #ifndef DALI_SCENE3D_MODEL_COMPONENTS_MATERIAL_H
2 #define DALI_SCENE3D_MODEL_COMPONENTS_MATERIAL_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/public-api/object/base-handle.h>
24 #include <dali/public-api/object/property-index-ranges.h>
25 #include <dali/public-api/object/property-value.h>
26 #include <dali/public-api/object/property.h>
27 #include <dali/public-api/rendering/sampler.h>
28 #include <dali/public-api/rendering/texture.h>
31 #include <dali-scene3d/public-api/api.h>
37 // Forward declarations.
41 } // namespace Internal
44 * @addtogroup dali_scene3d_model_components_material
49 * @brief Class for setting Material properties of 3D models
53 * @note This Material class is for setting Material properties of 3D models.
54 * This Material supports properties and textures for PBR.
55 * Also, Material can be shared with multiple ModelPrimitives and if the value is modified,
56 * the rendering results of all ModelPrimitives using this Material will be changed.
59 * Material material = Material::New();
60 * ModelPrimitive modelPrimitive = ModelPrimitive::New();
61 * modelPrimitive.SetMaterial(material);
62 * material.SetProperty(PropertyIndex, PropertyValue);
65 class DALI_SCENE3D_API Material : public Dali::BaseHandle
69 * @brief Enumeration for the start and end property ranges for material.
74 PROPERTY_START_INDEX = PROPERTY_REGISTRATION_START_INDEX, ///< Start index is used by the property registration macro. @SINCE_2_2.22
75 MATERIAL_PROPERTY_START_INDEX = PROPERTY_START_INDEX, ///< Start index of Control properties. @SINCE_2_2.22
76 MATERIAL_PROPERTY_END_INDEX = MATERIAL_PROPERTY_START_INDEX + 1000, ///< Reserving 1000 property indices. @SINCE_2_2.22
78 ANIMATABLE_PROPERTY_START_INDEX = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX, ///< @SINCE_2_2.22
79 ANIMATABLE_PROPERTY_END_INDEX = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1000, ///< Reserve animatable property indices, @SINCE_2_2.22
83 * @brief Enumeration for the instance of properties belonging to the Material class.
91 * @brief Name of material.
92 * @details type Property::STRING.
95 NAME = MATERIAL_PROPERTY_START_INDEX,
98 * @brief Property for the URL of the base color texture.
99 * @details Type Property::STRING.
105 * @brief Property for the base color factor of the material surface.
106 * @details Type Property::VECTOR4.
112 * @brief Property for the URL of the metallic-roughness texture.
113 * @details Type Property::STRING.
116 METALLIC_ROUGHNESS_URL,
119 * @brief Property for the metallic factor of the material surface.
120 * @details Type Property::FLOAT.
126 * @brief Property for the roughness factor of the material surface.
127 * @details Type Property::FLOAT.
133 * @brief Property for the URL of the normal texture.
134 * @details Type Property::STRING.
140 * @brief Property for the scale factor applied to normal vectors.
141 * @details Type Property::FLOAT.
147 * @brief Property for the URL of the occlusion texture.
148 * @details Type Property::STRING.
154 * @brief Property for the occlusion strength of the material surface.
155 * @details Type Property::FLOAT.
161 * @brief Property for the URL of the emissive texture.
162 * @details Type Property::STRING.
168 * @brief Emissive factor Property.
169 * @details type Property::VECTOR3.
175 * @brief Alpha mode Property.
176 * @details type Property::INTEGER.
182 * @brief Alpha cutoff Property.
183 * @details type Property::FLOAT.
189 * @brief Double sided Property.
190 * @details type Property::BOOLEAN.
196 *@brief Index of refraction (IOR) of the material surface
197 *@details type Property::FLOAT
203 * @brief Property for the URL of the specular texture.
204 * @details Type Property::STRING.
210 *@brief Property for the specular factor of the material surface.
211 *@details Type Property::FLOAT.
217 * @brief Property for the URL of the specular color texture.
218 * @details Type Property::STRING.
224 *@brief Property for the specular color factor of the material surface.
225 *@details Type Property::VECTOR3.
228 SPECULAR_COLOR_FACTOR,
235 * @brief Base Color Texture Property.
237 * @note This texture represents the base color of the material. In most cases, this will be the diffuse color of the material.
242 * @brief Metallic Roughness Texture Property.
244 * @note This texture represents the metallicness and roughness of the material. This texture can be used to make the material look more metallic or rough.
249 * @brief Normal Texture Property.
251 * @note This texture represents the surface of the material. This texture can be used to make the surface of the material look smooth or rough.
256 * @brief Occlusion Texture Property.
258 * @note This texture represents the depth of the material. This texture can be used to make the material look more three-dimensional.
263 * @brief Emissive Texture Property.
265 * @note This texture makes the material look like it's emitting light. This texture can be used to make the material look like it's glowing.
270 * @brief Specular Texture Property.
272 * @note This texture represents the specular reflection of the material. This texture can be used to make the material look more reflective.
277 * @brief Specular Color Texture Property.
279 * @note This texture represents the color of the specular reflection of the material. This texture can be used to set the color of the specular reflection of the material.
287 * @brief This indicates that the material is fully opaque and that the alpha value should be ignored.
293 * @brief This indicates that the material is either fully opaque or fully transparent depending on the alpha value. The alpha value is used to mask out areas of the material that should be transparent.
299 * @brief This indicates that the material is transparent and that the alpha value should be used to blend the material with the background.
305 public: // Creation & Destruction
307 * @brief Create an initialized Material.
310 * @return A handle to a newly allocated Dali resource
312 static Material New();
315 * @brief Creates an uninitialized Material.
317 * Only derived versions can be instantiated. Calling member
318 * functions with an uninitialized Dali::Object is not allowed.
327 * This is non-virtual since derived Handle types must not contain data or virtual methods.
334 * @brief Copy constructor.
337 * @param[in] material Handle to an object
339 Material(const Material& material);
342 * @brief Move constructor
345 * @param[in] rhs A reference to the moved handle
347 Material(Material&& rhs) noexcept;
350 * @brief Assignment operator.
353 * @param[in] material Handle to an object
354 * @return reference to this
356 Material& operator=(const Material& material);
359 * @brief Move assignment
362 * @param[in] rhs A reference to the moved handle
363 * @return A reference to this
365 Material& operator=(Material&& rhs) noexcept;
368 * @brief Downcasts an Object handle to Material.
370 * If handle points to a Material, the downcast produces valid handle.
371 * If not, the returned handle is left uninitialized.
374 * @param[in] handle Handle to an object
375 * @return Handle to a Material or an uninitialized handle
377 static Material DownCast(BaseHandle handle);
379 public: // Public Method
381 * @brief Sets the value of an existing property.
382 * @note BaseHandle is not subclass of Handle. So this API is not use Handle.SetProperty
385 * @param[in] index The index of the property
386 * @param[in] propertyValue The new value of the property
388 void SetProperty(Dali::Property::Index index, Dali::Property::Value propertyValue);
391 * @brief Retrieves a property value.
392 * @note BaseHandle is not subclass of Handle. So this API is not use Handle.SetProperty
395 * @param[in] index The index of the property
396 * @return The property value
397 * @note This returns the value set by SetProperty() or the animation target value if it is being animated.
399 Dali::Property::Value GetProperty(Dali::Property::Index index) const;
402 * @brief Convenience function for obtaining a property of a known type.
405 * @param[in] index The index of the property
406 * @return The property value
407 * @pre The property types match i.e. PropertyTypes::Get<T>() is equal to GetPropertyType(index).
411 T GetProperty(Dali::Property::Index index) const
413 Dali::Property::Value value = GetProperty(index);
415 return T(value.Get<T>());
419 * @brief Sets the texture for a given texture type.
422 * @param[in] index The texture type index
423 * @param[in] texture The texture to set.
425 void SetTexture(Scene3D::Material::TextureType index, Dali::Texture texture);
428 * @brief Gets the texture for a given texture type.
431 * @param[in] index The texture type index
432 * @return The texture at the given index.
434 Dali::Texture GetTexture(Scene3D::Material::TextureType index);
437 * @brief Sets the sampler for a given texture type.
440 * @param[in] index The texture type index
441 * @param[in] sampler The sampler to use for this texture type
443 void SetSampler(Scene3D::Material::TextureType index, Dali::Sampler sampler);
446 * @brief Gets the sampler for a given texture type.
449 * @param[in] index The texture type index
450 * @return The sampler used for this texture type
452 Dali::Sampler GetSampler(Scene3D::Material::TextureType index);
454 public: // Not intended for application developers
457 * @brief Creates a handle using the Scene3D::Internal implementation.
459 * @param[in] implementation The Material implementation
461 DALI_INTERNAL Material(Dali::Scene3D::Internal::Material* implementation);
469 } // namespace Scene3D
473 #endif // DALI_SCENE3D_MODEL_COMPONENTS_MATERIAL_H