[dali_2.3.24] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / internal / controls / scene-view / scene-view-impl.cpp
index bb44ab7..7fc62c1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 #include <dali/devel-api/adaptor-framework/window-devel.h>
 #include <dali/devel-api/common/stage.h>
 #include <dali/devel-api/rendering/frame-buffer-devel.h>
+#include <dali/integration-api/adaptor-framework/adaptor.h>
 #include <dali/integration-api/debug.h>
 #include <dali/public-api/math/math-utils.h>
 #include <dali/public-api/object/type-registry-helper.h>
 #include <dali/public-api/object/type-registry.h>
-#include <dali/integration-api/adaptor-framework/adaptor.h>
 #include <string_view>
 
 // INTERNAL INCLUDES
+#include <dali-scene3d/internal/common/image-resource-loader.h>
 #include <dali-scene3d/internal/controls/model/model-impl.h>
 #include <dali-scene3d/internal/graphics/builtin-shader-extern-gen.h>
-#include <dali-scene3d/public-api/loader/cube-map-loader.h>
+#include <dali-scene3d/internal/light/light-impl.h>
+
+#include <dali/integration-api/debug.h>
 
 using namespace Dali;
 
@@ -58,14 +61,23 @@ BaseHandle Create()
 
 // Setup properties, signals and actions using the type-registry.
 DALI_TYPE_REGISTRATION_BEGIN(Scene3D::SceneView, Toolkit::Control, Create);
+
+DALI_PROPERTY_REGISTRATION(Scene3D, SceneView, "AlphaMaskUrl", STRING, ALPHA_MASK_URL)
+DALI_PROPERTY_REGISTRATION(Scene3D, SceneView, "MaskContentScale", FLOAT, MASK_CONTENT_SCALE)
+DALI_PROPERTY_REGISTRATION(Scene3D, SceneView, "CropToMask", BOOLEAN, CROP_TO_MASK)
 DALI_TYPE_REGISTRATION_END()
 
-Property::Index   RENDERING_BUFFER    = Dali::Toolkit::Control::CONTROL_PROPERTY_END_INDEX + 1;
-constexpr int32_t DEFAULT_ORIENTATION = 0;
+Property::Index    RENDERING_BUFFER        = Dali::Toolkit::Control::CONTROL_PROPERTY_END_INDEX + 1;
+constexpr int32_t  DEFAULT_ORIENTATION     = 0;
+constexpr int32_t  INVALID_INDEX           = -1;
+constexpr uint32_t MAXIMUM_SIZE_SHADOW_MAP = 2048;
 
-constexpr uint8_t DEFAULT_FRAME_BUFFER_MULTI_SAMPLING_LEVEL = 4u;
+constexpr int32_t SCENE_ORDER_INDEX  = 100;
+constexpr int32_t SHADOW_ORDER_INDEX = 99;
 
 static constexpr std::string_view SKYBOX_INTENSITY_STRING = "uIntensity";
+static constexpr std::string_view Y_FLIP_MASK_TEXTURE     = "uYFlipMaskTexture";
+static constexpr float            FLIP_MASK_TEXTURE       = 1.0f;
 
 Dali::Actor CreateSkybox()
 {
@@ -130,7 +142,7 @@ Dali::Actor CreateSkybox()
   skyboxGeometry.AddVertexBuffer(vertexBuffer);
   skyboxGeometry.SetType(Geometry::TRIANGLES);
 
-  Dali::Shader   shaderSkybox = Shader::New(SHADER_SKYBOX_SHADER_VERT.data(), SHADER_SKYBOX_SHADER_FRAG.data());
+  Dali::Shader   shaderSkybox = Shader::New(SHADER_SKYBOX_SHADER_VERT.data(), SHADER_SKYBOX_SHADER_FRAG.data(), Shader::Hint::NONE, "SCENE3D_SKYBOX_CUBE");
   Dali::Renderer skyboxRenderer;
   skyboxRenderer = Renderer::New(skyboxGeometry, shaderSkybox);
   skyboxRenderer.SetProperty(Renderer::Property::DEPTH_INDEX, 2.0f);
@@ -147,6 +159,145 @@ Dali::Actor CreateSkybox()
   return skyboxActor;
 }
 
