]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
getShader Methode geändert,
authorPeter Schaefer <schaeferpm@gmail.com>
Mon, 18 Apr 2016 11:05:49 +0000 (13:05 +0200)
committerPeter Schaefer <schaeferpm@gmail.com>
Mon, 18 Apr 2016 11:05:49 +0000 (13:05 +0200)
Bloom läuft
Window Resize -> Buffer läuft

22 files changed:
CGUE2015_Weave.sln
Weave/Game.cpp
Weave/Graphix/Graphix.cpp
Weave/Graphix/Model/Model.cpp
Weave/Graphix/Model/Plane.cpp
Weave/Graphix/Model/SkyBox.cpp
Weave/Graphix/Shader.cpp
Weave/Graphix/Shader.h
Weave/Graphix/Textures/Texture.cpp
Weave/Graphix/Textures/Texture.h
Weave/Graphix/Textures/fBufferObject.cpp
Weave/Graphix/Textures/tImage.cpp
Weave/Scene/EventBox.cpp
Weave/Scene/Scene.cpp
Weave/Scene/Scene.h
Weave/Scene/SceneObject.cpp
Weave/Scene/Sky.cpp
shader/basicTexture_FS.hlsl
shader/basic_VS.hlsl
shader/blend_FS.hlsl [new file with mode: 0644]
shader/blur_FS.hlsl
shader/lightingTexture_FS.hlsl

