[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-scene3d / utc-Dali-Light.cpp
1 /*
2  * Copyright (c) 2024 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 #include <dali-toolkit-test-suite-utils.h>
19 #include <dali-toolkit/dali-toolkit.h>
20 #include <dali/devel-api/actors/actor-devel.h>
21 #include <stdlib.h>
22 #include <iostream>
23
24 #include <dali-scene3d/public-api/controls/model/model.h>
25 #include <dali-scene3d/public-api/controls/scene-view/scene-view.h>
26 #include <dali-scene3d/public-api/light/light.h>
27 #include <dali/public-api/object/property.h>
28 #include <toolkit-event-thread-callback.h>
29
30 using namespace Dali;
31 using namespace Dali::Toolkit;
32
33 void light_startup(void)
34 {
35   test_return_value = TET_UNDEF;
36 }
37
38 void light_cleanup(void)
39 {
40   test_return_value = TET_PASS;
41 }
42
43 namespace
44 {
45 const char* TEST_GLTF_FILE_NAME = TEST_RESOURCE_DIR "/BoxAnimated.gltf";
46 } // namespace
47
48 // Negative test case for a method
49 int UtcDaliLightUninitialized(void)
50 {
51   ToolkitTestApplication application;
52   tet_infoline("UtcDaliLightUninitialized");
53
54   Scene3D::Light light;
55
56   try
57   {
58     // New() must be called to create a Model or it wont be valid.
59     Actor a = Actor::New();
60     light.Add(a);
61     DALI_TEST_CHECK(false);
62   }
63   catch(Dali::DaliException& e)
64   {
65     // Tests that a negative test of an assertion succeeds
66     DALI_TEST_PRINT_ASSERT(e);
67     DALI_TEST_CHECK(!light);
68   }
69   END_TEST;
70 }
71
72 // Positive test case for a method
73 int UtcDaliLightNew(void)
74 {
75   ToolkitTestApplication application;
76   tet_infoline("UtcDaliLightNew");
77
78   Scene3D::Light light = Scene3D::Light::New();
79   DALI_TEST_CHECK(light);
80   END_TEST;
81 }
82
83 // Positive test case for a method
84 int UtcDaliLightDownCast(void)
85 {
86   ToolkitTestApplication application;
87   tet_infoline("UtcDaliLightDownCast");
88
89   Scene3D::Light light = Scene3D::Light::New();
90   BaseHandle     handle(light);
91
92   Scene3D::Light light2 = Scene3D::Light::DownCast(handle);
93   DALI_TEST_CHECK(light);
94   DALI_TEST_CHECK(light2);
95   DALI_TEST_CHECK(light == light2);
96   END_TEST;
97 }
98
99 // Positive test case for a method
100 int UtcDaliLightCopyAndAssignment(void)
101 {
102   ToolkitTestApplication application;
103
104   Scene3D::Light light = Scene3D::Light::New();
105   DALI_TEST_CHECK(light);
106
107   Scene3D::Light copy(light);
108   DALI_TEST_CHECK(light == copy);
109
110   Scene3D::Light assign;
111   DALI_TEST_CHECK(!assign);
112
113   assign = copy;
114   DALI_TEST_CHECK(assign == light);
115
116   END_TEST;
117 }
118
119 int UtcDaliLightMoveConstructor(void)
120 {
121   ToolkitTestApplication application;
122
123   Scene3D::Light light = Scene3D::Light::New();
124   DALI_TEST_EQUALS(1, light.GetBaseObject().ReferenceCount(), TEST_LOCATION);
125   light.SetProperty(Actor::Property::SENSITIVE, false);
126   DALI_TEST_CHECK(false == light.GetProperty<bool>(Actor::Property::SENSITIVE));
127
128   Scene3D::Light moved = std::move(light);
129   DALI_TEST_CHECK(moved);
130   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
131   DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
132   DALI_TEST_CHECK(!light);
133
134   END_TEST;
135 }
136
137 int UtcDaliLightMoveAssignment(void)
138 {
139   ToolkitTestApplication application;
140
141   Scene3D::Light light = Scene3D::Light::New();
142   DALI_TEST_EQUALS(1, light.GetBaseObject().ReferenceCount(), TEST_LOCATION);
143   light.SetProperty(Actor::Property::SENSITIVE, false);
144   DALI_TEST_CHECK(false == light.GetProperty<bool>(Actor::Property::SENSITIVE));
145
146   Scene3D::Light moved;
147   moved = std::move(light);
148   DALI_TEST_CHECK(moved);
149   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
150   DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
151   DALI_TEST_CHECK(!light);
152
153   END_TEST;
154 }
155
156 // For TC coverage
157 int UtcDaliLightSize(void)
158 {
159   ToolkitTestApplication application;
160
161   Scene3D::Light light = Scene3D::Light::New();
162   application.GetScene().Add(light);
163
164   application.SendNotification();
165   application.Render();
166
167   light.SetProperty(Dali::Actor::Property::SIZE, Vector3::ONE);
168   DALI_TEST_EQUALS(Vector3::ONE, light.GetProperty<Vector3>(Dali::Actor::Property::SIZE), 0.01f, TEST_LOCATION);
169   DALI_TEST_EQUALS(Vector3::ZERO, light.GetNaturalSize(), 0.01f, TEST_LOCATION);
170
171   application.SendNotification();
172   application.Render();
173
174   light.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FIXED);
175   DALI_TEST_EQUALS(ResizePolicy::FIXED, light.GetProperty<ResizePolicy::Type>(Dali::Actor::Property::WIDTH_RESIZE_POLICY), TEST_LOCATION);
176
177   application.SendNotification();
178   application.Render();
179
180   float widthForHeight = light.GetWidthForHeight(light.GetProperty<float>(Dali::Actor::Property::SIZE_HEIGHT));
181   float heightForWidth = light.GetHeightForWidth(light.GetProperty<float>(Dali::Actor::Property::SIZE_WIDTH));
182   DALI_TEST_EQUALS(0.0f, widthForHeight, 0.01f, TEST_LOCATION);
183   DALI_TEST_EQUALS(0.0f, heightForWidth, 0.01f, TEST_LOCATION);
184
185   END_TEST;
186 }
187
188 int UtcDaliLightOnScene01(void)
189 {
190   ToolkitTestApplication application;
191
192   Scene3D::Light light = Scene3D::Light::New();
193   application.GetScene().Add(light);
194
195   application.SendNotification();
196   application.Render();
197
198   // Light is added on layer when on scene
199   DALI_TEST_EQUALS(true, light.GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE), TEST_LOCATION);
200
201   application.GetScene().Remove(light);
202
203   application.SendNotification();
204   application.Render();
205
206   // Light is removed from layer when on scene
207   DALI_TEST_EQUALS(false, light.GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE), TEST_LOCATION);
208
209   END_TEST;
210 }
211
212 // Add a light on SceneView directly
213 int UtcDaliLightAdd01(void)
214 {
215   ToolkitTestApplication application;
216   Scene3D::SceneView     sceneView = Scene3D::SceneView::New();
217   sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
218   sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
219   sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
220   sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
221   application.GetScene().Add(sceneView);
222
223   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
224   sceneView.Add(model);
225
226   application.SendNotification();
227   application.Render();
228   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
229   application.SendNotification();
230   application.Render();
231
232   Scene3D::Light light = Scene3D::Light::New();
233   light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
234   Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
235   sceneView.Add(light);
236
237   application.SendNotification();
238   application.Render();
239
240   Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
241   DALI_TEST_CHECK(renderer);
242   Shader shader = renderer.GetShader();
243   DALI_TEST_CHECK(shader);
244
245   DALI_TEST_EQUALS(1u, sceneView.GetActivatedLightCount(), TEST_LOCATION);
246   auto countPropertyIndex = shader.GetPropertyIndex("uLightCount");
247   DALI_TEST_CHECK(countPropertyIndex != Dali::Property::INVALID_INDEX);
248   DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(countPropertyIndex), TEST_LOCATION);
249   auto colorPropertyIndex = shader.GetPropertyIndex("uLightColor[0]");
250   DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 1.0f), shader.GetCurrentProperty<Vector3>(colorPropertyIndex), 0.01f, TEST_LOCATION);
251   auto directionPropertyIndex = shader.GetPropertyIndex("uLightDirection[0]");
252   DALI_TEST_EQUALS(Vector3(1.0f, 0.0f, 0.0f), shader.GetCurrentProperty<Vector3>(directionPropertyIndex), 0.01f, TEST_LOCATION);
253
254   light.Enable(false);
255
256   DALI_TEST_EQUALS(0u, sceneView.GetActivatedLightCount(), TEST_LOCATION);
257   DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(countPropertyIndex), TEST_LOCATION);
258
259   END_TEST;
260 }
261
262 // Add a light on an Actor that is child of SceneView.
263 int UtcDaliLightAdd02(void)
264 {
265   ToolkitTestApplication application;
266
267   Scene3D::SceneView sceneView = Scene3D::SceneView::New();
268   sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
269   sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
270   sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
271   sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
272   application.GetScene().Add(sceneView);
273
274   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
275   sceneView.Add(model);
276
277   application.SendNotification();
278   application.Render();
279   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
280   application.SendNotification();
281   application.Render();
282
283   Actor actor = Actor::New();
284   sceneView.Add(actor);
285
286   Scene3D::Light light = Scene3D::Light::New();
287   light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
288   Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
289   actor.Add(light);
290
291   application.SendNotification();
292   application.Render();
293
294   Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
295   DALI_TEST_CHECK(renderer);
296   Shader shader = renderer.GetShader();
297   DALI_TEST_CHECK(shader);
298
299   DALI_TEST_EQUALS(1u, sceneView.GetActivatedLightCount(), TEST_LOCATION);
300   auto countPropertyIndex = shader.GetPropertyIndex("uLightCount");
301   DALI_TEST_CHECK(countPropertyIndex != DALI_KEY_INVALID);
302   DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(countPropertyIndex), TEST_LOCATION);
303   auto colorPropertyIndex = shader.GetPropertyIndex("uLightColor[0]");
304   DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 1.0f), shader.GetCurrentProperty<Vector3>(colorPropertyIndex), 0.01f, TEST_LOCATION);
305   auto directionPropertyIndex = shader.GetPropertyIndex("uLightDirection[0]");
306   DALI_TEST_EQUALS(Vector3(1.0f, 0.0f, 0.0f), shader.GetCurrentProperty<Vector3>(directionPropertyIndex), 0.01f, TEST_LOCATION);
307
308   light.Enable(false);
309
310   DALI_TEST_EQUALS(0u, sceneView.GetActivatedLightCount(), TEST_LOCATION);
311   DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(countPropertyIndex), TEST_LOCATION);
312
313   END_TEST;
314 }
315
316 // Enable a light after it is added on SceneView.
317 int UtcDaliLightAdd03(void)
318 {
319   ToolkitTestApplication application;
320
321   Scene3D::SceneView sceneView = Scene3D::SceneView::New();
322   sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
323   sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
324   sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
325   sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
326   application.GetScene().Add(sceneView);
327
328   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
329   sceneView.Add(model);
330
331   application.SendNotification();
332   application.Render();
333   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
334   application.SendNotification();
335   application.Render();
336
337   Scene3D::Light light = Scene3D::Light::New();
338   light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
339   Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
340   light.Enable(false);
341   sceneView.Add(light);
342
343   application.SendNotification();
344   application.Render();
345
346   Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
347   DALI_TEST_CHECK(renderer);
348   Shader shader = renderer.GetShader();
349   DALI_TEST_CHECK(shader);
350
351   DALI_TEST_EQUALS(0u, sceneView.GetActivatedLightCount(), TEST_LOCATION);
352   auto countPropertyIndex = shader.GetPropertyIndex("uLightCount");
353   DALI_TEST_CHECK(countPropertyIndex != DALI_KEY_INVALID);
354   DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(countPropertyIndex), TEST_LOCATION);
355
356   light.Enable(true);
357
358   application.SendNotification();
359   application.Render();
360
361   DALI_TEST_EQUALS(1u, sceneView.GetActivatedLightCount(), TEST_LOCATION);
362   DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(countPropertyIndex), TEST_LOCATION);
363   auto colorPropertyIndex = shader.GetPropertyIndex("uLightColor[0]");
364   DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 1.0f), shader.GetCurrentProperty<Vector3>(colorPropertyIndex), 0.01f, TEST_LOCATION);
365   auto directionPropertyIndex = shader.GetPropertyIndex("uLightDirection[0]");
366   DALI_TEST_EQUALS(Vector3(1.0f, 0.0f, 0.0f), shader.GetCurrentProperty<Vector3>(directionPropertyIndex), 0.01f, TEST_LOCATION);
367
368   light.Enable(false);
369
370   application.SendNotification();
371   application.Render();
372
373   DALI_TEST_EQUALS(0u, sceneView.GetActivatedLightCount(), TEST_LOCATION);
374   DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(countPropertyIndex), TEST_LOCATION);
375
376   END_TEST;
377 }
378
379 int UtcDaliLightAdd04(void)
380 {
381   ToolkitTestApplication application;
382
383   Scene3D::SceneView sceneView = Scene3D::SceneView::New();
384   sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
385   sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
386   sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
387   sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
388   application.GetScene().Add(sceneView);
389
390   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
391   sceneView.Add(model);
392
393   application.SendNotification();
394   application.Render();
395   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
396   application.SendNotification();
397   application.Render();
398
399   Scene3D::Light light1 = Scene3D::Light::New();
400   light1.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
401   Dali::DevelActor::LookAt(light1, Vector3(1.0f, 0.0f, 0.0f));
402   sceneView.Add(light1);
403
404   Scene3D::Light light2 = Scene3D::Light::New();
405   light2.SetProperty(Dali::Actor::Property::COLOR, Color::RED);
406   Dali::DevelActor::LookAt(light2, Vector3(0.0f, 0.0f, -1.0f));
407   sceneView.Add(light2);
408
409   application.SendNotification();
410   application.Render();
411
412   Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
413   DALI_TEST_CHECK(renderer);
414   Shader shader = renderer.GetShader();
415   DALI_TEST_CHECK(shader);
416
417   DALI_TEST_EQUALS(2u, sceneView.GetActivatedLightCount(), TEST_LOCATION);
418   auto countPropertyIndex = shader.GetPropertyIndex("uLightCount");
419   DALI_TEST_CHECK(countPropertyIndex != DALI_KEY_INVALID);
420   DALI_TEST_EQUALS(2, shader.GetProperty<int32_t>(countPropertyIndex), TEST_LOCATION);
421   auto colorPropertyIndex1 = shader.GetPropertyIndex("uLightColor[0]");
422   DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 1.0f), shader.GetCurrentProperty<Vector3>(colorPropertyIndex1), 0.01f, TEST_LOCATION);
423   auto directionPropertyIndex1 = shader.GetPropertyIndex("uLightDirection[0]");
424   DALI_TEST_EQUALS(Vector3(1.0f, 0.0f, 0.0f), shader.GetCurrentProperty<Vector3>(directionPropertyIndex1), 0.01f, TEST_LOCATION);
425   auto colorPropertyIndex2 = shader.GetPropertyIndex("uLightColor[1]");
426   DALI_TEST_EQUALS(Vector3(1.0f, 0.0f, 0.0f), shader.GetCurrentProperty<Vector3>(colorPropertyIndex2), 0.01f, TEST_LOCATION);
427   auto directionPropertyIndex2 = shader.GetPropertyIndex("uLightDirection[1]");
428   DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, -1.0f), shader.GetCurrentProperty<Vector3>(directionPropertyIndex2), 0.01f, TEST_LOCATION);
429
430   light1.Enable(false);
431
432   application.SendNotification();
433   application.Render();
434
435   DALI_TEST_EQUALS(1u, sceneView.GetActivatedLightCount(), TEST_LOCATION);
436   DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(countPropertyIndex), TEST_LOCATION);
437
438   // After light1 is disable, shader uniforms of lights are reordered.
439   DALI_TEST_EQUALS(Vector3(1.0f, 0.0f, 0.0f), shader.GetCurrentProperty<Vector3>(colorPropertyIndex1), 0.01f, TEST_LOCATION);
440   DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, -1.0f), shader.GetCurrentProperty<Vector3>(directionPropertyIndex1), 0.01f, TEST_LOCATION);
441
442   END_TEST;
443 }
444
445 // Check unactivated light in SceneView becomes activated when a light become disabled.
446 int UtcDaliLightAdd05(void)
447 {
448   ToolkitTestApplication application;
449
450   Scene3D::SceneView sceneView = Scene3D::SceneView::New();
451   sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
452   sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
453   sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
454   sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
455   application.GetScene().Add(sceneView);
456
457   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
458   sceneView.Add(model);
459
460   application.SendNotification();
461   application.Render();
462   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
463   application.SendNotification();
464   application.Render();
465
466   uint32_t                    maxLightCount = Scene3D::Light::GetMaximumEnabledLightCount();
467   std::vector<Scene3D::Light> lightList;
468   for(uint32_t i = 0; i < maxLightCount; ++i)
469   {
470     Scene3D::Light light = Scene3D::Light::New();
471     light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
472     Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
473     sceneView.Add(light);
474     lightList.push_back(light);
475   }
476
477   Scene3D::Light light2 = Scene3D::Light::New();
478   light2.SetProperty(Dali::Actor::Property::COLOR, Color::RED);
479   Dali::DevelActor::LookAt(light2, Vector3(0.0f, 0.0f, -1.0f));
480   sceneView.Add(light2);
481   lightList.push_back(light2);
482
483   application.SendNotification();
484   application.Render();
485
486   Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
487   DALI_TEST_CHECK(renderer);
488   Shader shader = renderer.GetShader();
489   DALI_TEST_CHECK(shader);
490
491   DALI_TEST_EQUALS(maxLightCount, sceneView.GetActivatedLightCount(), TEST_LOCATION);
492   auto countPropertyIndex = shader.GetPropertyIndex("uLightCount");
493   DALI_TEST_CHECK(countPropertyIndex != DALI_KEY_INVALID);
494   DALI_TEST_EQUALS(static_cast<int32_t>(maxLightCount), shader.GetProperty<int32_t>(countPropertyIndex), TEST_LOCATION);
495   for(uint32_t i = 0; i < maxLightCount; ++i)
496   {
497     std::string colorStringKey     = std::string("uLightColor[") + std::to_string(i) + "]";
498     auto        colorPropertyIndex = shader.GetPropertyIndex(colorStringKey);
499     DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 1.0f), shader.GetCurrentProperty<Vector3>(colorPropertyIndex), 0.01f, TEST_LOCATION);
500
501     std::string directionStringKey     = std::string("uLightDirection[") + std::to_string(i) + "]";
502     auto        directionPropertyIndex = shader.GetPropertyIndex(directionStringKey);
503     DALI_TEST_EQUALS(Vector3(1.0f, 0.0f, 0.0f), shader.GetCurrentProperty<Vector3>(directionPropertyIndex), 0.01f, TEST_LOCATION);
504   }
505
506   lightList[2].Enable(false);
507
508   application.SendNotification();
509   application.Render();
510
511   DALI_TEST_EQUALS(maxLightCount, sceneView.GetActivatedLightCount(), TEST_LOCATION);
512   DALI_TEST_EQUALS(static_cast<int32_t>(maxLightCount), shader.GetProperty<int32_t>(countPropertyIndex), TEST_LOCATION);
513   for(uint32_t i = 0; i < maxLightCount; ++i)
514   {
515     tet_printf("i : %d\n", i);
516     Vector3 color, direction;
517     if(i == maxLightCount - 1)
518     {
519       color     = Vector3(1.0f, 0.0f, 0.0f);
520       direction = Vector3(0.0f, 0.0f, -1.0f);
521     }
522     else
523     {
524       color     = Vector3(0.0f, 0.0f, 1.0f);
525       direction = Vector3(1.0f, 0.0f, 0.0f);
526     }
527     std::string colorStringKey     = std::string("uLightColor[") + std::to_string(i) + "]";
528     auto        colorPropertyIndex = shader.GetPropertyIndex(colorStringKey);
529     DALI_TEST_EQUALS(color, shader.GetCurrentProperty<Vector3>(colorPropertyIndex), 0.01f, TEST_LOCATION);
530
531     std::string directionStringKey     = std::string("uLightDirection[") + std::to_string(i) + "]";
532     auto        directionPropertyIndex = shader.GetPropertyIndex(directionStringKey);
533     DALI_TEST_EQUALS(direction, shader.GetCurrentProperty<Vector3>(directionPropertyIndex), 0.01f, TEST_LOCATION);
534   }
535
536   for(uint32_t i = 0; i < lightList.size(); ++i)
537   {
538     if(i == 2)
539     {
540       DALI_TEST_EQUALS(false, lightList[i].IsEnabled(), TEST_LOCATION);
541     }
542     else
543     {
544       DALI_TEST_EQUALS(true, lightList[i].IsEnabled(), TEST_LOCATION);
545     }
546   }
547
548   END_TEST;
549 }
550
551 int UtcDaliLightModelAddAndRemove(void)
552 {
553   ToolkitTestApplication application;
554
555   Scene3D::SceneView sceneView = Scene3D::SceneView::New();
556   sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
557   sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
558   sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
559   sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
560   application.GetScene().Add(sceneView);
561
562   Scene3D::Light light = Scene3D::Light::New();
563   light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
564   Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
565   sceneView.Add(light);
566
567   application.SendNotification();
568   application.Render();
569
570   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
571   sceneView.Add(model);
572
573   application.SendNotification();
574   application.Render();
575   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
576   application.SendNotification();
577   application.Render();
578
579   Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
580   DALI_TEST_CHECK(renderer);
581   Shader shader = renderer.GetShader();
582   DALI_TEST_CHECK(shader);
583
584   DALI_TEST_EQUALS(1u, sceneView.GetActivatedLightCount(), TEST_LOCATION);
585   auto countPropertyIndex = shader.GetPropertyIndex("uLightCount");
586   DALI_TEST_CHECK(countPropertyIndex != DALI_KEY_INVALID);
587   DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(countPropertyIndex), TEST_LOCATION);
588
589   auto colorPropertyIndex = shader.GetPropertyIndex("uLightColor[0]");
590   DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 1.0f), shader.GetCurrentProperty<Vector3>(colorPropertyIndex), 0.01f, TEST_LOCATION);
591   auto directionPropertyIndex = shader.GetPropertyIndex("uLightDirection[0]");
592   DALI_TEST_EQUALS(Vector3(1.0f, 0.0f, 0.0f), shader.GetCurrentProperty<Vector3>(directionPropertyIndex), 0.01f, TEST_LOCATION);
593
594   DALI_TEST_EQUALS(1u, sceneView.GetActivatedLightCount(), TEST_LOCATION);
595
596   model.Unparent();
597
598   DALI_TEST_EQUALS(1u, sceneView.GetActivatedLightCount(), TEST_LOCATION);
599
600   END_TEST;
601 }
602
603 // Enable Shadow and add the light to SceneView.
604 int UtcDaliLightEnableShadowOnScene01(void)
605 {
606   ToolkitTestApplication application;
607
608   Scene3D::SceneView sceneView = Scene3D::SceneView::New();
609   sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
610   sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
611   sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
612   sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
613   application.GetScene().Add(sceneView);
614
615   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
616   sceneView.Add(model);
617
618   application.SendNotification();
619   application.Render();
620   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
621   application.SendNotification();
622   application.Render();
623
624   // Light is added on layer when on scene
625   DALI_TEST_EQUALS(true, model.GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE), TEST_LOCATION);
626
627   Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
628   DALI_TEST_CHECK(renderer);
629   Shader shader = renderer.GetShader();
630   DALI_TEST_CHECK(shader);
631
632   auto shadowEnabledIndex = shader.GetPropertyIndex("uIsShadowEnabled");
633   DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
634   DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
635
636   Scene3D::Light light = Scene3D::Light::New();
637   light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
638   Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
639   light.EnableShadow(true);
640
641   DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
642   DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
643
644   sceneView.Add(light);
645
646   DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
647   DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
648
649   END_TEST;
650 }
651
652 // Add the light to SceneView and Enable Shadow.
653 int UtcDaliLightEnableShadowOnScene02(void)
654 {
655   ToolkitTestApplication application;
656
657   Scene3D::SceneView sceneView = Scene3D::SceneView::New();
658   sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
659   sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
660   sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
661   sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
662   application.GetScene().Add(sceneView);
663
664   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
665   sceneView.Add(model);
666
667   application.SendNotification();
668   application.Render();
669   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
670   application.SendNotification();
671   application.Render();
672
673   // Light is added on layer when on scene
674   DALI_TEST_EQUALS(true, model.GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE), TEST_LOCATION);
675
676   Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
677   DALI_TEST_CHECK(renderer);
678   Shader shader = renderer.GetShader();
679   DALI_TEST_CHECK(shader);
680
681   auto shadowEnabledIndex = shader.GetPropertyIndex("uIsShadowEnabled");
682   DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
683   DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
684
685   Scene3D::Light light = Scene3D::Light::New();
686   light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
687   Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
688   sceneView.Add(light);
689
690   DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
691   DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
692
693   light.EnableShadow(true);
694
695   DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
696   DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
697
698   light.EnableShadow(true);
699
700   DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
701   DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
702
703   END_TEST;
704 }
705
706 // Add the light to SceneView and Add Model.
707 int UtcDaliLightEnableShadowOnScene03(void)
708 {
709   ToolkitTestApplication application;
710
711   Scene3D::SceneView sceneView = Scene3D::SceneView::New();
712   sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
713   sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
714   sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
715   sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
716   application.GetScene().Add(sceneView);
717
718   Scene3D::Light light = Scene3D::Light::New();
719   light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
720   Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
721   light.EnableShadow(true);
722   sceneView.Add(light);
723
724   application.SendNotification();
725   application.Render();
726
727   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
728   sceneView.Add(model);
729
730   application.SendNotification();
731   application.Render();
732   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
733   application.SendNotification();
734   application.Render();
735
736   // Light is added on layer when on scene
737   DALI_TEST_EQUALS(true, model.GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE), TEST_LOCATION);
738
739   Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
740   DALI_TEST_CHECK(renderer);
741   Shader shader = renderer.GetShader();
742   DALI_TEST_CHECK(shader);
743
744   auto shadowEnabledIndex = shader.GetPropertyIndex("uIsShadowEnabled");
745   DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
746   DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
747
748   END_TEST;
749 }
750
751 int UtcDaliLightEnableShadowOnScene04(void)
752 {
753   tet_infoline("Test when shader language version is low\n");
754   ToolkitTestApplication application;
755
756   auto originalShaderVersion = application.GetGlAbstraction().GetShaderLanguageVersion();
757
758   // Change the shader language version forcely!
759   application.GetGlAbstraction().mShaderLanguageVersion = 200;
760
761   try
762   {
763     Scene3D::SceneView sceneView = Scene3D::SceneView::New();
764     sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
765     sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
766     sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
767     sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
768     application.GetScene().Add(sceneView);
769
770     Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
771     sceneView.Add(model);
772
773     application.SendNotification();
774     application.Render();
775     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
776     application.SendNotification();
777     application.Render();
778
779     // Light is added on layer when on scene
780     DALI_TEST_EQUALS(true, model.GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE), TEST_LOCATION);
781
782     Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
783     DALI_TEST_CHECK(renderer);
784     Shader shader = renderer.GetShader();
785     DALI_TEST_CHECK(shader);
786
787     auto shadowEnabledIndex = shader.GetPropertyIndex("uIsShadowEnabled");
788     DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
789     DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
790
791     Scene3D::Light light = Scene3D::Light::New();
792     light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
793     Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
794     sceneView.Add(light);
795
796     DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
797     DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
798
799     light.EnableShadow(true);
800
801     DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
802     DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
803
804     light.EnableShadow(true);
805
806     DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
807     DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
808   }
809   catch(...)
810   {
811     DALI_TEST_CHECK(false);
812   }
813
814   // Revert shader version. We should revert it even if UTC failed.
815   application.GetGlAbstraction().mShaderLanguageVersion = originalShaderVersion;
816
817   END_TEST;
818 }
819
820 int UtcDaliLightEnableShadowOnScene05(void)
821 {
822   tet_infoline("Test when shader language version is low\n");
823   ToolkitTestApplication application;
824
825   auto originalShaderVersion = application.GetGlAbstraction().GetShaderLanguageVersion();
826
827   // Change the shader language version forcely!
828   application.GetGlAbstraction().mShaderLanguageVersion = 200;
829
830   try
831   {
832     Scene3D::SceneView sceneView = Scene3D::SceneView::New();
833     sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
834     sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
835     sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
836     sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
837     application.GetScene().Add(sceneView);
838
839     Scene3D::Light light = Scene3D::Light::New();
840     light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
841     Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
842     light.EnableShadow(true);
843     sceneView.Add(light);
844
845     application.SendNotification();
846     application.Render();
847
848     Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
849     sceneView.Add(model);
850
851     application.SendNotification();
852     application.Render();
853     DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
854     application.SendNotification();
855     application.Render();
856
857     // Light is added on layer when on scene
858     DALI_TEST_EQUALS(true, model.GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE), TEST_LOCATION);
859
860     Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
861     DALI_TEST_CHECK(renderer);
862     Shader shader = renderer.GetShader();
863     DALI_TEST_CHECK(shader);
864
865     auto shadowEnabledIndex = shader.GetPropertyIndex("uIsShadowEnabled");
866     DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
867     DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
868
869     // Change material information, for line coverage.
870     auto modelNode = model.FindChildModelNodeByName("node2");
871     DALI_TEST_CHECK(modelNode);
872     DALI_TEST_GREATER(modelNode.GetModelPrimitiveCount(), 0u, TEST_LOCATION);
873     auto modelPrimitive = modelNode.GetModelPrimitive(0u);
874     DALI_TEST_CHECK(modelPrimitive);
875     auto material = modelPrimitive.GetMaterial();
876     DALI_TEST_CHECK(material);
877
878     auto originBaseColorFactor = material.GetProperty<Dali::Vector4>(Dali::Scene3D::Material::Property::BASE_COLOR_FACTOR);
879     auto expectBaseColorFactor = Vector4(originBaseColorFactor.r + 0.05f, originBaseColorFactor.g - 0.05f, originBaseColorFactor.b, originBaseColorFactor.a);
880     material.SetProperty(Dali::Scene3D::Material::Property::BASE_COLOR_FACTOR, expectBaseColorFactor);
881
882     application.SendNotification();
883     application.Render();
884
885     DALI_TEST_EQUALS(material.GetProperty<Dali::Vector4>(Dali::Scene3D::Material::Property::BASE_COLOR_FACTOR), expectBaseColorFactor, TEST_LOCATION);
886   }
887   catch(...)
888   {
889     DALI_TEST_CHECK(false);
890   }
891
892   // Revert shader version. We should revert it even if UTC failed.
893   application.GetGlAbstraction().mShaderLanguageVersion = originalShaderVersion;
894
895   END_TEST;
896 }
897
898 // Disable Shadow
899 int UtcDaliLightDisableShadow01(void)
900 {
901   ToolkitTestApplication application;
902
903   Scene3D::SceneView sceneView = Scene3D::SceneView::New();
904   sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
905   sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
906   sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
907   sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
908   application.GetScene().Add(sceneView);
909
910   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
911   sceneView.Add(model);
912
913   Scene3D::Light light = Scene3D::Light::New();
914   light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
915   Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
916   light.EnableShadow(true);
917   sceneView.Add(light);
918
919   application.SendNotification();
920   application.Render();
921   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
922   application.SendNotification();
923   application.Render();
924
925   // Light is added on layer when on scene
926   DALI_TEST_EQUALS(true, model.GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE), TEST_LOCATION);
927
928   Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
929   DALI_TEST_CHECK(renderer);
930   Shader shader = renderer.GetShader();
931   DALI_TEST_CHECK(shader);
932
933   auto shadowEnabledIndex = shader.GetPropertyIndex("uIsShadowEnabled");
934   DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
935   DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
936
937   light.EnableShadow(false);
938
939   DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
940   DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
941
942   light.EnableShadow(true);
943
944   DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
945   DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
946
947   light.Unparent();
948
949   DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
950   DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
951
952   END_TEST;
953 }
954
955 // Disable Shadow
956 int UtcDaliLightDisableShadow02(void)
957 {
958   ToolkitTestApplication application;
959
960   Scene3D::SceneView sceneView = Scene3D::SceneView::New();
961   sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
962   sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
963   sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
964   sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
965   application.GetScene().Add(sceneView);
966
967   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
968   sceneView.Add(model);
969
970   Scene3D::Light light = Scene3D::Light::New();
971   light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
972   Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
973   light.EnableShadow(true);
974   sceneView.Add(light);
975
976   application.SendNotification();
977   application.Render();
978   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
979   application.SendNotification();
980   application.Render();
981
982   // Light is added on layer when on scene
983   DALI_TEST_EQUALS(true, model.GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE), TEST_LOCATION);
984
985   Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
986   DALI_TEST_CHECK(renderer);
987   Shader shader = renderer.GetShader();
988   DALI_TEST_CHECK(shader);
989
990   auto shadowEnabledIndex = shader.GetPropertyIndex("uIsShadowEnabled");
991   DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
992   DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
993
994   light.EnableShadow(false);
995
996   DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
997   DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
998
999   light.EnableShadow(true);
1000
1001   DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
1002   DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
1003
1004   Scene3D::Light newLight = Scene3D::Light::New();
1005   newLight.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
1006   Dali::DevelActor::LookAt(newLight, Vector3(1.0f, 0.0f, 0.0f));
1007   newLight.EnableShadow(true);
1008   sceneView.Add(newLight);
1009
1010   DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
1011   DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
1012
1013   // Disable light's shadow, the shadow of newLight is rendered
1014   light.EnableShadow(false);
1015
1016   DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
1017   DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
1018
1019   // Enable light's shadow, but newLight's shadow is rendered.
1020   light.EnableShadow(true);
1021
1022   DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
1023   DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
1024
1025   // Disable newLight's shadow, light's shadow is rendered.
1026   newLight.Unparent();
1027
1028   DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
1029   DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
1030
1031   // Every shadow is disabled.
1032   light.Unparent();
1033
1034   DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
1035   DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
1036
1037   END_TEST;
1038 }
1039
1040 // Make a light EnableShadow that is not enabled on scene
1041 int UtcDaliLightEnableShadowOfNotEnabledLight(void)
1042 {
1043   ToolkitTestApplication application;
1044
1045   Scene3D::SceneView sceneView = Scene3D::SceneView::New();
1046   sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
1047   sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1048   sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
1049   sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
1050   application.GetScene().Add(sceneView);
1051
1052   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1053   sceneView.Add(model);
1054
1055   uint32_t                    maxLightCount = Scene3D::Light::GetMaximumEnabledLightCount();
1056   std::vector<Scene3D::Light> lights;
1057   for(uint32_t i = 0; i < maxLightCount; ++i)
1058   {
1059     Scene3D::Light light = Scene3D::Light::New();
1060     light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
1061     Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
1062     sceneView.Add(light);
1063     lights.push_back(light);
1064   }
1065
1066   Scene3D::Light shadowLight = Scene3D::Light::New();
1067   shadowLight.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
1068   Dali::DevelActor::LookAt(shadowLight, Vector3(1.0f, 0.0f, 0.0f));
1069   sceneView.Add(shadowLight);
1070
1071   application.SendNotification();
1072   application.Render();
1073   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1074   application.SendNotification();
1075   application.Render();
1076
1077   // Light is added on layer when on scene
1078   DALI_TEST_EQUALS(true, model.GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE), TEST_LOCATION);
1079
1080   Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
1081   DALI_TEST_CHECK(renderer);
1082   Shader shader = renderer.GetShader();
1083   DALI_TEST_CHECK(shader);
1084
1085   auto shadowEnabledIndex = shader.GetPropertyIndex("uIsShadowEnabled");
1086   DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
1087   DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
1088
1089   shadowLight.EnableShadow(true);
1090
1091   DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
1092   DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
1093
1094   lights[0].Enable(false);
1095
1096   DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
1097   DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
1098
1099   END_TEST;
1100 }
1101
1102 // Set/Get Shadow Properties
1103 int UtcDaliLightSetGetProperty(void)
1104 {
1105   ToolkitTestApplication application;
1106
1107   Scene3D::SceneView sceneView = Scene3D::SceneView::New();
1108   sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
1109   sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1110   sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
1111   sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
1112   application.GetScene().Add(sceneView);
1113
1114   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1115   sceneView.Add(model);
1116
1117   Scene3D::Light light = Scene3D::Light::New();
1118   light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
1119   Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
1120   light.EnableShadow(true);
1121   sceneView.Add(light);
1122
1123   application.SendNotification();
1124   application.Render();
1125   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1126   application.SendNotification();
1127   application.Render();
1128
1129   // Light is added on layer when on scene
1130   DALI_TEST_EQUALS(true, model.GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE), TEST_LOCATION);
1131
1132   DALI_TEST_EQUALS(0.001f, light.GetShadowBias(), TEST_LOCATION);
1133   light.SetShadowBias(0.1f);
1134   DALI_TEST_EQUALS(0.1f, light.GetShadowBias(), TEST_LOCATION);
1135
1136   DALI_TEST_EQUALS(0.5f, light.GetShadowIntensity(), TEST_LOCATION);
1137   light.SetShadowIntensity(0.1f);
1138   DALI_TEST_EQUALS(0.1f, light.GetShadowIntensity(), TEST_LOCATION);
1139
1140   END_TEST;
1141 }
1142
1143 // Enable PCF for soft shadow edge.
1144 int UtcDaliLightShadowSoftFiltering(void)
1145 {
1146   ToolkitTestApplication application;
1147
1148   Scene3D::SceneView sceneView = Scene3D::SceneView::New();
1149   sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
1150   sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1151   sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
1152   sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
1153   application.GetScene().Add(sceneView);
1154
1155   Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1156   sceneView.Add(model);
1157
1158   Scene3D::Light light = Scene3D::Light::New();
1159   light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
1160   Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
1161   light.EnableShadow(true);
1162   sceneView.Add(light);
1163
1164   application.SendNotification();
1165   application.Render();
1166   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1167   application.SendNotification();
1168   application.Render();
1169
1170   // Light is added on layer when on scene
1171   DALI_TEST_EQUALS(true, model.GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE), TEST_LOCATION);
1172
1173   Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
1174   DALI_TEST_CHECK(renderer);
1175   Shader shader = renderer.GetShader();
1176   DALI_TEST_CHECK(shader);
1177
1178   DALI_TEST_EQUALS(false, light.IsShadowSoftFilteringEnabled(), TEST_LOCATION);
1179   auto shadowFilteringEnabledIndex = shader.GetPropertyIndex("uEnableShadowSoftFiltering");
1180   DALI_TEST_CHECK(shadowFilteringEnabledIndex != DALI_KEY_INVALID);
1181   DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowFilteringEnabledIndex), TEST_LOCATION);
1182
1183   light.EnableShadowSoftFiltering(true);
1184   DALI_TEST_EQUALS(true, light.IsShadowSoftFilteringEnabled(), TEST_LOCATION);
1185
1186   DALI_TEST_CHECK(shadowFilteringEnabledIndex != DALI_KEY_INVALID);
1187   DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowFilteringEnabledIndex), TEST_LOCATION);
1188
1189   light.EnableShadowSoftFiltering(false);
1190   DALI_TEST_EQUALS(false, light.IsShadowSoftFilteringEnabled(), TEST_LOCATION);
1191   DALI_TEST_CHECK(shadowFilteringEnabledIndex != DALI_KEY_INVALID);
1192   DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowFilteringEnabledIndex), TEST_LOCATION);
1193
1194   END_TEST;
1195 }
1196
1197 namespace
1198 {
1199 constexpr int32_t SCENE_ORDER_INDEX = 100;
1200 constexpr int32_t SHADOW_ORDER_INDEX = 99;
1201 }
1202
1203 int UtcDaliLightShadowRenderTask(void)
1204 {
1205   ToolkitTestApplication application;
1206   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
1207
1208   uint32_t baseRenderTaskCount = application.GetScene().GetRenderTaskList().GetTaskCount();
1209
1210   Scene3D::SceneView sceneView = Scene3D::SceneView::New();
1211   sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
1212   sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
1213   sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
1214   sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
1215   application.GetScene().Add(sceneView);
1216
1217   DALI_TEST_EQUALS(baseRenderTaskCount + 1u, taskList.GetTaskCount(), TEST_LOCATION);
1218
1219   sceneView.UseFramebuffer(true);
1220
1221   DALI_TEST_EQUALS(baseRenderTaskCount + 1u, taskList.GetTaskCount(), TEST_LOCATION);
1222   DALI_TEST_EQUALS(0, taskList.GetTask(baseRenderTaskCount - 1u).GetOrderIndex(), TEST_LOCATION);
1223   DALI_TEST_EQUALS(SCENE_ORDER_INDEX, taskList.GetTask(baseRenderTaskCount).GetOrderIndex(), TEST_LOCATION);
1224
1225   Scene3D::Light light = Scene3D::Light::New();
1226   light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
1227   Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
1228   light.EnableShadow(true);
1229
1230   tet_printf("Do not create rendertask until light is scene on");
1231   DALI_TEST_EQUALS(baseRenderTaskCount + 1u, taskList.GetTaskCount(), TEST_LOCATION);
1232
1233   sceneView.Add(light);
1234
1235   tet_printf("Create shadowmap rendertask after light is scene on");
1236   DALI_TEST_EQUALS(baseRenderTaskCount + 2u, taskList.GetTaskCount(), TEST_LOCATION);
1237   DALI_TEST_EQUALS(0, taskList.GetTask(baseRenderTaskCount - 1u).GetOrderIndex(), TEST_LOCATION);
1238   DALI_TEST_EQUALS(SCENE_ORDER_INDEX, taskList.GetTask(baseRenderTaskCount).GetOrderIndex(), TEST_LOCATION);
1239   DALI_TEST_EQUALS(SHADOW_ORDER_INDEX, taskList.GetTask(baseRenderTaskCount + 1u).GetOrderIndex(), TEST_LOCATION);
1240
1241   application.SendNotification();
1242
1243   tet_printf("Check render task list sorted");
1244   DALI_TEST_EQUALS(SHADOW_ORDER_INDEX, taskList.GetTask(baseRenderTaskCount).GetOrderIndex(), TEST_LOCATION);
1245   DALI_TEST_EQUALS(SCENE_ORDER_INDEX, taskList.GetTask(baseRenderTaskCount + 1u).GetOrderIndex(), TEST_LOCATION);
1246
1247   light.EnableShadow(false);
1248
1249   tet_printf("Check shadowmap rendertask removed");
1250   DALI_TEST_EQUALS(baseRenderTaskCount + 1u, taskList.GetTaskCount(), TEST_LOCATION);
1251   DALI_TEST_EQUALS(0, taskList.GetTask(baseRenderTaskCount - 1u).GetOrderIndex(), TEST_LOCATION);
1252   DALI_TEST_EQUALS(SCENE_ORDER_INDEX, taskList.GetTask(baseRenderTaskCount).GetOrderIndex(), TEST_LOCATION);
1253
1254   END_TEST;
1255 }