+void SetShadowLightConstraint(Dali::CameraActor selectedCamera, Dali::CameraActor shadowLightCamera)
+{
+  shadowLightCamera.SetProperty(Dali::CameraActor::Property::ASPECT_RATIO, 1.0f);
+  shadowLightCamera.SetProperty(Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE, 1.0f);
+  shadowLightCamera.SetProperty(Dali::CameraActor::Property::NEAR_PLANE_DISTANCE, 0.5f);
+  shadowLightCamera.SetProperty(Dali::CameraActor::Property::FAR_PLANE_DISTANCE, 3.5f);
+
+  //< Make constraint for above properties.
+  shadowLightCamera.RemoveConstraints();
+
+  // Compute ViewProjectionMatrix and store it to "tempViewProjectionMatrix" property
+  auto       tempViewProjectionMatrixIndex = shadowLightCamera.RegisterProperty("tempViewProjectionMatrix", Matrix::IDENTITY);
+  Constraint projectionMatrixConstraint    = Constraint::New<Matrix>(shadowLightCamera, tempViewProjectionMatrixIndex, [](Matrix& output, const PropertyInputContainer& inputs) {
+    Matrix worldMatrix  = inputs[0]->GetMatrix();
+    float  tangentFov_2 = tanf(inputs[4]->GetFloat());
+    float  nearDistance = inputs[5]->GetFloat();
+    float  farDistance  = inputs[6]->GetFloat();
+    float  aspectRatio  = inputs[7]->GetFloat();
+    float  nearY        = 0.0f;
+    float  nearX        = 0.0f;
+    float  farY         = 0.0f;
+    float  farX         = 0.0f;
+    if(inputs[1]->GetInteger() == Dali::Camera::ProjectionMode::PERSPECTIVE_PROJECTION)
+    {
+      if(inputs[2]->GetInteger() == Dali::DevelCameraActor::ProjectionDirection::VERTICAL)
+      {
+        nearY = tangentFov_2 * nearDistance;
+        nearX = nearY * aspectRatio;
+        farY  = tangentFov_2 * farDistance;
+        farX  = farY * aspectRatio;
+      }
+      else
+      {
+        nearX = tangentFov_2 * nearDistance;
+        nearY = nearX / aspectRatio;
+        farX  = tangentFov_2 * farDistance;
+        farY  = farX / aspectRatio;
+      }
+    }
+    else
+    {
+      if(inputs[2]->GetInteger() == Dali::DevelCameraActor::ProjectionDirection::VERTICAL)
+      {
+        nearY = inputs[3]->GetFloat();
+        nearX = nearY * aspectRatio;
+      }
+      else
+      {
+        nearX = inputs[3]->GetFloat();
+        nearY = nearX / aspectRatio;
+      }
+      farX = nearX;
+      farY = nearY;
+    }
+
+    std::vector<Vector4> points;
+    points.push_back(Vector4(nearX, nearY, nearDistance, 1.0f));
+    points.push_back(Vector4(-nearX, nearY, nearDistance, 1.0f));
+    points.push_back(Vector4(-nearX, -nearY, nearDistance, 1.0f));
+    points.push_back(Vector4(nearX, -nearY, nearDistance, 1.0f));
+    points.push_back(Vector4(farX, farY, farDistance, 1.0f));
+    points.push_back(Vector4(-farX, farY, farDistance, 1.0f));
+    points.push_back(Vector4(-farX, -farY, farDistance, 1.0f));
+    points.push_back(Vector4(farX, -farY, farDistance, 1.0f));
+
+    Matrix  shadowCameraWorldMatrix = inputs[8]->GetMatrix();
+    Vector4 worldCenter;
+    for(auto&& point : points)
+    {
+      point = worldMatrix * point;
+      worldCenter += point;
+    }
+    worldCenter /= 8.0f;
+    shadowCameraWorldMatrix.SetTranslation(Vector3(worldCenter));
+    Matrix shadowCameraViewMatrix = shadowCameraWorldMatrix;
+    shadowCameraViewMatrix.Invert();
+
+    Vector3 areaMin = Vector3::ONE * MAXFLOAT, areaMax = Vector3::ONE * -MAXFLOAT;
+    for(auto&& point : points)
+    {
+      Vector4 pointV = shadowCameraViewMatrix * point;
+      areaMin.x      = std::min(areaMin.x, pointV.x);
+      areaMin.y      = std::min(areaMin.y, pointV.y);
+      areaMin.z      = std::min(areaMin.z, pointV.z);
+      areaMax.x      = std::max(areaMax.x, pointV.x);
+      areaMax.y      = std::max(areaMax.y, pointV.y);
+      areaMax.z      = std::max(areaMax.z, pointV.z);
+    }
+
+    Vector2 center        = Vector2(areaMax + areaMin) * 0.5;
+    float   delta         = std::max(std::abs(areaMax.x - areaMin.x), std::abs(areaMax.y - areaMin.y));
+    float   delta_2       = delta * 0.5f;
+    Vector2 squareAreaMin = center - Vector2::ONE * delta_2;
+    Vector2 squareAreaMax = center + Vector2::ONE * delta_2;
+    float   deltaZ        = areaMax.z - areaMin.z;
+
+    float right  = -squareAreaMin.x;
+    float left   = -squareAreaMax.x;
+    float top    = squareAreaMin.y;
+    float bottom = squareAreaMax.y;
+    float near   = areaMin.z;
+    float far    = areaMax.z;
+
+    float* projMatrix = output.AsFloat();
+
+    projMatrix[0] = -2.0f / delta;
+    projMatrix[1] = 0.0f;
+    projMatrix[2] = 0.0f;
+    projMatrix[3] = 0.0f;
+
+    projMatrix[4] = 0.0f;
+    projMatrix[5] = -2.0f / delta;
+    projMatrix[6] = 0.0f;
+    projMatrix[7] = 0.0f;
+
+    projMatrix[8]  = 0.0f;
+    projMatrix[9]  = 0.0f;
+    projMatrix[10] = 2.0f / deltaZ;
+    projMatrix[11] = 0.0f;
+
+    projMatrix[12] = -(right + left) / delta;
+    projMatrix[13] = -(top + bottom) / delta;
+    projMatrix[14] = -(near + far) / deltaZ;
+    projMatrix[15] = 1.0f;
+
+    output = output * shadowCameraViewMatrix;
+  });
+  projectionMatrixConstraint.AddSource(Source{selectedCamera, Dali::Actor::Property::WORLD_MATRIX});
+  projectionMatrixConstraint.AddSource(Source{selectedCamera, Dali::CameraActor::Property::PROJECTION_MODE});
+  projectionMatrixConstraint.AddSource(Source{selectedCamera, Dali::DevelCameraActor::Property::PROJECTION_DIRECTION});
+  projectionMatrixConstraint.AddSource(Source{selectedCamera, Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE});
+  projectionMatrixConstraint.AddSource(Source{selectedCamera, Dali::CameraActor::Property::FIELD_OF_VIEW});
+  projectionMatrixConstraint.AddSource(Source{selectedCamera, Dali::CameraActor::Property::NEAR_PLANE_DISTANCE});
+  projectionMatrixConstraint.AddSource(Source{selectedCamera, Dali::CameraActor::Property::FAR_PLANE_DISTANCE});
+  projectionMatrixConstraint.AddSource(Source{selectedCamera, Dali::CameraActor::Property::ASPECT_RATIO});
+  projectionMatrixConstraint.AddSource(Source{shadowLightCamera, Dali::Actor::Property::WORLD_MATRIX});
+  projectionMatrixConstraint.ApplyPost();
+}
+
 } // anonymous namespace
 
 SceneView::SceneView()
@@ -154,7 +305,9 @@ SceneView::SceneView()
   mWindowOrientation(DEFAULT_ORIENTATION),
   mSkybox(),
   mSkyboxOrientation(Quaternion()),
-  mSkyboxIntensity(1.0f)
+  mSkyboxIntensity(1.0f),
+  mLightObservers(),
+  mShaderManager(new Scene3D::Loader::ShaderManager())
 {
 }
 
@@ -177,6 +330,9 @@ SceneView::~SceneView()
       Dali::AsyncTaskManager::Get().RemoveTask(mSkyboxLoadTask);
       mSkyboxLoadTask.Reset();
     }
+
+    // Request image resource GC
+    Dali::Scene3D::Internal::ImageResourceLoader::RequestGarbageCollect();
   }
 }
 