index 014bd360d6e4fe72b107f7d5243f04d5f22d9f7f..af72ee48921cdbbdb556e7bbe805b035a17af118 100644 (file)
@@ -11,6 +11,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shader", "shader", "{75179E
                shader\basic_VS.hlsl = shader\basic_VS.hlsl
                shader\basicTexture_FS.hlsl = shader\basicTexture_FS.hlsl
                shader\basicTexture_VS.hlsl = shader\basicTexture_VS.hlsl
+               shader\blend_FS.hlsl = shader\blend_FS.hlsl
                shader\blur_FS.hlsl = shader\blur_FS.hlsl
                shader\lightingTexture_FS.hlsl = shader\lightingTexture_FS.hlsl
                shader\perspective_VS.hlsl = shader\perspective_VS.hlsl
index ca049e70c06d074e2bbc62296dd252d2218643b7..8fa4a328499b47cae6aae6ef0f4099ff1d84c1ff 100644 (file)
@@ -45,28 +45,30 @@ Game::Game() : playing(true)
 \r
        // load LVL\r
 \r
-       SceneObject* tmp_world = new Level(Shader::gLighting(), "level_1", "model_levelTest_2D.jpg");\r
+       auto defaultShader = Shader::getShader(SH_LIGHTING);\r
+\r
+       SceneObject* tmp_world = new Level(defaultShader, "level_1", "model_levelTest_2D.jpg");\r
 \r
        //tmp_world->ignore = true;\r
        current_world->addObject(tmp_world);\r
 \r
-//     current_world->addObject(new SceneObject(Shader::gLighting(), translate(vec3(-3.f, 1.f, 0.f)), vec4(1.0f, 1.0f, 1.0f, 3.0f), new BBox(), ""));\r
+//     current_world->addObject(new SceneObject(defaultShader, translate(vec3(-3.f, 1.f, 0.f)), vec4(1.0f, 1.0f, 1.0f, 3.0f), new BBox(), ""));\r
 \r
        //Player\r
-       SceneObject* tmp_playerObject = new Marvin(Shader::gLighting(), translate(vec3(1.f, 3.f, 1.f))*rotate((float)M_PI_4,vec3(0.f,1.f,0.f)));\r
+       SceneObject* tmp_playerObject = new Marvin(defaultShader, translate(vec3(1.f, 3.f, 1.f))*rotate((float)M_PI_4,vec3(0.f,1.f,0.f)));\r
 \r
        tmp_playerObject->yStatic= false;\r
 \r
        current_world->addObject(tmp_playerObject);\r
        current_world->setLookAt(tmp_playerObject);\r
 \r
-       //current_world->addObject(new SceneObject(Shader::gLighting(), glm::mat4(1.0f), "Player.dae", "model_player.png"));\r
-       //current_world->addObject(new SceneObject(Shader::gLighting(), translate(vec3(-3.f, .4f, 0.f))*scale(vec3(3.f)), "cow/cow.dae", "model_cow_2D.jpg"));\r
-       current_world->addObject(new SceneObject(Shader::gLighting(), translate(vec3(-3.f, .4f, 0.f)), vec4(3.0f, 0.5f, 0.4f, 1.5f), "duck_col", "model_duck_2D.png"));\r
-       current_world->addObject(new SceneObject(Shader::gLighting(), translate(vec3(-5.f, .4f, 0.f)), vec4(3.0f, 3.f, 0.4f, 1.5f), "duck", "model_duck_2D.png"));\r
-       current_world->addObject(new SceneObject(Shader::gLighting(), translate(vec3(0.f, .4f, 0.f)), vec4(3.0f, 3.f, 0.4f, 1.5f), "lever", "model_duck_2D.png"));\r
+       //current_world->addObject(new SceneObject(defaultShader, glm::mat4(1.0f), "Player.dae", "model_player.png"));\r
+       //current_world->addObject(new SceneObject(defaultShader, translate(vec3(-3.f, .4f, 0.f))*scale(vec3(3.f)), "cow/cow.dae", "model_cow_2D.jpg"));\r
+       current_world->addObject(new SceneObject(defaultShader, translate(vec3(-3.f, .4f, 0.f)), vec4(3.0f, 0.5f, 0.4f, 1.5f), "duck_col", "model_duck_2D.png"));\r
+       current_world->addObject(new SceneObject(defaultShader, translate(vec3(-5.f, .4f, 0.f)), vec4(3.0f, 3.f, 0.4f, 1.5f), "duck", "model_duck_2D.png"));\r
+       current_world->addObject(new SceneObject(defaultShader, translate(vec3(0.f, .4f, 0.f)), vec4(3.0f, 3.f, 0.4f, 1.5f), "lever", "model_duck_2D.png"));\r
 \r
-       current_world->addObject(new SceneObject(Shader::gLighting(), translate(vec3(-5.f, 3.f, 0.f)), vec4(3.0f, 3.f, 0.4f, 1.5f), "SkyBox", "model_SkyBox_2D.png"));\r
+       current_world->addObject(new SceneObject(defaultShader, translate(vec3(-5.f, 3.f, 0.f)), vec4(3.0f, 3.f, 0.4f, 1.5f), "SkyBox", "model_SkyBox_2D.png"));\r
 \r
        //current_world->addObject(new EventBox(translate(vec3(3.f, .4f, 0.f)),EB_LOSTZONE));\r
        current_world->addObject(new EventBox(translate(vec3(3.f, .4f, -15.f)), EB_WINZONE));\r
@@ -136,9 +138,13 @@ void Game::play()
 \r
 void Game::update(float deltaT)\r
 {\r
-\r
+       /* ADJUST WINDOWS SIZE*/\r
        if (Graphix::getWindowHeight() != current_world->getViewport().getHeight() || Graphix::getWindowWidth() != current_world->getViewport().getWidth())\r
-               current_world->getViewport().setView(0, 0, Graphix::getWindowWidth(), Graphix::getWindowHeight());\r
+       {\r
+               current_world->setView(0, 0, Graphix::getWindowWidth(), Graphix::getWindowHeight());\r
+\r
+       }\r
+               \r
        if (playing){\r
                current_world->update(deltaT);\r
                \r
index 530973c49f453a4136c0ab2d502a2dace43ccd4e..90ba04c872394214d2f611b52e1028174e6a1172 100644 (file)
@@ -144,7 +144,7 @@ void Graphix::init()
        glEnable(GL_BLEND);\r
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);\r
 \r
-       glClearColor(0.9f, 0.9f, 1.0f, 1.f);\r
+       glClearColor(0.0f, 0.0f, 0.0f, 1.f);\r
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);\r
        glClearAccum(0.f, 0.f, 0.f, 0.f);\r
        glClear(GL_ACCUM_BUFFER_BIT);\r
@@ -285,4 +285,4 @@ SDL_Window* Graphix::sdl_window;
 \r
 SDL_GLContext Graphix::sdl_glcontext;\r
 \r
-short Graphix::effects = EF_TRANSPARENCY;\r
+short Graphix::effects = EF_TRANSPARENCY | EF_BLOOM;\r
index 5ea99ca84f2ca4d3194de2389dc6fd4c626e3a86..ed8520138ea758d54abe26de37c48618d1bb48a3 100644 (file)
@@ -145,7 +145,7 @@ void Model::drawWire(const mat4& _modelMat, const vec4& _color) const
 \r
        useModel(_modelMat);\r
 \r
-       Shader::gActive()->setUniformLocation("uFragmentColor", _color);\r
+       Shader::getShader()->setUniformLocation("uFragmentColor", _color);\r
 \r
        drawWire();\r
 \r
@@ -154,9 +154,9 @@ void Model::drawWire(const mat4& _modelMat, const vec4& _color) const
 void Model::drawBBox(const mat4& _modelMat, const vec4& _color) const\r
 {\r
        Graphix::getGlError();\r
-       Shader::gBasic()->useShader();\r
+       Shader::getShader(SH_BASIC)->useShader();\r
 \r
-       Shader::gActive()->setUniformLocation("uFragmentColor", _color);\r
+       Shader::getShader()->setUniformLocation("uFragmentColor", _color);\r
 \r
        Graphix::getGlError();\r
 \r
@@ -194,7 +194,7 @@ void Model::useModel(const mat4& _modelMat) const
 \r
        /* use MODEL*/\r
        uint vao = -1;\r
-       auto i = shader_map.find(*Shader::gActive());\r
+       auto i = shader_map.find(*Shader::getShader());\r
        if (i == shader_map.end())\r
                Message::error("Model: Shader wurde nicht an das Model gebunden.");\r
        else\r
@@ -204,7 +204,7 @@ void Model::useModel(const mat4& _modelMat) const
 \r
 \r
        /* use ModelMAT*/\r
-       Shader::gActive()->setUniformLocation("uModel", _modelMat);\r
+       Shader::getShader()->setUniformLocation("uModel", _modelMat);\r
 \r
 }\r
 \r
@@ -233,7 +233,7 @@ Model* Model::getBBoxModel()
        {\r
                BoundingBox = new BBox();\r
                BoundingBox->bindModel();\r
-               BoundingBox->bindShader(Shader::gBasic());\r
+               BoundingBox->bindShader(Shader::getShader(SH_BASIC));\r
        }\r
        return BoundingBox;\r
 }\r
