/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/Engine/RendererCore/Components/Implementation/CameraComponent.cpp
815 строк
23 KB
C-Core
Render Pipeline Blackboards (#1974)
06 июл 2026, 13:55
Не верифицирован
06 июл 2026, 13:55
5715bdc
Код
Авторство
О чём код?
#include <RendererCore/RendererCorePCH.h> #include <Core/ResourceManager/Resource.h> #include <Core/WorldSerializer/WorldReader.h> #include <Core/WorldSerializer/WorldWriter.h> #include <RendererCore/Components/BlackboardComponent.h> #include <RendererCore/Components/CameraComponent.h> #include <RendererCore/Debug/DebugRenderer.h> #include <RendererCore/Pipeline/RenderPipelineResource.h> #include <RendererCore/Pipeline/View.h> #include <RendererCore/RenderWorld/RenderWorld.h> #include <RendererCore/Textures/Texture2DResource.h> ezCameraComponentManager::ezCameraComponentManager(ezWorld* pWorld) : ezComponentManager<ezCameraComponent, ezBlockStorageType::Compact>(pWorld) { ezRenderWorld::s_CameraConfigsModifiedEvent.AddEventHandler(ezMakeDelegate(&ezCameraComponentManager::OnCameraConfigsChanged, this)); } ezCameraComponentManager::~ezCameraComponentManager() { ezRenderWorld::s_CameraConfigsModifiedEvent.RemoveEventHandler(ezMakeDelegate(&ezCameraComponentManager::OnCameraConfigsChanged, this)); } void ezCameraComponentManager::Initialize() { auto desc = EZ_CREATE_MODULE_UPDATE_FUNCTION_DESC(ezCameraComponentManager::Update, this); desc.m_Phase = ezWorldUpdatePhase::PostTransform; this->RegisterUpdateFunction(desc); ezRenderWorld::s_ViewCreatedEvent.AddEventHandler(ezMakeDelegate(&ezCameraComponentManager::OnViewCreated, this)); } void ezCameraComponentManager::Deinitialize() { ezRenderWorld::s_ViewCreatedEvent.RemoveEventHandler(ezMakeDelegate(&ezCameraComponentManager::OnViewCreated, this)); SUPER::Deinitialize(); } void ezCameraComponentManager::Update(const ezWorldModule::UpdateContext& context) { for (auto hCameraComponent : m_ModifiedCameras) { ezCameraComponent* pCameraComponent = nullptr; if (!TryGetComponent(hCameraComponent, pCameraComponent)) { continue; } if (ezView* pView = ezRenderWorld::GetViewByUsageHint(pCameraComponent->GetUsageHint(), ezCameraUsageHint::None, GetWorld())) { pCameraComponent->ApplySettingsToView(pView); } pCameraComponent->m_bIsModified = false; } m_ModifiedCameras.Clear(); for (auto hCameraComponent : m_RenderTargetCameras) { ezCameraComponent* pCameraComponent = nullptr; if (!TryGetComponent(hCameraComponent, pCameraComponent)) { continue; } pCameraComponent->UpdateRenderTargetCamera(); } for (auto it = GetComponents(); it.IsValid(); ++it) { if (it->IsActiveAndInitialized() && it->m_bShowStats && it->GetUsageHint() == ezCameraUsageHint::MainView) { if (ezView* pView = ezRenderWorld::GetViewByUsageHint(ezCameraUsageHint::MainView, ezCameraUsageHint::EditorView, GetWorld())) { it->ShowStats(pView); } } } } void ezCameraComponentManager::ReinitializeAllRenderTargetCameras() { EZ_LOCK(GetWorld()->GetWriteMarker()); for (auto it = GetComponents(); it.IsValid(); ++it) { if (it->IsActiveAndInitialized()) { it->DeactivateRenderToTexture(); it->ActivateRenderToTexture(); } } } const ezCameraComponent* ezCameraComponentManager::GetCameraByUsageHint(ezCameraUsageHint::Enum usageHint) const { for (auto it = GetComponents(); it.IsValid(); ++it) { if (it->IsActiveAndInitialized() && it->GetUsageHint() == usageHint) { return it; } } return nullptr; } ezCameraComponent* ezCameraComponentManager::GetCameraByUsageHint(ezCameraUsageHint::Enum usageHint) { for (auto it = GetComponents(); it.IsValid(); ++it) { if (it->IsActiveAndInitialized() && it->GetUsageHint() == usageHint) { return it; } } return nullptr; } void ezCameraComponentManager::AddRenderTargetCamera(ezCameraComponent* pComponent) { m_RenderTargetCameras.PushBack(pComponent->GetHandle()); } void ezCameraComponentManager::RemoveRenderTargetCamera(ezCameraComponent* pComponent) { m_RenderTargetCameras.RemoveAndSwap(pComponent->GetHandle()); } void ezCameraComponentManager::OnViewCreated(ezView* pView) { // Mark all cameras as modified so the new view gets the proper settings for (auto it = GetComponents(); it.IsValid(); ++it) { it->MarkAsModified(this); } } void ezCameraComponentManager::OnCameraConfigsChanged(void* dummy) { ReinitializeAllRenderTargetCameras(); } ////////////////////////////////////////////////////////////////////////// // clang-format off EZ_BEGIN_COMPONENT_TYPE(ezCameraComponent, 11, ezComponentMode::Static) { EZ_BEGIN_PROPERTIES { EZ_MEMBER_PROPERTY("EditorShortcut", m_iEditorShortcut)->AddAttributes(new ezDefaultValueAttribute(-1), new ezClampValueAttribute(-1, 9)), EZ_ENUM_ACCESSOR_PROPERTY("UsageHint", ezCameraUsageHint, GetUsageHint, SetUsageHint), EZ_ENUM_ACCESSOR_PROPERTY("Mode", ezCameraMode, GetCameraMode, SetCameraMode), EZ_ACCESSOR_PROPERTY("RenderTarget", GetRenderTargetFile, SetRenderTargetFile)->AddAttributes(new ezAssetBrowserAttribute("CompatibleAsset_Texture_Target", ezDependencyFlags::Package)), EZ_ACCESSOR_PROPERTY("RenderTargetOffset", GetRenderTargetRectOffset, SetRenderTargetRectOffset)->AddAttributes(new ezClampValueAttribute(ezVec2(0.0f), ezVec2(0.9f))), EZ_ACCESSOR_PROPERTY("RenderTargetSize", GetRenderTargetRectSize, SetRenderTargetRectSize)->AddAttributes(new ezDefaultValueAttribute(ezVec2(1.0f)), new ezClampValueAttribute(ezVec2(0.1f), ezVec2(1.0f))), EZ_ACCESSOR_PROPERTY("NearPlane", GetNearPlane, SetNearPlane)->AddAttributes(new ezDefaultValueAttribute(0.25f), new ezClampValueAttribute(0.01f, 4.0f)), EZ_ACCESSOR_PROPERTY("FarPlane", GetFarPlane, SetFarPlane)->AddAttributes(new ezDefaultValueAttribute(1000.0f), new ezClampValueAttribute(5.0, 10000.0f)), EZ_ACCESSOR_PROPERTY("FOV", GetFieldOfView, SetFieldOfView)->AddAttributes(new ezDefaultValueAttribute(60.0f), new ezClampValueAttribute(1.0f, 170.0f)), EZ_ACCESSOR_PROPERTY("Dimensions", GetOrthoDimension, SetOrthoDimension)->AddAttributes(new ezDefaultValueAttribute(10.0f), new ezClampValueAttribute(0.01f, 10000.0f)), EZ_SET_MEMBER_PROPERTY("IncludeTags", m_IncludeTags)->AddAttributes(new ezTagSetWidgetAttribute("Default")), EZ_SET_MEMBER_PROPERTY("ExcludeTags", m_ExcludeTags)->AddAttributes(new ezTagSetWidgetAttribute("Default")), EZ_ACCESSOR_PROPERTY("CameraRenderPipeline", GetRenderPipelineEnum, SetRenderPipelineEnum)->AddAttributes(new ezDynamicStringEnumAttribute("CameraPipelines")), EZ_ACCESSOR_PROPERTY("BlackboardName", GetBlackboardName, SetBlackboardName), EZ_ACCESSOR_PROPERTY("Aperture", GetAperture, SetAperture)->AddAttributes(new ezDefaultValueAttribute(1.0f), new ezClampValueAttribute(1.0f, 32.0f), new ezSuffixAttribute(" f-stop(s)")), EZ_ACCESSOR_PROPERTY("ShutterTime", GetShutterTime, SetShutterTime)->AddAttributes(new ezDefaultValueAttribute(ezTime::MakeFromSeconds(1.0)), new ezClampValueAttribute(ezTime::MakeFromSeconds(1.0f / 100000.0f), ezTime::MakeFromSeconds(600.0f))), EZ_ACCESSOR_PROPERTY("ISO", GetISO, SetISO)->AddAttributes(new ezDefaultValueAttribute(100.0f), new ezClampValueAttribute(50.0f, 64000.0f)), EZ_ACCESSOR_PROPERTY("ExposureCompensation", GetExposureCompensation, SetExposureCompensation)->AddAttributes(new ezClampValueAttribute(-32.0f, 32.0f)), EZ_MEMBER_PROPERTY("ShowStats", m_bShowStats), //EZ_ACCESSOR_PROPERTY_READ_ONLY("EV100", GetEV100), //EZ_ACCESSOR_PROPERTY_READ_ONLY("FinalExposure", GetExposure), } EZ_END_PROPERTIES; EZ_BEGIN_ATTRIBUTES { new ezCategoryAttribute("Rendering"), new ezDirectionVisualizerAttribute(ezBasisAxis::PositiveX, 1.0f, ezColor::DarkSlateBlue), new ezCameraVisualizerAttribute("Mode", "FOV", "Dimensions", "NearPlane", "FarPlane"), } EZ_END_ATTRIBUTES; } EZ_END_DYNAMIC_REFLECTED_TYPE; // clang-format on ezCameraComponent::ezCameraComponent() = default; ezCameraComponent::~ezCameraComponent() = default; void ezCameraComponent::SerializeComponent(ezWorldWriter& inout_stream) const { SUPER::SerializeComponent(inout_stream); auto& s = inout_stream.GetStream(); s << m_UsageHint.GetValue(); s << m_Mode.GetValue(); s << m_fNearPlane; s << m_fFarPlane; s << m_fPerspectiveFieldOfView; s << m_fOrthoDimension; // Version 2 till 7 // s << m_hRenderPipeline; // Version 3 s << m_fAperture; s << static_cast<float>(m_ShutterTime.GetSeconds()); s << m_fISO; s << m_fExposureCompensation; // Version 4 m_IncludeTags.Save(s); m_ExcludeTags.Save(s); // Version 6 s << m_hRenderTarget; // Version 7 s << m_vRenderTargetRectOffset; s << m_vRenderTargetRectSize; // Version 8 s << m_sRenderPipeline; // Version 10 s << m_bShowStats; // Version 11 s << m_sBlackboardName; } void ezCameraComponent::DeserializeComponent(ezWorldReader& inout_stream) { SUPER::DeserializeComponent(inout_stream); const ezUInt32 uiVersion = inout_stream.GetComponentTypeVersion(GetStaticRTTI()); auto& s = inout_stream.GetStream(); ezCameraUsageHint::StorageType usage; s >> usage; if (uiVersion == 1 && usage > ezCameraUsageHint::MainView) usage = ezCameraUsageHint::None; m_UsageHint.SetValue(usage); ezCameraMode::StorageType cam; s >> cam; m_Mode.SetValue(cam); s >> m_fNearPlane; s >> m_fFarPlane; s >> m_fPerspectiveFieldOfView; s >> m_fOrthoDimension; if (uiVersion >= 2 && uiVersion <= 7) { ezRenderPipelineResourceHandle m_hRenderPipeline; s >> m_hRenderPipeline; } if (uiVersion >= 3) { s >> m_fAperture; float shutterTime; s >> shutterTime; m_ShutterTime = ezTime::MakeFromSeconds(shutterTime); s >> m_fISO; s >> m_fExposureCompensation; } if (uiVersion >= 4) { m_IncludeTags.Load(s, ezTagRegistry::GetGlobalRegistry()); m_ExcludeTags.Load(s, ezTagRegistry::GetGlobalRegistry()); } if (uiVersion >= 6) { s >> m_hRenderTarget; } if (uiVersion >= 7) { s >> m_vRenderTargetRectOffset; s >> m_vRenderTargetRectSize; } if (uiVersion >= 8) { s >> m_sRenderPipeline; } if (uiVersion >= 10) { s >> m_bShowStats; } if (uiVersion >= 11) { s >> m_sBlackboardName; } MarkAsModified(); } void ezCameraComponent::UpdateRenderTargetCamera() { if (!m_bRenderTargetInitialized) return; // recreate everything, if the view got invalidated in between if (m_hRenderTargetView.IsInvalidated()) { DeactivateRenderToTexture(); ActivateRenderToTexture(); } ezView* pView = nullptr; if (!ezRenderWorld::TryGetView(m_hRenderTargetView, pView)) return; ApplySettingsToView(pView); if (m_Mode == ezCameraMode::PerspectiveFixedFovX || m_Mode == ezCameraMode::PerspectiveFixedFovY) m_RenderTargetCamera.SetCameraMode(GetCameraMode(), m_fPerspectiveFieldOfView, m_fNearPlane, m_fFarPlane); else m_RenderTargetCamera.SetCameraMode(GetCameraMode(), m_fOrthoDimension, m_fNearPlane, m_fFarPlane); m_RenderTargetCamera.LookAt( GetOwner()->GetGlobalPosition(), GetOwner()->GetGlobalPosition() + GetOwner()->GetGlobalDirForwards(), GetOwner()->GetGlobalDirUp()); } void ezCameraComponent::ShowStats(ezView* pView) { if (!m_bShowStats) return; // draw stats { const ezStringView sName = GetOwner()->GetName(); ezStringBuilder sb; sb.SetFormat("Camera '{0}':\nEV100: {1}, Exposure: {2}", sName.IsEmpty() ? pView->GetName() : sName, GetEV100(), GetExposure()); ezDebugRenderer::DrawInfoText(pView->GetHandle(), ezDebugTextPlacement::TopLeft, "CamStats", sb, ezColor::White); } // draw frustum { const ezGameObject* pOwner = GetOwner(); ezVec3 vPosition = pOwner->GetGlobalPosition(); ezVec3 vForward = pOwner->GetGlobalDirForwards(); ezVec3 vUp = pOwner->GetGlobalDirUp(); const ezMat4 viewMatrix = ezGraphicsUtils::CreateLookAtViewMatrix(vPosition, vPosition + vForward, vUp); ezMat4 projectionMatrix = pView->GetProjectionMatrix(ezCameraEye::Left); // todo: Stereo support ezMat4 viewProjectionMatrix = projectionMatrix * viewMatrix; ezFrustum frustum = ezFrustum::MakeFromMVP(viewProjectionMatrix); // TODO: limit far plane to 10 meters ezDebugRenderer::DrawLineFrustum(GetWorld(), frustum, ezColor::LimeGreen); } } void ezCameraComponent::SetUsageHint(ezEnum<ezCameraUsageHint> val) { if (val == m_UsageHint) return; DeactivateRenderToTexture(); m_UsageHint = val; ActivateRenderToTexture(); MarkAsModified(); } void ezCameraComponent::SetRenderTargetFile(ezStringView sFile) { DeactivateRenderToTexture(); if (!sFile.IsEmpty()) { m_hRenderTarget = ezResourceManager::LoadResource<ezRenderToTexture2DResource>(sFile); } else { m_hRenderTarget.Invalidate(); } ActivateRenderToTexture(); MarkAsModified(); } ezStringView ezCameraComponent::GetRenderTargetFile() const { return m_hRenderTarget.GetResourceID(); } void ezCameraComponent::SetRenderTargetRectOffset(ezVec2 value) { DeactivateRenderToTexture(); m_vRenderTargetRectOffset.x = ezMath::Clamp(value.x, 0.0f, 0.9f); m_vRenderTargetRectOffset.y = ezMath::Clamp(value.y, 0.0f, 0.9f); ActivateRenderToTexture(); } void ezCameraComponent::SetRenderTargetRectSize(ezVec2 value) { DeactivateRenderToTexture(); m_vRenderTargetRectSize.x = ezMath::Clamp(value.x, 0.1f, 1.0f); m_vRenderTargetRectSize.y = ezMath::Clamp(value.y, 0.1f, 1.0f); ActivateRenderToTexture(); } void ezCameraComponent::SetCameraMode(ezEnum<ezCameraMode> val) { if (val == m_Mode) return; m_Mode = val; MarkAsModified(); } void ezCameraComponent::SetNearPlane(float fVal) { if (fVal == m_fNearPlane) return; m_fNearPlane = fVal; MarkAsModified(); } void ezCameraComponent::SetFarPlane(float fVal) { if (fVal == m_fFarPlane) return; m_fFarPlane = fVal; MarkAsModified(); } void ezCameraComponent::SetFieldOfView(float fVal) { if (fVal == m_fPerspectiveFieldOfView) return; m_fPerspectiveFieldOfView = fVal; MarkAsModified(); } void ezCameraComponent::SetOrthoDimension(float fVal) { if (fVal == m_fOrthoDimension) return; m_fOrthoDimension = fVal; MarkAsModified(); } ezRenderPipelineResourceHandle ezCameraComponent::GetRenderPipeline() const { return m_hCachedRenderPipeline; } ezSharedPtr<ezBlackboard> ezCameraComponent::GetBlackboard() const { return m_pBlackboard; } ezViewHandle ezCameraComponent::GetRenderTargetView() const { return m_hRenderTargetView; } const char* ezCameraComponent::GetRenderPipelineEnum() const { return m_sRenderPipeline.GetData(); } void ezCameraComponent::SetBlackboardName(const char* szName) { if (m_sBlackboardName == szName) return; m_sBlackboardName.Assign(szName); if (IsActiveAndInitialized()) { m_pBlackboard = ezBlackboardComponent::FindBlackboard(*GetOwner(), m_sBlackboardName); } MarkAsModified(); } void ezCameraComponent::SetRenderPipelineEnum(const char* szFile) { DeactivateRenderToTexture(); m_sRenderPipeline.Assign(szFile); ActivateRenderToTexture(); MarkAsModified(); } void ezCameraComponent::SetAperture(float fAperture) { if (m_fAperture == fAperture) return; m_fAperture = fAperture; MarkAsModified(); } void ezCameraComponent::SetShutterTime(ezTime shutterTime) { if (m_ShutterTime == shutterTime) return; m_ShutterTime = shutterTime; MarkAsModified(); } void ezCameraComponent::SetISO(float fISO) { if (m_fISO == fISO) return; m_fISO = fISO; MarkAsModified(); } void ezCameraComponent::SetExposureCompensation(float fEC) { if (m_fExposureCompensation == fEC) return; m_fExposureCompensation = fEC; MarkAsModified(); } float ezCameraComponent::GetEV100() const { // From: course_notes_moving_frostbite_to_pbr.pdf // EV number is defined as: // 2^ EV_s = N^2 / t and EV_s = EV_100 + log2 (S /100) // This gives // EV_s = log2 (N^2 / t) // EV_100 + log2 (S /100) = log2 (N^2 / t) // EV_100 = log2 (N^2 / t) - log2 (S /100) // EV_100 = log2 (N^2 / t . 100 / S) return ezMath::Log2((m_fAperture * m_fAperture) / m_ShutterTime.AsFloatInSeconds() * 100.0f / m_fISO) - m_fExposureCompensation; } float ezCameraComponent::GetExposure() const { // Compute the maximum luminance possible with H_sbs sensitivity // maxLum = 78 / ( S * q ) * N^2 / t // = 78 / ( S * q ) * 2^ EV_100 // = 78 / (100 * 0.65) * 2^ EV_100 // = 1.2 * 2^ EV // Reference : http://en.wikipedia.org/wiki/Film_speed float maxLuminance = 1.2f * ezMath::Pow2(GetEV100()); return 1.0f / maxLuminance; } void ezCameraComponent::ApplySettingsToView(ezView* pView) const { if (m_UsageHint == ezCameraUsageHint::None) return; float fFovOrDim = m_fPerspectiveFieldOfView; if (m_Mode == ezCameraMode::OrthoFixedWidth || m_Mode == ezCameraMode::OrthoFixedHeight) { fFovOrDim = m_fOrthoDimension; } ezCamera* pCamera = pView->GetCamera(); pCamera->SetCameraMode(m_Mode, fFovOrDim, m_fNearPlane, ezMath::Max(m_fNearPlane + 0.00001f, m_fFarPlane)); pCamera->SetExposure(GetExposure()); pView->m_IncludeTags = m_IncludeTags; pView->m_ExcludeTags = m_ExcludeTags; const ezTag& tagEditor = ezTagRegistry::GetGlobalRegistry().RegisterTag("Editor"); pView->m_ExcludeTags.Set(tagEditor); if (m_hCachedRenderPipeline.IsValid()) { pView->SetRenderPipelineResource(m_hCachedRenderPipeline); } pView->SetBlackboard(m_pBlackboard); } void ezCameraComponent::ResourceChangeEventHandler(const ezResourceEvent& e) { switch (e.m_Type) { case ezResourceEvent::Type::ResourceExists: case ezResourceEvent::Type::ResourceCreated: return; case ezResourceEvent::Type::ResourceDeleted: case ezResourceEvent::Type::ResourceContentUnloading: case ezResourceEvent::Type::ResourceContentUpdated: // triggers a recreation of the view ezRenderWorld::DeleteView(m_hRenderTargetView); m_hRenderTargetView.Invalidate(); break; default: break; } } void ezCameraComponent::MarkAsModified() { if (!m_bIsModified) { GetWorld()->GetComponentManager<ezCameraComponentManager>()->m_ModifiedCameras.PushBack(GetHandle()); m_bIsModified = true; } } void ezCameraComponent::MarkAsModified(ezCameraComponentManager* pCameraManager) { if (!m_bIsModified) { pCameraManager->m_ModifiedCameras.PushBack(GetHandle()); m_bIsModified = true; } } void ezCameraComponent::ActivateRenderToTexture() { if (m_UsageHint != ezCameraUsageHint::RenderTarget) return; if (m_bRenderTargetInitialized || !m_hRenderTarget.IsValid() || m_sRenderPipeline.IsEmpty() || !IsActiveAndInitialized()) return; ezResourceLock<ezRenderToTexture2DResource> pRenderTarget(m_hRenderTarget, ezResourceAcquireMode::BlockTillLoaded_NeverFail); if (pRenderTarget.GetAcquireResult() != ezResourceAcquireResult::Final) { return; } // query the render pipeline to use if (const auto* pConfig = ezRenderWorld::FindCameraConfig(m_sRenderPipeline)) { m_hCachedRenderPipeline = pConfig->m_hRenderPipeline; } if (!m_hCachedRenderPipeline.IsValid()) return; m_bRenderTargetInitialized = true; EZ_ASSERT_DEV(m_hRenderTargetView.IsInvalidated(), "Render target view is already created"); ezStringBuilder name; name.SetFormat("Camera RT: {0}", GetOwner()->GetName()); ezView* pRenderTargetView = nullptr; m_hRenderTargetView = ezRenderWorld::CreateView(name, pRenderTargetView); pRenderTargetView->SetRenderPipelineResource(m_hCachedRenderPipeline); pRenderTargetView->SetWorld(GetWorld()); pRenderTargetView->SetCamera(&m_RenderTargetCamera); pRenderTarget->m_ResourceEvents.AddEventHandler(ezMakeDelegate(&ezCameraComponent::ResourceChangeEventHandler, this)); ezGALRenderTargets renderTargets; renderTargets.m_hRTs[0] = pRenderTarget->GetGALTexture(); pRenderTargetView->SetRenderTargets(renderTargets); const float maxSizeX = 1.0f - m_vRenderTargetRectOffset.x; const float maxSizeY = 1.0f - m_vRenderTargetRectOffset.y; const float resX = (float)pRenderTarget->GetWidth(); const float resY = (float)pRenderTarget->GetHeight(); const float width = resX * ezMath::Min(maxSizeX, m_vRenderTargetRectSize.x); const float height = resY * ezMath::Min(maxSizeY, m_vRenderTargetRectSize.y); const float offsetX = m_vRenderTargetRectOffset.x * resX; const float offsetY = m_vRenderTargetRectOffset.y * resY; pRenderTargetView->SetViewport(ezRectFloat(offsetX, offsetY, width, height)); pRenderTarget->AddRenderView(m_hRenderTargetView); GetWorld()->GetComponentManager<ezCameraComponentManager>()->AddRenderTargetCamera(this); } void ezCameraComponent::DeactivateRenderToTexture() { if (!m_bRenderTargetInitialized) return; m_bRenderTargetInitialized = false; m_hCachedRenderPipeline.Invalidate(); EZ_ASSERT_DEBUG(m_hRenderTarget.IsValid(), "Render Target should be valid"); if (m_hRenderTarget.IsValid()) { ezResourceLock<ezRenderToTexture2DResource> pRenderTarget(m_hRenderTarget, ezResourceAcquireMode::BlockTillLoaded); pRenderTarget->RemoveRenderView(m_hRenderTargetView); pRenderTarget->m_ResourceEvents.RemoveEventHandler(ezMakeDelegate(&ezCameraComponent::ResourceChangeEventHandler, this)); } if (!m_hRenderTargetView.IsInvalidated()) { ezRenderWorld::DeleteView(m_hRenderTargetView); m_hRenderTargetView.Invalidate(); } GetWorld()->GetComponentManager<ezCameraComponentManager>()->RemoveRenderTargetCamera(this); } void ezCameraComponent::OnActivated() { SUPER::OnActivated(); ActivateRenderToTexture(); m_pBlackboard = ezBlackboardComponent::FindBlackboard(*GetOwner(), m_sBlackboardName); } void ezCameraComponent::OnDeactivated() { DeactivateRenderToTexture(); SUPER::OnDeactivated(); } ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// #include <Foundation/Serialization/AbstractObjectGraph.h> #include <Foundation/Serialization/GraphPatch.h> class ezCameraComponentPatch_4_5 : public ezGraphPatch { public: ezCameraComponentPatch_4_5() : ezGraphPatch("ezCameraComponent", 5) { } virtual void Patch(ezGraphPatchContext& ref_context, ezAbstractObjectGraph* pGraph, ezAbstractObjectNode* pNode) const override { pNode->RenameProperty("Usage Hint", "UsageHint"); pNode->RenameProperty("Near Plane", "NearPlane"); pNode->RenameProperty("Far Plane", "FarPlane"); pNode->RenameProperty("Include Tags", "IncludeTags"); pNode->RenameProperty("Exclude Tags", "ExcludeTags"); pNode->RenameProperty("Render Pipeline", "RenderPipeline"); pNode->RenameProperty("Shutter Time", "ShutterTime"); pNode->RenameProperty("Exposure Compensation", "ExposureCompensation"); } }; ezCameraComponentPatch_4_5 g_ezCameraComponentPatch_4_5; ////////////////////////////////////////////////////////////////////////// class ezCameraComponentPatch_8_9 : public ezGraphPatch { public: ezCameraComponentPatch_8_9() : ezGraphPatch("ezCameraComponent", 9) { } virtual void Patch(ezGraphPatchContext& ref_context, ezAbstractObjectGraph* pGraph, ezAbstractObjectNode* pNode) const override { // convert the "ShutterTime" property from float to ezTime if (auto pProp = pNode->FindProperty("ShutterTime")) { if (pProp->m_Value.IsA<float>()) { const float shutterTime = pProp->m_Value.Get<float>(); pProp->m_Value = ezTime::MakeFromSeconds(shutterTime); } } } }; ezCameraComponentPatch_8_9 g_ezCameraComponentPatch_8_9; EZ_STATICLINK_FILE(RendererCore, RendererCore_Components_Implementation_CameraComponent);