]> git.leopard-lacewing.eu Git - cgue_weave.git/commitdiff
materials added
authorLockedLunatic <locked.lunatic@aon.at>
Tue, 28 Apr 2015 14:25:59 +0000 (16:25 +0200)
committerLockedLunatic <locked.lunatic@aon.at>
Tue, 28 Apr 2015 14:25:59 +0000 (16:25 +0200)
14 files changed:
Weave/Game.cpp
Weave/Graphix/Model/IMesh.cpp
Weave/Graphix/Model/IMesh.h
Weave/Graphix/Model/IMetaMesh.cpp
Weave/Graphix/Model/IMetaMesh.h
Weave/Graphix/Model/Model.cpp
Weave/Graphix/Model/Model.h
Weave/Graphix/Model/SkyBox.cpp
Weave/Graphix/Model/SkyBox.h
Weave/Scene/Marvin.cpp
Weave/Scene/SceneObject.cpp
Weave/Scene/SceneObject.h
Weave/Scene/Sky.cpp
shader/lightingTexture_FS.hlsl

index 8ee76204258090e33ccee9bfd8e35682f54afa2d..8d079d0f74119432fe8c94d79e27300493686899 100644 (file)
@@ -52,9 +52,9 @@ Game::Game() : playing(true)
 //     Shader* shaderSky = new Shader("skybox_VS.hlsl", "skybox_FS.hlsl");
 
        // load LVL
-       current_world->addObject(new SceneObject(shader1, scale(3.f * vec3(1.f,.3f,1.f)), "level_test.dae", "model_levelTest_2D.png"));
+       current_world->addObject(new SceneObject(shader1, scale(3.f * vec3(1.f, .3f, 1.f)), vec4(4.0f, 1.0f, 1.0f, 2.0f), "level_test.dae", "model_levelTest_2D.png"));
 
-       current_world->addObject(new SceneObject(shader1, translate(vec3(-3.f,1.f,0.f)), new BBox() , ""));
+       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(), ""));
 
        //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)));
@@ -97,7 +97,7 @@ Game::Game() : playing(true)
        //ein Gegner
        //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))*scale(vec3(.4f)), "duck.dae", "model_duck_2D.png"));
+       current_world->addObject(new SceneObject(shader1, translate(vec3(-3.f, .4f, 0.f))*scale(vec3(.4f)), vec4(3.0f, 0.5f, 0.4f, 1.5f), "duck.dae", "model_duck_2D.png"));
 
 
        //import("level_test.dae", current_world, shader1);
@@ -127,7 +127,7 @@ void Game::play()
                if (sleep_time < 0)
                        sleep_time = 0;
 
-               Sleep(sleep_time);              
+               Sleep(sleep_time);
 
                Events::processEvents();
 
index 37264f501a98ff917289fa606d4999267959f601..9adaad2ee472aaabf85081b8a26ff81726957fd8 100644 (file)
@@ -67,6 +67,12 @@ void IMesh::useModelMat(const mat4& _model, Shader* _shader) const
        Model::useModelMat(_model * modelMat, _shader);
 }
 
+void IMesh::useMaterial(const vec4& _material, Shader* _shader) const
+{
+       //      Model::useMaterial(_material, _shader);
+       Model::useMaterial(_material, _shader);
+}
+
 //void IMesh::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const
 //{
 //
index 51117f96f87e40f0eeed61b6b3dfc7c74f5dfa16..b36d7404d2a1fa74d486c90f2f314eca3214bfe5 100644 (file)
@@ -20,6 +20,7 @@ public:
        virtual ~IMesh();
 
        void useModelMat(const mat4& model, Shader* shader) const;
+       void useMaterial(const vec4& material, Shader* shader) const;
 
        //void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const;
 
index e95314eef0c162a85c6d4bb4a35ea1c1a444a531..9ef7481fcbc115a043371e46baa2881c64d1c86a 100644 (file)
@@ -80,11 +80,11 @@ void IMetaMesh::bindShader(Shader* _shader)
        }
 }
 