@@ -244,8 +244,9 @@ Model* Model::getPlaneModel()
        {\r
                PlaneModel = new Plane();\r
                PlaneModel->bindModel();\r
-               PlaneModel->bindShader(Shader::gBasicTexture());\r
-               PlaneModel->bindShader(Shader::gBlur());\r
+               PlaneModel->bindShader(Shader::getShader(SH_BASICTEXTURE));\r
+               PlaneModel->bindShader(Shader::getShader(SH_BLUR));\r
+               PlaneModel->bindShader(Shader::getShader(SH_BLEND));\r
        }\r
        return PlaneModel;\r
 }\r
index c34955d6c4c2181d11770a54dcda8f4ad26c6ecd..7772e7966de55cfcf2b6f2bca820c0d3687b2e50 100644 (file)
@@ -31,8 +31,8 @@ void Plane::drawModel() const
 {
        useModel(mat4(1.f));
 
-       Shader::gActive()->setUniformLocation("uPlain", 1);
-       Shader::gActive()->setUniformLocation("uFar", 0);
+       Shader::getShader()->setUniformLocation("uPlain", 1);
+       Shader::getShader()->setUniformLocation("uFar", 0);
 
        //glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
        glDrawArrays(GL_QUADS, 0, 4);
index 64f9919a0fd869b53749ff559acfc8dc1ce0b2d0..4b777d0488575520bc5764bc1946b40ccf6b728f 100644 (file)
@@ -38,8 +38,8 @@ void SkyBox::drawModel(const mat4& _modelMat) const
 \r
        useModel(_modelMat);\r
 \r
-       Shader::gActive()->setUniformLocation("uPlain", 0);\r
-       Shader::gActive()->setUniformLocation("uFar", 1);\r
+       Shader::getShader()->setUniformLocation("uPlain", 0);\r
+       Shader::getShader()->setUniformLocation("uFar", 1);\r
 \r
        Model::drawModel();\r
        //glEnable(GL_DEPTH_TEST);\r
index 2a29b5e8c357961b8a0845599278ee70cd069e12..9285906e2d201f2925e9c0d2b9f64451a9925b18 100644 (file)
@@ -27,7 +27,7 @@ Shader::~Shader()
 
 void Shader::useShader() const
 {
-       shActive = this;
+       shList[SH_ACTIVE] = this;
        glUseProgram(handle);
 }
 
@@ -221,48 +221,34 @@ GLuint Shader::loadProgram(GLuint _shader1, GLuint _shader2){
 
 void Shader::init()
 {
-       if(shBasic==nullptr)
-               shBasic = new Shader("basic_VS.hlsl", "basic_FS.hlsl");
-       if (shBasicTexture == nullptr)
-               shBasicTexture = new Shader("basic_VS.hlsl", "basicTexture_FS.hlsl");
-       if(shLighting==nullptr)
-               shLighting = new Shader("basicTexture_VS.hlsl", "lightingTexture_FS.hlsl");
-       if(shBlur==nullptr)
-               shBlur = new Shader("basic_VS.hlsl", "blur_FS.hlsl");
-}
-
-void Shader::cleanup()
-{
-       delete shBasic, shBasicTexture, shLighting, shBlur;
-}
+       if (!initShader)
+       {
+               shList[SH_BASIC] = new Shader("basic_VS.hlsl", "basic_FS.hlsl");
+               shList[SH_BASICTEXTURE] = new Shader("basic_VS.hlsl", "basicTexture_FS.hlsl");
+               shList[SH_LIGHTING] = new Shader("basicTexture_VS.hlsl", "lightingTexture_FS.hlsl");
+               shList[SH_BLUR] = new Shader("basic_VS.hlsl", "blur_FS.hlsl");
+               shList[SH_BLEND] = new Shader("basic_VS.hlsl", "blend_FS.hlsl");
+       }
 
-const Shader * Shader::gActive()
-{
-       return shActive;
+       initShader = true;
 }
 
-const Shader * Shader::gBasic()
+void Shader::cleanup()
 {
-       return shBasic;
-}
+       if (initShader)
+       {
+               for (int i = 1; i < 6; i++)
+                       delete shList[i];
+       }
 
-const Shader * Shader::gBasicTexture()
-{
-       return shBasicTexture;
+       initShader = false;
 }
 
-const Shader * Shader::gLighting()
+const Shader* Shader::getShader(ShaderTarget _target)
 {
-       return shLighting;
+       return shList[_target];
 }
 
-const Shader * Shader::gBlur()
-{
-       return shBlur;
-}
 
-const Shader * Shader::shActive = nullptr;
-const Shader * Shader::shBasic = nullptr;
-const Shader * Shader::shBasicTexture = nullptr;
-const Shader * Shader::shLighting = nullptr;
-const Shader * Shader::shBlur = nullptr;
+bool Shader::initShader = false;
+const Shader* Shader::shList[6];
index 8a96a4f57fced2ee7ba850793114bd6951e3ade7..f30a52de746e1edb4b19d9371e0bb1a3df6b5585 100644 (file)
@@ -9,6 +9,15 @@ using std::string;
 
 typedef unsigned int uint;
 
+enum ShaderTarget {
+       SH_ACTIVE = 0,
+       SH_BASIC = 1,
+       SH_BASICTEXTURE = 2,
+       SH_LIGHTING = 3,
+       SH_BLUR = 4,
+       SH_BLEND = 5
+};
+
 class Shader
 {
 public:
@@ -34,11 +43,7 @@ public:
        int setUniformLocation(const string& name, const vec4& vec) const;
        int setUniformLocation(const string& name, const int& i) const;
 
-       static const Shader * gActive();
-       static const Shader * gBasic();
-       static const Shader * gBasicTexture();
-       static const Shader * gLighting();
-       static const Shader * gBlur();
+       static const Shader* getShader(ShaderTarget shTarget = SH_ACTIVE);
 
        static void init();
        static void cleanup();
@@ -49,11 +54,7 @@ private:
        uint loadShader(string& _shaderPath);
        uint loadProgram(uint _shader1, uint _shader2);
 
-
-       static const Shader * shActive;
-       static const Shader * shBasic;
-       static const Shader * shBasicTexture;
-       static const Shader * shLighting;
-       static const Shader * shBlur;
+       static bool initShader;
+       static const Shader * shList[];
 };
 
index c08d34bd9b0b1b984f91b2b9309923fb75c96c61..d016d5a6f5660bca924f32113d41dcc46b0fb3a9 100644 (file)
@@ -11,7 +11,7 @@ using std::unordered_map;
 
 
 Texture::Texture() 
-       : texture_internal(GL_RGB), texture_format(GL_RGB),texture_target(GL_TEXTURE_2D),texture_type(GL_UNSIGNED_BYTE)
+       : texture_internal(GL_RGB16F), texture_format(GL_RGB),texture_target(GL_TEXTURE_2D),texture_type(GL_UNSIGNED_BYTE)
 {
        glGenTextures(1, &handle);
 }
@@ -102,8 +102,16 @@ void Texture::useTexture(unsigned int _unit) const
        /* bind Texture*/
        glActiveTexture(GL_TEXTURE0 + _unit);
        glBindTexture(texture_target, handle);
-
-       Shader::gActive()->setUniformLocation("uColorTexture", _unit);
+       
+       switch (_unit)
+       {
+       case 1:
+               Shader::getShader()->setUniformLocation("uBlendTexture", _unit);
+               break;
+       default:
+               Shader::getShader()->setUniformLocation("uColorTexture", _unit);
+               break;
+       }
 }
 
 void Texture::updateSize(unsigned int _width, unsigned int _height)
@@ -111,6 +119,9 @@ void Texture::updateSize(unsigned int _width, unsigned int _height)
        if (_width == 0 || _height == 0)
                return;
 
+       width = _width;
+       height = _height;
+
        glBindTexture(texture_target, handle);
        glTexImage2D(texture_target, 0, texture_internal, width, height, 0, texture_format, texture_type, data);
 }
