From: Peter Schaefer Date: Wed, 13 Apr 2016 11:29:46 +0000 (+0200) Subject: defined static Shaders (Basic,Lighting,Blur) X-Git-Url: https://git.leopard-lacewing.eu/?a=commitdiff_plain;h=9ca5c3f3bc2e67b3a7cd7710c6a27aaaf42e7a85;p=cgue_weave.git defined static Shaders (Basic,Lighting,Blur) corrected const for Shader --- diff --git a/CGUE2015_Weave.sln b/CGUE2015_Weave.sln index e715e71..04a4572 100644 --- a/CGUE2015_Weave.sln +++ b/CGUE2015_Weave.sln @@ -14,6 +14,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shader", "shader", "{75179E 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\plane_VS.hlsl = shader\plane_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 diff --git a/Weave/Game.cpp b/Weave/Game.cpp index 3ef93e4..1778c4b 100644 --- a/Weave/Game.cpp +++ b/Weave/Game.cpp @@ -43,33 +43,30 @@ Game::Game() : playing(true) // Hauptfenster current_world = new Scene(0, 0, Graphix::getWindowWidth(), Graphix::getWindowHeight(), 45, 0.1f, 40, vec3(0.0f, 0.0f, 0.f)); - //Allg Shader - Shader* shader1 = new Shader("basicTexture_VS.hlsl", "lightingTexture_FS.hlsl"); - // load LVL - SceneObject* tmp_world = new Level(shader1, "level_1", "model_levelTest_2D.jpg"); + SceneObject* tmp_world = new Level(Shader::gLighting(), "level_1", "model_levelTest_2D.jpg"); //tmp_world->ignore = true; current_world->addObject(tmp_world); -// current_world->addObject(new SceneObject(shader1, translate(vec3(-3.f, 1.f, 0.f)), vec4(1.0f, 1.0f, 1.0f, 3.0f), new BBox(), "")); +// 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(), "")); //Player - SceneObject* tmp_playerObject = new Marvin(shader1, 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(Shader::gLighting(), 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(shader1, glm::mat4(1.0f), "Player.dae", "model_player.png")); - //current_world->addObject(new SceneObject(shader1, translate(vec3(-3.f, .4f, 0.f))*scale(vec3(3.f)), "cow/cow.dae", "model_cow_2D.jpg")); - current_world->addObject(new SceneObject(shader1, 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(shader1, 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(shader1, 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(), 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(shader1, 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(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 EventBox(translate(vec3(3.f, .4f, 0.f)),EB_LOSTZONE)); current_world->addObject(new EventBox(translate(vec3(3.f, .4f, -15.f)), EB_WINZONE)); diff --git a/Weave/Graphix/Graphix.cpp b/Weave/Graphix/Graphix.cpp index 3a98fbb..4db3355 100644 --- a/Weave/Graphix/Graphix.cpp +++ b/Weave/Graphix/Graphix.cpp @@ -3,7 +3,6 @@ #include "Debug.h" #include "../Message.h" -#include "Shader.h" #include using std::string; @@ -146,7 +145,6 @@ void Graphix::init() glClearAccum(0.f, 0.f, 0.f, 0.f); glClear(GL_ACCUM_BUFFER_BIT); - shader_BBox = new Shader("basic_VS.hlsl", "basic_FS.hlsl"); } void Graphix::FullScreen(bool _enable, bool _keepDesktopResolution) @@ -227,8 +225,6 @@ void Graphix::swap() void Graphix::cleanup() { - delete shader_BBox; - //SDL_SetWindowGrab(sdl_window, SDL_FALSE); SDL_GL_DeleteContext(sdl_glcontext); @@ -284,5 +280,3 @@ SDL_Window* Graphix::sdl_window; SDL_GLContext Graphix::sdl_glcontext; short Graphix::effects = EF_TRANSPARENCY; - -Shader* Graphix::shader_BBox; diff --git a/Weave/Graphix/Graphix.h b/Weave/Graphix/Graphix.h index bde1f6a..337482d 100644 --- a/Weave/Graphix/Graphix.h +++ b/Weave/Graphix/Graphix.h @@ -14,8 +14,6 @@ enum Effects { EF_BLOOM = BIT(3) }; -class Shader; - class Graphix { public: @@ -42,8 +40,6 @@ public: static unsigned int getGlError(); - static Shader* shader_BBox; - private: static void updateEffects(); diff --git a/Weave/Graphix/Model/IMetaMesh.cpp b/Weave/Graphix/Model/IMetaMesh.cpp index 6cb7e04..b536c17 100644 --- a/Weave/Graphix/Model/IMetaMesh.cpp +++ b/Weave/Graphix/Model/IMetaMesh.cpp @@ -130,7 +130,7 @@ void IMetaMesh::unbindModel() } } -void IMetaMesh::bindShader(Shader* _shader) +void IMetaMesh::bindShader(const Shader* _shader) { for (auto i = models.begin(); i != models.end(); ++i) { @@ -138,7 +138,7 @@ void IMetaMesh::bindShader(Shader* _shader) } } -void IMetaMesh::unbindShader(Shader* _shader) +void IMetaMesh::unbindShader(const Shader* _shader) { for (auto i = models.begin(); i != models.end(); ++i) { diff --git a/Weave/Graphix/Model/IMetaMesh.h b/Weave/Graphix/Model/IMetaMesh.h index 781fd29..287add2 100644 --- a/Weave/Graphix/Model/IMetaMesh.h +++ b/Weave/Graphix/Model/IMetaMesh.h @@ -15,12 +15,12 @@ public: IMetaMesh(const std::string& modelpath, const vec3& scale = vec3(1.f), bool isConvex = true); ~IMetaMesh(); - void bindShader(Shader* shader) override; + void bindShader(const Shader* shader) override; void bindModel() override; void unbindModel() override; - void unbindShader(Shader* shader) override; + void unbindShader(const Shader* shader) override; void drawModel(const mat4& modelMat) const override; diff --git a/Weave/Graphix/Model/Model.cpp b/Weave/Graphix/Model/Model.cpp index a9739ae..7afe8de 100644 --- a/Weave/Graphix/Model/Model.cpp +++ b/Weave/Graphix/Model/Model.cpp @@ -74,7 +74,7 @@ void Model::unbindModel() } -void Model::bindShader(Shader* _shader) +void Model::bindShader(const Shader* _shader) { auto i = shader_map.find(*_shader); if (i != shader_map.end()) @@ -114,7 +114,7 @@ void Model::bindShader(Shader* _shader) } -void Model::unbindShader(Shader* _shader) +void Model::unbindShader(const Shader* _shader) { glDeleteVertexArrays(1, &(shader_map[*_shader])); shader_map.erase(*_shader); @@ -155,8 +155,8 @@ void Model::drawWire(const mat4& _modelMat) const void Model::drawBBox(const mat4& _modelMat, const vec4& _color) const { Graphix::getGlError(); - Graphix::shader_BBox->useShader(); - int tmp = Graphix::shader_BBox->getUniformLocation("uFragmentColor"); + Shader::gBasic()->useShader(); + int tmp = Shader::gBasic()->getUniformLocation("uFragmentColor"); if (tmp >= 0) glUniform4fv(tmp, 1, value_ptr(_color)); Graphix::getGlError(); @@ -171,7 +171,7 @@ void Model::drawBBox(const mat4& _modelMat, const vec4& _color) const vec3 size = (max - min); vec3 center = (max + min) * .5f; - Graphix::shader_BBox->useShader(); + Shader::gBasic()->useShader(); getBBoxModel()->drawModel(_modelMat*translate(center)*glm::scale(size)); // } @@ -231,11 +231,9 @@ void Model::bindBuffer(const uint &buffer, const uint target, const uint index, void Model::useModel(const mat4& _modelMat) const { - auto active_shader = Shader::getActive(); - /* use MODEL*/ uint vao = -1; - auto i = shader_map.find(*active_shader); + auto i = shader_map.find(*Shader::gActive()); if (i == shader_map.end()) Message::error("Model: Shader wurde nicht an das Model gebunden."); else @@ -245,7 +243,7 @@ void Model::useModel(const mat4& _modelMat) const /* use ModelMAT*/ - int tmp = active_shader->getUniformLocation("uModel"); + int tmp = Shader::gActive()->getUniformLocation("uModel"); if (tmp >= 0) glUniformMatrix4fv(tmp, 1, GL_FALSE, value_ptr(_modelMat)); @@ -276,7 +274,7 @@ Model* Model::getBBoxModel() { BoundingBox = new BBox(); BoundingBox->bindModel(); - BoundingBox->bindShader(Graphix::shader_BBox); + BoundingBox->bindShader(Shader::gBasic()); } return BoundingBox; } diff --git a/Weave/Graphix/Model/Model.h b/Weave/Graphix/Model/Model.h index dba4ac8..81499e5 100644 --- a/Weave/Graphix/Model/Model.h +++ b/Weave/Graphix/Model/Model.h @@ -20,8 +20,8 @@ public: virtual void unbindModel(); /* Binds Model to the Shader*/ - virtual void bindShader(Shader* shader); - virtual void unbindShader(Shader* shader); + virtual void bindShader(const Shader* shader); + virtual void unbindShader(const Shader* shader); /* Draws Model */ virtual void drawModel(const mat4& modelMat) const; diff --git a/Weave/Graphix/Shader.cpp b/Weave/Graphix/Shader.cpp index a54b9c0..46af2c1 100644 --- a/Weave/Graphix/Shader.cpp +++ b/Weave/Graphix/Shader.cpp @@ -27,15 +27,10 @@ Shader::~Shader() void Shader::useShader() const { - active = this; + shActive = this; glUseProgram(handle); } -Shader const* Shader::getActive() -{ - return active; -} - int Shader::getAttribLocation(const string& name) const { int ind = glGetAttribLocation(handle, name.c_str()); @@ -148,5 +143,42 @@ GLuint Shader::loadProgram(GLuint _shader1, GLuint _shader2){ return programHandle; } +void Shader::init() +{ + if(shBasic==nullptr) + shBasic = new Shader("basic_VS.hlsl", "basic_FS.hlsl"); + if(shLighting==nullptr) + shLighting = new Shader("basicTexture_VS.hlsl", "lightingTexture_FS.hlsl"); + if(shBlur==nullptr) + shBlur = new Shader("plane_VS.hlsl", "blur_FS.hlsl"); +} + +void Shader::cleanup() +{ + delete shBasic, shLighting, shBlur; +} + +const Shader * Shader::gActive() +{ + return shActive; +} + +const Shader * Shader::gBasic() +{ + return shBasic; +} + +const Shader * Shader::gLighting() +{ + return shLighting; +} + +const Shader * Shader::gBlur() +{ + return shBlur; +} -Shader const * Shader::active = nullptr; \ No newline at end of file +const Shader * Shader::shActive = nullptr; +const Shader * Shader::shBasic = nullptr; +const Shader * Shader::shLighting = nullptr; +const Shader * Shader::shBlur = nullptr; diff --git a/Weave/Graphix/Shader.h b/Weave/Graphix/Shader.h index 0dd95f1..460ee3d 100644 --- a/Weave/Graphix/Shader.h +++ b/Weave/Graphix/Shader.h @@ -15,13 +15,19 @@ public: void useShader() const; - static Shader const* getActive(); - int getAttribLocation(const string& name) const; int getUniformLocation(const string& name) const; uint getHandle() const; operator uint() const; + static const Shader * gActive(); + static const Shader * gBasic(); + static const Shader * gLighting(); + static const Shader * gBlur(); + + static void init(); + static void cleanup(); + private: uint handle; @@ -29,6 +35,9 @@ private: uint loadProgram(uint _shader1, uint _shader2); - static Shader const * active; + static const Shader * shActive; + static const Shader * shBasic; + static const Shader * shLighting; + static const Shader * shBlur; }; diff --git a/Weave/Graphix/Texture.cpp b/Weave/Graphix/Texture.cpp index 83ac7ee..0acf729 100644 --- a/Weave/Graphix/Texture.cpp +++ b/Weave/Graphix/Texture.cpp @@ -141,7 +141,7 @@ void Texture::useTexture() const { /* bind Texture*/ - auto tmp = Shader::getActive()->getUniformLocation("uColorTexture"); + auto tmp = Shader::gActive()->getUniformLocation("uColorTexture"); if (tmp < 0) { return; } @@ -152,7 +152,7 @@ void Texture::useTexture() const glUniform1i(tmp, unit); /* bind Material*/ - int tmp2 = Shader::getActive()->getUniformLocation("material"); + int tmp2 = Shader::gActive()->getUniformLocation("material"); if (tmp2 >= 0) glUniform4fv(tmp2, 1, value_ptr(material)); diff --git a/Weave/Graphix/ViewPort.cpp b/Weave/Graphix/ViewPort.cpp index 80f68b8..8ef047e 100644 --- a/Weave/Graphix/ViewPort.cpp +++ b/Weave/Graphix/ViewPort.cpp @@ -36,7 +36,7 @@ void ViewPort::useViewPort() const glViewport(xpos, ypos, width, height); } -void ViewPort::bindView(Shader* shader) const{ +void ViewPort::bindView(const Shader* shader) const{ shader->useShader(); int tmp = -1; @@ -53,7 +53,7 @@ void ViewPort::bindView(Shader* shader) const{ 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; diff --git a/Weave/Graphix/ViewPort.h b/Weave/Graphix/ViewPort.h index 1ea3588..4770d2e 100644 --- a/Weave/Graphix/ViewPort.h +++ b/Weave/Graphix/ViewPort.h @@ -15,8 +15,8 @@ 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 bindView(const Shader* shader) const; + void bindView(const Shader* shader, vec3 lookat) const; void rotateView(float angle_x, float angle_y); vec3 rotateDirection(const vec3 & direction) const; diff --git a/Weave/Scene/EventBox.cpp b/Weave/Scene/EventBox.cpp index b320c05..ab47b88 100644 --- a/Weave/Scene/EventBox.cpp +++ b/Weave/Scene/EventBox.cpp @@ -1,6 +1,7 @@ #include "EventBox.h" -#include "../Graphix/Graphix.h" +//#include "../Graphix/Graphix.h" +#include "../Graphix/Shader.h" #include "../Graphix/Model.h" #include "../Events.h" @@ -12,7 +13,7 @@ EventBox::EventBox(const mat4& _modelMat, uint _EB_TYPE) : - SceneObject(Graphix::shader_BBox, _modelMat, vec4(0.f), Model::getBBoxModel(), ""), + SceneObject(Shader::gBasic(), _modelMat, vec4(0.f), Model::getBBoxModel(), ""), eb_type(_EB_TYPE) { collide_group = COL_EVENT; diff --git a/Weave/Scene/Level.cpp b/Weave/Scene/Level.cpp index 49c02a9..3b436a7 100644 --- a/Weave/Scene/Level.cpp +++ b/Weave/Scene/Level.cpp @@ -7,7 +7,7 @@ #include "../GLM.h" -Level::Level(Shader* _shader, std::string _modelpath, std::string _texturepath) : SceneObject(_shader, mat4(1.f), vec4(1.f), Model::newIMetaModel(_modelpath+".dae"), _texturepath) +Level::Level(const Shader* _shader, std::string _modelpath, std::string _texturepath) : SceneObject(_shader, mat4(1.f), vec4(1.f), Model::newIMetaModel(_modelpath+".dae"), _texturepath) { collide_group = COL_LEVEL; collide_with = COL_MARVIN | COL_ENEMY; diff --git a/Weave/Scene/Level.h b/Weave/Scene/Level.h index ffe7690..937a4fc 100644 --- a/Weave/Scene/Level.h +++ b/Weave/Scene/Level.h @@ -9,7 +9,7 @@ class Level : public SceneObject { public: - Level(Shader* shader,std::string modelpath, std::string texturepath); + Level(const Shader* shader,std::string modelpath, std::string texturepath); ~Level(); virtual void collides(SceneObject* other, btPersistentManifold* contactManifold, float deltaT=1.f) override; diff --git a/Weave/Scene/Marvin.cpp b/Weave/Scene/Marvin.cpp index 75db2fc..098ee24 100644 --- a/Weave/Scene/Marvin.cpp +++ b/Weave/Scene/Marvin.cpp @@ -12,7 +12,7 @@ #define SPEED_MOVE_NORMAL 1.5f #define MOVE_FASTER 2.5f -Marvin::Marvin(Shader* _shader, const mat4& _modelMat) : +Marvin::Marvin(const Shader* _shader, const mat4& _modelMat) : SceneObject(_shader, _modelMat, vec4(7.0f, 0.7f, 1.0f, 3.0f), "Player", "model_player_2D.png") { collide_group = COL_MARVIN; diff --git a/Weave/Scene/Marvin.h b/Weave/Scene/Marvin.h index ddd4ad7..8415a1b 100644 --- a/Weave/Scene/Marvin.h +++ b/Weave/Scene/Marvin.h @@ -9,7 +9,7 @@ class Marvin : public SceneObject { public: - Marvin(Shader* shader, const mat4& modelMat); + Marvin(const Shader* shader, const mat4& modelMat); ~Marvin(); virtual void update(float) override; diff --git a/Weave/Scene/Scene.cpp b/Weave/Scene/Scene.cpp index 7871ed4..dd8dcb1 100644 --- a/Weave/Scene/Scene.cpp +++ b/Weave/Scene/Scene.cpp @@ -166,9 +166,9 @@ void Scene::draw() const viewPort.useViewPort(); //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::gBasic(), lookat->getPosition() + vec3(0.0f, 1.0f, 0.0f)); for (auto i = ShaderSet.cbegin(); i != ShaderSet.cend(); ++i) { @@ -188,7 +188,7 @@ void Scene::draw() const void Scene::addObject(SceneObject* _add) { SceneObjects.push_back(_add); - ShaderSet.insert(_add->getShader()); + ShaderSet.insert(_add->gShader()); bt_collision_world->addCollisionObject(*_add, _add->getCollideGroup(), _add->getCollideWith()); bt_dynamics_world->addCollisionObject(*_add,_add->getCollideGroup(),_add->getCollideWith()); diff --git a/Weave/Scene/Scene.h b/Weave/Scene/Scene.h index baddcb2..551af96 100644 --- a/Weave/Scene/Scene.h +++ b/Weave/Scene/Scene.h @@ -41,7 +41,7 @@ protected: SceneObject* lookat; std::list SceneObjects; - std::set ShaderSet; + std::set ShaderSet; float currenttime; std::stack timestamps; diff --git a/Weave/Scene/SceneObject.cpp b/Weave/Scene/SceneObject.cpp index c2ecd43..9a271f1 100644 --- a/Weave/Scene/SceneObject.cpp +++ b/Weave/Scene/SceneObject.cpp @@ -28,7 +28,7 @@ static inline bool file_exist(const std::string& name) { } -SceneObject::SceneObject(Shader* _shader, const mat4& _modelMat, const vec4& _material, string _modelpath, string texturepath) : +SceneObject::SceneObject(const Shader* _shader, const mat4& _modelMat, const vec4& _material, string _modelpath, string texturepath) : model(nullptr), collision(nullptr), modelMat(_modelMat), @@ -122,7 +122,7 @@ move_delta(0) // bt_rigid_body } -SceneObject::SceneObject(Shader* _shader, const mat4& _modelMat, const vec4& _material, Model* _model, string texturepath) : +SceneObject::SceneObject(const Shader* _shader, const mat4& _modelMat, const vec4& _material, Model* _model, string texturepath) : model(_model), collision(nullptr), modelMat(_modelMat), @@ -259,6 +259,20 @@ void SceneObject::collides(SceneObject* _other, btPersistentManifold* _contactMa } +const Shader * SceneObject::gShader() const +{ + return shader; +} + +const Texture * SceneObject::gTexture() const +{ + return texture; +} + +const Model * SceneObject::gModel() const +{ + return model; +} vec3 SceneObject::getPosition() const { @@ -323,22 +337,6 @@ void SceneObject::setMainScene(Scene* _scene) mainScene = _scene; } - -Shader* SceneObject::getShader() const -{ - return shader; -} - -Texture* SceneObject::getTexture() const -{ - return texture; -} - -Model* SceneObject::getModel() const -{ - return model; -} - SceneObject::operator btCollisionObject *() const { return bt_collision_object; @@ -358,4 +356,5 @@ short SceneObject::getCollideGroup() const short SceneObject::getCollideWith() const { return collide_with; -} \ No newline at end of file +} + diff --git a/Weave/Scene/SceneObject.h b/Weave/Scene/SceneObject.h index f05f299..20d2886 100644 --- a/Weave/Scene/SceneObject.h +++ b/Weave/Scene/SceneObject.h @@ -29,8 +29,8 @@ class SceneObject public: //SceneObject(Shader* _shader, mat4& model); - SceneObject(Shader* _shader, const mat4& modelMat, const vec4& material, string modelpath, string texturepath); - SceneObject(Shader* _shader, const mat4& modelMat, const vec4& material, Model* model, string texturepath); + SceneObject(const Shader* _shader, const mat4& modelMat, const vec4& material, string modelpath, string texturepath); + SceneObject(const Shader* _shader, const mat4& modelMat, const vec4& material, Model* model, string texturepath); virtual ~SceneObject(); @@ -58,11 +58,9 @@ public: void setCollision(bool); - Shader* getShader() const; - - Texture* getTexture() const; - - Model* getModel() const; + const Shader * gShader() const; + const Texture * gTexture() const; + const Model * gModel() const; __declspec(deprecated) void setEnemy(bool isenemy); @@ -87,7 +85,7 @@ protected: mat4 modelMat; - Shader* shader; + const Shader * shader; Texture* texture; Model* model; Model* collision; diff --git a/Weave/main.cpp b/Weave/main.cpp index 7bd981a..1e3f647 100644 --- a/Weave/main.cpp +++ b/Weave/main.cpp @@ -16,6 +16,7 @@ #include "Message.h" #include "Graphix\Graphix.h" +#include "Graphix\Shader.h" //#include "Graphix\Scene.h" #include "Events.h" @@ -40,11 +41,12 @@ void logSDLerror(ostream &os, const char *msg) #include "btBulletDynamicsCommon.h" int main(int argc, char *argv[]) -{ +{ btBoxShape * box = new btBoxShape(btVector3(1, 1, 1)); delete box; Graphix::init(); + Shader::init(); bool play(true); @@ -69,7 +71,7 @@ int main(int argc, char *argv[]) } - + Shader::cleanup(); Graphix::cleanup(); return 0; diff --git a/shader/basicTexture_VS.hlsl b/shader/basicTexture_VS.hlsl index f017f1f..b2cc1cf 100644 --- a/shader/basicTexture_VS.hlsl +++ b/shader/basicTexture_VS.hlsl @@ -1,5 +1,5 @@ //Vertex Shader -#version 330 +#version 330 core in vec3 aNormal, aPosition; in vec2 aUV; diff --git a/shader/basic_VS.hlsl b/shader/basic_VS.hlsl index 6e75553..55bb6c2 100644 --- a/shader/basic_VS.hlsl +++ b/shader/basic_VS.hlsl @@ -1,5 +1,5 @@ //Vertex Shader -#version 330 +#version 330 core in vec3 aPosition; uniform mat4 uProjection; diff --git a/shader/blur_FS.hlsl b/shader/blur_FS.hlsl index fd99996..ce74b5c 100644 --- a/shader/blur_FS.hlsl +++ b/shader/blur_FS.hlsl @@ -1,47 +1,37 @@ //Fragment Shader -#version 330 -//"in" attributes from our vertex shader -varying vec4 vColor; -varying vec2 fUVs; +#version 330 core +in vec2 fUVs; -//declare uniforms -uniform sampler2D u_texture; -uniform float resolution; -uniform float radius; -uniform vec2 dir; - -void main() { - //this will be our RGBA sum - vec4 sum = vec4(0.0); - - //our original texcoord for this fragment - vec2 tc = fUVs; - - //the amount to blur, i.e. how far off center to sample from - //1.0 -> blur by one pixel - //2.0 -> blur by two pixels, etc. - float blur = radius / resolution; - - //the direction of our blur - //(1.0, 0.0) -> x-axis blur - //(0.0, 1.0) -> y-axis blur - float hstep = dir.x; - float vstep = dir.y; +out vec4 gl_FragColor; - //apply blurring, using a 9-tap filter with predefined gaussian weights - - sum += texture2D(u_texture, vec2(tc.x - 4.0*blur*hstep, tc.y - 4.0*blur*vstep)) * 0.0162162162; - sum += texture2D(u_texture, vec2(tc.x - 3.0*blur*hstep, tc.y - 3.0*blur*vstep)) * 0.0540540541; - sum += texture2D(u_texture, vec2(tc.x - 2.0*blur*hstep, tc.y - 2.0*blur*vstep)) * 0.1216216216; - sum += texture2D(u_texture, vec2(tc.x - 1.0*blur*hstep, tc.y - 1.0*blur*vstep)) * 0.1945945946; - - sum += texture2D(u_texture, vec2(tc.x, tc.y)) * 0.2270270270; - - sum += texture2D(u_texture, vec2(tc.x + 1.0*blur*hstep, tc.y + 1.0*blur*vstep)) * 0.1945945946; - sum += texture2D(u_texture, vec2(tc.x + 2.0*blur*hstep, tc.y + 2.0*blur*vstep)) * 0.1216216216; - sum += texture2D(u_texture, vec2(tc.x + 3.0*blur*hstep, tc.y + 3.0*blur*vstep)) * 0.0540540541; - sum += texture2D(u_texture, vec2(tc.x + 4.0*blur*hstep, tc.y + 4.0*blur*vstep)) * 0.0162162162; - - //discard alpha for our simple demo, multiply by vertex color and return - gl_FragColor = vColor * vec4(sum.rgb, 1.0); +uniform sampler2D u_texture; +uniform bool uHorizontal; +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]; + 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]; + } + } + 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]; + } + } + gl_FragColor = vec4(result, 1.0); } \ No newline at end of file diff --git a/shader/plane_VS.hlsl b/shader/plane_VS.hlsl new file mode 100644 index 0000000..8bb350d --- /dev/null +++ b/shader/plane_VS.hlsl @@ -0,0 +1,12 @@ +//Vertex Shader +#version 330 core +in vec3 aPosition; +in vec2 aUVs; + +out vec2 fUVs; + +void main() +{ + gl_Position = vec4(aPosition, 1.0f); + fUVs = aUVs; +} \ No newline at end of file