Merge changes I776588c1,I7292a2fb into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-scene3d / internal / controls / scene-view / scene-view-impl.cpp
index 1c4a9a8..0c377cc 100644 (file)
@@ -39,6 +39,9 @@
 // INTERNAL INCLUDES
 #include <dali-scene3d/internal/controls/model/model-impl.h>
 #include <dali-scene3d/internal/graphics/builtin-shader-extern-gen.h>
+#include <dali-scene3d/internal/light/light-impl.h>
+
+#include <dali/integration-api/debug.h>
 
 using namespace Dali;
 
@@ -59,8 +62,10 @@ BaseHandle Create()
 DALI_TYPE_REGISTRATION_BEGIN(Scene3D::SceneView, Toolkit::Control, Create);
 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;
 
 static constexpr std::string_view SKYBOX_INTENSITY_STRING = "uIntensity";
 
@@ -144,6 +149,143 @@ 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 View Matrix of ShadowLightCamera
+  // Input : ShadowLightCamera's world position, world orientation
+  auto       tempViewMatrixIndex  = shadowLightCamera.RegisterProperty("tempViewMatrix", Matrix::IDENTITY);
+  Constraint viewMatrixConstraint = Constraint::New<Matrix>(shadowLightCamera, tempViewMatrixIndex, [](Matrix& output, const PropertyInputContainer& inputs)
+                                                            {
+                                                              output = inputs[0]->GetMatrix();
+                                                              output.Invert(); });
+  viewMatrixConstraint.AddSource(Source{shadowLightCamera, Dali::Actor::Property::WORLD_MATRIX});
+  viewMatrixConstraint.ApplyPost();
+
+  // Compute Orthographic Size / Near / Far and store it to "TempCameraProperty" property that is a Vector3 property
+  auto       tempProjectionMatrixIndex  = shadowLightCamera.RegisterProperty("tempProjectionMatrix", Matrix::IDENTITY);
+  Constraint projectionMatrixConstraint = Constraint::New<Matrix>(shadowLightCamera, tempProjectionMatrixIndex, [](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));
+
+                                                                    Vector3 areaMin = Vector3::ONE * MAXFLOAT, areaMax = Vector3::ONE * -MAXFLOAT;
+                                                                    for(auto&& point : points)
+                                                                    {
+                                                                      Vector4 pointW = worldMatrix * point;
+                                                                      Vector4 pointV = inputs[8]->GetMatrix() * pointW;
+                                                                      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) / 2.0f;
+                                                                    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; });
+  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, tempViewMatrixIndex});
+  projectionMatrixConstraint.ApplyPost();
+}
+
 } // anonymous namespace
 
 SceneView::SceneView()
@@ -151,7 +293,8 @@ SceneView::SceneView()
   mWindowOrientation(DEFAULT_ORIENTATION),
   mSkybox(),
   mSkyboxOrientation(Quaternion()),
-  mSkyboxIntensity(1.0f)
+  mSkyboxIntensity(1.0f),
+  mShaderManager(new Scene3D::Loader::ShaderManager())
 {
 }
 
@@ -273,16 +416,16 @@ 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);
+    item->NotifyImageBasedLightTexture(mDiffuseTexture, mSpecularTexture, mIblScaleFactor, mSpecularMipmapLevels);
     mItems.push_back(item);
   }
 }
 
-void SceneView::UnregisterSceneItem(Scene3D::Internal::ImageBasedLightObserver* item)
+void SceneView::UnregisterSceneItem(Scene3D::Internal::LightObserver* item)
 {
   if(item)
   {
@@ -353,6 +496,7 @@ void SceneView::SetImageBasedLightSource(const std::string& diffuseUrl, const st
     mDiffuseTexture.Reset();
     mSpecularTexture.Reset();
 
+    mSpecularMipmapLevels = 1u;
     NotifyImageBasedLightTextureChange();
   }
   else
@@ -390,7 +534,7 @@ 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();
   }
 }
 
