]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
Bloom with downsampling
authorPeter Schaefer <schaeferpm@gmail.com>
Tue, 7 Jun 2016 05:50:20 +0000 (07:50 +0200)
committerPeter Schaefer <schaeferpm@gmail.com>
Tue, 7 Jun 2016 05:50:20 +0000 (07:50 +0200)
Weave/GLM.h
Weave/Graphix/Textures/Texture.cpp
Weave/Graphix/Textures/Texture.h
Weave/Graphix/Textures/fBufferObject.cpp
Weave/Scene/Scene.cpp

index cefa0699211f0509f3a198527346d165e8ab2608..9b824708d99abf3e97468bf40496879672021960 100644 (file)
@@ -11,10 +11,6 @@ using glm::vec3;
 using glm::mat4;
 using glm::vec4;
 
-#ifdef  GLM_FORCE_RADIANS ;
-hello
-#endif //  GLM_FORCE_RADIANS ;
-
 using glm::translate;
 using glm::rotate;
 //using glm::scale;
index fd3edd4da1f88f6dd5cf908febe3933fddb03348..e763834615046348f2419c06af80663133b2fa3e 100644 (file)
@@ -141,6 +141,14 @@ void Texture::updateSize(unsigned int _width, unsigned int _height)
        glTexImage2D(texture_target, 0, texture_internal, width, height, 0, texture_format, texture_type, data);
 }
 
+void Texture::downscale(unsigned int _lvl)
+{
+       glBindTexture(texture_target, handle);
+       glGenerateMipmap(texture_target);
+       glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+       //glTexParameteri(texture_target, GL_TEXTURE_BASE_LEVEL, _lvl);
+}
+
 
 unordered_map<string, Texture::texHandle> Texture::texture_Map;
 unordered_map<unsigned int, Texture::texHandle*> Texture::handle_Map;
\ No newline at end of file
index 14c76f0cb135ba8042f8ecaec6c0ced6e68154ac..d1ec8c26990d533e18f5b6e1f0c223a4e7ec0ec8 100644 (file)
@@ -38,6 +38,7 @@ public:
        virtual void useTexture(bindTarget = uCOLOR) const;
 
        virtual void updateSize(unsigned int width = 0, unsigned int height = 0);
+       virtual void downscale(unsigned int lvl);
 
        virtual operator unsigned int() const;
 
index 5c4dac2697ec21d3858aa3577ece27dcbcfdb4a4..5c45e42627f383348761e15e11c263102e9e721f 100644 (file)
@@ -113,4 +113,4 @@ void fBufferObject::updateSize(unsigned int _width, unsigned int _height)
 
        if (rBO != nullptr)
                rBO->updateSize(_width, _height);
-}
+}
\ No newline at end of file
index e30e9ea0824f91e51006078331174fbe92a6af8c..a168b5cb2820583e4b5be21cf1b343707a73f7a7 100644 (file)
@@ -77,14 +77,14 @@ lookat(_lookat)
        for (int i = 0; i < 2; i++)
        {
                blurPingPong[i] = new fBufferObject(1, false);
-               blurPingPong[i]->bindBuffer(Graphix::getWindowWidth(), Graphix::getWindowHeight());
+               blurPingPong[i]->bindBuffer(Graphix::getWindowWidth()/2, Graphix::getWindowHeight()/2);
        }
 
        shadowdir = new dBufferObject();
        shadowdir->bindBuffer(Graphix::getWindowWidth(), Graphix::getWindowHeight());
 
        postRender = new fBufferObject(2, false);
-       postRender->bindBuffer(Graphix::getWindowWidth(), Graphix::getWindowHeight());
+       postRender->bindBuffer(Graphix::getWindowWidth()/2, Graphix::getWindowHeight()/2);
 
        fBufferObject::clearBuffer();
 
@@ -275,7 +275,9 @@ void Scene::draw() const
        if (Graphix::testEffect(EF_BLOOM))
        {
                /* DRAW BRIGHTNESS */
+               glViewport(0, 0, Graphix::getWindowWidth() / 2, Graphix::getWindowHeight() / 2);
                postRender->useBuffer();
+               render->getTexture()->downscale(1);
                //glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
                glClear(GL_COLOR_BUFFER_BIT);
                Shader::getShader(SH_BASICTEXTURE)->useShader();
@@ -286,24 +288,25 @@ void Scene::draw() const
 
                /* BLUR BRIGHTNESS */
                Shader::getShader(SH_BLUR)->useShader();
-               
 
-               for (int i = 0; i < 10; i++)
+               for (int i = 0; i < 4; i++)
                {
                        blurPingPong[horizontal]->useBuffer();
-                       //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+                       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
                        Shader::getShader(SH_BLUR)->setUniformLocation("uHorizontal", horizontal);
                        if (firstit)
+                       {
                                postRender->getTexture(1)->useTexture();
+                               firstit = false;
+                       }
                        else
                                blurPingPong[!horizontal]->getTexture()->useTexture();
 
                        Model::getPlaneModel()->drawModel(mat4(1.f));
 
                        horizontal = !horizontal;
-                       if (firstit)
-                               firstit = false;
                }
+               glViewport(0, 0, Graphix::getWindowWidth(), Graphix::getWindowHeight());
        }
 
 
@@ -321,11 +324,15 @@ void Scene::draw() const
        {
                /* BLEND BRIGHTNESS TO ORIGINAL*/
                Shader::getShader(SH_BLEND)->useShader();
+               //Shader::getShader(SH_BASICTEXTURE)->useShader();
+
                fBufferObject::clearBuffer();
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
                //SceneObjects.front()->gTexture()->useTexture();
                //shadowdir->getTexture()->useTexture();
+               
                render->getTexture(0)->useTexture(uCOLOR);
+               //postRender->getTexture(1)->useTexture(uCOLOR);
                blurPingPong[!horizontal]->getTexture()->useTexture(uBLEND);
                Model::getPlaneModel()->drawModel(mat4(1.f));
        }