-void IMetaMesh::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const
+void IMetaMesh::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat, const vec4& _material) const
 {
        for (auto i = models.begin(); i != models.end(); ++i)
        {
-               (*i)->drawModel(_shader,_texture,_modelMat);
+               (*i)->drawModel(_shader, _texture, _modelMat, _material);
        }
 }
 
index 0f20711233f7efbd4cdb5dd919b5971429731267..864130632e3f804a37c348ad514c6bb9b76bca67 100644 (file)
@@ -20,7 +20,7 @@ public:
 
        void bindShader(Shader* shader);
 
-       void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const;
+       void drawModel(Shader* shader, Texture* texture, const mat4& modelMat, const vec4& material) const;
 
        void drawBBox(Shader* shader, const mat4& modelMat) const;
 
index 08f087ec7931b1de374cbdaa4c3fa4dccbefd1f8..f12b67d6af7534cef426e8a482ebd96611df6ef8 100644 (file)
@@ -81,7 +81,7 @@ void Model::drawModel() const
        glBindVertexArray(0);
 }
 
-void Model::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const
+void Model::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat, const vec4& _material) const
 {
        //Message::info("Error from before?");
        //Graphix::getGlError();
@@ -94,6 +94,9 @@ void Model::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat)
        useModelMat(_modelMat, _shader);
        //Message::info("IMesh loading MMatrix");
        //Graphix::getGlError();
+       useMaterial(_material, _shader);
+       //Message::info("IMesh loading MMatrix");
+       //Graphix::getGlError();
        drawModel();
        //Message::info("IMesh drawing Elements");
        //Graphix::getGlError();
@@ -114,7 +117,7 @@ void Model::drawBBox(Shader* _shader,const mat4& _modelMat) const
                
        }
 //     BoundingBox->bindShader(_shader);
-       BoundingBox->drawModel(Graphix::shader_BBox, (Texture*)nullptr, _modelMat*translate(BBposition)*scale(BBsize));
+       BoundingBox->drawModel(Graphix::shader_BBox, (Texture*)nullptr, _modelMat*translate(BBposition)*scale(BBsize), vec4(1.0f, 1.0f, 1.0f, 3.0f));
 }
 
 void Model::updateBB(const vec3& _min, const vec3& _max)
@@ -233,6 +236,13 @@ void Model::useModelMat(const mat4& _model, Shader* _shader) const
                glUniformMatrix4fv(tmp, 1, GL_FALSE, value_ptr(_model));
 }
 
+void Model::useMaterial(const vec4& _material, Shader* _shader) const
+{
+       int tmp = _shader->getUniformLocation("material");
+       if (tmp >= 0)
+               glUniform4fv(tmp, 1, value_ptr(_material));
+}
+
 Model* Model::BoundingBox = nullptr;
 Shader* Model::BBoxShader = nullptr;
 bool Model::exBBox = false;
\ No newline at end of file
index af8a43e157522cf4ff06c59c9ab077f80381f8f9..9a83e9318ed017d6c166c23e5ac00c9d69b08a3a 100644 (file)
@@ -18,7 +18,7 @@ public:
        virtual void bindShader(Shader* shader);
 
        /* Draws Model */
-       virtual void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const;
+       virtual void drawModel(Shader* shader, Texture* texture, const mat4& modelMat, const vec4& material) const;
 
        /* Draws a BoundingBox around the Model */
        virtual void drawBBox(Shader* shader, const mat4& modelMat) const;
@@ -42,6 +42,7 @@ protected:
        virtual void useModel(Shader* shader) const;
        virtual void useTexture(Texture* texture, Shader* shader) const;
        virtual void useModelMat(const mat4& model, Shader* shader) const;
+       virtual void useMaterial(const vec4& material, Shader* shader) const;
        virtual void drawModel() const;
 
 
index 9c37e0c8861c5c0dd5538ec61a8ba7c625fed0da..ff7cfd55a52211e610d725bdee48bdbfa955272f 100644 (file)
@@ -25,10 +25,10 @@ SkyBox::~SkyBox()
 {
 }
 
