]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
experimented with glClear
authorPeter Schaefer <schaeferpm@gmail.com>
Fri, 24 Jun 2016 02:56:07 +0000 (04:56 +0200)
committerPeter Schaefer <schaeferpm@gmail.com>
Fri, 24 Jun 2016 02:56:07 +0000 (04:56 +0200)
renamed clearBuffer -> leaveBuffer
GlitchFix BasixTexture Shader
added Glow to Persistent Objects (only if Bloom Enabled)

14 files changed:
Weave/Graphix/Textures/BufferObject.h
Weave/Graphix/Textures/Texture.cpp
Weave/Graphix/Textures/Texture.h
Weave/Graphix/Textures/dBufferObject.cpp
Weave/Graphix/Textures/dBufferObject.h
Weave/Graphix/Textures/fBufferObject.cpp
Weave/Graphix/Textures/fBufferObject.h
Weave/Graphix/Textures/rBufferObject.cpp
Weave/Graphix/Textures/rBufferObject.h
Weave/Scene/Scene.cpp
Weave/Scene/SceneObject.cpp
Weave/Scene/SceneObject.h
shader/basicTexture_FS.hlsl
shader/lightingTexture_FS.hlsl

index 1eda41736a85b0e2351bacb217f0cf950277261b..fcc089fff14617fad8f6f4741bfa3fdaa4eb4d0f 100644 (file)
@@ -8,8 +8,9 @@ public:
        virtual void bindBuffer(unsigned int width = 0, unsigned int height = 0) = 0;
        virtual void unbindBuffer() = 0;
        virtual void useBuffer() const = 0;
+       virtual void clearUseBuffer(unsigned int mask) const = 0;
 
-       virtual void updateSize(unsigned int _width, unsigned int _height) = 0;
+       virtual void updateSize(unsigned int width, unsigned int height) = 0;
 
        virtual operator unsigned int() const 
        {
index 8db49054e73e642f38cf6acf02f56e42f0c7eccf..3da446573dacc3ea4846b0af005afb6ebc0b3c18 100644 (file)
@@ -118,7 +118,17 @@ void Texture::bindTexture(unsigned int _width, unsigned int _height, bool shadow
                //glTexParameteri(texture_target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
        }
 
+       //if (data != nullptr)
+       //{
+       //      float* _data = new float[width*height*4]();
+       //      std::fill_n(_data, width*height * 4, 0);
+       //      glTexImage2D(texture_target, 0, texture_internal, width, height, 0, texture_format, texture_type, _data);
+       //      delete _data;
+       //}
+       //
+       //else
        glTexImage2D(texture_target, 0, texture_internal, width, height, 0, texture_format, texture_type, data);
+
 }
 
 void Texture::unbindTexture()
@@ -137,6 +147,16 @@ void Texture::useTexture(bindTarget _unit) const
        Shader::getShader()->setUniformLocation(bindTargets[_unit], _unit);
 }
 
+void Texture::leaveTexture(bindTarget _unit)
+{
+
+       /* bind Texture*/
+       glActiveTexture(GL_TEXTURE0 + _unit);
+       glBindTexture(GL_TEXTURE_2D, 0);        //BADHACK
+
+       Shader::getShader()->setUniformLocation(bindTargets[_unit], _unit);
+}
+
 void Texture::updateSize(unsigned int _width, unsigned int _height)
 {
        if (_width == 0 || _height == 0)
index d43cab71695aefc938f3ce2d4b55aac4d65f789f..8f058afa9dea9d8d472135b1807d13e5258a3aef 100644 (file)
@@ -39,6 +39,8 @@ public:
        virtual void unbindTexture();
        virtual void useTexture(bindTarget = uCOLOR) const;
 
+       static void leaveTexture(bindTarget = uCOLOR);
+
        virtual void updateSize(unsigned int width = 0, unsigned int height = 0);
        virtual void downscale(unsigned int lvl);
 
index 02099719ec259a3a906bfb55fed737d6460d7a6a..52e3f598697aed030abedf1df9d549f77b947a05 100644 (file)
@@ -57,6 +57,14 @@ void dBufferObject::bindBuffer(unsigned int _width, unsigned int _height)
 
 }
 
