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 1/3] 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) { From 1b4dded11e922597b3a78b6157a0d67a61d03a58 Mon Sep 17 00:00:00 2001 From: artkez <33177434+artkez@users.noreply.github.com> Date: Fri, 17 Jun 2022 11:14:27 +0300 Subject: [PATCH 2/3] Added Smoothstep and Step Material Nodes --- Source/Editor/Surface/Archetypes/Math.cs | 54 ++++++++++++++++++++++++ Source/Engine/Visject/ShaderGraph.cpp | 17 ++++++++ 2 files changed, 71 insertions(+) diff --git a/Source/Editor/Surface/Archetypes/Math.cs b/Source/Editor/Surface/Archetypes/Math.cs index 063e2f931..ee62e735b 100644 --- a/Source/Editor/Surface/Archetypes/Math.cs +++ b/Source/Editor/Surface/Archetypes/Math.cs @@ -441,6 +441,60 @@ namespace FlaxEditor.Surface.Archetypes NodeElementArchetype.Factory.Output(0, string.Empty, typeof(Float3), 2), } }, + new NodeArchetype + { + TypeID = 50, + Title = "Smoothstep", + Description = "Returns a smooth Hermite interpolation between 0 and 1, if value is in the range [min, max].", + Flags = NodeFlags.MaterialGraph, + Size = new Float2(110, 60), + ConnectionsHints = ConnectionsHint.Numeric, + IndependentBoxes = new[] + { + 0, + 1, + 2 + }, + DependentBoxes = new[] { 3 }, + DefaultValues = new object[] + { + 0.0f, + 1.0f, + }, + Elements = new[] + { + NodeElementArchetype.Factory.Input(0, "Min", true, null, 0), + NodeElementArchetype.Factory.Input(1, "Max", true, null, 1), + NodeElementArchetype.Factory.Input(2, "Value", true, null, 2, 1), + NodeElementArchetype.Factory.Output(0, "Result", null, 3) + }, + }, + new NodeArchetype + { + TypeID = 51, + Title = "Step", + Description = "Compares two values, returning 0 or 1 based on which value is greater.", + Flags = NodeFlags.MaterialGraph, + Size = new Float2(110, 40), + ConnectionsHints = ConnectionsHint.Numeric, + IndependentBoxes = new[] + { + 0, + 1, + }, + DependentBoxes = new[] { 2 }, + DefaultValues = new object[] + { + 0.0f, + 1.0f, + }, + Elements = new[] + { + NodeElementArchetype.Factory.Input(0, "Min", true, null, 0), + NodeElementArchetype.Factory.Input(1, "Max", true, null, 1), + NodeElementArchetype.Factory.Output(0, "Result", null, 2) + }, + }, }; } } diff --git a/Source/Engine/Visject/ShaderGraph.cpp b/Source/Engine/Visject/ShaderGraph.cpp index 82a09c909..5a0437e9e 100644 --- a/Source/Engine/Visject/ShaderGraph.cpp +++ b/Source/Engine/Visject/ShaderGraph.cpp @@ -417,6 +417,23 @@ void ShaderGenerator::ProcessGroupMath(Box* box, Node* node, Value& value) value = writeLocal(ValueType::Float3, String::Format(TEXT("QuatRotateVector({0}, {1})"), quaternion.Value, vector.Value), node); break; } + // Smoothstep + case 50: + { + Value v1 = tryGetValue(node->GetBox(0), Value::Zero); + Value v2 = tryGetValue(node->GetBox(1), Value::Zero); + Value v3 = tryGetValue(node->GetBox(2), Value::Zero); + value = writeFunction3(node, v1, v2, v3, TEXT("smoothstep"), v1.Type); + break; + } + // Step + case 51: + { + Value v1 = tryGetValue(node->GetBox(0), Value::Zero); + Value v2 = tryGetValue(node->GetBox(1), Value::Zero); + value = writeFunction2(node, v1, v2, TEXT("step")); + break; + } default: break; } From 0872d10f43833d1eecc258ffa7f82ce976385a6d Mon Sep 17 00:00:00 2001 From: artkez <33177434+artkez@users.noreply.github.com> Date: Fri, 17 Jun 2022 11:20:26 +0300 Subject: [PATCH 3/3] Revert "Added Smoothstep and Step Material Nodes" This reverts commit 1b4dded11e922597b3a78b6157a0d67a61d03a58. --- Source/Editor/Surface/Archetypes/Math.cs | 54 ------------------------ Source/Engine/Visject/ShaderGraph.cpp | 17 -------- 2 files changed, 71 deletions(-) diff --git a/Source/Editor/Surface/Archetypes/Math.cs b/Source/Editor/Surface/Archetypes/Math.cs index ee62e735b..063e2f931 100644 --- a/Source/Editor/Surface/Archetypes/Math.cs +++ b/Source/Editor/Surface/Archetypes/Math.cs @@ -441,60 +441,6 @@ namespace FlaxEditor.Surface.Archetypes NodeElementArchetype.Factory.Output(0, string.Empty, typeof(Float3), 2), } }, - new NodeArchetype - { - TypeID = 50, - Title = "Smoothstep", - Description = "Returns a smooth Hermite interpolation between 0 and 1, if value is in the range [min, max].", - Flags = NodeFlags.MaterialGraph, - Size = new Float2(110, 60), - ConnectionsHints = ConnectionsHint.Numeric, - IndependentBoxes = new[] - { - 0, - 1, - 2 - }, - DependentBoxes = new[] { 3 }, - DefaultValues = new object[] - { - 0.0f, - 1.0f, - }, - Elements = new[] - { - NodeElementArchetype.Factory.Input(0, "Min", true, null, 0), - NodeElementArchetype.Factory.Input(1, "Max", true, null, 1), - NodeElementArchetype.Factory.Input(2, "Value", true, null, 2, 1), - NodeElementArchetype.Factory.Output(0, "Result", null, 3) - }, - }, - new NodeArchetype - { - TypeID = 51, - Title = "Step", - Description = "Compares two values, returning 0 or 1 based on which value is greater.", - Flags = NodeFlags.MaterialGraph, - Size = new Float2(110, 40), - ConnectionsHints = ConnectionsHint.Numeric, - IndependentBoxes = new[] - { - 0, - 1, - }, - DependentBoxes = new[] { 2 }, - DefaultValues = new object[] - { - 0.0f, - 1.0f, - }, - Elements = new[] - { - NodeElementArchetype.Factory.Input(0, "Min", true, null, 0), - NodeElementArchetype.Factory.Input(1, "Max", true, null, 1), - NodeElementArchetype.Factory.Output(0, "Result", null, 2) - }, - }, }; } } diff --git a/Source/Engine/Visject/ShaderGraph.cpp b/Source/Engine/Visject/ShaderGraph.cpp index 5a0437e9e..82a09c909 100644 --- a/Source/Engine/Visject/ShaderGraph.cpp +++ b/Source/Engine/Visject/ShaderGraph.cpp @@ -417,23 +417,6 @@ void ShaderGenerator::ProcessGroupMath(Box* box, Node* node, Value& value) value = writeLocal(ValueType::Float3, String::Format(TEXT("QuatRotateVector({0}, {1})"), quaternion.Value, vector.Value), node); break; } - // Smoothstep - case 50: - { - Value v1 = tryGetValue(node->GetBox(0), Value::Zero); - Value v2 = tryGetValue(node->GetBox(1), Value::Zero); - Value v3 = tryGetValue(node->GetBox(2), Value::Zero); - value = writeFunction3(node, v1, v2, v3, TEXT("smoothstep"), v1.Type); - break; - } - // Step - case 51: - { - Value v1 = tryGetValue(node->GetBox(0), Value::Zero); - Value v2 = tryGetValue(node->GetBox(1), Value::Zero); - value = writeFunction2(node, v1, v2, TEXT("step")); - break; - } default: break; }