@@ -276,26 +432,24 @@ void SceneView::SelectCamera(const std::string& name)
   UpdateCamera(GetCamera(name));
 }
 
-void SceneView::RegisterSceneItem(Scene3D::Internal::ImageBasedLightObserver* item)
+void SceneView::RegisterSceneItem(Scene3D::Internal::LightObserver* item)
 {
   if(item)
   {
-    item->NotifyImageBasedLightTexture(mDiffuseTexture, mSpecularTexture, mIblScaleFactor);
-    mItems.push_back(item);
+    item->NotifyImageBasedLightTexture(mDiffuseTexture, mSpecularTexture, mIblScaleFactor, mSpecularMipmapLevels);
+    item->NotifyShadowMapTexture(mShadowTexture);
+    mLightObservers.PushBack(item);
   }
 }
 
-void SceneView::UnregisterSceneItem(Scene3D::Internal::ImageBasedLightObserver* item)
+void SceneView::UnregisterSceneItem(Scene3D::Internal::LightObserver* item)
 {
   if(item)
   {
-    for(uint32_t i = 0; i < mItems.size(); ++i)
+    auto iter = mLightObservers.Find(item);
+    if(iter != mLightObservers.End())
     {
-      if(mItems[i] == item)
-      {
-        mItems.erase(mItems.begin() + i);
-        break;
-      }
+      mLightObservers.Erase(iter);
     }
   }
 }