+void dBufferObject::clearUseBuffer(unsigned int _mask) const
+{
+       glBindFramebuffer(buffer_target, handle);
+
+       if (_mask & GL_DEPTH_BUFFER_BIT)
+               glClear(GL_DEPTH_BUFFER_BIT);
+}
+
 //void dBufferObject::unbindBuffer()
 //{
 //     for (unsigned int i = 0; i < dim; i++)
index 8e764dda360325b61c17f641b00f04dd3782f19b..86ac23d706d75ad37a5ef55415869d4f0e3bfa05 100644 (file)
@@ -16,6 +16,7 @@ public:
 //     virtual void unbindBuffer() override;   
 
 //     virtual void useBuffer() const override;
+       virtual void clearUseBuffer(unsigned int mask = 256) const override;
 
 //     virtual void clearBuffer() const override;
 
index 5c45e42627f383348761e15e11c263102e9e721f..704732ab41843832773f9b58b9e3730997e5cff5 100644 (file)
@@ -52,7 +52,7 @@ void fBufferObject::bindBuffer(unsigned int _width, unsigned int _height)
        glBindFramebuffer(buffer_target, handle);
 
        /*Bind Texture Buffers (COLOR)*/
-       unsigned int* attachments = new unsigned int[dim];
+       attachments = new unsigned int[dim];
        for (unsigned int i = 0; i < dim; i++)
        {
                textures[i].bindTexture(_width, _height);
@@ -72,12 +72,12 @@ void fBufferObject::bindBuffer(unsigned int _width, unsigned int _height)
        glDrawBuffers(dim, attachments);
        if (glCheckFramebufferStatus(buffer_target) != GL_FRAMEBUFFER_COMPLETE)
                Message::error("fBufferObject: Framebuffer not complete!");
-
-       delete attachments;
 }
 
 void fBufferObject::unbindBuffer()
 {
+       delete attachments;
+
        for (unsigned int i = 0; i < dim; i++)
        {
                textures[i].unbindTexture();
@@ -91,13 +91,35 @@ void fBufferObject::unbindBuffer()
 
 }
 
+void fBufferObject::clearUseBuffer(unsigned int _mask) const
+{
+       glBindFramebuffer(buffer_target, handle);
+
+       if (dim <= 1)
+               glClear(_mask);
+       else
+       { 
+               if(_mask & GL_COLOR_BUFFER_BIT)
+               for (unsigned int i = 0; i < dim; i++)
+               {
+                       glDrawBuffer(attachments[i]);
+                       glClearColor(0.f, 0.f, 0.f, 1.f);
+                       glClear(GL_COLOR_BUFFER_BIT);
+                       glClear(GL_DEPTH_BUFFER_BIT);
+               }
+
+               glDrawBuffers(dim, attachments);
+               glClear(_mask);
+       }
+}
+
 void fBufferObject::useBuffer() const
 {
        glBindFramebuffer(buffer_target, handle);
 
 }
 
-void fBufferObject::clearBuffer()
+void fBufferObject::leaveBuffer()
 {
        glBindFramebuffer(GL_FRAMEBUFFER, 0);
 }
index 92654d337f2d37d64b7892567a97dfd0488cdb99..d04be4f87eb550f286c04a1bf779eb37a4f08ea6 100644 (file)
@@ -14,10 +14,11 @@ public:
 
        virtual void bindBuffer(unsigned int width = 0, unsigned int height = 0) override;
        virtual void unbindBuffer() override;   
+       virtual void clearUseBuffer(unsigned int mask = 16640) const override;
 
        virtual void useBuffer() const override;
 
-       static void clearBuffer();
+       static void leaveBuffer();
 
        virtual void updateSize(unsigned int _width, unsigned int _height) override;
 
@@ -27,6 +28,7 @@ public:
 protected:
        unsigned int dim;
        Texture* textures = nullptr;
+       unsigned int* attachments;
 
        rBufferObject* rBO = nullptr;
        
index 46589449151b4c3cd9a547814a8a8a3f0b4f48de..3abd1a6aeb6f8ee8c3ede3ab17ce1ec3ca267573 100644 (file)
@@ -36,13 +36,21 @@ void rBufferObject::unbindBuffer()
        glGenRenderbuffers(1, &handle);
 }
 