@@ -411,6 +555,129 @@ 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.
+  Vector3  size               = Self().GetProperty<Vector3>(Dali::Actor::Property::SIZE);
+  uint32_t shadowMapBufferSize = std::min(static_cast<uint32_t>(std::max(size.width, size.height)), MAXIMUM_SIZE_SHADOW_MAP);
+  UpdateShadowMapBuffer(shadowMapBufferSize);
+
+  // use lightCamera as a camera of shadow render task.
+  mShadowMapRenderTask.SetCameraActor(lightCamera);
+
+  mShaderManager->SetShadow(light);
+}
+
+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();
+  mShadowMapRenderTask.SetCameraActor(CameraActor());
+
+  mShadowLight.Reset();
+
+  for(auto&& lightEntity : mLights)
+  {
+    if(!lightEntity.second || !lightEntity.first.IsShadowEnabled())
+    {
+      continue;
+    }
+    SetShadow(lightEntity.first);
+    break;
+  }
+}
+
+uint32_t SceneView::GetActivatedLightCount() const
+{
+  return mShaderManager->GetLightCount();
+}
+
 void SceneView::UseFramebuffer(bool useFramebuffer)
 {
   if(mUseFrameBuffer != useFramebuffer)
@@ -501,6 +768,16 @@ Quaternion SceneView::GetSkyboxOrientation() const
   return mSkyboxOrientation;
 }
 
+Dali::Scene3D::Loader::ShaderManagerPtr SceneView::GetShaderManager() const
+{
+  return mShaderManager;
+}
+
+void SceneView::UpdateShadowUniform(Scene3D::Light light)
+{
+  mShaderManager->UpdateShadowUniform(light);
+}
+
 ///////////////////////////////////////////////////////////
 //
 // Private methods
@@ -522,9 +799,29 @@ void SceneView::OnSceneConnection(int depth)
   Window window = DevelWindow::Get(Self());
   if(window)
   {
+    // Only for on-screen window
     window.ResizeSignal().Connect(this, &SceneView::OnWindowResized);
-    RenderTaskList taskList = window.GetRenderTaskList();
-    mRenderTask             = taskList.CreateTask();
+
+    mWindow            = window;
+    mWindowOrientation = DevelWindow::GetPhysicalOrientation(window);
+  }
+
+  // On-screen / Off-screen window
+  mSceneHolder = Integration::SceneHolder::Get(Self());
+  if(mSceneHolder)
+  {
+    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(CameraActor());
+
+    mRenderTask = taskList.CreateTask();
     mRenderTask.SetSourceActor(mRootLayer);
     mRenderTask.SetExclusive(true);
     mRenderTask.SetInputEnabled(true);
@@ -532,7 +829,6 @@ void SceneView::OnSceneConnection(int depth)
     mRenderTask.SetScreenToFrameBufferMappingActor(Self());
 
     UpdateRenderTask();
-    mWindow = window;
   }
 
   Control::OnSceneConnection(depth);
@@ -546,14 +842,27 @@ void SceneView::OnSceneDisconnection()
   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();
 }
@@ -630,6 +939,10 @@ void SceneView::UpdateCamera(CameraActor camera)
   }
 
   mSelectedCamera = camera;
+  if(mShadowLight)
+  {
+    SetShadowLightConstraint(mSelectedCamera, GetImplementation(mShadowLight).GetCamera());
+  }
   UpdateRenderTask();
 }
 
@@ -646,6 +959,9 @@ void SceneView::UpdateRenderTask()
     const float aspectRatio = size.width / size.height;
     mSelectedCamera.SetAspectRatio(aspectRatio);
 
+    uint32_t shadowMapBufferSize = std::min(static_cast<uint32_t>(std::max(size.width, size.height)), MAXIMUM_SIZE_SHADOW_MAP);
+    UpdateShadowMapBuffer(shadowMapBufferSize);
+
     if(mUseFrameBuffer)
     {
       Dali::FrameBuffer currentFrameBuffer = mRenderTask.GetFrameBuffer();
@@ -667,19 +983,10 @@ void SceneView::UpdateRenderTask()
         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)
-        {
-          Toolkit::GetImplementation(mVisual).EnablePreMultipliedAlpha(true);
-        }
-
         Toolkit::DevelControl::RegisterVisual(*this, RENDERING_BUFFER, mVisual);
 
         mRenderTask.SetFrameBuffer(mFrameBuffer);
@@ -745,6 +1052,14 @@ void SceneView::UpdateSkybox(const std::string& skyboxUrl, Scene3D::EnvironmentM
       Dali::AsyncTaskManager::Get().RemoveTask(mSkyboxLoadTask);
       mSkyboxLoadTask.Reset();
     }
+
+    if(mSkybox)
+    {
+      mSkybox.Unparent();
+      mSkybox.Reset();
+      mSkyboxTexture.Reset();
+    }
+
     mSkyboxDirty         = false;
     mSkyboxResourceReady = true;
   }