@@ -303,13 +457,13 @@ void SceneView::UnregisterSceneItem(Scene3D::Internal::ImageBasedLightObserver*
 void SceneView::SetImageBasedLightSource(const std::string& diffuseUrl, const std::string& specularUrl, float scaleFactor)
 {
   bool needIblReset = false;
-  bool isOnScene = Self().GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE);
+  bool isOnScene    = Self().GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE);
   if(mDiffuseIblUrl != diffuseUrl)
   {
     mDiffuseIblUrl = diffuseUrl;
     if(mDiffuseIblUrl.empty())
     {
-      needIblReset             = true;
+      needIblReset = true;
     }
     else
     {
@@ -323,7 +477,7 @@ void SceneView::SetImageBasedLightSource(const std::string& diffuseUrl, const st
     mSpecularIblUrl = specularUrl;
     if(mSpecularIblUrl.empty())
     {
-      needIblReset              = true;
+      needIblReset = true;
     }
     else
     {
@@ -356,7 +510,11 @@ void SceneView::SetImageBasedLightSource(const std::string& diffuseUrl, const st
     mDiffuseTexture.Reset();
     mSpecularTexture.Reset();
 
+    mSpecularMipmapLevels = 1u;
     NotifyImageBasedLightTextureChange();
+
+    // Request image resource GC
+    Dali::Scene3D::Internal::ImageResourceLoader::RequestGarbageCollect();
   }
   else
   {
@@ -366,8 +524,11 @@ void SceneView::SetImageBasedLightSource(const std::string& diffuseUrl, const st
       {
         Dali::AsyncTaskManager::Get().RemoveTask(mIblDiffuseLoadTask);
         mIblDiffuseLoadTask.Reset();
+
+        // Request image resource GC
+        Dali::Scene3D::Internal::ImageResourceLoader::RequestGarbageCollect();
       }
-      mIblDiffuseLoadTask = new EnvironmentMapLoadTask(mDiffuseIblUrl, MakeCallback(this, &SceneView::OnIblDiffuseLoadComplete));
+      mIblDiffuseLoadTask = new EnvironmentMapLoadTask(mDiffuseIblUrl, Scene3D::EnvironmentMapType::CUBEMAP, MakeCallback(this, &SceneView::OnIblDiffuseLoadComplete));
       Dali::AsyncTaskManager::Get().AddTask(mIblDiffuseLoadTask);
       mIblDiffuseDirty = false;
     }
@@ -378,8 +539,11 @@ void SceneView::SetImageBasedLightSource(const std::string& diffuseUrl, const st
       {
         Dali::AsyncTaskManager::Get().RemoveTask(mIblSpecularLoadTask);
         mIblSpecularLoadTask.Reset();
+
+        // Request image resource GC
+        Dali::Scene3D::Internal::ImageResourceLoader::RequestGarbageCollect();
       }
-      mIblSpecularLoadTask = new EnvironmentMapLoadTask(mSpecularIblUrl, MakeCallback(this, &SceneView::OnIblSpecularLoadComplete));
+      mIblSpecularLoadTask = new EnvironmentMapLoadTask(mSpecularIblUrl, Scene3D::EnvironmentMapType::CUBEMAP, MakeCallback(this, &SceneView::OnIblSpecularLoadComplete));
       Dali::AsyncTaskManager::Get().AddTask(mIblSpecularLoadTask);
       mIblSpecularDirty = false;
     }
@@ -393,14 +557,14 @@ void SceneView::SetImageBasedLightSource(const std::string& diffuseUrl, const st
   // If diffuse and specular textures are already loaded, emits resource ready signal here.
   if(IsResourceReady())
   {
-    Control::SetResourceReady(false);
+    Control::SetResourceReady();
   }
 }
 
 void SceneView::SetImageBasedLightScaleFactor(float scaleFactor)
 {
   mIblScaleFactor = scaleFactor;
-  for(auto&& item : mItems)
+  for(auto&& item : mLightObservers)
   {
     if(item)
     {
@@ -414,6 +578,150 @@ float SceneView::GetImageBasedLightScaleFactor() const
   return mIblScaleFactor;
 }
 
+void SceneView::AddLight(Scene3D::Light light)
+{
+  bool enabled = mShaderManager->AddLight(light);
+  mLights.push_back(std::make_pair(light, enabled));
+
+  if(light.IsShadowEnabled())
+  {
+    SetShadow(light);
+  }
+}
+
+void SceneView::RemoveLight(Scene3D::Light light)
+{
+  mShaderManager->RemoveLight(light);
+  for(uint32_t i = 0; i < mLights.size(); ++i)
+  {
+    if(mLights[i].first == light)
+    {
+      mLights.erase(mLights.begin() + i);
+      break;
+    }
+  }
+
+  if(mLights.size() > mShaderManager->GetLightCount())
+  {
+    for(auto&& waitingLight : mLights)
+    {
+      if(waitingLight.second)
+      {
+        continue;
+      }
+
+      waitingLight.second = mShaderManager->AddLight(waitingLight.first);
+      break;
+    }
+  }
+
+  if(light == mShadowLight)
+  {
+    RemoveShadow(light);
+  }
+
+  if(!mShadowLight)
+  {
+    for(auto&& lightEntity : mLights)
+    {
+      if(!lightEntity.second || !lightEntity.first.IsShadowEnabled())
+      {
+        continue;
+      }
+      SetShadow(lightEntity.first);
+      break;
+    }
+  }
+}
+
+void SceneView::SetShadow(Scene3D::Light light)
+{
+  if(!!mShadowLight)
+  {
+    return;
+  }
+
+  auto foundLight = std::find_if(mLights.begin(), mLights.end(), [light](std::pair<Scene3D::Light, bool> lightEntity) -> bool { return (lightEntity.second && lightEntity.first == light); });
+
+  if(foundLight == mLights.end())
+  {
+    return;
+  }
+
+  mShadowLight = light;
+
+  // Directional Light setting.
+  CameraActor lightCamera    = GetImplementation(light).GetCamera();
+  CameraActor selectedCamera = GetSelectedCamera();
+  SetShadowLightConstraint(selectedCamera, lightCamera);
+
+  // make framebuffer for depth map and set it to render task.
+  uint32_t shadowMapBufferSize = std::min(std::max(GetResolutionWidth(), GetResolutionHeight()), MAXIMUM_SIZE_SHADOW_MAP);
+  UpdateShadowMapBuffer(shadowMapBufferSize);
+
+  // use lightCamera as a camera of shadow render task.
+  if(mShadowMapRenderTask)
+  {
+    mShadowMapRenderTask.SetCameraActor(lightCamera);
+  }
+
+  mShaderManager->SetShadow(light);
+  UpdateShadowMapBuffer(shadowMapBufferSize);
+}
+
+void SceneView::RemoveShadow(Scene3D::Light light)
+{
+  if(mShadowLight != light)
+  {
+    return;
+  }
+
+  // remove all constraint from light camera
+  CameraActor lightCamera = GetImplementation(mShadowLight).GetCamera();
+  lightCamera.RemoveConstraints();
+
+  // reset framebuffer and remove it from render task.
+  mShadowFrameBuffer.Reset();
+  mShaderManager->RemoveShadow();
+  if(mShadowMapRenderTask)
+  {
+    mShadowMapRenderTask.SetCameraActor(CameraActor());
+  }
+
+  mShadowLight.Reset();
+
+  mShadowTexture.Reset();
+  for(auto&& item : mLightObservers)
+  {
+    if(item)
+    {
+      item->NotifyShadowMapTexture(mShadowTexture);
+    }
+  }
+
+  for(auto&& lightEntity : mLights)
+  {
+    if(!lightEntity.second || !lightEntity.first.IsShadowEnabled())
+    {
+      continue;
+    }
+    SetShadow(lightEntity.first);
+    break;
+  }
+
+  if(mSceneHolder && mShadowMapRenderTask)
+  {
+    RenderTaskList taskList = mSceneHolder.GetRenderTaskList();
+    taskList.RemoveTask(mShadowMapRenderTask);
+    mShadowMapRenderTask.Reset();
+  }
+}
+
+uint32_t SceneView::GetActivatedLightCount() const
+{
+  return mShaderManager->GetLightCount();
+}
+
 void SceneView::UseFramebuffer(bool useFramebuffer)
 {
   if(mUseFrameBuffer != useFramebuffer)
@@ -428,62 +736,80 @@ bool SceneView::IsUsingFramebuffer() const
   return mUseFrameBuffer;
 }
 
-void SceneView::SetSkybox(const std::string& skyboxUrl, Scene3D::SceneView::SkyboxType skyboxType)
+void SceneView::SetResolution(uint32_t width, uint32_t height)
 {
-  mSkyboxEnvironmentMapType = skyboxType;
-  bool isOnScene = Self().GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE);
-  if(mSkyboxUrl != skyboxUrl)
+  if(mWindowWidth != width || mWindowHeight != height)
   {
-    mSkyboxDirty         = true;
-    mSkyboxResourceReady = false;
-    mSkyboxUrl           = skyboxUrl;
+    mWindowWidth  = width;
+    mWindowHeight = height;
+    if(mUseFrameBuffer)
+    {
+      mWindowSizeChanged = true;
+      UpdateRenderTask();
+    }
   }
+}
 
-  if(mSkyboxUrl.empty())
+uint32_t SceneView::GetResolutionWidth()
+{
+  if(!mUseFrameBuffer || mWindowWidth == 0u || mWindowHeight == 0u)
   {
-    if(mSkyboxLoadTask)
-    {
-      Dali::AsyncTaskManager::Get().RemoveTask(mSkyboxLoadTask);
-      mSkyboxLoadTask.Reset();
-    }
-    if(mSkyboxImageLoader)
-    {
-      mSkyboxImageLoader.Cancel(mSkyboxImageId);
-    }
-    mSkyboxDirty         = false;
-    mSkyboxResourceReady = true;
+    return static_cast<uint32_t>(Self().GetProperty<float>(Dali::Actor::Property::SIZE_WIDTH));
   }
-  else
+  return mWindowWidth;
+}
+
+uint32_t SceneView::GetResolutionHeight()
+{
+  if(!mUseFrameBuffer || mWindowWidth == 0u || mWindowHeight == 0u)
   {
-    if(isOnScene && mSkyboxDirty)
+    return static_cast<uint32_t>(Self().GetProperty<float>(Dali::Actor::Property::SIZE_HEIGHT));
+  }
+  return mWindowHeight;
+}
+
+void SceneView::ResetResolution()
+{
+  SetResolution(0u, 0u);
+}
+
+void SceneView::SetFramebufferMultiSamplingLevel(uint8_t multiSamplingLevel)
+{
+  if(mFrameBufferMultiSamplingLevel != multiSamplingLevel)
+  {
+    mFrameBufferMultiSamplingLevel = multiSamplingLevel;
+
+    // Create new framebuffer with changed multiSamplingLevel.
+    if(mRenderTask && mFrameBuffer && mTexture)
     {
-      if(mSkyboxLoadTask)
-      {
-        Dali::AsyncTaskManager::Get().RemoveTask(mSkyboxLoadTask);
-        mSkyboxLoadTask.Reset();
-      }
-      if(mSkyboxImageLoader)
-      {
-        mSkyboxImageLoader.Cancel(mSkyboxImageId);
-      }
-      if(mSkyboxEnvironmentMapType == Scene3D::SceneView::SkyboxType::CUBEMAP)
-      {
-        mSkyboxLoadTask = new EnvironmentMapLoadTask(mSkyboxUrl, MakeCallback(this, &SceneView::OnSkyboxLoadComplete));
-        Dali::AsyncTaskManager::Get().AddTask(mSkyboxLoadTask);
-      }
-      else
-      {
-        mSkyboxImageLoader = Dali::Toolkit::AsyncImageLoader::New();
-        mSkyboxImageLoader.ImageLoadedSignal().Connect(this, &SceneView::OnSkyboxEquirectangularLoadComplete);
-        mSkyboxImageId = mSkyboxImageLoader.Load(mSkyboxUrl);
-      }
-      mSkyboxDirty = false;
+      mFrameBuffer = FrameBuffer::New(GetResolutionWidth(), GetResolutionHeight(), FrameBuffer::Attachment::DEPTH_STENCIL);
+      mFrameBuffer.AttachColorTexture(mTexture);
+      DevelFrameBuffer::SetMultiSamplingLevel(mFrameBuffer, mFrameBufferMultiSamplingLevel);
+      mRenderTask.SetFrameBuffer(mFrameBuffer);
+
+      // Note : we don't need to create new visual since visual's url is depend on mTexture.
     }
   }
+}
 
-  if(IsResourceReady())
+uint8_t SceneView::GetFramebufferMultiSamplingLevel() const
+{
+  return mFrameBufferMultiSamplingLevel;
+}
+
+void SceneView::SetSkybox(const std::string& skyboxUrl)
+{
+  if(mSkyboxUrl != skyboxUrl)
   {
-    Control::SetResourceReady(false);
+    UpdateSkybox(skyboxUrl, mSkyboxEnvironmentMapType);
+  }
+}
+
+void SceneView::SetSkyboxEnvironmentMapType(Scene3D::EnvironmentMapType skyboxEnvironmentMapType)
+{
+  if(mSkyboxEnvironmentMapType != skyboxEnvironmentMapType)
+  {
+    UpdateSkybox(mSkyboxUrl, skyboxEnvironmentMapType);
   }
 }
 
@@ -521,6 +847,128 @@ Quaternion SceneView::GetSkyboxOrientation() const
   return mSkyboxOrientation;
 }
 
+Dali::Scene3D::Loader::ShaderManagerPtr SceneView::GetShaderManager() const
+{
+  return mShaderManager;
+}
+
+void SceneView::UpdateShadowUniform(Scene3D::Light light)
+{
+  mShaderManager->UpdateShadowUniform(light);
+}
+
+void SceneView::SetAlphaMaskUrl(std::string& alphaMaskUrl)
+{
+  if(mAlphaMaskUrl != alphaMaskUrl)
+  {
+    mAlphaMaskUrl           = alphaMaskUrl;
+    mMaskingPropertyChanged = true;
+    UpdateRenderTask();
+  }
+}
+
+std::string SceneView::GetAlphaMaskUrl()
+{
+  return mAlphaMaskUrl;
+}
+
+void SceneView::SetMaskContentScaleFactor(float maskContentScaleFactor)
+{
+  if(mMaskContentScaleFactor != maskContentScaleFactor)
+  {
+    mMaskContentScaleFactor = maskContentScaleFactor;
+    mMaskingPropertyChanged = true;
+    UpdateRenderTask();
+  }
+}
+
+float SceneView::GetMaskContentScaleFactor()
+{
+  return mMaskContentScaleFactor;
+}
+
+void SceneView::EnableCropToMask(bool enableCropToMask)
+{
+  if(mCropToMask != enableCropToMask)
+  {
+    mCropToMask             = enableCropToMask;
+    mMaskingPropertyChanged = true;
+    UpdateRenderTask();
+  }
+}
+
+bool SceneView::IsEnabledCropToMask()
+{
+  return mCropToMask;
+}
+
+Dali::RenderTask SceneView::GetRenderTask()
+{
+  return mRenderTask;
+}
+
+void SceneView::SetProperty(BaseObject* object, Property::Index index, const Property::Value& value)
+{
+  Scene3D::SceneView sceneView = Scene3D::SceneView::DownCast(Dali::BaseHandle(object));
+
+  if(sceneView)
+  {
+    SceneView& sceneViewImpl(GetImpl(sceneView));
+
+    switch(index)
+    {
+      case Scene3D::SceneView::Property::ALPHA_MASK_URL:
+      {
+        std::string alphaMaskUrl = value.Get<std::string>();
+        sceneViewImpl.SetAlphaMaskUrl(alphaMaskUrl);
+        break;
+      }
+      case Scene3D::SceneView::Property::MASK_CONTENT_SCALE:
+      {
+        sceneViewImpl.SetMaskContentScaleFactor(value.Get<float>());
+        break;
+      }
+      case Scene3D::SceneView::Property::CROP_TO_MASK:
+      {
+        sceneViewImpl.EnableCropToMask(value.Get<bool>());
+        break;
+      }
+    }
+  }
+}
+
+Property::Value SceneView::GetProperty(BaseObject* object, Property::Index index)
+{
+  Property::Value value;
+
+  Scene3D::SceneView sceneView = Scene3D::SceneView::DownCast(Dali::BaseHandle(object));
+
+  if(sceneView)
+  {
+    SceneView& sceneViewImpl(GetImpl(sceneView));
+
+    switch(index)
+    {
+      case Scene3D::SceneView::Property::ALPHA_MASK_URL:
+      {
+        value = sceneViewImpl.GetAlphaMaskUrl();
+        break;
+      }
+      case Scene3D::SceneView::Property::MASK_CONTENT_SCALE:
+      {
+        value = sceneViewImpl.GetMaskContentScaleFactor();
+        break;
+      }
+      case Scene3D::SceneView::Property::CROP_TO_MASK:
+      {
+        value = sceneViewImpl.IsEnabledCropToMask();
+        break;
+      }
+    }
+  }
+  return value;
+}
+
 ///////////////////////////////////////////////////////////
 //
 // Private methods
@@ -536,23 +984,33 @@ void SceneView::OnSceneConnection(int depth)
 
   if(!mSkyboxUrl.empty())
   {
-    SetSkybox(mSkyboxUrl, mSkyboxEnvironmentMapType);
+    UpdateSkybox(mSkyboxUrl, mSkyboxEnvironmentMapType);
   }
 
   Window window = DevelWindow::Get(Self());
   if(window)
   {
+    // Only for on-screen window
     window.ResizeSignal().Connect(this, &SceneView::OnWindowResized);
-    RenderTaskList taskList = window.GetRenderTaskList();
+
+    mWindow            = window;
+    mWindowOrientation = DevelWindow::GetPhysicalOrientation(window);
+  }
+
+  // On-screen / Off-screen window
+  mSceneHolder = Integration::SceneHolder::Get(Self());
+  if(mSceneHolder)
+  {
+    RenderTaskList taskList = mSceneHolder.GetRenderTaskList();
     mRenderTask             = taskList.CreateTask();
     mRenderTask.SetSourceActor(mRootLayer);
     mRenderTask.SetExclusive(true);
     mRenderTask.SetInputEnabled(true);
     mRenderTask.SetCullMode(false);
+    mRenderTask.SetOrderIndex(SCENE_ORDER_INDEX);
     mRenderTask.SetScreenToFrameBufferMappingActor(Self());
 
     UpdateRenderTask();
-    mWindow = window;
   }
 
   Control::OnSceneConnection(depth);
@@ -560,20 +1018,33 @@ void SceneView::OnSceneConnection(int depth)
 
 void SceneView::OnSceneDisconnection()
 {
-  mItems.clear();
+  mLightObservers.Clear();
 
   Window window = mWindow.GetHandle();
   if(window)
   {
     window.ResizeSignal().Disconnect(this, &SceneView::OnWindowResized);
-    RenderTaskList taskList = window.GetRenderTaskList();
+  }
+  mWindow.Reset();
+
+  if(mSceneHolder)
+  {
     if(mRenderTask)
     {
+      RenderTaskList taskList = mSceneHolder.GetRenderTaskList();
       taskList.RemoveTask(mRenderTask);
-      mFrameBuffer.Reset();
+      mRenderTask.Reset();
+    }
+    if(mShadowMapRenderTask)
+    {
+      RenderTaskList taskList = mSceneHolder.GetRenderTaskList();
+      taskList.RemoveTask(mShadowMapRenderTask);
+      mShadowMapRenderTask.Reset();
     }
+    mSceneHolder.Reset();
   }
-  mWindow.Reset();
+  mFrameBuffer.Reset();
+  mShadowFrameBuffer.Reset();
 
   Control::OnSceneDisconnection();
 }
@@ -590,10 +1061,9 @@ void SceneView::OnInitialize()
   mRootLayer.SetProperty(Dali::Actor::Property::INHERIT_SCALE, false);
   self.Add(mRootLayer);
 
-  mDefaultCamera = Dali::CameraActor::New();
+  mDefaultCamera = Dali::CameraActor::New3DCamera();
   mDefaultCamera.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
   mDefaultCamera.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
-  mDefaultCamera.SetNearClippingPlane(1.0f);
   AddCamera(mDefaultCamera);
   UpdateCamera(mDefaultCamera);
 }
@@ -651,6 +1121,10 @@ void SceneView::UpdateCamera(CameraActor camera)
   }
 
   mSelectedCamera = camera;
+  if(mShadowLight)
+  {
+    SetShadowLightConstraint(mSelectedCamera, GetImplementation(mShadowLight).GetCamera());
+  }
   UpdateRenderTask();
 }
 
@@ -662,50 +1136,56 @@ void SceneView::UpdateRenderTask()
     {
       mRenderTask.SetCameraActor(mSelectedCamera);
     }
+    uint32_t width  = GetResolutionWidth();
+    uint32_t height = GetResolutionHeight();
 
-    Vector3     size        = Self().GetProperty<Vector3>(Dali::Actor::Property::SIZE);
-    const float aspectRatio = size.width / size.height;
-    mSelectedCamera.SetAspectRatio(aspectRatio);
+    uint32_t shadowMapBufferSize = std::min(std::max(width, height), MAXIMUM_SIZE_SHADOW_MAP);
+    UpdateShadowMapBuffer(shadowMapBufferSize);
 
     if(mUseFrameBuffer)
     {
       Dali::FrameBuffer currentFrameBuffer = mRenderTask.GetFrameBuffer();
       if(!currentFrameBuffer ||
-         !Dali::Equals(currentFrameBuffer.GetColorTexture().GetWidth(), size.width) ||
-         !Dali::Equals(currentFrameBuffer.GetColorTexture().GetHeight(), size.height))
+         !Dali::Equals(currentFrameBuffer.GetColorTexture().GetWidth(), width) ||
+         !Dali::Equals(currentFrameBuffer.GetColorTexture().GetHeight(), height) ||
+         mMaskingPropertyChanged ||
+         mWindowSizeChanged)
       {
         mRootLayer.SetProperty(Dali::Actor::Property::COLOR_MODE, ColorMode::USE_OWN_COLOR);
         mRenderTask.ResetViewportGuideActor();
         mRenderTask.SetViewport(Dali::Viewport(Vector4::ZERO));
 
         // create offscreen buffer of new size to render our child actors to
-        mTexture     = Dali::Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, unsigned(size.width), unsigned(size.height));
-        mFrameBuffer = FrameBuffer::New(size.width, size.height, FrameBuffer::Attachment::DEPTH_STENCIL);
+        mTexture     = Dali::Texture::New(TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height);
+        mFrameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::DEPTH_STENCIL);
         mFrameBuffer.AttachColorTexture(mTexture);
-        DevelFrameBuffer::SetMultiSamplingLevel(mFrameBuffer, DEFAULT_FRAME_BUFFER_MULTI_SAMPLING_LEVEL);
+        DevelFrameBuffer::SetMultiSamplingLevel(mFrameBuffer, mFrameBufferMultiSamplingLevel);
         Dali::Toolkit::ImageUrl imageUrl = Dali::Toolkit::Image::GenerateUrl(mFrameBuffer, 0u);
 
         Property::Map imagePropertyMap;
         imagePropertyMap.Insert(Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE);
         imagePropertyMap.Insert(Toolkit::ImageVisual::Property::URL, imageUrl.GetUrl());
-        // To make sure this visual call LoadTexture API immediate.
-        imagePropertyMap.Insert(Toolkit::ImageVisual::Property::LOAD_POLICY, Toolkit::ImageVisual::LoadPolicy::IMMEDIATE);
-        imagePropertyMap.Insert(Toolkit::ImageVisual::Property::RELEASE_POLICY, Toolkit::ImageVisual::ReleasePolicy::DESTROYED);
         // To flip rendered scene without CameraActor::SetInvertYAxis() to avoid backface culling.
         imagePropertyMap.Insert(Toolkit::ImageVisual::Property::PIXEL_AREA, Vector4(0.0f, 1.0f, 1.0f, -1.0f));
-        mVisual = Toolkit::VisualFactory::Get().CreateVisual(imagePropertyMap);
-
-        // Use premultiplied alpha when we use FBO
-        if(mVisual)
+        if(!mAlphaMaskUrl.empty())
         {
-          Toolkit::GetImplementation(mVisual).EnablePreMultipliedAlpha(true);
+          imagePropertyMap.Insert(Toolkit::ImageVisual::Property::ALPHA_MASK_URL, mAlphaMaskUrl);
+          imagePropertyMap.Insert(Toolkit::ImageVisual::Property::SYNCHRONOUS_LOADING, true);
+          imagePropertyMap.Insert(Toolkit::ImageVisual::Property::MASK_CONTENT_SCALE, mMaskContentScaleFactor);
+          imagePropertyMap.Insert(Toolkit::ImageVisual::Property::CROP_TO_MASK, mCropToMask);
+          imagePropertyMap.Insert(Toolkit::DevelImageVisual::Property::MASKING_TYPE, Toolkit::DevelImageVisual::MaskingType::MASKING_ON_RENDERING);
+          Self().RegisterProperty(Y_FLIP_MASK_TEXTURE, FLIP_MASK_TEXTURE);
         }
 
+        mVisual = Toolkit::VisualFactory::Get().CreateVisual(imagePropertyMap);
         Toolkit::DevelControl::RegisterVisual(*this, RENDERING_BUFFER, mVisual);
 
         mRenderTask.SetFrameBuffer(mFrameBuffer);
         mRenderTask.SetClearEnabled(true);
         mRenderTask.SetClearColor(Color::TRANSPARENT);
+
+        mMaskingPropertyChanged = false;
+        mWindowSizeChanged      = false;
       }
     }
     else