-void SkyBox::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat) const
+void SkyBox::drawModel(Shader* _shader, Texture* _texture, const mat4& _modelMat, const vec4& _material) const
 {
        glDisable(GL_DEPTH_TEST);
-       Model::drawModel(_shader, _texture, _modelMat);
+       Model::drawModel(_shader, _texture, _modelMat, _material);
        glEnable(GL_DEPTH_TEST);
 }
 
@@ -36,6 +36,10 @@ void SkyBox::useModelMat(const mat4& _model, Shader* _shader) const
 {
 }
 
+void SkyBox::useMaterial(const vec4& _material, Shader* _shader) const
+{
+}
+
 void SkyBox::useTexture(Texture* _texture, Shader* _shader) const
 {
 }
index 5bf15525a5d63c50ed73324a056a2d5de6ae2264..14da4b93a349f3afad6ca057bdb890261e86812c 100644 (file)
@@ -9,10 +9,11 @@ public:
        SkyBox();
        ~SkyBox();
 
-       void drawModel(Shader* shader, Texture* texture, const mat4& modelMat) const;
+       void drawModel(Shader* shader, Texture* texture, const mat4& modelMat, const vec4& material) const;
 
        //uncommend following lines to use default Loaders
        void useModelMat(const mat4& model, Shader* shader) const;
+       void useMaterial(const vec4& material, Shader* shader) const;
        void useTexture(Texture* texture, Shader* shader) const;
 
        void drawBBox(Shader* shader, const mat4& modelMat) const;
index 3759689527399e9f963c2ae6792bc65b094f0bb3..e0ec59d85c45824fc817e00aeb137fa8f23d0822 100644 (file)
@@ -3,7 +3,7 @@
 #include "../Graphix/Shader.h"
 
 
-Marvin::Marvin(Shader* _shader, const mat4& _modelMat) : SceneObject(_shader,_modelMat,"Player.dae","model_player_2D.png")
+Marvin::Marvin(Shader* _shader, const mat4& _modelMat) : SceneObject(_shader, _modelMat, vec4(7.0f, 0.7f, 1.0f, 3.0f), "Player.dae", "model_player_2D.png")
 {
        
 }
index 2845187bd6851895438456ac7dacc4cd8bbf32be..51f8b1438e223ef50368f57d9507aa286774dfdf 100644 (file)
@@ -20,9 +20,10 @@ using std::string;
 
 #define YFALL_SPEED 9.8f
 
-SceneObject::SceneObject(Shader* _shader, const mat4& _modelMat, string _modelpath, string texturepath, unsigned int _model_index) :
+SceneObject::SceneObject(Shader* _shader, const mat4& _modelMat, const vec4& _material, string _modelpath, string texturepath, unsigned int _model_index) :
 model(new IMetaMesh(_modelpath)),
 modelMat(_modelMat),
+material(_material),
 shader(_shader),
 mainScene(NULL),
 collision_ignore(false),
@@ -48,9 +49,10 @@ yStatic(true)
 
 }
 
-SceneObject::SceneObject(Shader* _shader, const mat4& _modelMat, Model* _model, string texturepath) :
+SceneObject::SceneObject(Shader* _shader, const mat4& _modelMat, const vec4& _material, Model* _model, string texturepath) :
 model(_model),
 modelMat(_modelMat),
+material(_material),
 shader(_shader),
 mainScene(NULL),
 collision_ignore(false),
@@ -140,7 +142,7 @@ void SceneObject::draw() const
 
        //      drawModel();
 
-       model->drawModel(shader, texture, modelMat);
+       model->drawModel(shader, texture, modelMat, material);
        if (Events::isKToggleActive(SDLK_F6))
                model->drawBBox(shader, modelMat);
 }
@@ -168,6 +170,10 @@ void SceneObject::setModel(mat4& _modelMat){
        modelMat = _modelMat;
 }
 