@@ -766,7 +1081,7 @@ void SceneView::UpdateSkybox(const std::string& skyboxUrl, Scene3D::EnvironmentM
 
   if(IsResourceReady())
   {
-    Control::SetResourceReady(false);
+    Control::SetResourceReady();
   }
 }
 
@@ -786,12 +1101,12 @@ void SceneView::OnSkyboxLoadComplete()
   mSkyboxResourceReady = true;
   if(IsResourceReady())
   {
-    Control::SetResourceReady(false);
+    Control::SetResourceReady();
   }
 
-  mSkyboxTexture = (mSkyboxLoadTask->HasSucceeded()) ? mSkyboxLoadTask->GetEnvironmentMap().GetTexture() : Texture();
+  mSkyboxTexture = mSkyboxLoadTask->GetLoadedTexture();
   Shader skyboxShader;
-  if(mSkyboxEnvironmentMapType == Scene3D::EnvironmentMapType::CUBEMAP)
+  if(mSkyboxLoadTask->GetEnvironmentMapType() == Scene3D::EnvironmentMapType::CUBEMAP)
   {
     skyboxShader = Shader::New(SHADER_SKYBOX_SHADER_VERT.data(), SHADER_SKYBOX_SHADER_FRAG.data());
   }
@@ -814,7 +1129,7 @@ void SceneView::OnSkyboxLoadComplete()
 
 void SceneView::OnIblDiffuseLoadComplete()
 {
-  mDiffuseTexture          = (mIblDiffuseLoadTask->HasSucceeded()) ? mIblDiffuseLoadTask->GetEnvironmentMap().GetTexture() : Texture();
+  mDiffuseTexture          = mIblDiffuseLoadTask->GetLoadedTexture();
   mIblDiffuseResourceReady = true;
   if(mIblDiffuseResourceReady && mIblSpecularResourceReady)
   {
@@ -825,7 +1140,8 @@ void SceneView::OnIblDiffuseLoadComplete()
 
 void SceneView::OnIblSpecularLoadComplete()
 {
-  mSpecularTexture          = (mIblSpecularLoadTask->HasSucceeded()) ? mIblSpecularLoadTask->GetEnvironmentMap().GetTexture() : Texture();
+  mSpecularTexture          = mIblSpecularLoadTask->GetLoadedTexture();
+  mSpecularMipmapLevels     = mIblSpecularLoadTask->GetMipmapLevels();
   mIblSpecularResourceReady = true;
   if(mIblDiffuseResourceReady && mIblSpecularResourceReady)
   {
@@ -839,7 +1155,7 @@ void SceneView::OnIblLoadComplete()
   NotifyImageBasedLightTextureChange();
   if(IsResourceReady())
   {
-    Control::SetResourceReady(false);
+    Control::SetResourceReady();
   }
 }
 
@@ -849,7 +1165,30 @@ void SceneView::NotifyImageBasedLightTextureChange()
   {
     if(item)
     {
-      item->NotifyImageBasedLightTexture(mDiffuseTexture, mSpecularTexture, mIblScaleFactor);
+      item->NotifyImageBasedLightTexture(mDiffuseTexture, mSpecularTexture, mIblScaleFactor, mSpecularMipmapLevels);
+    }
+  }
+}
+
+void SceneView::UpdateShadowMapBuffer(uint32_t shadowMapSize)
+{
+  Dali::FrameBuffer currentShadowFrameBuffer = mShadowMapRenderTask.GetFrameBuffer();
+  if(mShadowLight &&
+     (!currentShadowFrameBuffer ||
+      !Dali::Equals(DevelFrameBuffer::GetDepthTexture(currentShadowFrameBuffer).GetWidth(), shadowMapSize)))
+  {
+    mShadowFrameBuffer.Reset();
+    Dali::Texture shadowTexture = Dali::Texture::New(TextureType::TEXTURE_2D, Pixel::DEPTH_UNSIGNED_INT, shadowMapSize, shadowMapSize);
+    mShadowFrameBuffer          = FrameBuffer::New(shadowMapSize, shadowMapSize, FrameBuffer::Attachment::NONE);
+    DevelFrameBuffer::AttachDepthTexture(mShadowFrameBuffer, shadowTexture);
+    mShadowMapRenderTask.SetFrameBuffer(mShadowFrameBuffer);
+
+    for(auto&& item : mItems)
+    {
+      if(item)
+      {
+        item->NotifyShadowMapTexture(shadowTexture);
+      }
     }
   }
 }