// 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>
using namespace Dali;
Property::Index RENDERING_BUFFER = Dali::Toolkit::Control::CONTROL_PROPERTY_END_INDEX + 1;
constexpr int32_t DEFAULT_ORIENTATION = 0;
+constexpr int32_t INVALID_INDEX = -1;
static constexpr std::string_view SKYBOX_INTENSITY_STRING = "uIntensity";
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);
+
+ if(mActivatedLightCount > 0)
+ {
+ uint32_t maxLightCount = Scene3D::Internal::Light::GetMaximumEnabledLightCount();
+ for(uint32_t i = 0; i < maxLightCount; ++i)
+ {
+ if(mActivatedLights[i])
+ {
+ item->NotifyLightAdded(i, mActivatedLights[i]);
+ }
+ }
+ }
mItems.push_back(item);
}
}
-void SceneView::UnregisterSceneItem(Scene3D::Internal::ImageBasedLightObserver* item)
+void SceneView::UnregisterSceneItem(Scene3D::Internal::LightObserver* item)
{
if(item)
{
{
if(mItems[i] == item)
{
+ if(mActivatedLightCount > 0)
+ {
+ uint32_t maxLightCount = Scene3D::Internal::Light::GetMaximumEnabledLightCount();
+ for(uint32_t i = 0; i < maxLightCount; ++i)
+ {
+ if(mActivatedLights[i])
+ {
+ item->NotifyLightRemoved(i);
+ }
+ }
+ }
mItems.erase(mItems.begin() + i);
break;
}
mDiffuseTexture.Reset();
mSpecularTexture.Reset();
+ mSpecularMipmapLevels = 1u;
NotifyImageBasedLightTextureChange();
}
else
return mIblScaleFactor;
}
+void SceneView::AddLight(Scene3D::Light light)
+{
+ bool enabled = AddLightInternal(light);
+ mLights.push_back(std::make_pair(light, enabled));
+}
+
+void SceneView::RemoveLight(Scene3D::Light light)
+{
+ if(mActivatedLights.empty())
+ {
+ return;
+ }
+
+ bool needToDisable = false;
+ for(uint32_t i = 0; i < mLights.size(); ++i)
+ {
+ if(mLights[i].first == light)
+ {
+ // If mLights[i].second is true, it means the light is currently activated in Scene.
+ // Then it should be removed from mActivatedLights list too.
+ needToDisable = mLights[i].second;
+ mLights.erase(mLights.begin() + i);
+ break;
+ }
+ }
+
+ uint32_t maxNumberOfLight = Scene3D::Internal::Light::GetMaximumEnabledLightCount();
+ if(needToDisable)
+ {
+ uint32_t removedIndex = RemoveLightInternal(light);
+ if(mActivatedLightCount < maxNumberOfLight && mLights.size() >= maxNumberOfLight)
+ {
+ for(auto && lightItem : mLights)
+ {
+ if(lightItem.second == false)
+ {
+ lightItem.second = AddLightInternal(lightItem.first);
+ break;
+ }
+ }
+ }
+
+ // To remove empty entity of mActivatedLights, moves last object to empty position.
+ // Because one Light is removed, mActivatedLights[mActivatedLightCount] is current last object of the list.
+ if(!mActivatedLights[removedIndex] && mActivatedLightCount > 0 && removedIndex < mActivatedLightCount)
+ {
+ Scene3D::Light reorderingLight = mActivatedLights[mActivatedLightCount];
+ RemoveLightInternal(reorderingLight);
+ AddLightInternal(reorderingLight);
+ }
+ }
+}
+
+uint32_t SceneView::GetActivatedLightCount() const
+{
+ return mActivatedLightCount;
+}
+
void SceneView::UseFramebuffer(bool useFramebuffer)
{
if(mUseFrameBuffer != useFramebuffer)
if(mRenderTask)
{
taskList.RemoveTask(mRenderTask);
+ mRenderTask.Reset();
mFrameBuffer.Reset();
}
}
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);
Dali::AsyncTaskManager::Get().RemoveTask(mSkyboxLoadTask);
mSkyboxLoadTask.Reset();
}
+
+ if(mSkybox)
+ {
+ mSkybox.Unparent();
+ mSkybox.Reset();
+ mSkyboxTexture.Reset();
+ }
+
mSkyboxDirty = false;
mSkyboxResourceReady = true;
}
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());
}
void SceneView::OnIblSpecularLoadComplete()
{
mSpecularTexture = mIblSpecularLoadTask->GetLoadedTexture();
+ mSpecularMipmapLevels = mIblSpecularLoadTask->GetMipmapLevels();
mIblSpecularResourceReady = true;
if(mIblDiffuseResourceReady && mIblSpecularResourceReady)
{
{
if(item)
{
- item->NotifyImageBasedLightTexture(mDiffuseTexture, mSpecularTexture, mIblScaleFactor);
+ item->NotifyImageBasedLightTexture(mDiffuseTexture, mSpecularTexture, mIblScaleFactor, mSpecularMipmapLevels);
}
}
}
+bool SceneView::AddLightInternal(Scene3D::Light light)
+{
+ uint32_t maxNumberOfLight = Scene3D::Internal::Light::GetMaximumEnabledLightCount();
+ if(mActivatedLightCount == 0)
+ {
+ mActivatedLights.resize(maxNumberOfLight);
+ }
+
+ bool enabled = false;
+ if(mActivatedLightCount < maxNumberOfLight)
+ {
+ uint32_t newLightIndex = 0u;
+ for(; newLightIndex < maxNumberOfLight; ++newLightIndex)
+ {
+ if(!mActivatedLights[newLightIndex])
+ {
+ mActivatedLights[newLightIndex] = light;
+ break;
+ }
+ }
+
+ for(auto&& item : mItems)
+ {
+ if(item)
+ {
+ item->NotifyLightAdded(newLightIndex, light);
+ }
+ }
+
+ mActivatedLightCount++;
+ enabled = true;
+ }
+ return enabled;
+}
+
+int32_t SceneView::RemoveLightInternal(Scene3D::Light light)
+{
+ int32_t removedIndex = INVALID_INDEX;
+ uint32_t maxNumberOfLight = Scene3D::Internal::Light::GetMaximumEnabledLightCount();
+ for(uint32_t i = 0; i < maxNumberOfLight; ++i)
+ {
+ if(mActivatedLights[i] == light)
+ {
+ for(auto&& item : mItems)
+ {
+ if(item)
+ {
+ item->NotifyLightRemoved(i);
+ }
+ }
+ mActivatedLights[i].Reset();
+ mActivatedLightCount--;
+ removedIndex = i;
+ break;
+ }
+ }
+
+ return removedIndex;
+}
+
} // namespace Internal
} // namespace Scene3D
} // namespace Dali