1 #ifndef DALI_SCENE3D_LIGHT_H
2 #define DALI_SCENE3D_LIGHT_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.h>
23 #include <dali/public-api/common/dali-common.h>
26 #include <dali-scene3d/public-api/api.h>
32 namespace Internal DALI_INTERNAL
38 * @addtogroup dali_toolkit_controls_light
43 * @brief This class is to define 3D Light source.
44 * Currently this Light class supports Directional Light that lits every position from the same direction. (e.g, Sun light)
45 * If a Light object is added on SceneView, the 3D objects in the SceneView are shined the Light.
46 * DALi Scene3D limits the maximum enabled light count per each SceneView.
47 * Currently the maximum number is set to 5, and it can be retrieved by using GetMaximumEnabledLightCount().
48 * If more than 5 enabled Light objects are added on SceneView, SceneView turns on only 5 lights in the order the lights were added.
49 * This Light can be added to SceneView directly but also it can be added on other Actor.
50 * When a parent actor is added to a SceneView, its Light behaves in the SceneView the same as if it were added directly to the SceneView.
51 * @note Light inherits Actor, so Light color and direction can be controlled by setting Actor's COLOR and ORIENTATION Property.
52 * Dali::DevelActor::LookAt() method can be used to set light direction easily.
53 * @note Default light direction is to Z-axis
55 * Scene3D::SceneView sceneView = Scene3D::SceneView::New();
56 * Scene3D::Lightlight = Scene3D::Light::New();
57 * light.SetProperty(Dali::Actor::Property::COLOR, Color::BROWN);
58 * Dali::DevelActor::LookAt(light, Vector3(1.0f, 1.0f, 1.0f));
59 * sceneView.Add(light);
63 class DALI_SCENE3D_API Light : public Dali::Toolkit::Control
67 * @brief Create an initialized Light.
70 * @return A handle to a newly allocated Dali resource
75 * @brief Creates an uninitialized Light.
77 * Only derived versions can be instantiated. Calling member
78 * functions with an uninitialized Dali::Object is not allowed.
87 * This is non-virtual since derived Handle types must not contain data or virtual methods.
94 * @brief Copy constructor.
97 * @param[in] light Handle to an object
99 Light(const Light& light);
102 * @brief Move constructor
105 * @param[in] rhs A reference to the moved handle
107 Light(Light&& rhs) noexcept;
110 * @brief Assignment operator.
113 * @param[in] light Handle to an object
114 * @return reference to this
116 Light& operator=(const Light& light);
119 * @brief Move assignment
122 * @param[in] rhs A reference to the moved handle
123 * @return A reference to this
125 Light& operator=(Light&& rhs) noexcept;
128 * @brief Downcasts an Object handle to Light.
130 * If handle points to a Light, the downcast produces valid handle.
131 * If not, the returned handle is left uninitialized.
134 * @param[in] handle Handle to an object
135 * @return Handle to a Light or an uninitialized handle
137 static Light DownCast(BaseHandle handle);
140 * @brief Enables this light.
141 * The Light is turned on when the Light object is added on SceneView and enabled.
143 * @note SceneView can turn on only up to maximum enabled light count that can be retrieved by GetMaximumEnabledLightCount().
144 * @param[in] enable True to make this Light enable.
146 void Enable(bool enable);
149 * @brief Checks whether this light is enabled or not.
151 * @return True if this light is enabled.
153 bool IsEnabled() const;
156 * @brief Retrieves maximum enabled light count.
158 * @return The number of maximum enabled light count.
160 static uint32_t GetMaximumEnabledLightCount();
163 * @brief Enables shadow for this light.
164 * Dali::Scene3D generates shadow by using shadow map.
165 * For the Directional Light, the shadow map is created to cover view frustum of current selected camera.
166 * This means that if the distance between the near and far planes is too large,
167 * the shadow map has to cover an unnecessarily large area. This results in lower shadow quality.
169 * @note This light should be already turned on in the SceneView.
170 * @note (When enable is true) If there is previous light already enabled shadow in the SceneView, this function call is ignored.
171 * @note (When enable is false, and this light is currently used for shader)
172 * If there are other lights those are turned on and shadow enabled, one of the light will be used for shadow automatically.
173 * @param[in] enable True to make this Light's shadow enable.
175 void EnableShadow(bool enable);
178 * @brief Checks whether the shadow of this light is enabled or not.
180 * @return True if the shadow of this light is enabled.
182 bool IsShadowEnabled() const;
185 * @brief Enables filtering to soften the edge of shadow.
186 * Basically the shadow is hard shadow that has sharp edge.
187 * This method enables soft filtering to make the sharp edge to smoothing.
189 * @note This soft filtering requires expensive computation power.
190 * @param[in] useSoftFiltering True to soften the shadow edge.
192 void EnableShadowSoftFiltering(bool useSoftFiltering);
195 * @brief Checks whether the shadow uses soft filtering.
197 * @return True if the shadow edge is soften.
199 bool IsShadowSoftFilteringEnabled() const;
202 * @brief Sets shadow intensity.
203 * If the intensity is larger, the shadow area will be darker.
204 * The intensity value is between [0, 1].
205 * Default value is 0.5
207 * @param[in] shadowIntensity Shadow intensity value
209 void SetShadowIntensity(float shadowIntensity);
212 * @brief Retrieve shadow intensity.
214 * @return Current shadow intensity value.
216 float GetShadowIntensity() const;
219 * @brief Sets shadow bias.
220 * Shadow bias is an offset value to remove shadow acne that is a visual artifact can be shown on the Shadow
221 * Default value is 0.001
223 * @param[in] shadowBias bias value to remove shadow acne.
224 * @note If the shadow bias is too large, the object will appear detached from the shadow.
226 void SetShadowBias(float shadowBias);
229 * @brief Retrieves shadow bias value.
231 * @return Shadow bias value.
233 float GetShadowBias() const;
235 public: // Not intended for application developers
238 * @brief Creates a handle using the Toolkit::Internal implementation.
240 * @param[in] implementation The Control implementation
242 DALI_INTERNAL Light(Internal::Light& implementation);
245 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
247 * @param[in] internal A pointer to the internal CustomActor
249 DALI_INTERNAL Light(Dali::Internal::CustomActor* internal);
256 } // namespace Scene3D
260 #endif // DALI_SCENE3D_LIGHT_H