From e548dbfb1933ba349461512162c8c70a486426a7 Mon Sep 17 00:00:00 2001 From: artkez <33177434+artkez@users.noreply.github.com> Date: Thu, 16 Jun 2022 10:28:57 +0300 Subject: [PATCH] EnvironmentProbe selectable resolution --- .../Engine/Core/Config/GraphicsSettings.cpp | 1 + Source/Engine/Core/Config/GraphicsSettings.h | 16 +++++++++++++ Source/Engine/Graphics/Graphics.cpp | 1 + Source/Engine/Graphics/Graphics.h | 5 ++++ .../Engine/Level/Actors/EnvironmentProbe.cpp | 9 +++++++- Source/Engine/Level/Actors/EnvironmentProbe.h | 17 ++++++++++++++ Source/Engine/Renderer/ProbesRenderer.cpp | 23 +++++++++++++++---- 7 files changed, 66 insertions(+), 6 deletions(-) diff --git a/Source/Engine/Core/Config/GraphicsSettings.cpp b/Source/Engine/Core/Config/GraphicsSettings.cpp index 75f302701..6e6e604f3 100644 --- a/Source/Engine/Core/Config/GraphicsSettings.cpp +++ b/Source/Engine/Core/Config/GraphicsSettings.cpp @@ -13,6 +13,7 @@ void GraphicsSettings::Apply() Graphics::ShadowsQuality = ShadowsQuality; Graphics::ShadowMapsQuality = ShadowMapsQuality; Graphics::AllowCSMBlending = AllowCSMBlending; + Graphics::DefaultProbeResolution = (int32)DefaultProbeResolution; Graphics::GlobalSDFQuality = GlobalSDFQuality; Graphics::GIQuality = GIQuality; Graphics::GlobalSurfaceAtlasResolution = GlobalSurfaceAtlasResolution; diff --git a/Source/Engine/Core/Config/GraphicsSettings.h b/Source/Engine/Core/Config/GraphicsSettings.h index 920a3cc0f..1e735b507 100644 --- a/Source/Engine/Core/Config/GraphicsSettings.h +++ b/Source/Engine/Core/Config/GraphicsSettings.h @@ -63,6 +63,22 @@ public: API_FIELD(Attributes="EditorOrder(1320), DefaultValue(false), EditorDisplay(\"Quality\", \"Allow CSM Blending\")") bool AllowCSMBlending = false; + /// + /// Default probes cubemap resolution. + /// + API_ENUM() enum class DefaultProbeResolutions + { + _64 = 64, + _128 = 128, + _256 = 256, + _512 = 512, + _1024 = 1024, + _2048 = 2048, + _4096 = 4096, + }; + API_FIELD(Attributes = "EditorOrder(1500), DefaultValue(DefaultProbeResolutions._512), EditorDisplay(\"Quality\", \"Default Probe Resolution\")") + DefaultProbeResolutions DefaultProbeResolution = DefaultProbeResolutions::_512; + /// /// If checked, enables Global SDF rendering. This can be used in materials, shaders, and particles. /// diff --git a/Source/Engine/Graphics/Graphics.cpp b/Source/Engine/Graphics/Graphics.cpp index 0f0a60c2f..52e0686d2 100644 --- a/Source/Engine/Graphics/Graphics.cpp +++ b/Source/Engine/Graphics/Graphics.cpp @@ -14,6 +14,7 @@ Quality Graphics::VolumetricFogQuality = Quality::High; Quality Graphics::ShadowsQuality = Quality::Medium; Quality Graphics::ShadowMapsQuality = Quality::Medium; bool Graphics::AllowCSMBlending = false; +int32 Graphics::DefaultProbeResolution = 512; Quality Graphics::GlobalSDFQuality = Quality::High; Quality Graphics::GIQuality = Quality::High; int32 Graphics::GlobalSurfaceAtlasResolution = 2048; diff --git a/Source/Engine/Graphics/Graphics.h b/Source/Engine/Graphics/Graphics.h index a1aed898c..45f5ea42e 100644 --- a/Source/Engine/Graphics/Graphics.h +++ b/Source/Engine/Graphics/Graphics.h @@ -53,6 +53,11 @@ public: /// API_FIELD() static bool AllowCSMBlending; + /// + /// Default probes cubemap resolution. + /// + API_FIELD() static int32 DefaultProbeResolution; + /// /// The Global SDF quality. Controls the volume texture resolution and amount of cascades to use. /// diff --git a/Source/Engine/Level/Actors/EnvironmentProbe.cpp b/Source/Engine/Level/Actors/EnvironmentProbe.cpp index ea9e7bd07..445607a1d 100644 --- a/Source/Engine/Level/Actors/EnvironmentProbe.cpp +++ b/Source/Engine/Level/Actors/EnvironmentProbe.cpp @@ -13,6 +13,7 @@ #include "Engine/ContentImporters/AssetsImportingManager.h" #include "Engine/Serialization/Serialization.h" #include "Engine/Level/Scene/Scene.h" +#include "Engine/Graphics/Graphics.h" EnvironmentProbe::EnvironmentProbe(const SpawnParams& params) : Actor(params) @@ -80,8 +81,12 @@ void EnvironmentProbe::Bake(float timeout) void EnvironmentProbe::SetProbeData(TextureData& data) { + int32 probeResolution = (int32)CubemapResolution; + // if Use Graphics Settings + if (probeResolution == 0) probeResolution = Graphics::DefaultProbeResolution; + // Validate input data - ASSERT(data.GetArraySize() == 6 && data.Height == ENV_PROBES_RESOLUTION && data.Width == ENV_PROBES_RESOLUTION); + ASSERT(data.GetArraySize() == 6 && data.Height == probeResolution && data.Width == probeResolution); // Check if was using custom probe if (_isUsingCustomProbe) @@ -170,6 +175,7 @@ void EnvironmentProbe::Serialize(SerializeStream& stream, const void* otherObj) SERIALIZE_GET_OTHER_OBJ(EnvironmentProbe); SERIALIZE_MEMBER(Radius, _radius); + SERIALIZE(CubemapResolution); SERIALIZE(Brightness); SERIALIZE(AutoUpdate); SERIALIZE(CaptureNearPlane); @@ -183,6 +189,7 @@ void EnvironmentProbe::Deserialize(DeserializeStream& stream, ISerializeModifier Actor::Deserialize(stream, modifier); DESERIALIZE_MEMBER(Radius, _radius); + DESERIALIZE(CubemapResolution); DESERIALIZE(Brightness); DESERIALIZE(AutoUpdate); DESERIALIZE(CaptureNearPlane); diff --git a/Source/Engine/Level/Actors/EnvironmentProbe.h b/Source/Engine/Level/Actors/EnvironmentProbe.h index cc84d2f1b..fdab53eb8 100644 --- a/Source/Engine/Level/Actors/EnvironmentProbe.h +++ b/Source/Engine/Level/Actors/EnvironmentProbe.h @@ -19,6 +19,23 @@ private: AssetReference _probe; public: + /// + /// The reflections texture resolution. + /// + API_ENUM() enum class CubemapResolutions + { + UseGraphicsSettings = 0, + _64 = 64, + _128 = 128, + _256 = 256, + _512 = 512, + _1024 = 1024, + _2048 = 2048, + _4096 = 4096, + }; + API_FIELD(Attributes = "EditorOrder(0), DefaultValue(CubemapResolutions.UseGraphicsSettings), EditorDisplay(\"Probe\")") + CubemapResolutions CubemapResolution = CubemapResolutions::UseGraphicsSettings; + /// /// The reflections brightness. /// diff --git a/Source/Engine/Renderer/ProbesRenderer.cpp b/Source/Engine/Renderer/ProbesRenderer.cpp index 6038b8362..4cc407390 100644 --- a/Source/Engine/Renderer/ProbesRenderer.cpp +++ b/Source/Engine/Renderer/ProbesRenderer.cpp @@ -22,6 +22,7 @@ #include "Engine/Graphics/Textures/TextureData.h" #include "Engine/Graphics/RenderTask.h" #include "Engine/Engine/Engine.h" +#include "Engine/Graphics/Graphics.h" /// /// Custom task called after downloading probe texture data to save it. @@ -278,7 +279,15 @@ bool ProbesRenderer::Init() // Init rendering pipeline _output = GPUDevice::Instance->CreateTexture(TEXT("Output")); - if (_output->Init(GPUTextureDescription::New2D(ENV_PROBES_RESOLUTION, ENV_PROBES_RESOLUTION, ENV_PROBES_FORMAT))) + int32 probeResolution = ENV_PROBES_RESOLUTION; + if (_current.Type == EntryType::EnvProbe) + { + auto envProbe = (EnvironmentProbe*)_current.Actor.Get(); + probeResolution = (int32)envProbe->CubemapResolution; + // if Use Graphics Settings + if (probeResolution == 0) probeResolution = Graphics::DefaultProbeResolution; + } + if (_output->Init(GPUTextureDescription::New2D(probeResolution, probeResolution, ENV_PROBES_FORMAT))) return true; _task = New(); auto task = _task; @@ -300,15 +309,15 @@ bool ProbesRenderer::Init() view.StaticFlagsMask = StaticFlags::ReflectionProbe; view.MaxShadowsQuality = Quality::Low; task->IsCameraCut = true; - task->Resize(ENV_PROBES_RESOLUTION, ENV_PROBES_RESOLUTION); + task->Resize(probeResolution, probeResolution); task->Render.Bind(onRender); // Init render targets _probe = GPUDevice::Instance->CreateTexture(TEXT("ProbesUpdate.Probe")); - if (_probe->Init(GPUTextureDescription::NewCube(ENV_PROBES_RESOLUTION, ENV_PROBES_FORMAT, GPUTextureFlags::ShaderResource | GPUTextureFlags::RenderTarget | GPUTextureFlags::PerMipViews, 0))) + if (_probe->Init(GPUTextureDescription::NewCube(probeResolution, ENV_PROBES_FORMAT, GPUTextureFlags::ShaderResource | GPUTextureFlags::RenderTarget | GPUTextureFlags::PerMipViews, 0))) return true; _tmpFace = GPUDevice::Instance->CreateTexture(TEXT("ProbesUpdate.TmpFae")); - if (_tmpFace->Init(GPUTextureDescription::New2D(ENV_PROBES_RESOLUTION, ENV_PROBES_RESOLUTION, 0, ENV_PROBES_FORMAT, GPUTextureFlags::ShaderResource | GPUTextureFlags::RenderTarget | GPUTextureFlags::PerMipViews))) + if (_tmpFace->Init(GPUTextureDescription::New2D(probeResolution, probeResolution, 0, ENV_PROBES_FORMAT, GPUTextureFlags::ShaderResource | GPUTextureFlags::RenderTarget | GPUTextureFlags::PerMipViews))) return true; // Mark as ready @@ -465,9 +474,13 @@ void ProbesRenderer::onRender(RenderTask* task, GPUContext* context) // Init float customCullingNear = -1; + int32 probeResolution = ENV_PROBES_RESOLUTION; if (_current.Type == EntryType::EnvProbe) { auto envProbe = (EnvironmentProbe*)_current.Actor.Get(); + probeResolution = (int32)envProbe->CubemapResolution; + // if Use Graphics Settings + if (probeResolution == 0) probeResolution = Graphics::DefaultProbeResolution; LOG(Info, "Updating Env probe '{0}'...", envProbe->ToString()); Vector3 position = envProbe->GetPosition(); float radius = envProbe->GetScaledRadius(); @@ -523,7 +536,7 @@ void ProbesRenderer::onRender(RenderTask* task, GPUContext* context) { PROFILE_GPU("Copy Face"); context->SetRenderTarget(_probe->View(faceIndex)); - context->SetViewportAndScissors(ENV_PROBES_RESOLUTION, ENV_PROBES_RESOLUTION); + context->SetViewportAndScissors(probeResolution, probeResolution); auto probeFrame = _output->View(); if (setLowerHemisphereToBlack && faceIndex != 2) {