1 #ifndef DALI_SCENE3D_LIGHT_IMPL_H
2 #define DALI_SCENE3D_LIGHT_IMPL_H
5 * Copyright (c) 2024 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-toolkit/public-api/controls/control-impl.h>
23 #include <dali/public-api/common/dali-common.h>
24 #include <dali/public-api/object/weak-handle.h>
25 #include <string_view>
28 #include <dali-scene3d/public-api/controls/scene-view/scene-view.h>
29 #include <dali-scene3d/public-api/light/light.h>
36 * @addtogroup dali_scene3d_light
43 * @brief This is the internal base class for custom node of Light.
47 class DALI_SCENE3D_API Light : public Toolkit::Internal::Control
50 // Creation & Destruction
52 * @brief Creates a new LightImpl instance that does not require touch by default.
54 * If touch is required, then the user can connect to this class' touch signal.
56 * @return A handle to the Light instance
58 static Scene3D::Light New();
61 * @copydoc Scene3D::Light::Enable()
63 void Enable(bool enable);
66 * @copydoc Scene3D::Light::IsEnabled()
68 bool IsEnabled() const;
71 * @copydoc Scene3D::Light::EnableShadow()
73 void EnableShadow(bool enable);
76 * @copydoc Scene3D::Light::IsShadowEnabled()
78 bool IsShadowEnabled() const;
81 * @copydoc Scene3D::Light::GetCamera()
83 CameraActor GetCamera() const;
86 * @copydoc Scene3D::Light::EnableShadowSoftFiltering()
88 void EnableShadowSoftFiltering(bool useSoftFiltering);
91 * @copydoc Scene3D::Light::IsShadowSoftFilteringEnabled()
93 bool IsShadowSoftFilteringEnabled() const;
96 * @copydoc Scene3D::Light::SetShadowIntensity()
98 void SetShadowIntensity(float shadowIntensity);
101 * @copydoc Scene3D::Light::GetShadowIntensity()
103 float GetShadowIntensity() const;
106 * @copydoc Scene3D::Light::SetShadowBias()
108 void SetShadowBias(float shadowBias);
111 * @copydoc Scene3D::Light::GetShadowBias()
113 float GetShadowBias() const;
117 * @brief Virtual destructor.
122 protected: // From CustomActorImpl
124 * @copydoc CustomActorImpl::OnSceneConnection()
125 * @note If overridden, then an up-call to Light::OnSceneConnection MUST be made at the end.
127 void OnSceneConnection(int depth) override;
130 * @copydoc CustomActorImpl::OnSceneDisconnection()
131 * @note If overridden, then an up-call to Light::OnSceneDisconnection MUST be made at the end.
133 void OnSceneDisconnection() override;
136 * @copydoc CustomActorImpl::OnChildAdd()
137 * @note If overridden, then an up-call to Light::OnChildAdd MUST be made at the end.
139 void OnChildAdd(Actor& child) override;
142 * @copydoc CustomActorImpl::OnChildRemove()
143 * @note If overridden, then an up-call to Light::OnChildRemove MUST be made at the end.
145 void OnChildRemove(Actor& child) override;
148 * @copydoc CustomActorImpl::OnSizeSet()
149 * @note If overridden, then an up-call to Light::OnSizeSet MUST be made at the end.
151 void OnSizeSet(const Vector3& targetSize) override;
154 * @copydoc CustomActorImpl::OnSizeAnimation()
155 * @note If overridden, then an up-call to Light::OnSizeAnimation MUST be made at the end.
157 void OnSizeAnimation(Animation& animation, const Vector3& targetSize) override;
160 * @copydoc CustomActorImpl::OnRelayout()
162 void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
165 * @copydoc CustomActorImpl::OnSetResizePolicy()
167 void OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension) override;
170 * @copydoc CustomActorImpl::GetNaturalSize()
172 Vector3 GetNaturalSize() override;
175 * @copydoc CustomActorImpl::CalculateChildSize()
177 float CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension) override;
180 * @copydoc CustomActorImpl::GetHeightForWidth()
182 float GetHeightForWidth(float width) override;
185 * @copydoc CustomActorImpl::GetWidthForHeight()
187 float GetWidthForHeight(float height) override;
190 * @copydoc CustomActorImpl::RelayoutDependentOnChildren()
192 bool RelayoutDependentOnChildren(Dimension::Type dimension = Dimension::ALL_DIMENSIONS) override;
195 * @copydoc CustomActorImpl::OnCalculateRelayoutSize()
197 void OnCalculateRelayoutSize(Dimension::Type dimension) override;
200 * @copydoc CustomActorImpl::OnLayoutNegotiated()
202 void OnLayoutNegotiated(float size, Dimension::Type dimension) override;
208 * @brief Light constructor.
213 * @brief Second phase initialization.
217 public: // Public Method
219 * @copydoc Scene3D::Light::GetMaximumEnabledLightCount()
221 static uint32_t GetMaximumEnabledLightCount();
224 * @brief Retrieves Light Enabled Uniform Name for shader()
225 * @return string_view for LightEnabledUniformName
227 static std::string_view GetLightCountUniformName();
230 * @brief Retrieves Light Direction Uniform Name for shader()
231 * @return string_view for LightDirectionUniformName
233 static std::string_view GetLightDirectionUniformName();
236 * @brief Retrieves Light Color Uniform Name for shader()
237 * @return string_view for LightColorUniformName
239 static std::string_view GetLightColorUniformName();
242 * @brief Retrieves Uniform Name to define shadow is enabled or not.
243 * @return string_view for ShadowEnabledUniformName
245 static std::string_view GetShadowEnabledUniformName();
248 * @brief Retrieves Uniform Name for View/Projection matrix of the Shadow.
249 * @return string_view for ShadowViewProjectionMatrixUniformName
251 static std::string_view GetShadowViewProjectionMatrixUniformName();
254 void UpdateShadowUniforms();
259 // Not copyable or movable
260 DALI_INTERNAL Light(const Light&) = delete; ///< Deleted copy constructor.
261 DALI_INTERNAL Light(Light&&) = delete; ///< Deleted move constructor.
262 DALI_INTERNAL Light& operator=(const Light&) = delete; ///< Deleted copy assignment operator.
263 DALI_INTERNAL Light& operator=(Light&&) = delete; ///< Deleted move assignment operator.
266 Dali::CameraActor mLightSourceActor;
267 WeakHandle<Scene3D::SceneView> mParentSceneView;
268 bool mIsEnabled{true};
269 bool mIsShadowEnabled{false};
270 bool mUseSoftFiltering{false};
271 float mShadowIntensity{0.5f};
272 float mShadowBias{0.001f};
277 * @brief Gets implementation from the handle.
280 * @return Implementation
281 * @pre handle is initialized and points to a node
283 DALI_SCENE3D_API Internal::Light& GetImplementation(Dali::Scene3D::Light& handle);
286 * @brief Gets implementation from the handle.
289 * @return Implementation
290 * @pre Handle is initialized and points to a node.
292 DALI_SCENE3D_API const Internal::Light& GetImplementation(const Dali::Scene3D::Light& handle);
294 } // namespace Internal
299 } // namespace Scene3D
303 #endif // DALI_SCENE3D_LIGHT_IMPL_H