@@ -726,6 +1206,12 @@ void SceneView::UpdateRenderTask()
       }
     }
 
+    if(width > 0u && height > 0u)
+    {
+      float aspectRatio = static_cast<float>(width) / static_cast<float>(height);
+      mSelectedCamera.SetAspectRatio(aspectRatio);
+    }
+
     RotateCamera();
   }
 }
@@ -748,11 +1234,61 @@ void SceneView::RotateCamera()
   }
 }
 
-void SceneView::OnSkyboxEquirectangularLoadComplete(uint32_t loadedTaskId, PixelData pixelData)
+void SceneView::UpdateSkybox(const std::string& skyboxUrl, Scene3D::EnvironmentMapType skyboxEnvironmentMapType)
 {
-  mSkyboxTexture = Texture::New(TextureType::TEXTURE_2D, pixelData.GetPixelFormat(), pixelData.GetWidth(), pixelData.GetHeight());
-  mSkyboxTexture.Upload(pixelData, 0, 0, 0, 0, pixelData.GetWidth(), pixelData.GetHeight());
-  OnSkyboxLoadComplete();
+  bool isOnScene = Self().GetProperty<bool>(Dali::Actor::Property::CONNECTED_TO_SCENE);
+  if(mSkyboxUrl != skyboxUrl || mSkyboxEnvironmentMapType != skyboxEnvironmentMapType)
+  {
+    mSkyboxDirty              = true;
+    mSkyboxResourceReady      = false;
+    mSkyboxUrl                = skyboxUrl;
+    mSkyboxEnvironmentMapType = skyboxEnvironmentMapType;
+  }
+
+  if(mSkyboxUrl.empty())
+  {
+    if(mSkyboxLoadTask)
+    {
+      Dali::AsyncTaskManager::Get().RemoveTask(mSkyboxLoadTask);
+      mSkyboxLoadTask.Reset();
+    }
+
+    if(mSkybox)
+    {
+      mSkybox.Unparent();
+      mSkybox.Reset();
+      mSkyboxTexture.Reset();
+    }
+
+    mSkyboxDirty         = false;
+    mSkyboxResourceReady = true;
+
+    // Request image resource GC
+    Dali::Scene3D::Internal::ImageResourceLoader::RequestGarbageCollect();
+  }
+  else
+  {
+    if(isOnScene && mSkyboxDirty)
+    {
+      if(mSkyboxLoadTask)
+      {
+        Dali::AsyncTaskManager::Get().RemoveTask(mSkyboxLoadTask);
+        mSkyboxLoadTask.Reset();
+
+        // Request image resource GC
+        Dali::Scene3D::Internal::ImageResourceLoader::RequestGarbageCollect();
+      }
+
+      mSkyboxLoadTask = new EnvironmentMapLoadTask(mSkyboxUrl, mSkyboxEnvironmentMapType, MakeCallback(this, &SceneView::OnSkyboxLoadComplete));
+      Dali::AsyncTaskManager::Get().AddTask(mSkyboxLoadTask);
+      mSkyboxDirty = false;
+    }
+  }
+
+  if(IsResourceReady())
+  {
+    Control::SetResourceReady();
+  }
 }
 
 void SceneView::OnSkyboxLoadComplete()