index 5da8a95dfc7d16764f1ad71127a6533a30a2b586..ff15a825f7b74a51602f2835a16059491ac3160c 100644 (file)
@@ -34,7 +34,7 @@ protected:
        unsigned int texture_format;
        unsigned int texture_type;
 
-       void* data = nullptr;
+       void* data = NULL;
 
        unsigned int width = 0, height = 0;
 
index ea23db11fb1b58098d64ee7f6a972cd9fd1d140f..ebef23240b99a9b0f4b35dd0d8515e94d9235b72 100644 (file)
@@ -27,7 +27,7 @@ fBufferObject::fBufferObject(unsigned int _dim, bool _rbo)
 
 fBufferObject::~fBufferObject()
 {
-       delete textures;
+//     delete textures;
 
        if (rBO != nullptr)
                delete rBO;
index 9b0dea0f51f40ec1b5adf2bd11fc7dcf0dc21ec6..3e6a9dd3ddd1688687b28880aa8e60ee537f7579 100644 (file)
@@ -61,10 +61,10 @@ void tImage::useTexture(unsigned int _unit) const
        glActiveTexture(GL_TEXTURE0 + _unit);
        glBindTexture(texture_target, handle);
 
-       Shader::gActive()->setUniformLocation("uColorTexture", _unit);
+       Shader::getShader()->setUniformLocation("uColorTexture", _unit);
 
        /* bind Material*/
-       Shader::gActive()->setUniformLocation("material", material);
+       Shader::getShader()->setUniformLocation("material", material);
 }
 
 
