From d163220156393d9a52a43bc70c37a37d161e017e Mon Sep 17 00:00:00 2001 From: Almamu Date: Sun, 20 Apr 2025 23:19:01 +0200 Subject: [PATCH] chore: rewritten bloom effect as a json object inside C++ so it's easier to follow --- .../Application/CWallpaperApplication.cpp | 174 ++++++++++-------- .../Assets/CVirtualContainer.cpp | 4 + .../Assets/CVirtualContainer.h | 10 + 3 files changed, 114 insertions(+), 74 deletions(-) diff --git a/src/WallpaperEngine/Application/CWallpaperApplication.cpp b/src/WallpaperEngine/Application/CWallpaperApplication.cpp index 9f493b9..ff45582 100644 --- a/src/WallpaperEngine/Application/CWallpaperApplication.cpp +++ b/src/WallpaperEngine/Application/CWallpaperApplication.cpp @@ -84,82 +84,108 @@ void CWallpaperApplication::setupContainer (CCombinedContainer& container, const // add the effect file for screen bloom // add some model for the image element even if it's going to waste rendering cycles - virtualContainer->add ("effects/wpenginelinux/bloomeffect.json", - "{" - "\t\"name\":\"camerabloom_wpengine_linux\"," - "\t\"group\":\"wpengine_linux_camera\"," - "\t\"dependencies\":[]," - "\t\"passes\":" - "\t[" - "\t\t{" - "\t\t\t\"material\": \"materials/util/downsample_quarter_bloom.json\"," - "\t\t\t\"target\": \"_rt_4FrameBuffer\"," - "\t\t\t\"bind\":" - "\t\t\t[" - "\t\t\t\t{" - "\t\t\t\t\t\"name\": \"_rt_FullFrameBuffer\"," - "\t\t\t\t\t\"index\": 0" - "\t\t\t\t}" - "\t\t\t]" - "\t\t}," - "\t\t{" - "\t\t\t\"material\": \"materials/util/downsample_eighth_blur_v.json\"," - "\t\t\t\"target\": \"_rt_8FrameBuffer\"," - "\t\t\t\"bind\":" - "\t\t\t[" - "\t\t\t\t{" - "\t\t\t\t\t\"name\": \"_rt_4FrameBuffer\"," - "\t\t\t\t\t\"index\": 0" - "\t\t\t\t}" - "\t\t\t]" - "\t\t}," - "\t\t{" - "\t\t\t\"material\": \"materials/util/blur_h_bloom.json\"," - "\t\t\t\"target\": \"_rt_Bloom\"," - "\t\t\t\"bind\":" - "\t\t\t[" - "\t\t\t\t{" - "\t\t\t\t\t\"name\": \"_rt_8FrameBuffer\"," - "\t\t\t\t\t\"index\": 0" - "\t\t\t\t}" - "\t\t\t]" - "\t\t}," - "\t\t{" - "\t\t\t\"material\": \"materials/util/combine.json\"," - "\t\t\t\"target\": \"_rt_FullFrameBuffer\"," - "\t\t\t\"bind\":" - "\t\t\t[" - "\t\t\t\t{" - "\t\t\t\t\t\"name\": \"_rt_imageLayerComposite_-1_a\"," - "\t\t\t\t\t\"index\": 0" - "\t\t\t\t}," - "\t\t\t\t{" - "\t\t\t\t\t\"name\": \"_rt_Bloom\"," - "\t\t\t\t\t\"index\": 1" - "\t\t\t\t}" - "\t\t\t]" - "\t\t}" - "\t]" - "}"); + virtualContainer->add ( + "effects/wpenginelinux/bloomeffect.json", + { + {"name", "camerabloom_wpengine_linux"}, + {"group", "wpengine_linux_camera"}, + {"dependencies", json::array ()}, + {"passes", + json::array ( + { + { + {"material", "materials/util/downsample_quarter_bloom.json"}, + {"target", "_rt_4FrameBuffer"}, + { + "bind", + json::array ( + { + { + {"name", "_rt_FullFrameBuffer"}, + {"index", 0} + } + } + ) + } + }, + { + {"material", "materials/util/downsample_eighth_blur_v.json"}, + {"target", "_rt_8FrameBuffer"}, + { + "bind", + json::array ( + { + { + {"name", "_rt_4FrameBuffer"}, + {"index", 0} + } + } + ) + } + }, + { + {"material", "materials/util/blur_h_bloom.json"}, + {"target", "_rt_Bloom"}, + { + "bind", + json::array ( + { + { + {"name", "_rt_8FrameBuffer"}, + {"index", 0} + } + } + ) + } + }, + { + {"material", "materials/util/combine.json"}, + {"target", "_rt_FullFrameBuffer"}, + { + "bind", + json::array ( + { + { + {"name", "_rt_imageLayerComposite_-1_a"}, + {"index", 0} + }, + { + {"name", "_rt_Bloom"}, + {"index", 1} + } + } + ) + } + } + } + ), + } + } + ); - virtualContainer->add ("models/wpenginelinux.json", "{" - "\t\"material\":\"materials/wpenginelinux.json\"" - "}"); + virtualContainer->add ( + "models/wpenginelinux.json", + { + {"material","materials/wpenginelinux.json"} + } + ); - // models require materials, so add that too - virtualContainer->add ("materials/wpenginelinux.json", "{" - "\t\"passes\":" - "\t\t[" - "\t\t\t{" - "\t\t\t\t\"blending\": \"normal\"," - "\t\t\t\t\"cullmode\": \"nocull\"," - "\t\t\t\t\"depthtest\": \"disabled\"," - "\t\t\t\t\"depthwrite\": \"disabled\"," - "\t\t\t\t\"shader\": \"genericimage2\"," - "\t\t\t\t\"textures\": [\"_rt_FullFrameBuffer\"]" - "\t\t\t}" - "\t\t]" - "}"); + virtualContainer->add( + "materials/wpenginelinux.json", + { + {"passes", json::array ( + { + { + {"blending", "normal"}, + {"cullmode", "nocull"}, + {"depthtest", "disabled"}, + {"depthwrite", "disabled"}, + {"shader", "genericimage2"}, + {"textures", json::array ({"_rt_FullFrameBuffer"})} + } + } + )}} + ); container.add (virtualContainer); } diff --git a/src/WallpaperEngine/Assets/CVirtualContainer.cpp b/src/WallpaperEngine/Assets/CVirtualContainer.cpp index 63324af..96ccddc 100644 --- a/src/WallpaperEngine/Assets/CVirtualContainer.cpp +++ b/src/WallpaperEngine/Assets/CVirtualContainer.cpp @@ -19,6 +19,10 @@ void CVirtualContainer::add (const std::filesystem::path& filename, const std::s this->add (filename, copy, contents.length () + 1); } +void CVirtualContainer::add (const std::filesystem::path& filename, const json& contents) { + this->add (filename, contents.dump ()); +} + const uint8_t* CVirtualContainer::readFile (const std::filesystem::path& filename, uint32_t* length) const { const auto cur = this->m_virtualFiles.find (filename); diff --git a/src/WallpaperEngine/Assets/CVirtualContainer.h b/src/WallpaperEngine/Assets/CVirtualContainer.h index 1befb6a..be2e19e 100644 --- a/src/WallpaperEngine/Assets/CVirtualContainer.h +++ b/src/WallpaperEngine/Assets/CVirtualContainer.h @@ -5,8 +5,11 @@ #include "CContainer.h" #include "CFileEntry.h" +#include + namespace WallpaperEngine::Assets { +using json = nlohmann::json; /** * Virtual container implementation, provides virtual files for the backgrounds to use */ @@ -28,6 +31,13 @@ class CVirtualContainer final : public CContainer { * @param contents */ void add (const std::filesystem::path& filename, const std::string& contents); + /** + * Adds a new file to the virtual container from a json object + * @param filename + * @param contents + */ + void add (const std::filesystem::path& filename, const json& contents); + /** @inheritdoc */ const uint8_t* readFile (const std::filesystem::path& filename, uint32_t* length) const override;