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
// Hauptfenster\r
current_world = new Scene(0, 0, Graphix::getWindowWidth(), Graphix::getWindowHeight(), 45, 0.1f, 40, vec3(0.0f, 0.0f, 0.f));\r
\r
- //Allg Shader\r
- Shader* shader1 = new Shader("basicTexture_VS.hlsl", "lightingTexture_FS.hlsl");\r
-\r
// load LVL\r
\r
- SceneObject* tmp_world = new Level(shader1, "level_1", "model_levelTest_2D.jpg");\r
+ SceneObject* tmp_world = new Level(Shader::gLighting(), "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(shader1, 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(Shader::gLighting(), 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(shader1, 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(Shader::gLighting(), 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(shader1, glm::mat4(1.0f), "Player.dae", "model_player.png"));\r
- //current_world->addObject(new SceneObject(shader1, translate(vec3(-3.f, .4f, 0.f))*scale(vec3(3.f)), "cow/cow.dae", "model_cow_2D.jpg"));\r
- 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"));\r
- 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"));\r
- 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"));\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
\r
- 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"));\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
\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
#include "Debug.h"\r
\r
#include "../Message.h"\r
-#include "Shader.h"\r
#include <string>\r
\r
using std::string;\r
glClearAccum(0.f, 0.f, 0.f, 0.f);\r
glClear(GL_ACCUM_BUFFER_BIT);\r
\r
- shader_BBox = new Shader("basic_VS.hlsl", "basic_FS.hlsl");\r
}\r
\r
void Graphix::FullScreen(bool _enable, bool _keepDesktopResolution)\r
\r
void Graphix::cleanup()\r
{\r
- delete shader_BBox;\r
-\r
//SDL_SetWindowGrab(sdl_window, SDL_FALSE);\r
\r
SDL_GL_DeleteContext(sdl_glcontext);\r
SDL_GLContext Graphix::sdl_glcontext;\r
\r
short Graphix::effects = EF_TRANSPARENCY;\r
-\r
-Shader* Graphix::shader_BBox;\r
EF_BLOOM = BIT(3)
};
-class Shader;
-
class Graphix
{
public:
static unsigned int getGlError();
- static Shader* shader_BBox;
-
private:
static void updateEffects();
}\r
}\r
\r
-void IMetaMesh::bindShader(Shader* _shader)\r
+void IMetaMesh::bindShader(const Shader* _shader)\r
{\r
for (auto i = models.begin(); i != models.end(); ++i)\r
{\r
}\r
}\r
\r
-void IMetaMesh::unbindShader(Shader* _shader)\r
+void IMetaMesh::unbindShader(const Shader* _shader)\r
{\r
for (auto i = models.begin(); i != models.end(); ++i)\r
{\r
IMetaMesh(const std::string& modelpath, const vec3& scale = vec3(1.f), bool isConvex = true);\r
~IMetaMesh();\r
\r
- void bindShader(Shader* shader) override;\r
+ void bindShader(const Shader* shader) override;\r
\r
void bindModel() override;\r
\r
void unbindModel() override;\r
- void unbindShader(Shader* shader) override;\r
+ void unbindShader(const Shader* shader) override;\r
\r
void drawModel(const mat4& modelMat) const override;\r
\r
}\r
\r
\r
-void Model::bindShader(Shader* _shader)\r
+void Model::bindShader(const Shader* _shader)\r
{\r
auto i = shader_map.find(*_shader);\r
if (i != shader_map.end())\r
\r
}\r
\r
-void Model::unbindShader(Shader* _shader)\r
+void Model::unbindShader(const Shader* _shader)\r
{\r
glDeleteVertexArrays(1, &(shader_map[*_shader]));\r
shader_map.erase(*_shader);\r
void Model::drawBBox(const mat4& _modelMat, const vec4& _color) const\r
{\r
Graphix::getGlError();\r
- Graphix::shader_BBox->useShader();\r
- int tmp = Graphix::shader_BBox->getUniformLocation("uFragmentColor");\r
+ Shader::gBasic()->useShader();\r
+ int tmp = Shader::gBasic()->getUniformLocation("uFragmentColor");\r
if (tmp >= 0)\r
glUniform4fv(tmp, 1, value_ptr(_color));\r
Graphix::getGlError();\r
\r
vec3 size = (max - min);\r
vec3 center = (max + min) * .5f;\r
- Graphix::shader_BBox->useShader();\r
+ Shader::gBasic()->useShader();\r
getBBoxModel()->drawModel(_modelMat*translate(center)*glm::scale(size)); //\r
}\r
\r
void Model::useModel(const mat4& _modelMat) const\r
{\r
\r
- auto active_shader = Shader::getActive();\r
-\r
/* use MODEL*/\r
uint vao = -1;\r
- auto i = shader_map.find(*active_shader);\r
+ auto i = shader_map.find(*Shader::gActive());\r
if (i == shader_map.end())\r
Message::error("Model: Shader wurde nicht an das Model gebunden.");\r
else\r
\r
\r
/* use ModelMAT*/\r
- int tmp = active_shader->getUniformLocation("uModel");\r
+ int tmp = Shader::gActive()->getUniformLocation("uModel");\r
if (tmp >= 0)\r
glUniformMatrix4fv(tmp, 1, GL_FALSE, value_ptr(_modelMat));\r
\r
{\r
BoundingBox = new BBox();\r
BoundingBox->bindModel();\r
- BoundingBox->bindShader(Graphix::shader_BBox);\r
+ BoundingBox->bindShader(Shader::gBasic());\r
}\r
return BoundingBox;\r
}\r
virtual void unbindModel();\r
\r
/* Binds Model to the Shader*/\r
- virtual void bindShader(Shader* shader);\r
- virtual void unbindShader(Shader* shader);\r
+ virtual void bindShader(const Shader* shader);\r
+ virtual void unbindShader(const Shader* shader);\r
\r
/* Draws Model */\r
virtual void drawModel(const mat4& modelMat) const;\r
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());
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;
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;
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;
};
{
/* bind Texture*/
- auto tmp = Shader::getActive()->getUniformLocation("uColorTexture");
+ auto tmp = Shader::gActive()->getUniformLocation("uColorTexture");
if (tmp < 0) {
return;
}
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));
glViewport(xpos, ypos, width, height);
}
-void ViewPort::bindView(Shader* shader) const{
+void ViewPort::bindView(const Shader* shader) const{
shader->useShader();
int tmp = -1;
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;
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;
#include "EventBox.h"
-#include "../Graphix/Graphix.h"
+//#include "../Graphix/Graphix.h"
+#include "../Graphix/Shader.h"
#include "../Graphix/Model.h"
#include "../Events.h"
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;
#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;
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;
#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;
public SceneObject
{
public:
- Marvin(Shader* shader, const mat4& modelMat);
+ Marvin(const Shader* shader, const mat4& modelMat);
~Marvin();
virtual void update(float) override;
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)
{
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());
SceneObject* lookat;
std::list<SceneObject*> SceneObjects;
- std::set<Shader*> ShaderSet;
+ std::set<const Shader *> ShaderSet;
float currenttime;
std::stack<Timestamp> timestamps;
}
-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),
// 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),
}
+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
{
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;
short SceneObject::getCollideWith() const
{
return collide_with;
-}
\ No newline at end of file
+}
+
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();
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);
mat4 modelMat;
- Shader* shader;
+ const Shader * shader;
Texture* texture;
Model* model;
Model* collision;
#include "Message.h"
#include "Graphix\Graphix.h"
+#include "Graphix\Shader.h"
//#include "Graphix\Scene.h"
#include "Events.h"
#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);
}
-
+ Shader::cleanup();
Graphix::cleanup();
return 0;
//Vertex Shader
-#version 330
+#version 330 core
in vec3 aNormal, aPosition;
in vec2 aUV;
//Vertex Shader
-#version 330
+#version 330 core
in vec3 aPosition;
uniform mat4 uProjection;
//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
--- /dev/null
+//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