From 318fe00dafb5d7582640836ec21e2de374660b15 Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Sat, 30 Sep 2023 18:29:22 -0400 Subject: [PATCH] Serialized all env settings now --- Editor/src/Windows/EditorInterface.cpp | 3 +- Nuake/src/Rendering/SceneRenderer.cpp | 7 +- Nuake/src/Rendering/SceneRenderer.h | 2 - Nuake/src/Scene/Lighting/Environment.cpp | 259 +++++++++++++++++++++-- Nuake/src/Scene/Lighting/Environment.h | 22 +- 5 files changed, 259 insertions(+), 34 deletions(-) diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 7aa815aa..0999ba9d 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -903,7 +903,7 @@ namespace Nuake { ImGui::TableSetupColumn("set", 0, 0.6); ImGui::TableSetupColumn("reset", 0, 0.1); - SSR* ssr = scene->m_SceneRenderer->mSSR.get(); + SSR* ssr = env->mSSR.get(); { ImGui::TableNextColumn(); // Title @@ -1112,7 +1112,6 @@ namespace Nuake { ImGui::TableSetupColumn("name", 0, 0.3); ImGui::TableSetupColumn("set", 0, 0.6); ImGui::TableSetupColumn("reset", 0, 0.1); - { ImGui::TableNextColumn(); diff --git a/Nuake/src/Rendering/SceneRenderer.cpp b/Nuake/src/Rendering/SceneRenderer.cpp index 988e3417..c4712899 100644 --- a/Nuake/src/Rendering/SceneRenderer.cpp +++ b/Nuake/src/Rendering/SceneRenderer.cpp @@ -26,7 +26,6 @@ namespace Nuake mShadingBuffer = CreateScope(true, defaultResolution); mShadingBuffer->SetTexture(CreateRef(defaultResolution, GL_RGB, GL_RGB16F, GL_FLOAT)); - mSSR = CreateScope(); mToneMapBuffer = CreateScope(false, defaultResolution); mToneMapBuffer->SetTexture(CreateRef(defaultResolution, GL_RGB), GL_COLOR_ATTACHMENT0); @@ -152,8 +151,8 @@ namespace Nuake if (sceneEnv->SSREnabled) { - mSSR->Resize(framebuffer.GetSize()); - mSSR->Draw(mGBuffer.get(), framebuffer.GetTexture(), mView, mProjection, scene.GetCurrentCamera()); + sceneEnv->mSSR->Resize(framebuffer.GetSize()); + sceneEnv->mSSR->Draw(mGBuffer.get(), framebuffer.GetTexture(), mView, mProjection, scene.GetCurrentCamera()); framebuffer.Bind(); { @@ -162,7 +161,7 @@ namespace Nuake shader->Bind(); shader->SetUniformTex("u_Source", mToneMapBuffer->GetTexture().get(), 0); - shader->SetUniformTex("u_Source2", mSSR->OutputFramebuffer->GetTexture().get(), 1); + shader->SetUniformTex("u_Source2", sceneEnv->mSSR->OutputFramebuffer->GetTexture().get(), 1); Renderer::DrawQuad(); } framebuffer.Unbind(); diff --git a/Nuake/src/Rendering/SceneRenderer.h b/Nuake/src/Rendering/SceneRenderer.h index 0f791e22..f82267dc 100644 --- a/Nuake/src/Rendering/SceneRenderer.h +++ b/Nuake/src/Rendering/SceneRenderer.h @@ -19,8 +19,6 @@ namespace Nuake void BeginRenderScene(const Matrix4& projection, const Matrix4& view, const Vector3& camPos); void RenderScene(Scene& scene, FrameBuffer& framebuffer); - Scope mSSR; - FrameBuffer& GetGBuffer() const { return *mGBuffer; diff --git a/Nuake/src/Scene/Lighting/Environment.cpp b/Nuake/src/Scene/Lighting/Environment.cpp index 87b3126a..7149adc4 100644 --- a/Nuake/src/Scene/Lighting/Environment.cpp +++ b/Nuake/src/Scene/Lighting/Environment.cpp @@ -1,16 +1,46 @@ #pragma once #include "Environment.h" -#include "src/Rendering/Renderer.h" + #include "src/Core/Core.h" + namespace Nuake { + Environment::Environment() { m_AmbientColor = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); ProceduralSkybox = CreateRef(); + + CurrentSkyType = SkyType::ProceduralSky; + AmbientColor = Color(0.2, 0.2, 0.2, 1.0f); + AmbientTerm = 0.5f; + + VolumetricEnabled = true; + VolumetricFog = 0.9f; + VolumetricStepCount = 50.0f; + + // Bloom + BloomEnabled = true; + SSAOEnabled = true; + SSREnabled = true; + + // DOF + DOFEnabled = false; + BarrelDistortionEnabled = false; + BarrelDistortion = 0.0f; + BarrelEdgeDistortion = 0.0f; + BarrelScale = 1.0f; + + // Vignette + VignetteEnabled = false; + VignetteIntensity = 150.0f; + VignetteExtend = 0.150f; + + // POST FX mBloom = CreateScope(4); mVolumetric = CreateScope(); mSSAO = CreateScope(); + mSSR = CreateScope(); } glm::vec4 Environment::GetAmbientColor() @@ -23,12 +53,6 @@ namespace Nuake { m_AmbientColor = color; } - void Environment::Push() - { - Renderer::m_Shader->SetUniform1f("u_FogAmount", VolumetricFog); - Renderer::m_Shader->SetUniform1f("u_FogStepCount", VolumetricStepCount); - } - Ref Environment::Copy() { Ref copy = CreateRef(); @@ -52,29 +76,234 @@ namespace Nuake { { BEGIN_SERIALIZE(); SERIALIZE_VAL(CurrentSkyType); - SERIALIZE_VEC4(AmbientColor); + + // Bloom + SERIALIZE_VAL(BloomEnabled); + SERIALIZE_VAL_LBL("BloomThreshold", mBloom->GetThreshold()); + SERIALIZE_VAL_LBL("BloomIteration", mBloom->GetIteration()); + + // Volumetric + SERIALIZE_VAL(VolumetricEnabled); SERIALIZE_VAL(VolumetricFog); SERIALIZE_VAL(VolumetricStepCount); + + // SSR + SERIALIZE_VAL(SSREnabled); + SERIALIZE_VAL_LBL("SSRRayStep", mSSR->RayStep); + SERIALIZE_VAL_LBL("SSRIterationCount", mSSR->IterationCount); + SERIALIZE_VAL_LBL("SSRDistanceBias", mSSR->DistanceBias); + SERIALIZE_VAL_LBL("SSRSampleCount", mSSR->SampleCount); + SERIALIZE_VAL_LBL("SSRSamplingEnabled", mSSR->SamplingEnabled); + SERIALIZE_VAL_LBL("SSRExpoStep", mSSR->ExpoStep); + SERIALIZE_VAL_LBL("SSRAdaptiveStep", mSSR->AdaptiveStep); + SERIALIZE_VAL_LBL("SSRBinarySearch", mSSR->BinarySearch); + SERIALIZE_VAL_LBL("SSRSampleingCoefficient", mSSR->SampleingCoefficient); + + // SSAO + SERIALIZE_VAL(SSAOEnabled); + SERIALIZE_VAL_LBL("SSAORadius", mSSAO->Radius); + SERIALIZE_VAL_LBL("SSAOBias", mSSAO->Bias); + SERIALIZE_VAL_LBL("SSAOArea", mSSAO->Area); + SERIALIZE_VAL_LBL("SSAOFalloff", mSSAO->Falloff); + SERIALIZE_VAL_LBL("SSAOStrength", mSSAO->Strength); + + // DOF + SERIALIZE_VAL(DOFEnabled); + + // Barrel distortion + SERIALIZE_VAL(BarrelDistortionEnabled); + SERIALIZE_VAL(BarrelDistortion); + SERIALIZE_VAL(BarrelEdgeDistortion); + SERIALIZE_VAL(BarrelScale); + + // Vignette + SERIALIZE_VAL(VignetteEnabled); + SERIALIZE_VAL(VignetteExtend); + SERIALIZE_VAL(VignetteIntensity); + + SERIALIZE_VAL(AmbientTerm); SERIALIZE_VEC4(AmbientColor); + SERIALIZE_OBJECT(ProceduralSkybox); END_SERIALIZE(); } bool Environment::Deserialize(const json& j) { + // SKY if (j.contains("CurrentSkyType")) + { CurrentSkyType = j["CurrentSkyType"]; - if (j.contains("AmbientColor")) - DESERIALIZE_VEC4(j["AmbientColor"], AmbientColor); - if (j.contains("VolumetricFog")) - VolumetricFog = j["VolumetricFog"]; - if (j.contains("VolumetricStepCount")) - VolumetricStepCount = j["VolumetricStepCount"]; + } + if (j.contains("ProceduralSkybox")) { ProceduralSkybox->Deserialize(j["ProceduralSkybox"]); } - + + // Ambient + if (j.contains("AmbientTerm")) + { + AmbientTerm = j["AmbientTerm"]; + } + + if (j.contains("AmbientColor")) + { + DESERIALIZE_VEC4(j["AmbientColor"], AmbientColor); + } + + // Bloom + if (j.contains("BloomEnabled")) + { + BloomEnabled = j["BloomEnabled"]; + } + + if (j.contains("BloomThreshold")) + { + mBloom->SetThreshold(j["BloomThreshold"]); + } + + if (j.contains("BloomIteration")) + { + mBloom->SetIteration(j["BloomIteration"]); + } + + // SSR + if (j.contains("SSREnabled")) + { + SSREnabled = j["SSREnabled"]; + } + + if (j.contains("SSRRayStep")) + { + mSSR->RayStep = j["SSRRayStep"]; + } + + if (j.contains("SSRIterationCount")) + { + mSSR->IterationCount = j["SSRIterationCount"]; + } + + if (j.contains("SSRDistanceBias")) + { + mSSR->DistanceBias = j["SSRDistanceBias"]; + } + + if (j.contains("SSRSampleCount")) + { + mSSR->SampleCount = j["SSRSampleCount"]; + } + + if (j.contains("SSRSamplingEnabled")) + { + mSSR->SamplingEnabled = j["SSRSamplingEnabled"]; + } + + if (j.contains("SSRExpoStep")) + { + mSSR->ExpoStep = j["SSRExpoStep"]; + } + + if (j.contains("SSRAdaptiveStep")) + { + mSSR->AdaptiveStep = j["SSRAdaptiveStep"]; + } + + if (j.contains("SSRBinarySearch")) + { + mSSR->BinarySearch = j["SSRBinarySearch"]; + } + + if (j.contains("SSRSampleingCoefficient")) + { + mSSR->SampleingCoefficient = j["SSRSampleingCoefficient"]; + } + + // Volumetric + if (j.contains("VolumetricEnabled")) + { + VolumetricEnabled = j["VolumetricEnabled"]; + } + + if (j.contains("VolumetricFog")) + { + VolumetricFog = j["VolumetricFog"]; + } + + if (j.contains("VolumetricStepCount")) + { + VolumetricStepCount = j["VolumetricStepCount"]; + } + + // SSAO + if (j.contains("SSAOEnabled")) + { + SSAOEnabled = j["SSAOEnabled"]; + } + + if (j.contains("SSAORadius")) + { + mSSAO->Radius = j["SSAORadius"]; + } + + if (j.contains("SSAOBias")) + { + mSSAO->Bias = j["SSAOBias"]; + } + + if (j.contains("SSAOArea")) + { + mSSAO->Area = j["SSAOArea"]; + } + + if (j.contains("SSAOFalloff")) + { + mSSAO->Falloff = j["SSAOFalloff"]; + } + + if (j.contains("SSAOStrength")) + { + mSSAO->Strength = j["SSAOStrength"]; + } + + // DOF + if (j.contains("DOFEnabled")) + { + DOFEnabled = j["DOFEnabled"]; + } + + // Barrel distortion + if (j.contains("BarrelDistortionEnabled")) + { + BarrelDistortionEnabled = j["BarrelDistortionEnabled"]; + } + + if (j.contains("BarrelEdgeDistortion")) + { + BarrelEdgeDistortion = j["BarrelEdgeDistortion"]; + } + + if (j.contains("BarrelScale")) + { + BarrelScale = j["BarrelScale"]; + } + + // Vignette + if (j.contains("VignetteEnabled")) + { + VignetteEnabled = j["VignetteEnabled"]; + } + + if (j.contains("VignetteExtend")) + { + VignetteExtend = j["VignetteExtend"]; + } + + if (j.contains("VignetteIntensity")) + { + VignetteIntensity = j["VignetteIntensity"]; + } + return false; } } diff --git a/Nuake/src/Scene/Lighting/Environment.h b/Nuake/src/Scene/Lighting/Environment.h index 533a56ac..0d81b1b4 100644 --- a/Nuake/src/Scene/Lighting/Environment.h +++ b/Nuake/src/Scene/Lighting/Environment.h @@ -7,12 +7,14 @@ #include "src/Rendering/PostFX/Bloom.h" #include "src/Rendering/PostFX/Volumetric.h" #include "src/Rendering/PostFX/SSAO.h" +#include "src/Rendering/PostFX/SSR.h" #include namespace Nuake { - enum class SkyType { + enum class SkyType + { ProceduralSky = 0, ClearColor = 1 // CubeMap @@ -23,27 +25,27 @@ namespace Nuake public: Environment(); - SkyType CurrentSkyType = SkyType::ProceduralSky; - - Color AmbientColor = Color(0, 0, 0, 1); + SkyType CurrentSkyType; Ref ProceduralSkybox; - bool VolumetricEnabled = true; - float VolumetricFog = 0.90f; - float VolumetricStepCount = 50.f; + Color AmbientColor; - float AmbientTerm = 0.5f; + bool VolumetricEnabled; + float VolumetricFog; + float VolumetricStepCount; + + float AmbientTerm; float Exposure = 3.5f; float Gamma = 1.1f; bool BloomEnabled = true; Scope mBloom; Scope mVolumetric; - bool SSAOEnabled = true; Scope mSSAO; bool SSREnabled = true; + Scope mSSR; bool DOFEnabled = false; @@ -62,8 +64,6 @@ namespace Nuake glm::vec4 GetAmbientColor(); void SetAmbientColor(glm::vec4 color); - void Push(); - Ref Copy(); json Serialize() override;