index 6b272cc677581649056f5dfb8f62d04a27a12d4d..1c54ff551e7dd207d64a944452c76ab96ed87c78 100644 (file)
@@ -13,7 +13,7 @@
 
 
 EventBox::EventBox(const mat4& _modelMat, uint _EB_TYPE) : 
-       SceneObject(Shader::gBasic(), _modelMat, vec4(0.f), Model::getBBoxModel(), ""), 
+       SceneObject(Shader::getShader(SH_BASIC), _modelMat, vec4(0.f), Model::getBBoxModel(), ""),
        eb_type(_EB_TYPE)
 {
        collide_group = COL_EVENT;
index d0f1204e11cc68fad2ae0088002f50ac9c3cc9e3..3c7f60d9c30d1ba14db97f8c5fcb81f947184829 100644 (file)
@@ -57,13 +57,24 @@ lookat(_lookat)
 
        bt_dynamics_world->setGravity(btVector3(0, YFALL_SPEED, 0));
 
-       render = new fBufferObject(1);
 
-//     blur = new fBufferObject(2,false);
+       render = new fBufferObject();
 
-//     blur->bindBuffer(Graphix::getWindowWidth(), Graphix::getWindowHeight());
        render->bindBuffer(Graphix::getWindowWidth(), Graphix::getWindowHeight());
 
+
+       blurPingPong = new fBufferObject*[2];
+       blurPingPong[0] = new fBufferObject(1, false);
+       blurPingPong[1] = new fBufferObject(1, false);
+
+       blurPingPong[0]->bindBuffer(Graphix::getWindowWidth(), Graphix::getWindowHeight());
+       blurPingPong[1]->bindBuffer(Graphix::getWindowWidth(), Graphix::getWindowHeight());
+
+       
+       postRender = new fBufferObject(2, false);
+
+       postRender->bindBuffer(Graphix::getWindowWidth(), Graphix::getWindowHeight());
+
        render->clearBuffer();
 }
 
