diff --git a/Source/Engine/Core/Config/GraphicsSettings.cpp b/Source/Engine/Core/Config/GraphicsSettings.cpp index d10df48d2..6ae8d5a4a 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::PostProcessSettings = PostProcessSettings; diff --git a/Source/Engine/Core/Config/GraphicsSettings.h b/Source/Engine/Core/Config/GraphicsSettings.h index 2ce028c95..e6ab31c3c 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 aaa5dc2d8..2d0698877 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; PostProcessSettings Graphics::PostProcessSettings; diff --git a/Source/Engine/Graphics/Graphics.h b/Source/Engine/Graphics/Graphics.h index c5933cfc1..65c80c25b 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 31f60bb4d..231439a5a 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 b2dac5f15..65b4d3b59 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 3582cab32..41bf78c51 100644 --- a/Source/Engine/Renderer/ProbesRenderer.cpp +++ b/Source/Engine/Renderer/ProbesRenderer.cpp @@ -23,6 +23,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. @@ -279,7 +280,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; @@ -301,15 +310,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(); @@ -525,7 +538,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) {