From 3749d7e06b5f0316488482f757e97beb03393f41 Mon Sep 17 00:00:00 2001 From: Peter Schaefer Date: Tue, 7 Jun 2016 07:50:20 +0200 Subject: [PATCH] Bloom with downsampling --- Weave/GLM.h | 4 ---- Weave/Graphix/Textures/Texture.cpp | 8 ++++++++ Weave/Graphix/Textures/Texture.h | 1 + Weave/Graphix/Textures/fBufferObject.cpp | 2 +- Weave/Scene/Scene.cpp | 21 ++++++++++++++------- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Weave/GLM.h b/Weave/GLM.h index cefa069..9b82470 100644 --- a/Weave/GLM.h +++ b/Weave/GLM.h @@ -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; diff --git a/Weave/Graphix/Textures/Texture.cpp b/Weave/Graphix/Textures/Texture.cpp index fd3edd4..e763834 100644 --- a/Weave/Graphix/Textures/Texture.cpp +++ b/Weave/Graphix/Textures/Texture.cpp @@ -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 Texture::texture_Map; unordered_map Texture::handle_Map; \ No newline at end of file diff --git a/Weave/Graphix/Textures/Texture.h b/Weave/Graphix/Textures/Texture.h index 14c76f0..d1ec8c2 100644 --- a/Weave/Graphix/Textures/Texture.h +++ b/Weave/Graphix/Textures/Texture.h @@ -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; diff --git a/Weave/Graphix/Textures/fBufferObject.cpp b/Weave/Graphix/Textures/fBufferObject.cpp index 5c4dac2..5c45e42 100644 --- a/Weave/Graphix/Textures/fBufferObject.cpp +++ b/Weave/Graphix/Textures/fBufferObject.cpp @@ -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 diff --git a/Weave/Scene/Scene.cpp b/Weave/Scene/Scene.cpp index e30e9ea..a168b5c 100644 --- a/Weave/Scene/Scene.cpp +++ b/Weave/Scene/Scene.cpp @@ -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)); } -- 2.47.3