[NUI.Scene3D] Add Shadow for a Directional Light
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Scene3D / src / public / Light / Light.cs
1 /*
2  * Copyright(c) 2023 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 using System;
19 using System.Runtime.InteropServices;
20 using System.ComponentModel;
21 using Tizen.NUI;
22 using Tizen.NUI.Binding;
23 using Tizen.NUI.BaseComponents;
24
25 namespace Tizen.NUI.Scene3D
26 {
27     /// <summary>
28     /// This class is to define 3D Light source.
29     /// Currently this Light class supports Directional Light that lights every position from the same direction. (e.g, Sun light)
30     /// If a Light object is added on SceneView, the 3D objects in the SceneView are shined the Light.
31     /// NUI Scene3D limits the maximum enabled light count per each SceneView.
32     /// Currently the maximum number is set to 5, and it can be retrieved by using <see cref="MaximumActivatedLightCount"/>.
33     /// If more than 5 enabled Light objects are added on SceneView, SceneView turns on only 5 lights in the order the lights were added.
34     /// This Light can be added to SceneView directly but also it can be added on other View.
35     /// 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.
36     /// </summary>
37     /// <remarks>
38     /// Light inherits View, so Light color and direction can be controlled by setting View's <see cref="View.Color"/> and <see cref="View.Orientation"/> Property.
39     /// <see cref="View.LookAt(Vector3, Vector3, Vector3, Vector3)"/> method can be used to set light direction easily.
40     /// </remarks>
41     /// <remarks>
42     /// Default light direction is to Z-axis
43     /// </remarks>
44     /// <example>
45     /// <code>
46     /// SceneView sceneView = new SceneView();
47     /// Light light = new Light();
48     /// light.Color = Color.Brown;
49     /// light.LookAt(new Vector3(1.0f, 1.0f, 1.0f));
50     /// sceneView.Add(light);
51     /// </code>
52     /// </example>
53     [EditorBrowsable(EditorBrowsableState.Never)]
54     public class Light : View
55     {
56         internal Light(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
57         {
58         }
59
60         /// <summary>
61         /// Create an initialized Light.
62         /// </summary>
63         [EditorBrowsable(EditorBrowsableState.Never)]
64         public Light() : this(Interop.Light.New(), true)
65         {
66             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
67         }
68
69         /// <summary>
70         /// Copy constructor.
71         /// </summary>
72         /// <param name="light">Source object to copy.</param>
73         [EditorBrowsable(EditorBrowsableState.Never)]
74         public Light(Light light) : this(Interop.Light.NewLight(Light.getCPtr(light)), true)
75         {
76             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
77         }
78
79         /// <summary>
80         /// Maximum Activated Light Count.
81         /// It is possible to add more Lights to the SceneView than the Maximum Activated Light Count,
82         /// but only up to the Maximum Activated Light Count Lights will work.
83         /// </summary>
84         /// <remarks>
85         /// This property is read only.
86         /// </remarks>
87         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
88         [EditorBrowsable(EditorBrowsableState.Never)]
89         public uint MaximumActivatedLightCount
90         {
91             get
92             {
93                 return Interop.Light.GetMaximumEnabledLightCount();
94             }
95         }
96
97         /// <summary>
98         /// The Light is turned on when the Light object is added on SceneView and enabled.
99         /// And checks whether this light is enabled or not.
100         /// </summary>
101         /// <remarks>
102         /// SceneView can turn on only up to maximum enabled light count that can be retrieved by GetMaximumEnabledLightCount().
103         /// </remarks>
104         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
105         [EditorBrowsable(EditorBrowsableState.Never)]
106         public bool IsLightEnabled
107         {
108             get
109             {
110
111                 bool isEnabled = Interop.Light.IsEnabled(SwigCPtr);
112                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
113                 return isEnabled;
114             }
115             set
116             {
117                 Interop.Light.Enable(SwigCPtr, value);
118                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
119             }
120         }
121
122         /// <summary>
123         /// Make the light enable shadow for this light or not.
124         /// NUI.Scene3D generates shadow by using shadow map.
125         /// For the Directional Light, the shadow map is created to cover view frustum of current selected camera.
126         /// This means that if the distance between the near and far planes is too large,
127         /// the shadow map has to cover an unnecessarily large area. This results in lower shadow quality.
128         /// </summary>
129         /// <remarks>
130         /// This light should be already turned on in the SceneView.
131         /// (When true) If there is previous light already enabled shadow in the SceneView, this function call is ignored.
132         /// (When false, and this light is currently used for shader)
133         /// If there are other lights those are turned on and shadow enabled, one of the light will be used for shadow automatically.
134         /// </remarks>
135         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
136         [EditorBrowsable(EditorBrowsableState.Never)]
137         public bool IsShadowEnabled
138         {
139             get
140             {
141
142                 bool isEnabled = Interop.Light.IsShadowEnabled(SwigCPtr);
143                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
144                 return isEnabled;
145             }
146             set
147             {
148                 Interop.Light.EnableShadow(SwigCPtr, value);
149                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
150             }
151         }
152
153         /// <summary>
154         /// Make the shadow edge soften or not.
155         /// Basically the shadow is hard shadow that has sharp edge.
156         /// This method enables soft filtering to make the sharp edge to smoothing.
157         /// </summary>
158         /// <remarks>
159         /// This soft filtering requires expensive computation power.
160         /// </remarks>
161         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
162         [EditorBrowsable(EditorBrowsableState.Never)]
163         public bool IsShadowSoftFilteringEnabled
164         {
165             get
166             {
167
168                 bool isEnabled = Interop.Light.IsShadowSoftFilteringEnabled(SwigCPtr);
169                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
170                 return isEnabled;
171             }
172             set
173             {
174                 Interop.Light.EnableShadowSoftFiltering(SwigCPtr, value);
175                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
176             }
177         }
178
179         /// <summary>
180         /// Sets and gets shadow intensity.
181         /// If the intensity is larger, the shadow area will be darker.
182         /// The intensity value is between [0, 1].
183         /// Default value is 0.5
184         /// </summary>
185         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
186         [EditorBrowsable(EditorBrowsableState.Never)]
187         public float ShadowIntensity
188         {
189             get
190             {
191
192                 float shadowIntensity = Interop.Light.GetShadowIntensity(SwigCPtr);
193                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
194                 return shadowIntensity;
195             }
196             set
197             {
198                 Interop.Light.SetShadowIntensity(SwigCPtr, value);
199                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
200             }
201         }
202
203         /// <summary>
204         /// Sets and gets shadow bias.
205         /// Shadow bias is an offset value to remove shadow acne that is a visual artifact can be shown on the Shadow
206         /// Default value is 0.001
207         /// </summary>
208         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
209         [EditorBrowsable(EditorBrowsableState.Never)]
210         public float ShadowBias
211         {
212             get
213             {
214
215                 float shadowBias = Interop.Light.GetShadowBias(SwigCPtr);
216                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
217                 return shadowBias;
218             }
219             set
220             {
221                 Interop.Light.SetShadowBias(SwigCPtr, value);
222                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
223             }
224         }
225     }
226 }