END_TEST;
}
+
+// Enable Shadow and add the light to SceneView.
+int UtcDaliLightEnableShadowOnScene01(void)
+{
+ ToolkitTestApplication application;
+
+ Scene3D::SceneView sceneView = Scene3D::SceneView::New();
+ sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+ sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+ sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
+ sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
+ application.GetScene().Add(sceneView);
+
+ Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
+ sceneView.Add(model);
+
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+ application.SendNotification();
+ application.Render();
+
+ // Light is added on layer when on scene
+ DALI_TEST_EQUALS(true, model.GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE), TEST_LOCATION);
+
+ Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
+ DALI_TEST_CHECK(renderer);
+ Shader shader = renderer.GetShader();
+ DALI_TEST_CHECK(shader);
+
+ auto shadowEnabledIndex = shader.GetPropertyIndex("uIsShadowEnabled");
+ DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
+
+ Scene3D::Light light = Scene3D::Light::New();
+ light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
+ Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
+ light.EnableShadow(true);
+
+ DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
+
+ sceneView.Add(light);
+
+ DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
+
+ END_TEST;
+}
+
+// Add the light to SceneView and Enable Shadow.
+int UtcDaliLightEnableShadowOnScene02(void)
+{
+ ToolkitTestApplication application;
+
+ Scene3D::SceneView sceneView = Scene3D::SceneView::New();
+ sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+ sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+ sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
+ sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
+ application.GetScene().Add(sceneView);
+
+ Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
+ sceneView.Add(model);
+
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+ application.SendNotification();
+ application.Render();
+
+ // Light is added on layer when on scene
+ DALI_TEST_EQUALS(true, model.GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE), TEST_LOCATION);
+
+ Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
+ DALI_TEST_CHECK(renderer);
+ Shader shader = renderer.GetShader();
+ DALI_TEST_CHECK(shader);
+
+ auto shadowEnabledIndex = shader.GetPropertyIndex("uIsShadowEnabled");
+ DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
+
+ Scene3D::Light light = Scene3D::Light::New();
+ light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
+ Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
+ sceneView.Add(light);
+
+ DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
+
+ light.EnableShadow(true);
+
+ DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
+
+ light.EnableShadow(true);
+
+ DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
+
+ END_TEST;
+}
+
+// Add the light to SceneView and Add Model.
+int UtcDaliLightEnableShadowOnScene03(void)
+{
+ ToolkitTestApplication application;
+
+ Scene3D::SceneView sceneView = Scene3D::SceneView::New();
+ sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+ sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+ sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
+ sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
+ application.GetScene().Add(sceneView);
+
+ Scene3D::Light light = Scene3D::Light::New();
+ light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
+ Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
+ light.EnableShadow(true);
+ sceneView.Add(light);
+
+ application.SendNotification();
+ application.Render();
+
+ Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
+ sceneView.Add(model);
+
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+ application.SendNotification();
+ application.Render();
+
+ // Light is added on layer when on scene
+ DALI_TEST_EQUALS(true, model.GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE), TEST_LOCATION);
+
+ Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
+ DALI_TEST_CHECK(renderer);
+ Shader shader = renderer.GetShader();
+ DALI_TEST_CHECK(shader);
+
+ auto shadowEnabledIndex = shader.GetPropertyIndex("uIsShadowEnabled");
+ DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
+
+ END_TEST;
+}
+
+// Disable Shadow
+int UtcDaliLightDisableShadow01(void)
+{
+ ToolkitTestApplication application;
+
+ Scene3D::SceneView sceneView = Scene3D::SceneView::New();
+ sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+ sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+ sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
+ sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
+ application.GetScene().Add(sceneView);
+
+ Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
+ sceneView.Add(model);
+
+ Scene3D::Light light = Scene3D::Light::New();
+ light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
+ Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
+ light.EnableShadow(true);
+ sceneView.Add(light);
+
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+ application.SendNotification();
+ application.Render();
+
+ // Light is added on layer when on scene
+ DALI_TEST_EQUALS(true, model.GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE), TEST_LOCATION);
+
+ Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
+ DALI_TEST_CHECK(renderer);
+ Shader shader = renderer.GetShader();
+ DALI_TEST_CHECK(shader);
+
+ auto shadowEnabledIndex = shader.GetPropertyIndex("uIsShadowEnabled");
+ DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
+
+ light.EnableShadow(false);
+
+ DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
+
+ light.EnableShadow(true);
+
+ DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
+
+ light.Unparent();
+
+ DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
+
+ END_TEST;
+}
+
+// Disable Shadow
+int UtcDaliLightDisableShadow02(void)
+{
+ ToolkitTestApplication application;
+
+ Scene3D::SceneView sceneView = Scene3D::SceneView::New();
+ sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+ sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+ sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
+ sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
+ application.GetScene().Add(sceneView);
+
+ Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
+ sceneView.Add(model);
+
+ Scene3D::Light light = Scene3D::Light::New();
+ light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
+ Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
+ light.EnableShadow(true);
+ sceneView.Add(light);
+
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+ application.SendNotification();
+ application.Render();
+
+ // Light is added on layer when on scene
+ DALI_TEST_EQUALS(true, model.GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE), TEST_LOCATION);
+
+ Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
+ DALI_TEST_CHECK(renderer);
+ Shader shader = renderer.GetShader();
+ DALI_TEST_CHECK(shader);
+
+ auto shadowEnabledIndex = shader.GetPropertyIndex("uIsShadowEnabled");
+ DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
+
+ light.EnableShadow(false);
+
+ DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
+
+ light.EnableShadow(true);
+
+ DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
+
+ Scene3D::Light newLight = Scene3D::Light::New();
+ newLight.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
+ Dali::DevelActor::LookAt(newLight, Vector3(1.0f, 0.0f, 0.0f));
+ newLight.EnableShadow(true);
+ sceneView.Add(newLight);
+
+ DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
+
+ // Disable light's shadow, the shadow of newLight is rendered
+ light.EnableShadow(false);
+
+ DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
+
+ // Enable light's shadow, but newLight's shadow is rendered.
+ light.EnableShadow(true);
+
+ DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
+
+ // Disable newLight's shadow, light's shadow is rendered.
+ newLight.Unparent();
+
+ DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
+
+ // Every shadow is disabled.
+ light.Unparent();
+
+ DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
+
+ END_TEST;
+}
+
+// Make a light EnableShadow that is not enabled on scene
+int UtcDaliLightEnableShadowOfNotEnabledLight(void)
+{
+ ToolkitTestApplication application;
+
+ Scene3D::SceneView sceneView = Scene3D::SceneView::New();
+ sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+ sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+ sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
+ sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
+ application.GetScene().Add(sceneView);
+
+ Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
+ sceneView.Add(model);
+
+ uint32_t maxLightCount = Scene3D::Light::GetMaximumEnabledLightCount();
+ std::vector<Scene3D::Light> lights;
+ for(uint32_t i = 0; i < maxLightCount; ++i)
+ {
+ Scene3D::Light light = Scene3D::Light::New();
+ light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
+ Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
+ sceneView.Add(light);
+ lights.push_back(light);
+ }
+
+ Scene3D::Light shadowLight = Scene3D::Light::New();
+ shadowLight.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
+ Dali::DevelActor::LookAt(shadowLight, Vector3(1.0f, 0.0f, 0.0f));
+ sceneView.Add(shadowLight);
+
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+ application.SendNotification();
+ application.Render();
+
+ // Light is added on layer when on scene
+ DALI_TEST_EQUALS(true, model.GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE), TEST_LOCATION);
+
+ Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
+ DALI_TEST_CHECK(renderer);
+ Shader shader = renderer.GetShader();
+ DALI_TEST_CHECK(shader);
+
+ auto shadowEnabledIndex = shader.GetPropertyIndex("uIsShadowEnabled");
+ DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
+
+ shadowLight.EnableShadow(true);
+
+ DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
+
+ lights[0].Enable(false);
+
+ DALI_TEST_CHECK(shadowEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowEnabledIndex), TEST_LOCATION);
+
+ END_TEST;
+}
+
+// Set/Get Shadow Properties
+int UtcDaliLightSetGetProperty(void)
+{
+ ToolkitTestApplication application;
+
+ Scene3D::SceneView sceneView = Scene3D::SceneView::New();
+ sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+ sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+ sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
+ sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
+ application.GetScene().Add(sceneView);
+
+ Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
+ sceneView.Add(model);
+
+ Scene3D::Light light = Scene3D::Light::New();
+ light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
+ Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
+ light.EnableShadow(true);
+ sceneView.Add(light);
+
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+ application.SendNotification();
+ application.Render();
+
+ // Light is added on layer when on scene
+ DALI_TEST_EQUALS(true, model.GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE), TEST_LOCATION);
+
+ DALI_TEST_EQUALS(0.001f, light.GetShadowBias(), TEST_LOCATION);
+ light.SetShadowBias(0.1f);
+ DALI_TEST_EQUALS(0.1f, light.GetShadowBias(), TEST_LOCATION);
+
+ DALI_TEST_EQUALS(0.5f, light.GetShadowIntensity(), TEST_LOCATION);
+ light.SetShadowIntensity(0.1f);
+ DALI_TEST_EQUALS(0.1f, light.GetShadowIntensity(), TEST_LOCATION);
+
+ END_TEST;
+}
+
+// Enable PCF for soft shadow edge.
+int UtcDaliLightShadowSoftFiltering(void)
+{
+ ToolkitTestApplication application;
+
+ Scene3D::SceneView sceneView = Scene3D::SceneView::New();
+ sceneView.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+ sceneView.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+ sceneView.SetProperty(Dali::Actor::Property::WIDTH_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
+ sceneView.SetProperty(Dali::Actor::Property::HEIGHT_RESIZE_POLICY, ResizePolicy::FILL_TO_PARENT);
+ application.GetScene().Add(sceneView);
+
+ Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
+ sceneView.Add(model);
+
+ Scene3D::Light light = Scene3D::Light::New();
+ light.SetProperty(Dali::Actor::Property::COLOR, Color::BLUE);
+ Dali::DevelActor::LookAt(light, Vector3(1.0f, 0.0f, 0.0f));
+ light.EnableShadow(true);
+ sceneView.Add(light);
+
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
+ application.SendNotification();
+ application.Render();
+
+ // Light is added on layer when on scene
+ DALI_TEST_EQUALS(true, model.GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE), TEST_LOCATION);
+
+ Renderer renderer = model.FindChildByName("node2").GetRendererAt(0u);
+ DALI_TEST_CHECK(renderer);
+ Shader shader = renderer.GetShader();
+ DALI_TEST_CHECK(shader);
+
+ DALI_TEST_EQUALS(false, light.IsShadowSoftFilteringEnabled(), TEST_LOCATION);
+ auto shadowFilteringEnabledIndex = shader.GetPropertyIndex("uEnableShadowSoftFiltering");
+ DALI_TEST_CHECK(shadowFilteringEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowFilteringEnabledIndex), TEST_LOCATION);
+
+ light.EnableShadowSoftFiltering(true);
+ DALI_TEST_EQUALS(true, light.IsShadowSoftFilteringEnabled(), TEST_LOCATION);
+
+ DALI_TEST_CHECK(shadowFilteringEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(1, shader.GetProperty<int32_t>(shadowFilteringEnabledIndex), TEST_LOCATION);
+
+ light.EnableShadowSoftFiltering(false);
+ DALI_TEST_EQUALS(false, light.IsShadowSoftFilteringEnabled(), TEST_LOCATION);
+ DALI_TEST_CHECK(shadowFilteringEnabledIndex != DALI_KEY_INVALID);
+ DALI_TEST_EQUALS(0, shader.GetProperty<int32_t>(shadowFilteringEnabledIndex), TEST_LOCATION);
+
+ END_TEST;
+}