@@ -769,22 +1305,15 @@ void SceneView::OnSkyboxLoadComplete()
   }
 
   mSkyboxResourceReady = true;
-  if(IsResourceReady())
-  {
-    Control::SetResourceReady(false);
-  }
-
+  mSkyboxTexture       = mSkyboxLoadTask->GetLoadedTexture();
   Shader skyboxShader;
-  if(mSkyboxEnvironmentMapType == Scene3D::SceneView::SkyboxType::CUBEMAP)
+  if(mSkyboxLoadTask->GetEnvironmentMapType() == Scene3D::EnvironmentMapType::CUBEMAP)
   {
-    mSkyboxTexture = (mSkyboxLoadTask->HasSucceeded()) ? mSkyboxLoadTask->GetEnvironmentMap().CreateTexture() : Texture();
-    skyboxShader   = Shader::New(SHADER_SKYBOX_SHADER_VERT.data(), SHADER_SKYBOX_SHADER_FRAG.data());
-    Dali::AsyncTaskManager::Get().RemoveTask(mSkyboxLoadTask);
-    mSkyboxLoadTask.Reset();
+    skyboxShader = Shader::New(SHADER_SKYBOX_SHADER_VERT.data(), SHADER_SKYBOX_SHADER_FRAG.data(), Shader::Hint::NONE, "SCENE3D_SKYBOX_CUBE");
   }
   else
   {
-    skyboxShader = Shader::New(SHADER_SKYBOX_SHADER_VERT.data(), SHADER_SKYBOX_EQUIRECTANGULAR_SHADER_FRAG.data());
+    skyboxShader = Shader::New(SHADER_SKYBOX_SHADER_VERT.data(), SHADER_SKYBOX_EQUIRECTANGULAR_SHADER_FRAG.data(), Shader::Hint::NONE, "SCENE3D_SKYBOX_EQUIRECTANGULAR");
   }
 
   Renderer skyboxRenderer = (mSkybox.GetRendererCount() > 0u) ? mSkybox.GetRendererAt(0u) : Renderer();