+void rBufferObject::clearUseBuffer(unsigned int _mask) const
+{
+       glBindFramebuffer(buffer_target, handle);
+
+       if (_mask & GL_DEPTH_BUFFER_BIT)
+               glClear(GL_DEPTH_BUFFER_BIT);
+}
+
 void rBufferObject::useBuffer() const
 {
        glBindRenderbuffer(buffer_target, handle);
 
 }
 
-void rBufferObject::clearBuffer()
+void rBufferObject::leaveBuffer()
 {
        glBindRenderbuffer(GL_RENDERBUFFER, 0);
 }
index e00af5387316fa6d1a64fdb93d212014bb2e779b..48d92dfda14eeb6ca1bf52c5943febf85515d42a 100644 (file)
@@ -11,10 +11,10 @@ public:
 
        virtual void bindBuffer(unsigned int width = 0, unsigned int height = 0) override;
        virtual void unbindBuffer() override;
+       virtual void clearUseBuffer(unsigned int mask = 256) const override;
 
        virtual void useBuffer() const override;
-
-       static void clearBuffer();
+       static void leaveBuffer();
 
        void updateSize(unsigned int _width, unsigned int _height) override;
 
index 25c94e3a5bf2a644200bbcd0dc20d55de168fa3c..d486fc02e0d073fb2981d445043a555d50411611 100644 (file)
@@ -87,7 +87,7 @@ lookat(_lookat)
        bt_dynamics_world->setGravity(btVector3(0, YFALL_SPEED, 0));
 
        /*BUFFERS*/
-       render = new fBufferObject();
+       render = new fBufferObject(2);
        render->bindBuffer(W_WIDTH, W_HEIGHT);
 
        blurPingPong = new fBufferObject*[2];
@@ -110,7 +110,7 @@ lookat(_lookat)
        motionVecs = new fBufferObject();
        motionVecs->bindBuffer(W_WIDTH , W_HEIGHT);
 
-       fBufferObject::clearBuffer();
+       fBufferObject::leaveBuffer();
 
        //Graphix::disableEffects(EF_BLOOM);
        //Graphix::disableEffects(EF_MOTION_BLUR);
@@ -330,7 +330,7 @@ void Scene::draw() const
        }
        else
        {
-               fBufferObject::clearBuffer();
+               fBufferObject::leaveBuffer();
        }
 
        /* DRAW SCENE -> SkyBox */
@@ -347,7 +347,7 @@ void Scene::draw() const
        if (lastScreen != nullptr)
                lastScreen->useBuffer();
        else
