Преглед изворни кода

Better approach on rendering the bloom effect, uses one less draw call

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
Alexis Maiquez пре 3 година
родитељ
комит
b5b7824233

+ 0 - 10
main.cpp

@@ -227,16 +227,6 @@ CVirtualContainer* buildVirtualContainer ()
         "\t\t\t\t\t\"index\": 1"
         "\t\t\t\t}"
         "\t\t\t]"
-        "\t\t},"
-        "\t\t{"
-        "\t\t\t\"material\": \"materials/wpenginelinux.json\","
-        "\t\t\t\"bind\":"
-        "\t\t\t["
-        "\t\t\t\t{"
-        "\t\t\t\t\t\"name\": \"_rt_imageLayerComposite_-1_b\","
-        "\t\t\t\t\t\"index\": 0"
-        "\t\t\t\t}"
-        "\t\t\t]"
         "\t\t}"
         "\t]"
         "}"

+ 16 - 16
src/WallpaperEngine/Render/CScene.cpp

@@ -102,15 +102,6 @@ CScene::CScene (Core::CScene* scene, CContext* context) :
         sceneWidth / 8, sceneHeight / 8
     );
 
-    this->_rt_FullFrameBuffer_b = this->createFBO (
-        "_rt_FullFrameBuffer_b",
-        ITexture::TextureFormat::ARGB8888,
-        ITexture::TextureFlags::NoInterpolation,
-        1.0,
-        sceneWidth, sceneHeight,
-        sceneWidth, sceneHeight
-    );
-
     //
     // Had to get a little creative with the effects to achieve the same bloom effect without any custom code
     // this custom image loads some effect files from the virtual container to achieve the same bloom effect
@@ -164,14 +155,15 @@ CScene::CScene (Core::CScene* scene, CContext* context) :
     auto json = nlohmann::json::parse (imagejson);
 
     // create image for bloom passes
-    auto bloomPass = this->createObject (
-        WallpaperEngine::Core::CObject::fromJSON (
-            json, this->getContainer ()
-        )
-    );
-
     if (this->getScene ()->isBloom () == true)
-        this->m_objectsByRenderOrder.emplace_back (bloomPass);
+        this->m_bloomObject = this->createObject (
+            WallpaperEngine::Core::CObject::fromJSON (
+                json, this->getContainer ()
+            )
+        );
+
+    this->_rt_imageCompositeLayer_bloom = this->findFBO ("_rt_imageLayerComposite_-1_b");
+    this->_rt_FullFrameBuffer = this->m_sceneFBO;
 }
 
 Render::CObject* CScene::createObject (Core::CObject* object)
@@ -252,6 +244,8 @@ void CScene::renderFrame (glm::ivec4 viewport)
         this->m_parallaxDisplacement.y = glm::mix (this->m_parallaxDisplacement.y, (this->m_mousePosition.y * amount) * influence, delay);
     }
 
+    this->m_sceneFBO = this->_rt_FullFrameBuffer;
+
     // use the scene's framebuffer by default
     glBindFramebuffer (GL_FRAMEBUFFER, this->getWallpaperFramebuffer());
     // ensure we render over the whole screen
@@ -261,6 +255,12 @@ void CScene::renderFrame (glm::ivec4 viewport)
 
     for (; cur != end; cur ++)
         (*cur)->render ();
+
+    if (this->getScene ()->isBloom () == true)
+    {
+        this->m_sceneFBO = this->_rt_imageCompositeLayer_bloom;
+        this->m_bloomObject->render ();
+    }
 }
 
 void CScene::updateMouse (glm::ivec4 viewport)

+ 3 - 1
src/WallpaperEngine/Render/CScene.h

@@ -36,6 +36,7 @@ namespace WallpaperEngine::Render
         Render::CObject* createObject (Core::CObject* object);
 
         CCamera* m_camera;
+        CObject* m_bloomObject;
         std::map<int, CObject*> m_objects;
         std::vector<CObject*> m_objectsByRenderOrder;
         glm::vec2 m_mousePosition;
@@ -43,6 +44,7 @@ namespace WallpaperEngine::Render
         CFBO* _rt_4FrameBuffer;
         CFBO* _rt_8FrameBuffer;
         CFBO* _rt_Bloom;
-        CFBO* _rt_FullFrameBuffer_b; // this one doesn't exist on the official wallpaper engine, but our approach requires it
+        CFBO* _rt_imageCompositeLayer_bloom; // this one doesn't exist on the official wallpaper engine, but our approach requires it
+        CFBO* _rt_FullFrameBuffer;
     };
 }

+ 0 - 8
src/WallpaperEngine/Render/Objects/CImage.cpp

@@ -92,14 +92,6 @@ CImage::CImage (CScene* scene, Core::Objects::CImage* image) :
     GLfloat realWidth = this->m_texture->getRealWidth () / 2.0f;
     GLfloat realHeight = this->m_texture->getRealHeight () / 2.0f;
 
-    // TODO: XXXHACK: QUICK HACK TO MAKE BLOOM LAYER BEHAVE IN A SPECIAL WAY, PREVENTS VERTICAL FLIP
-    if (this->getId () == 0xFFFFFFFF)
-    {
-        float tmpy = this->m_pos.y;
-        this->m_pos.y = this->m_pos.w;
-        this->m_pos.w = tmpy;
-    }
-
     // build a list of vertices, these might need some change later (or maybe invert the camera)
     GLfloat sceneSpacePosition [] = {
         this->m_pos.x, this->m_pos.y, 0.0f,