+void SceneObject::setMaterial(vec4& _material){
+       material = _material;
+}
+
 void SceneObject::turn(float angle, vec3& axis){
        //vec3  pos = getPosition();
        //modelMat = rotate(degree, axis)*modelMat;
index a2e7e744c511b8ea952adec83bf643de541ca23e..5014fbe38c838954688866f9e280a7b8cb669730 100644 (file)
@@ -18,8 +18,8 @@ class SceneObject
 public:
 
        //SceneObject(Shader* _shader, mat4& model);
-       SceneObject(Shader* _shader, const mat4& model, string modelpath, string texturepath, unsigned int model_index=0);
-       SceneObject(Shader* _shader, const mat4& modelMat, Model* model, string texturepath);
+       SceneObject(Shader* _shader, const mat4& model, const vec4& material, string modelpath, string texturepath, unsigned int model_index=0);
+       SceneObject(Shader* _shader, const mat4& modelMat, const vec4& material, Model* model, string texturepath);
 
        virtual ~SceneObject();
 
@@ -32,6 +32,7 @@ public:
 
        __declspec(deprecated)
        virtual void setModel(mat4&);
+       virtual void setMaterial(vec4&);
        __declspec(deprecated)
        virtual void turn(float angle, vec3& axis);
        virtual void turnTo(vec3& direction, float speed = 1);
@@ -62,6 +63,7 @@ public:
 protected:
 
        mat4 modelMat;
+       vec4 material;
        Shader* shader;
        Texture* texture;
        Model* model;
index 2d2b3ca809cc90c18fe54a7ba6daedd8b4f5ef8e..cedb4cdea12c71ad2b77503fc9165a3cd23f0b80 100644 (file)
@@ -4,7 +4,7 @@
 #include "../Graphix/Model.h"
 
 
-Sky::Sky() : SceneObject(new Shader("skybox_VS.hlsl","skybox_color_FS.hlsl"), mat4(1.f), new SkyBox(), "")
+Sky::Sky() : SceneObject(new Shader("skybox_VS.hlsl","skybox_color_FS.hlsl"), mat4(1.f), vec4(1.f), new SkyBox(), "")
 {
        
 }
index 24faf9347e2b4377891d8293652187e7aee6cd76..bf33ed51d9be0285b0e978e965523b48135464ea 100644 (file)
@@ -7,23 +7,24 @@ in float visNormal, SpecularCosPoint1, SpecularCosDirection1;
 out vec4 FragmentColor;
 
 uniform sampler2D uColorTexture;
+uniform vec4 material;                                 //vec4 in the form (ambient, point, directional, glossyness); so far it was (1, 1, 1, 3)
  
 void main()
 {
 
-       float specularConst = 3.0f;
+       float specularConst = material[3];
        vec3 normal = normalize(worldNormal);
        vec4 uvColor = texture(uColorTexture, fUVs);
 
 
+       vec3 AmbientLightColor = vec3(0.1f, 0.1f, 0.1f);
+
        vec3 PointLightDirection1 = normalize(worldLightPoint1);
        vec3 PointLightColor1 = vec3(30.0f, 30.0f, 30.0f);
 
        vec3 DirectionalLightDirection1 = normalize(vec3(-2.0f, -2.0f, -2.0f));
        vec3 DirectionalLightColor1 = vec3(1.0f, 1.0f, 1.0f);
 
-       vec3 AmbientLightColor = vec3(0.1f, 0.1f, 0.1f);
-
 
        float cosThetaPoint1 = clamp(dot(normal, PointLightDirection1), 0, 1);
        float cosThetaDirection1 = clamp(dot(normal, DirectionalLightDirection1), 0, 1);
@@ -34,9 +35,9 @@ void main()
        //      discard;
 
 
-       FragmentColor = vec4(uvColor.rgb * (AmbientLightColor
-               + PointLightColor1  * (cosThetaPoint1 + pow(SpecularCosPoint1, specularConst)) / squaredist1
-               + DirectionalLightColor1  * (cosThetaDirection1 + pow(SpecularCosDirection1, specularConst))
+       FragmentColor = vec4(uvColor.rgb * (AmbientLightColor * material[0]
+               + PointLightColor1 * material[1] * (cosThetaPoint1 + pow(SpecularCosPoint1, specularConst)) / squaredist1
+               + DirectionalLightColor1 * material[2] * (cosThetaDirection1 + pow(SpecularCosDirection1, specularConst))
                ), uvColor.a);