-               fBufferObject::clearBuffer();
+               fBufferObject::leaveBuffer();
 
        if (Events::isKToggleActive(SDLK_F6))
        {
@@ -374,7 +374,7 @@ void Scene::draw() const
                motionVecs->getTexture()->useTexture(uBLURVEC);
 
                bool firstit = true;
-               for (int i = 0; i < 1; i++)
+               for (int i = 0; i < 2; i++)
                {
 
                        postRenderPingPong[!postRenderPP]->useBuffer();
@@ -426,7 +426,7 @@ void Scene::draw() const
        //      }
 
        //      camera.useCamera();
-       //      fBufferObject::clearBuffer();
+       //      fBufferObject::leaveBuffer();
        //      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
        //      drawSceneObjects();
@@ -449,6 +449,16 @@ void Scene::draw() const
                Shader::getShader(SH_ACTIVE)->setUniformLocation("uFilterThreshold",1.2f);
                lastScreen->getTexture()->useTexture();
                Model::getPlaneModel()->drawModel(mat4(1.f));
+
+               horizontal_blurPP = !horizontal_blurPP;
+
+               blurPingPong[!horizontal_blurPP]->useBuffer();
+               glClear(GL_COLOR_BUFFER_BIT);
+               Shader::getShader(SH_BLEND)->useShader();
+               blurPingPong[horizontal_blurPP]->getTexture(0)->useTexture(uBLEND);
+               render->getTexture(1)->useTexture(uCOLOR);
+               Model::getPlaneModel()->drawModel(mat4(1.f));
+
                horizontal_blurPP = !horizontal_blurPP;
                
                /* BLUR BRIGHTNESS */
@@ -472,7 +482,7 @@ void Scene::draw() const
        /* FINAL DRAW -> if needed*/
        if (lastScreen != nullptr)
        {
-               fBufferObject::clearBuffer();
+               fBufferObject::leaveBuffer();
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
                if (Graphix::testEffect(EF_BLOOM))
@@ -486,7 +496,7 @@ void Scene::draw() const
                        Shader::getShader(SH_BASICTEXTURE)->useShader();
                }
 
-               lastScreen->getTexture()->useTexture(uCOLOR);
+               lastScreen->getTexture(0)->useTexture(uCOLOR);
                Model::getPlaneModel()->drawModel(mat4(1.f));
        }
 
index 25b243d931728eb3ea32888863cef479af9129ac..0e0d6cdbe224a97a90110b19ce86dc293931f445 100644 (file)
@@ -218,7 +218,12 @@ void SceneObject::draw(drawTarget _target) const
        case DRAW_Model:
        default:
                texture->useTexture();
+
+               if (timeresistant)
+                       Shader::getShader(SH_ACTIVE)->setUniformLocation("uAddGlow", true);
                model->drawModel(modelMat, dr_Model, vec4(0.9f, 0.f, 0.f, 1.f), currentAnimation, AnimationTime);
+               if (timeresistant)
+                       Shader::getShader(SH_ACTIVE)->setUniformLocation("uAddGlow", false);
                break;
        case DRAW_Wire:
                texture->useTexture();
index 1b6768854b5450d39df7a316291b2a2ba4d868ca..9f81f02947c63d986efe06d946e9619f5b85453f 100644 (file)
@@ -88,7 +88,7 @@ public:
        virtual void startanimation(uint index, float speed);
        virtual void setanimationtime(float time);
        virtual void setAnimationLoop(bool loop);
-       bool timeresistant;
+       bool timeresistant = false;
        bool ignore;
 
        bool movable = true;
index 6ab90c6d1ff735e59eff540b893f3624c76940a3..f22f0bec15d4b327112cea086f60a8390f8f8eb8 100644 (file)
@@ -21,5 +21,6 @@ void main()
                else
                        BrightColor = vec4(0.);
        }
+       BrightColor = vec4(0.f);
 
 }
\ No newline at end of file
index 4ccc4362ae0c51554853ea1e514bf0a11cc7de22..00840d04c00ccf297aeba878e1590f003334a7fa 100644 (file)
@@ -7,12 +7,14 @@ in vec3 PointLightPosition1, DirectionalLightDirection1;
 in vec4 DirLightSpacePos;
 
 layout(location = 0) out vec4 FragColor;
+layout(location = 1) out vec4 AddGlow;
 
 uniform sampler2D uColorTexture;
 uniform sampler2DShadow uPointLightXP;
 uniform vec4 material;                                 //vec4 in the form (ambient, point, directional, glossyness); so far it was (1, 1, 1, 3)
 uniform vec3 dirLightColor;
 uniform vec3 AmbientLightColor;
+uniform bool uAddGlow = false;
 
 float DirLightCalcShadowFactor(vec4 LightSpacePos)
 {
@@ -53,6 +55,13 @@ void main()
                + PointLightColor1 * material[1] * (cosThetaPoint1 + pow(SpecularCosPoint1, specularConst)) / squaredist1
                + DirLightCalcShadowFactor(DirLightSpacePos) * dirLightColor * material[2] * (cosThetaDirection1 + pow(SpecularCosDirection1, specularConst))
                ), uvColor.a);
+
+       if (uAddGlow)
+       {
+               AddGlow = vec4(0.f, dot(FragColor.rgb, vec3(0.2126f, 0.7152f, 0.0722f)),0.f,.6f);
+       }
+       else
+               AddGlow = vec4(0.f);
        
        //FragColor = vec4((normalize(worldNormal)+1)/2, 1.0f);
        //FragColor = vec4(length(DirectionalLightDirection1) - 1.0f, length(DirectionalLightDirection1) - 1.0f, length(DirectionalLightDirection1) - 1.0f, 1.0f);