@@ -85,6 +96,12 @@ Scene::~Scene()
        delete bt_dispatcher;
        delete bt_collision_configuration;
 
+       //fBO
+       delete render;
+       delete blurPingPong[0];
+       delete blurPingPong[1];
+       delete blurPingPong;
+
 
        //if (viewPort != nullptr)
        //      delete viewPort;
@@ -174,14 +191,19 @@ void Scene::update(float deltaT)
 
 void Scene::draw() const
 {
-       render->useBuffer();
-       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+       /* DRAW SCENE */
+       if (Graphix::testEffect(EF_BLOOM))
+       {
+               render->useBuffer();
+               glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+       }
        viewPort.useViewPort();
 
        //Skybox
        viewPort.bindView(SkyBox.gShader(), lookat->getPosition() + vec3(0.0f, 1.0f, 0.0f));
        //BBox
-       viewPort.bindView(Shader::gBasic(), lookat->getPosition() + vec3(0.0f, 1.0f, 0.0f));
+       viewPort.bindView(Shader::getShader(SH_BASIC), lookat->getPosition() + vec3(0.0f, 1.0f, 0.0f));
 
        for (auto i = ShaderSet.cbegin(); i != ShaderSet.cend(); ++i)
        {
@@ -195,13 +217,52 @@ void Scene::draw() const
                (*i)->draw();
        }
 
-       render->clearBuffer();
-       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-       Shader::gBlur()->useShader();
-       render->getTexture()->useTexture();
-       //SceneObjects.front()->gTexture()->useTexture();
-       Model::getPlaneModel()->drawModel(mat4(1.f));
-       
+
+       if (Graphix::testEffect(EF_BLOOM))
+       {
+               /* DRAW BRIGHTNESS */
+               postRender->useBuffer();
+               //glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
+               glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+               Shader::getShader(SH_BASICTEXTURE)->useShader();
+               Shader::getShader(SH_BASICTEXTURE)->setUniformLocation("uBrightness", 1);
+               render->getTexture()->useTexture();
+               Model::getPlaneModel()->drawModel(mat4(1.f));
+               Shader::getShader(SH_BASICTEXTURE)->setUniformLocation("uBrightness", 0);
+
+               /* BLUR BRIGHTNESS */
+               Shader::getShader(SH_BLUR)->useShader();
+               GLboolean horizontal = true, firstit = true;
+
+               for (int i = 0; i < 10; i++)
+               {
+                       blurPingPong[horizontal]->useBuffer();
+                       //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+                       Shader::getShader(SH_BLUR)->setUniformLocation("uHorizontal", horizontal);
+                       if (firstit)
+                               postRender->getTexture(1)->useTexture();
+                       else
+                               blurPingPong[!horizontal]->getTexture()->useTexture();
+
+                       Model::getPlaneModel()->drawModel(mat4(1.f));
+
+                       horizontal = !horizontal;
+                       if (firstit)
+                               firstit = false;
+               }
+
+
+               /* BLEND BRIGHTNESS TO ORIGINAL*/
+               Shader::getShader(SH_BLEND)->useShader();
+               render->clearBuffer();
+               //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+               //SceneObjects.front()->gTexture()->useTexture();
+               render->getTexture(0)->useTexture();
+               blurPingPong[!horizontal]->getTexture()->useTexture(1);
+               Model::getPlaneModel()->drawModel(mat4(1.f));
+       }
+
+
 }
 
 void Scene::addObject(SceneObject* _add)
