// 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)));
//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);
if (sleep_time < 0)
sleep_time = 0;
- Sleep(sleep_time);
+ Sleep(sleep_time);
Events::processEvents();
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
//{
//
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;
}
}
-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);
}
}
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;
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();
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();
}
// 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)
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
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;
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;
{
}
-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);
}
{
}
+void SkyBox::useMaterial(const vec4& _material, Shader* _shader) const
+{
+}
+
void SkyBox::useTexture(Texture* _texture, Shader* _shader) const
{
}
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;
#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")
{
}
#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),
}
-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),
// drawModel();
- model->drawModel(shader, texture, modelMat);
+ model->drawModel(shader, texture, modelMat, material);
if (Events::isKToggleActive(SDLK_F6))
model->drawBBox(shader, 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;
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();
__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);
protected:
mat4 modelMat;
+ vec4 material;
Shader* shader;
Texture* texture;
Model* model;
#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(), "")
{
}
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);
// 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);