From: LockedLunatic Date: Thu, 21 Apr 2016 00:28:32 +0000 (+0200) Subject: derzeitiger Stand X-Git-Url: https://git.leopard-lacewing.eu/?a=commitdiff_plain;h=0cbe6bd2eb7d6075ca7b6f5a227e8ebfffeef54b;p=cgue_weave.git derzeitiger Stand --- 0cbe6bd2eb7d6075ca7b6f5a227e8ebfffeef54b diff --cc CGUE2015_Weave.sln index 6e1ae8e,af72ee4..300f1ec --- a/CGUE2015_Weave.sln +++ b/CGUE2015_Weave.sln @@@ -14,9 -15,6 +15,8 @@@ Project("{2150E333-8FDC-42A3-9474-1A395 shader\blur_FS.hlsl = shader\blur_FS.hlsl shader\lightingTexture_FS.hlsl = shader\lightingTexture_FS.hlsl shader\perspective_VS.hlsl = shader\perspective_VS.hlsl + shader\shadowmapDir_FS.hlsl = shader\shadowmapDir_FS.hlsl + shader\shadowmapDir_VS.hlsl = shader\shadowmapDir_VS.hlsl - shader\skybox_VS.hlsl = shader\skybox_VS.hlsl shader\skyplane_color_FS.hlsl = shader\skyplane_color_FS.hlsl shader\skyplane_FS.hlsl = shader\skyplane_FS.hlsl shader\skyplane_VS.hlsl = shader\skyplane_VS.hlsl diff --cc Weave/Graphix/Graphix.cpp index a3118c9,90ba04c..d6d9e09 --- a/Weave/Graphix/Graphix.cpp +++ b/Weave/Graphix/Graphix.cpp @@@ -144,9 -148,7 +148,6 @@@ void Graphix::init( glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearAccum(0.f, 0.f, 0.f, 0.f); glClear(GL_ACCUM_BUFFER_BIT); -- - shader_BBox = new Shader("basic_VS.hlsl", "basic_FS.hlsl"); - shadow_dir = new Shader("shadowmapDir_VS.hlsl", "shadowmapDir_FS.hlsl"); } void Graphix::FullScreen(bool _enable, bool _keepDesktopResolution) diff --cc Weave/Graphix/Shader.cpp index b084561,9285906..1af65e0 --- a/Weave/Graphix/Shader.cpp +++ b/Weave/Graphix/Shader.cpp @@@ -141,3 -218,37 +218,38 @@@ GLuint Shader::loadProgram(GLuint _shad } return programHandle; } + + void Shader::init() + { + 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"); ++ shList[SH_SHADOWDIR] = new Shader("shadowmapDir_VS.hlsl", "shadowmapDir_FS.hlsl"); + } + + initShader = true; + } + + void Shader::cleanup() + { + if (initShader) + { + for (int i = 1; i < 6; i++) + delete shList[i]; + } + + initShader = false; + } + + const Shader* Shader::getShader(ShaderTarget _target) + { + return shList[_target]; + } + + + bool Shader::initShader = false; + const Shader* Shader::shList[6]; diff --cc Weave/Graphix/Shader.h index 027281a,f30a52d..77ebd46 --- a/Weave/Graphix/Shader.h +++ b/Weave/Graphix/Shader.h @@@ -7,6 -9,15 +9,16 @@@ 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 ++ SH_BLEND = 5, ++ SH_SHADOWDIR = 6 + }; + class Shader { public: diff --cc Weave/Graphix/Textures/Texture.cpp index 0000000,d016d5a..32703c4 mode 000000,100644..100644 --- a/Weave/Graphix/Textures/Texture.cpp +++ b/Weave/Graphix/Textures/Texture.cpp @@@ -1,0 -1,131 +1,149 @@@ + #include "Texture.h" + #include + + #include "../../Message.h" + #include "../Shader.h" + + #include "tImage.h" + + using std::string; + using std::unordered_map; + + + Texture::Texture() + : texture_internal(GL_RGB16F), texture_format(GL_RGB),texture_target(GL_TEXTURE_2D),texture_type(GL_UNSIGNED_BYTE) + { + glGenTextures(1, &handle); + } + + Texture::~Texture() + { + glDeleteTextures(1, &handle); + } + + Texture* Texture::newTImage(const string& _path, const vec4& _material) + { + texHandle& t_ptr = texture_Map[_path]; + + if (t_ptr.ptr == nullptr) + { + t_ptr.ptr = new tImage(_path, _material); + handle_Map[t_ptr.ptr->handle] = &t_ptr; + } + + ++t_ptr.count; + + return t_ptr.ptr; + } + + void Texture::deleteTImage(unsigned int _handle) + { + texHandle& t_ptr = *handle_Map[_handle]; + + if (t_ptr.ptr == nullptr) + { + Message::warning("deleteTexture: Image doesn't exist."); + return; + } + + --t_ptr.count; + + if (!t_ptr.count) + { + texture_Map.erase(*t_ptr.ptr); + //delete t_ptr.ptr; + } + } + + unsigned int Texture::getTTarget() const + { + return texture_target; + } + + + Texture::operator unsigned int() const + { + return handle; + } + + void Texture::bindTexture(unsigned int _width, unsigned int _height) + { + if (_width != 0 && _height != 0) + { + width = _width; + height = _height; + } + + glBindTexture(texture_target, handle); + + if(data!=nullptr) + glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + else + glTexParameteri(texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + glTexParameteri(texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glTexParameteri(texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + //glTexParameteri(texture_target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); + + glTexImage2D(texture_target, 0, texture_internal, width, height, 0, texture_format, texture_type, data); + } + + void Texture::unbindTexture() + { + glDeleteTextures(1, &handle); + glGenTextures(1, &handle); + } + + void Texture::useTexture(unsigned int _unit) const + { + + /* bind Texture*/ + glActiveTexture(GL_TEXTURE0 + _unit); + glBindTexture(texture_target, handle); + + switch (_unit) + { + case 1: + Shader::getShader()->setUniformLocation("uBlendTexture", _unit); + break; ++ case 2: ++ Shader::getShader()->setUniformLocation("upointLightxp", _unit); ++ break; ++ case 3: ++ Shader::getShader()->setUniformLocation("upointLightxm", _unit); ++ break; ++ case 4: ++ Shader::getShader()->setUniformLocation("upointLightyp", _unit); ++ break; ++ case 5: ++ Shader::getShader()->setUniformLocation("upointLightym", _unit); ++ break; ++ case 6: ++ Shader::getShader()->setUniformLocation("upointLightzp", _unit); ++ break; ++ case 7: ++ Shader::getShader()->setUniformLocation("upointLightzm", _unit); ++ break; + default: + Shader::getShader()->setUniformLocation("uColorTexture", _unit); + break; + } + } + + 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); + } + + + unordered_map Texture::texture_Map; + unordered_map Texture::handle_Map; diff --cc Weave/Graphix/ViewPort.cpp index 9f05ecb,c7a5d2e..8b93506 --- a/Weave/Graphix/ViewPort.cpp +++ b/Weave/Graphix/ViewPort.cpp @@@ -37,58 -36,23 +37,32 @@@ void ViewPort::useViewPort() cons glViewport(xpos, ypos, width, height); } - void ViewPort::bindView(Shader* shader) const{ + void ViewPort::bindView(const Shader* shader) const{ shader->useShader(); - int tmp = -1; - tmp = shader->getUniformLocation("uProjection"); - if (tmp >= 0) - glUniformMatrix4fv(tmp, 1, false, value_ptr(projection)); + shader->setUniformLocation("uProjection", projection); + shader->setUniformLocation("uInvProjection", glm::inverse(projection)); + shader->setUniformLocation("uView", view); - tmp = shader->getUniformLocation("uInvProjection"); - if (tmp >= 0) - glUniformMatrix4fv(tmp, 1, false, value_ptr(glm::inverse(projection))); - - tmp = shader->getUniformLocation("uView"); - if (tmp >= 0) - glUniformMatrix4fv(tmp, 1, false, value_ptr(view)); } - void ViewPort::bindView(Shader* shader, vec3 pos) const{ + void ViewPort::bindView(const Shader* shader, vec3 pos) const{ shader->useShader(); - int tmp = -1; - - tmp = shader->getUniformLocation("uProjection"); - if (tmp>=0) - glUniformMatrix4fv(tmp, 1, false, value_ptr(projection)); - - tmp = shader->getUniformLocation("uInvProjection"); - if (tmp >= 0) - glUniformMatrix4fv(tmp, 1, false, value_ptr(glm::inverse(projection))); - tmp = shader->getUniformLocation("uView"); - if (tmp >= 0) - glUniformMatrix4fv(tmp, 1, false, value_ptr(translate(view,-pos))); + shader->setUniformLocation("uProjection", projection); + shader->setUniformLocation("uInvProjection", glm::inverse(projection)); + shader->setUniformLocation("uView", translate(view, -pos)); } - void ViewPort::bindViewShadowDir(Shader* shader) const { ++void ViewPort::bindViewShadowDir(const Shader* shader) const { + shader->useShader(); - int tmp = -1; - - tmp = shader->getUniformLocation("uProjection"); - if (tmp >= 0) - glUniformMatrix4fv(tmp, 1, false, value_ptr(glm::mat4(1 / shadow_dist))); - - tmp = shader->getUniformLocation("uInvProjection"); - if (tmp >= 0) - glUniformMatrix4fv(tmp, 1, false, value_ptr(glm::mat4(shadow_dist))); + - tmp = shader->getUniformLocation("uView"); - if (tmp >= 0) - //TODO the real thing - glUniformMatrix4fv(tmp, 1, false, value_ptr(view)); ++ shader->setUniformLocation("uProjection", glm::mat4(1 / shadow_dist)); ++ shader->setUniformLocation("uInvProjection", glm::mat4(shadow_dist)); ++ //TODO the real thing ++ shader->setUniformLocation("uView", view); +} + void ViewPort::rotateView(float angle_x, float angle_y){ if (angle_y || angle_x){ diff --cc Weave/Graphix/ViewPort.h index fdf8bdf,4770d2e..62c02a6 --- a/Weave/Graphix/ViewPort.h +++ b/Weave/Graphix/ViewPort.h @@@ -15,9 -15,8 +15,9 @@@ public void setView(unsigned int x, unsigned int y, unsigned int width, unsigned int height, bool updateProjection = true); - void bindView(Shader* shader) const; - void bindView(Shader* shader, vec3 lookat) const; - void bindViewShadowDir(Shader* shader) const; + void bindView(const Shader* shader) const; + void bindView(const Shader* shader, vec3 lookat) const; ++ void bindViewShadowDir(const Shader* shader) const; void rotateView(float angle_x, float angle_y); vec3 rotateDirection(const vec3 & direction) const; diff --cc Weave/Scene/Scene.cpp index 848be43,3c7f60d..e1fd1ac --- a/Weave/Scene/Scene.cpp +++ b/Weave/Scene/Scene.cpp @@@ -54,6 -56,26 +56,30 @@@ lookat(_lookat bt_dynamics_world->setGravity(btVector3(0, YFALL_SPEED, 0)); + + + render = new fBufferObject(); + + 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()); + ++ shadowdir = new fBufferObject(); ++ ++ shadowdir->bindBuffer(Graphix::getWindowWidth(), Graphix::getWindowHeight()); ++ + + postRender = new fBufferObject(2, false); + + postRender->bindBuffer(Graphix::getWindowWidth(), Graphix::getWindowHeight()); + + render->clearBuffer(); } @@@ -74,6 -96,12 +100,15 @@@ Scene::~Scene( delete bt_dispatcher; delete bt_collision_configuration; + //fBO + delete render; + delete blurPingPong[0]; + delete blurPingPong[1]; + delete blurPingPong; + ++ delete shadowdir; ++ delete postRender; ++ //if (viewPort != nullptr) // delete viewPort; @@@ -163,14 -191,19 +198,28 @@@ void Scene::update(float deltaT void Scene::draw() const { ++ //Directional Light Shadow ++ shadowdir->useBuffer(); ++ viewPort.bindViewShadowDir(Shader::getShader(SH_SHADOWDIR)); ++ 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(); - //Directional Light Shadow - viewPort.bindViewShadowDir(Graphix::shadow_dir); //Skybox - viewPort.bindView(SkyBox.getShader(), lookat->getPosition() + vec3(0.0f, 1.0f, 0.0f)); + viewPort.bindView(SkyBox.gShader(), lookat->getPosition() + vec3(0.0f, 1.0f, 0.0f)); //BBox - viewPort.bindView(Graphix::shader_BBox, 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) { diff --cc Weave/Scene/Scene.h index baddcb2,82d09a4..ebe02e5 --- a/Weave/Scene/Scene.h +++ b/Weave/Scene/Scene.h @@@ -61,4 -64,8 +64,9 @@@ protected btSequentialImpulseConstraintSolver* bt_solver; btCollisionWorld* bt_collision_world; btDiscreteDynamicsWorld* bt_dynamics_world; + + fBufferObject* render; + fBufferObject* postRender; + fBufferObject** blurPingPong; ++ fBufferObject* shadowdir; };