@@ -235,4 +296,13 @@ void Scene::setLookAt(SceneObject* _lookat)
 ViewPort& Scene::getViewport()
 {
        return viewPort;
+}
+
+void Scene::setView(unsigned int x, unsigned int y, unsigned int width, unsigned int height, bool updateProjection)
+{
+       viewPort.setView(x, y, width, height, updateProjection);
+       render->updateSize(width, height);
+       postRender->updateSize(width, height);
+       blurPingPong[0]->updateSize(width, height);
+       blurPingPong[1]->updateSize(width, height);
 }
\ No newline at end of file
index 5db976fb4820907dba9ecdf409689f52ef911917..82d09a411c14ff3d2a30c02ed4d2e6acc0faa3ca 100644 (file)
@@ -36,6 +36,8 @@ public:
        void setLookAt(SceneObject* _lookat);
        ViewPort& getViewport();
 
+       void setView(unsigned int x, unsigned int y, unsigned int width, unsigned int height, bool updateProjection = true);
+
 protected:
        ViewPort viewPort;
        Sky SkyBox;
@@ -64,5 +66,6 @@ protected:
        btDiscreteDynamicsWorld* bt_dynamics_world;
 
        fBufferObject* render;
-       fBufferObject* blur;
+       fBufferObject* postRender;
+       fBufferObject** blurPingPong;
 };
index b807e0f06c8afddea217889d6fece00efb0869f6..63d5a34c033d4c9d8b7fdd56949c9c8e26075fdf 100644 (file)
@@ -246,8 +246,8 @@ void SceneObject::draw() const
 
        if (Events::isKToggleActive(SDLK_F6) && collision != nullptr)
        {
-               Shader::gBasic()->useShader();
-               collision->bindShader(Shader::gBasic());
+               Shader::getShader(SH_BASIC)->useShader();
+               collision->bindShader(Shader::getShader(SH_BASIC));
                collision->drawWire(modelMat);
                //collision->drawWire(modelMat);
        }
index 859ac74dfc6b1ac4b3edc14e059d5f809c3cd2a9..2584e893981dc42bd0ec4716a0a8f6e3ad0114b7 100644 (file)
@@ -10,7 +10,7 @@
 
 
 
-Sky::Sky() : SceneObject(Shader::gBasicTexture(), scale(vec3(20.f)), vec4(1.f), Model::getSkyBoxModel(), "model_skybox_2D.png")
+Sky::Sky() : SceneObject(Shader::getShader(SH_BASICTEXTURE), scale(vec3(20.f)), vec4(1.f), Model::getSkyBoxModel(), "model_skybox_2D.jpg")
 {
        modelMat[3][3] = 0.f;
 }
index 302d9497e2f3125302b445c6b05488955f6ce57c..6ab90c6d1ff735e59eff540b893f3624c76940a3 100644 (file)
@@ -4,10 +4,22 @@
 in vec2 fUVs;
 
 layout(location = 0) out vec4 FragColor;
+layout(location = 1) out vec4 BrightColor;
 
 uniform sampler2D uColorTexture;
+uniform bool uBrightness = false;
  
 void main()
 {
        FragColor = texture(uColorTexture, fUVs);
+
+       if (uBrightness)
+       {
+               float brightness = dot(FragColor.rgb, vec3(0.2126, 0.7152, 0.0722));
+               if (brightness > 1.)
+                       BrightColor = vec4(FragColor.rgb, 1.0);
+               else
+                       BrightColor = vec4(0.);
+       }
+
 }
\ No newline at end of file
index 4b0bf86b79f1dbb32d0e0982ee569f2dd96ef3da..04229273e2a99e1b8a0821bae9948892d5e90b2e 100644 (file)
@@ -4,9 +4,9 @@
 in vec3 aPosition;
 in vec2 aUV;
 
-uniform mat4 uProjection;
+uniform mat4 uProjection = mat4(1.f);
 uniform mat4 uModel = mat4(1.f);
-uniform mat4 uView;
+uniform mat4 uView = mat4(1.f);
 
 uniform bool uFar = false;
 uniform bool uPlain = false;
