From 38cb1b6575be38ad29e98f4c33665c214754a0c0 Mon Sep 17 00:00:00 2001 From: Peter Schaefer Date: Mon, 18 Apr 2016 13:05:49 +0200 Subject: [PATCH] =?utf8?q?getShader=20Methode=20ge=C3=A4ndert,=20Bloom=20l?= =?utf8?q?=C3=A4uft=20Window=20Resize=20->=20Buffer=20l=C3=A4uft?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- CGUE2015_Weave.sln | 1 + Weave/Game.cpp | 28 ++++--- Weave/Graphix/Graphix.cpp | 4 +- Weave/Graphix/Model/Model.cpp | 17 +++-- Weave/Graphix/Model/Plane.cpp | 4 +- Weave/Graphix/Model/SkyBox.cpp | 4 +- Weave/Graphix/Shader.cpp | 56 ++++++-------- Weave/Graphix/Shader.h | 23 +++--- Weave/Graphix/Textures/Texture.cpp | 17 ++++- Weave/Graphix/Textures/Texture.h | 2 +- Weave/Graphix/Textures/fBufferObject.cpp | 2 +- Weave/Graphix/Textures/tImage.cpp | 4 +- Weave/Scene/EventBox.cpp | 2 +- Weave/Scene/Scene.cpp | 96 ++++++++++++++++++++---- Weave/Scene/Scene.h | 5 +- Weave/Scene/SceneObject.cpp | 4 +- Weave/Scene/Sky.cpp | 2 +- shader/basicTexture_FS.hlsl | 12 +++ shader/basic_VS.hlsl | 4 +- shader/blend_FS.hlsl | 14 ++++ shader/blur_FS.hlsl | 24 +++--- shader/lightingTexture_FS.hlsl | 3 +- 22 files changed, 216 insertions(+), 112 deletions(-) create mode 100644 shader/blend_FS.hlsl diff --git a/CGUE2015_Weave.sln b/CGUE2015_Weave.sln index 014bd36..af72ee4 100644 --- a/CGUE2015_Weave.sln +++ b/CGUE2015_Weave.sln @@ -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 diff --git a/Weave/Game.cpp b/Weave/Game.cpp index ca049e7..8fa4a32 100644 --- a/Weave/Game.cpp +++ b/Weave/Game.cpp @@ -45,28 +45,30 @@ Game::Game() : playing(true) // load LVL - SceneObject* tmp_world = new Level(Shader::gLighting(), "level_1", "model_levelTest_2D.jpg"); + auto defaultShader = Shader::getShader(SH_LIGHTING); + + SceneObject* tmp_world = new Level(defaultShader, "level_1", "model_levelTest_2D.jpg"); //tmp_world->ignore = true; current_world->addObject(tmp_world); -// 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(), "")); +// 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(), "")); //Player - 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))); + 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))); tmp_playerObject->yStatic= false; current_world->addObject(tmp_playerObject); current_world->setLookAt(tmp_playerObject); - //current_world->addObject(new SceneObject(Shader::gLighting(), glm::mat4(1.0f), "Player.dae", "model_player.png")); - //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")); - 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")); - 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")); - 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")); + //current_world->addObject(new SceneObject(defaultShader, glm::mat4(1.0f), "Player.dae", "model_player.png")); + //current_world->addObject(new SceneObject(defaultShader, translate(vec3(-3.f, .4f, 0.f))*scale(vec3(3.f)), "cow/cow.dae", "model_cow_2D.jpg")); + 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")); + 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")); + 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")); - 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")); + 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")); //current_world->addObject(new EventBox(translate(vec3(3.f, .4f, 0.f)),EB_LOSTZONE)); current_world->addObject(new EventBox(translate(vec3(3.f, .4f, -15.f)), EB_WINZONE)); @@ -136,9 +138,13 @@ void Game::play() void Game::update(float deltaT) { - + /* ADJUST WINDOWS SIZE*/ if (Graphix::getWindowHeight() != current_world->getViewport().getHeight() || Graphix::getWindowWidth() != current_world->getViewport().getWidth()) - current_world->getViewport().setView(0, 0, Graphix::getWindowWidth(), Graphix::getWindowHeight()); + { + current_world->setView(0, 0, Graphix::getWindowWidth(), Graphix::getWindowHeight()); + + } + if (playing){ current_world->update(deltaT); diff --git a/Weave/Graphix/Graphix.cpp b/Weave/Graphix/Graphix.cpp index 530973c..90ba04c 100644 --- a/Weave/Graphix/Graphix.cpp +++ b/Weave/Graphix/Graphix.cpp @@ -144,7 +144,7 @@ void Graphix::init() glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glClearColor(0.9f, 0.9f, 1.0f, 1.f); + glClearColor(0.0f, 0.0f, 0.0f, 1.f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearAccum(0.f, 0.f, 0.f, 0.f); glClear(GL_ACCUM_BUFFER_BIT); @@ -285,4 +285,4 @@ SDL_Window* Graphix::sdl_window; SDL_GLContext Graphix::sdl_glcontext; -short Graphix::effects = EF_TRANSPARENCY; +short Graphix::effects = EF_TRANSPARENCY | EF_BLOOM; diff --git a/Weave/Graphix/Model/Model.cpp b/Weave/Graphix/Model/Model.cpp index 5ea99ca..ed85201 100644 --- a/Weave/Graphix/Model/Model.cpp +++ b/Weave/Graphix/Model/Model.cpp @@ -145,7 +145,7 @@ void Model::drawWire(const mat4& _modelMat, const vec4& _color) const useModel(_modelMat); - Shader::gActive()->setUniformLocation("uFragmentColor", _color); + Shader::getShader()->setUniformLocation("uFragmentColor", _color); drawWire(); @@ -154,9 +154,9 @@ void Model::drawWire(const mat4& _modelMat, const vec4& _color) const void Model::drawBBox(const mat4& _modelMat, const vec4& _color) const { Graphix::getGlError(); - Shader::gBasic()->useShader(); + Shader::getShader(SH_BASIC)->useShader(); - Shader::gActive()->setUniformLocation("uFragmentColor", _color); + Shader::getShader()->setUniformLocation("uFragmentColor", _color); Graphix::getGlError(); @@ -194,7 +194,7 @@ void Model::useModel(const mat4& _modelMat) const /* use MODEL*/ uint vao = -1; - auto i = shader_map.find(*Shader::gActive()); + auto i = shader_map.find(*Shader::getShader()); if (i == shader_map.end()) Message::error("Model: Shader wurde nicht an das Model gebunden."); else @@ -204,7 +204,7 @@ void Model::useModel(const mat4& _modelMat) const /* use ModelMAT*/ - Shader::gActive()->setUniformLocation("uModel", _modelMat); + Shader::getShader()->setUniformLocation("uModel", _modelMat); } @@ -233,7 +233,7 @@ Model* Model::getBBoxModel() { BoundingBox = new BBox(); BoundingBox->bindModel(); - BoundingBox->bindShader(Shader::gBasic()); + BoundingBox->bindShader(Shader::getShader(SH_BASIC)); } return BoundingBox; } @@ -244,8 +244,9 @@ Model* Model::getPlaneModel() { PlaneModel = new Plane(); PlaneModel->bindModel(); - PlaneModel->bindShader(Shader::gBasicTexture()); - PlaneModel->bindShader(Shader::gBlur()); + PlaneModel->bindShader(Shader::getShader(SH_BASICTEXTURE)); + PlaneModel->bindShader(Shader::getShader(SH_BLUR)); + PlaneModel->bindShader(Shader::getShader(SH_BLEND)); } return PlaneModel; } diff --git a/Weave/Graphix/Model/Plane.cpp b/Weave/Graphix/Model/Plane.cpp index c34955d..7772e79 100644 --- a/Weave/Graphix/Model/Plane.cpp +++ b/Weave/Graphix/Model/Plane.cpp @@ -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); diff --git a/Weave/Graphix/Model/SkyBox.cpp b/Weave/Graphix/Model/SkyBox.cpp index 64f9919..4b777d0 100644 --- a/Weave/Graphix/Model/SkyBox.cpp +++ b/Weave/Graphix/Model/SkyBox.cpp @@ -38,8 +38,8 @@ void SkyBox::drawModel(const mat4& _modelMat) const useModel(_modelMat); - Shader::gActive()->setUniformLocation("uPlain", 0); - Shader::gActive()->setUniformLocation("uFar", 1); + Shader::getShader()->setUniformLocation("uPlain", 0); + Shader::getShader()->setUniformLocation("uFar", 1); Model::drawModel(); //glEnable(GL_DEPTH_TEST); diff --git a/Weave/Graphix/Shader.cpp b/Weave/Graphix/Shader.cpp index 2a29b5e..9285906 100644 --- a/Weave/Graphix/Shader.cpp +++ b/Weave/Graphix/Shader.cpp @@ -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]; diff --git a/Weave/Graphix/Shader.h b/Weave/Graphix/Shader.h index 8a96a4f..f30a52d 100644 --- a/Weave/Graphix/Shader.h +++ b/Weave/Graphix/Shader.h @@ -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[]; }; diff --git a/Weave/Graphix/Textures/Texture.cpp b/Weave/Graphix/Textures/Texture.cpp index c08d34b..d016d5a 100644 --- a/Weave/Graphix/Textures/Texture.cpp +++ b/Weave/Graphix/Textures/Texture.cpp @@ -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); } diff --git a/Weave/Graphix/Textures/Texture.h b/Weave/Graphix/Textures/Texture.h index 5da8a95..ff15a82 100644 --- a/Weave/Graphix/Textures/Texture.h +++ b/Weave/Graphix/Textures/Texture.h @@ -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; diff --git a/Weave/Graphix/Textures/fBufferObject.cpp b/Weave/Graphix/Textures/fBufferObject.cpp index ea23db1..ebef232 100644 --- a/Weave/Graphix/Textures/fBufferObject.cpp +++ b/Weave/Graphix/Textures/fBufferObject.cpp @@ -27,7 +27,7 @@ fBufferObject::fBufferObject(unsigned int _dim, bool _rbo) fBufferObject::~fBufferObject() { - delete textures; +// delete textures; if (rBO != nullptr) delete rBO; diff --git a/Weave/Graphix/Textures/tImage.cpp b/Weave/Graphix/Textures/tImage.cpp index 9b0dea0..3e6a9dd 100644 --- a/Weave/Graphix/Textures/tImage.cpp +++ b/Weave/Graphix/Textures/tImage.cpp @@ -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); } diff --git a/Weave/Scene/EventBox.cpp b/Weave/Scene/EventBox.cpp index 6b272cc..1c54ff5 100644 --- a/Weave/Scene/EventBox.cpp +++ b/Weave/Scene/EventBox.cpp @@ -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; diff --git a/Weave/Scene/Scene.cpp b/Weave/Scene/Scene.cpp index d0f1204..3c7f60d 100644 --- a/Weave/Scene/Scene.cpp +++ b/Weave/Scene/Scene.cpp @@ -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 diff --git a/Weave/Scene/Scene.h b/Weave/Scene/Scene.h index 5db976f..82d09a4 100644 --- a/Weave/Scene/Scene.h +++ b/Weave/Scene/Scene.h @@ -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; }; diff --git a/Weave/Scene/SceneObject.cpp b/Weave/Scene/SceneObject.cpp index b807e0f..63d5a34 100644 --- a/Weave/Scene/SceneObject.cpp +++ b/Weave/Scene/SceneObject.cpp @@ -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); } diff --git a/Weave/Scene/Sky.cpp b/Weave/Scene/Sky.cpp index 859ac74..2584e89 100644 --- a/Weave/Scene/Sky.cpp +++ b/Weave/Scene/Sky.cpp @@ -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; } diff --git a/shader/basicTexture_FS.hlsl b/shader/basicTexture_FS.hlsl index 302d949..6ab90c6 100644 --- a/shader/basicTexture_FS.hlsl +++ b/shader/basicTexture_FS.hlsl @@ -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 diff --git a/shader/basic_VS.hlsl b/shader/basic_VS.hlsl index 4b0bf86..0422927 100644 --- a/shader/basic_VS.hlsl +++ b/shader/basic_VS.hlsl @@ -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 index 0000000..daf720b --- /dev/null +++ b/shader/blend_FS.hlsl @@ -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 diff --git a/shader/blur_FS.hlsl b/shader/blur_FS.hlsl index acbcedd..df8ce2a 100644 --- a/shader/blur_FS.hlsl +++ b/shader/blur_FS.hlsl @@ -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 diff --git a/shader/lightingTexture_FS.hlsl b/shader/lightingTexture_FS.hlsl index c3a96a7..7b8cb9d 100644 --- a/shader/lightingTexture_FS.hlsl +++ b/shader/lightingTexture_FS.hlsl @@ -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); -- 2.47.3