@@ -795,28 +1324,36 @@ void SceneView::OnSkyboxLoadComplete()
     skyboxRenderer.SetTextures(skyboxTextures);
     skyboxRenderer.SetShader(skyboxShader);
   }
+
+  mSkyboxLoadTask.Reset();
+
+  if(IsResourceReady())
+  {
+    Control::SetResourceReady();
+  }
 }
 
 void SceneView::OnIblDiffuseLoadComplete()
 {
-  mDiffuseTexture          = (mIblDiffuseLoadTask->HasSucceeded()) ? mIblDiffuseLoadTask->GetEnvironmentMap().CreateTexture() : Texture();
+  mDiffuseTexture          = mIblDiffuseLoadTask->GetLoadedTexture();
   mIblDiffuseResourceReady = true;
+  mIblDiffuseLoadTask.Reset();
   if(mIblDiffuseResourceReady && mIblSpecularResourceReady)
   {
     OnIblLoadComplete();
   }
-  mIblDiffuseLoadTask.Reset();
 }
 
 void SceneView::OnIblSpecularLoadComplete()
 {
-  mSpecularTexture          = (mIblSpecularLoadTask->HasSucceeded()) ? mIblSpecularLoadTask->GetEnvironmentMap().CreateTexture() : Texture();
+  mSpecularTexture          = mIblSpecularLoadTask->GetLoadedTexture();
+  mSpecularMipmapLevels     = mIblSpecularLoadTask->GetMipmapLevels();
   mIblSpecularResourceReady = true;
+  mIblSpecularLoadTask.Reset();
   if(mIblDiffuseResourceReady && mIblSpecularResourceReady)
   {
     OnIblLoadComplete();
   }
-  mIblSpecularLoadTask.Reset();
 }
 
 void SceneView::OnIblLoadComplete()