diff --git a/shader/blend_FS.hlsl b/shader/blend_FS.hlsl
new file mode 100644 (file)
index 0000000..daf720b
--- /dev/null
@@ -0,0 +1,14 @@
+//Fragment Shader
+#version 330 core
+//in worldNormal;
+in vec2 fUVs;
+
+layout(location = 0) out vec4 FragColor;
+
+uniform sampler2D uColorTexture;
+uniform sampler2D uBlendTexture;
+
+void main()
+{
+       FragColor = texture(uColorTexture, fUVs) + texture(uBlendTexture, fUVs);
+}
\ No newline at end of file
index acbcedd1e102e72ec74fc8b1b0a6c7348af9e5f1..df8ce2a2a255daa0ad6c2cfe212c9030c1090987 100644 (file)
@@ -2,36 +2,36 @@
 #version 330 core
 in vec2 fUVs;
 
-out vec4 gl_FragColor;
+layout(location = 0) out vec4 FragColor;
 
-uniform sampler2D u_texture;
+uniform sampler2D uColorTexture;
 uniform bool uHorizontal = true;
-uniform bool uSymetric = true;
+//uniform bool uSymetric = true;
 
 uniform float weight[5] = float[](0.2270270270, 0.1945945946, 0.1216216216, 0.0540540541, 0.0162162162);
 
 
 void main()
 {
-       vec2 tex_offset = 1.0 / textureSize(u_texture, 0); // gets size of single texel
-       vec3 result = texture(u_texture, fUVs).rgb * weight[0];
+       vec2 tex_offset = 1.0 / textureSize(uColorTexture, 0); // gets size of single texel
+       vec3 result = texture(uColorTexture, fUVs).rgb * weight[0];
        if (uHorizontal)
        {
                for (int i = 1; i < 5; ++i)
                {
-                       result += texture(u_texture, fUVs + vec2(tex_offset.x * i, 0.0)).rgb * weight[i];
-                       if(uSymetric)
-                               result += texture(u_texture, fUVs - vec2(tex_offset.x * i, 0.0)).rgb * weight[i];
+                       result += texture(uColorTexture, fUVs + vec2(tex_offset.x * i, 0.0)).rgb * weight[i];
+                       //if(uSymetric)
+                               result += texture(uColorTexture, fUVs - vec2(tex_offset.x * i, 0.0)).rgb * weight[i];
                }
        }
        else
        {
                for (int i = 1; i < 5; ++i)
                {
-                       result += texture(u_texture, fUVs + vec2(0.0, tex_offset.y * i)).rgb * weight[i];
-                       if(uSymetric)
-                               result += texture(u_texture, fUVs - vec2(0.0, tex_offset.y * i)).rgb * weight[i];
+                       result += texture(uColorTexture, fUVs + vec2(0.0, tex_offset.y * i)).rgb * weight[i];
+                       //if(uSymetric)
+                               result += texture(uColorTexture, fUVs - vec2(0.0, tex_offset.y * i)).rgb * weight[i];
                }
        }
-       gl_FragColor = vec4(result, 1.0);
+       FragColor = vec4(result, 1.0);
 }
\ No newline at end of file
index c3a96a7b2b6742541e7bd56c00471d66f581b9a2..7b8cb9d75b0b135f7393bd75887844c8ca654a66 100644 (file)
@@ -5,7 +5,7 @@ in vec2 fUVs;
 
 in vec3 PointLightPosition1, DirectionalLightDirection1;
 
-layout (location = 0) out vec4 FragColor;
+layout(location = 0) out vec4 FragColor;
 
 uniform sampler2D uColorTexture;
 uniform vec4 material;                                 //vec4 in the form (ambient, point, directional, glossyness); so far it was (1, 1, 1, 3)
@@ -42,7 +42,6 @@ void main()
                + DirectionalLightColor1 * material[2] * (cosThetaDirection1 + pow(SpecularCosDirection1, specularConst))
                ), uvColor.a);
 
-
        //FragColor = vec4((normalize(worldNormal)+1)/2, 1.0f);
        //FragColor = vec4(length(DirectionalLightDirection1) - 1.0f, length(DirectionalLightDirection1) - 1.0f, length(DirectionalLightDirection1) - 1.0f, 1.0f);