@@ -824,17 +1361,60 @@ void SceneView::OnIblLoadComplete()
   NotifyImageBasedLightTextureChange();
   if(IsResourceReady())
   {
-    Control::SetResourceReady(false);
+    Control::SetResourceReady();
   }
 }
 
 void SceneView::NotifyImageBasedLightTextureChange()
 {
-  for(auto&& item : mItems)
+  for(auto&& item : mLightObservers)
   {
     if(item)
     {
-      item->NotifyImageBasedLightTexture(mDiffuseTexture, mSpecularTexture, mIblScaleFactor);
+      item->NotifyImageBasedLightTexture(mDiffuseTexture, mSpecularTexture, mIblScaleFactor, mSpecularMipmapLevels);
+    }
+  }
+}
+
+void SceneView::UpdateShadowMapBuffer(uint32_t shadowMapSize)
+{
+  if(!mShadowLight || !mSceneHolder)
+  {
+    return;
+  }
+
+  if(!mShadowMapRenderTask)
+  {
+    RenderTaskList taskList = mSceneHolder.GetRenderTaskList();
+    mShadowMapRenderTask    = taskList.CreateTask();
+    mShadowMapRenderTask.SetSourceActor(mRootLayer);
+    mShadowMapRenderTask.SetExclusive(true);
+    mShadowMapRenderTask.SetInputEnabled(false);
+    mShadowMapRenderTask.SetCullMode(false);
+    mShadowMapRenderTask.SetClearEnabled(true);
+    mShadowMapRenderTask.SetClearColor(Color::WHITE);
+    mShadowMapRenderTask.SetRenderPassTag(10);
+    mShadowMapRenderTask.SetCameraActor(GetImplementation(mShadowLight).GetCamera());
+    mShadowMapRenderTask.SetOrderIndex(SHADOW_ORDER_INDEX);
+  }
+
+  Dali::FrameBuffer currentShadowFrameBuffer = mShadowMapRenderTask.GetFrameBuffer();
+  if(!currentShadowFrameBuffer ||
+     !mShadowTexture ||
+     !Dali::Equals(DevelFrameBuffer::GetDepthTexture(currentShadowFrameBuffer).GetWidth(), shadowMapSize))
+  {
+    mShadowFrameBuffer.Reset();
+    mShadowTexture     = Dali::Texture::New(TextureType::TEXTURE_2D, Pixel::DEPTH_UNSIGNED_INT, shadowMapSize, shadowMapSize);
+    mShadowFrameBuffer = FrameBuffer::New(shadowMapSize, shadowMapSize, FrameBuffer::Attachment::NONE);
+    DevelFrameBuffer::AttachDepthTexture(mShadowFrameBuffer, mShadowTexture);
+    mShadowMapRenderTask.SetFrameBuffer(mShadowFrameBuffer);
+
+    for(auto&& item : mLightObservers)
+    {
+      if(item)
+      {
+        item->NotifyShadowMapTexture(mShadowTexture);
+      }
     }
   }
 }