Large diffs are not rendered by default.

@@ -0,0 +1,34 @@
# Blender v2.67 (sub 0) OBJ File: ''
# www.blender.org
v -10.000000 -10.000000 10.000000
v -10.000000 -10.000000 -10.000000
v 10.000000 -10.000000 -10.000000
v 10.000000 -10.000000 10.000000
v -10.000000 10.000000 10.000000
v -10.000000 10.000000 -10.000000
v 10.000000 10.000000 -10.000000
v 10.000000 10.000000 10.000000
vt 0.000000 0.000000
vt 10.000000 0.000000
vt 0.000000 10.000000
vt 10.000000 10.000000
vn -10.000000 0.000000 0.000000
vn 0.000000 0.000000 -10.000000
vn 10.000000 -0.000000 0.000000
vn 0.000000 0.000000 10.000000
vn 0.000000 -10.000000 0.000000
vn 0.000000 10.000000 0.000000
s off
f 5/1/1 1/3/1 6/2/1
f 6/1/2 2/3/2 7/2/2
f 7/1/3 4/4/3 8/2/3
# hier
f 8/1/4 1/4/4 5/2/4
f 1/1/5 3/4/5 2/2/5
f 8/1/6 6/4/6 7/2/6
f 6/2/1 1/3/1 2/4/1
f 7/2/2 2/3/2 3/4/2
f 3/3/3 4/4/3 7/1/3
f 4/3/4 1/4/4 8/1/4
f 4/3/5 3/4/5 1/1/5
f 5/3/6 6/4/6 8/1/6
@@ -0,0 +1,162 @@
//LIT TEXTURE FRAGMENT SHADER
#version 330
#define LIGHTBUFFERSIZE 5

uniform mat4 modelMatrix;
uniform vec3 modelColor;
uniform vec3 cameraPos;
uniform vec3 lightCount;
uniform float shininess;

uniform sampler2D dTexture;
uniform sampler2D highlight;

in vec2 tCoord;
in vec3 fNormal;
in vec3 fPos;

out vec4 fColor;
out vec4 bColor;

struct DirLight
{
vec3 direction;

vec3 ambient;
vec3 diffuse;
vec3 specular;

}; uniform DirLight dirLight[LIGHTBUFFERSIZE];

struct PointLight
{
vec3 position;

vec3 ambient;
vec3 diffuse;
vec3 specular;

float constant;
float linear;
float quadratic;

}; uniform PointLight pointLight[LIGHTBUFFERSIZE];

struct SpotLight
{
vec3 position;
vec3 direction;

vec3 ambient;
vec3 diffuse;
vec3 specular;

float constant;
float linear;
float quadratic;

float cutOff;
float outerCutOff;

}; uniform SpotLight spotLight[LIGHTBUFFERSIZE];


vec3 CalcDirLight(DirLight, vec3, vec3, vec3);
vec3 CalcPointLight(PointLight, vec3, vec3, vec3);
vec3 CalcSpotLight(SpotLight, vec3, vec3, vec3);


void main( void )
{
vec3 wNormal = vec3 (modelMatrix * vec4(fNormal, 0));
vec3 viewDir = normalize(cameraPos - fPos);
vec3 tColor = texture(dTexture, tCoord).xyz;

vec3 color;

for (int i = 0; i < lightCount.x; i++)
color += CalcDirLight(dirLight[i], wNormal, viewDir, tColor);

for (int i = 0; i < lightCount.y; i++)
color += CalcPointLight(pointLight[i], wNormal, viewDir, tColor);

for (int i = 0; i < lightCount.z; i++)
color += CalcSpotLight(spotLight[i], wNormal, viewDir, tColor);


if (modelColor != vec3(0))
{
vec4 hColor = texture(highlight, tCoord);

if (hColor.a != 0)
color = mix(hColor.rgb * modelColor, color, 0.2f);
}
fColor = vec4(color, 1);

//float brightness = dot(fColor.rgb, vec3(0.2126, 0.7152, 0.0722) * 0.6);
//if(brightness > 1.0)
// bColor = vec4(fColor.rgb, 1.0);
}


vec3 CalcDirLight(DirLight light, vec3 normal, vec3 viewDir, vec3 tColor)
{
float diff = dot(-light.direction, normal) * 0.5f + 0.5f;
vec3 ref = reflect(light.direction, normal);
float spec = pow(max(dot(viewDir, ref), 0), shininess);

vec3 ambient = tColor * light.ambient;
vec3 diffuse = tColor * light.diffuse * diff;
vec3 specular = light.specular * spec;

return (ambient + diffuse + specular);
}


vec3 CalcPointLight(PointLight light, vec3 normal, vec3 viewDir, vec3 tColor)
{
vec3 lightDir = normalize(fPos - light.position);

float diff = max(0, dot(-lightDir, normal));
vec3 ref = reflect(lightDir, normal);
float spec = pow(max(dot(viewDir, ref), 0), shininess);


float distance = length(light.position - fPos);
float attenuation = 1.0f / (light.constant + light.linear * distance +
light.quadratic * (distance * distance));

vec3 ambient = light.ambient * modelColor;
vec3 diffuse = light.diffuse * diff * modelColor * attenuation;
vec3 specular = light.specular * spec * modelColor * attenuation;

return (ambient + diffuse + specular);
}


vec3 CalcSpotLight(SpotLight light, vec3 normal, vec3 viewDir, vec3 tColor)
{
vec3 lightDir = normalize(fPos - light.position);

float angle = dot(light.direction, lightDir);

float distance = length(light.position - fPos);
float attenuation = 1.0f / (light.constant + light.linear * distance +
light.quadratic * (distance * distance));

vec3 ambient = light.ambient * modelColor;

if (angle < light.cutOff)
return ambient;

float factor = clamp((angle - light.cutOff) / light.outerCutOff, 0, 1);

float diff = max(0, dot(-lightDir, normal));
vec3 ref = reflect(lightDir, normal);
float spec = pow(max(dot(viewDir, ref), 0), shininess);

vec3 diffuse = light.diffuse * diff * modelColor * attenuation;
vec3 specular = light.specular * spec * modelColor * attenuation;

return ambient + (diffuse + specular) * factor;
}
@@ -0,0 +1,22 @@
//LIT TEXTURE VERTEX SHADER
#version 330

uniform mat4 mvpMatrix;
uniform mat4 modelMatrix;

in vec3 vertex;
in vec3 normal;
in vec2 uv;

out vec3 fPos;
out vec3 fNormal;
out vec2 tCoord;

void main( void )
{
gl_Position = mvpMatrix * vec4(vertex, 1.f);

fPos = (modelMatrix * vec4(vertex, 1.f)).xyz;
fNormal = normal;
tCoord = uv;
}
@@ -6,6 +6,6 @@ uniform sampler2D skybox;

void main()
{
//fColor = texture(skybox, tCoord);
fColor = vec4(1,1,1,1);
fColor = texture(skybox, tCoord);
//fColor = vec4(1,1,1,1);
}
@@ -1,12 +1,13 @@
#version 330

in vec3 vertex;
in vec2 normal;
in vec2 uv;

out vec2 tCoord;

uniform mat4 MVmatrix;

out vec2 tCoord;

void main( void )
{
gl_Position = MVmatrix * vec4(vertex, 1);
@@ -3,12 +3,12 @@
#define LIGHTBUFFERSIZE 5

uniform mat4 modelMatrix;
uniform vec3 modelColor;
uniform vec3 cameraPos;
uniform vec3 lightCount;
uniform float shininess;

uniform sampler2D dTexture;
uniform sampler2D highlight;

uniform float score;
uniform float minHeight;
@@ -73,16 +73,9 @@ void main( void )
{
vec3 wNormal = vec3 (modelMatrix * vec4(fNormal, 0));
vec3 viewDir = normalize(cameraPos - fPos);
//vec3 tColor = texture(dTexture, tCoord).xyz;

vec3 tColor = vec3(1);

if(fPos.y < minHeight + maxHeight * score)
{
tColor = modelColor;
bColor = vec4(modelColor, 1);
}

vec3 tColor = texture(dTexture, tCoord).rgb;

vec3 color;

for (int i = 0; i < lightCount.x; i++)
@@ -94,7 +87,16 @@ void main( void )
for (int i = 0; i < lightCount.z; i++)
color += CalcSpotLight(spotLight[i], wNormal, viewDir, tColor);

fColor = vec4(color, 1);
vec4 hColor = vec4(0,0,0,1);

float cutoff = minHeight + maxHeight * score;
float multi = clamp((cutoff - fPos.y) * 4.0f , 0, 1);

if (fPos.y < minHeight + maxHeight * score)
hColor = texture(highlight, tCoord) * multi;

fColor = vec4(color.rgb + hColor.rgb, 1);
bColor = hColor / 3;
}


@@ -105,7 +107,7 @@ vec3 CalcDirLight(DirLight light, vec3 normal, vec3 viewDir, vec3 tColor)
float spec = pow(max(dot(viewDir, ref), 0), shininess);

vec3 ambient = tColor * light.ambient;
vec3 diffuse = tColor * light.diffuse * diff;
vec3 diffuse = tColor * light.diffuse * diff * tColor;
vec3 specular = light.specular * spec;

return (ambient + diffuse + specular);
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -25,7 +25,6 @@ void Board::ResetBoard()
{
Tile* tile = _boardArray[j][i];
tile->setOwner(Id::empty);
tile->getMaterial()->setColor(glm::vec3(1));
}
}
}
@@ -35,10 +35,12 @@ Level::Level() :GameObject("level")
_waterStatue = ObjectCache::find("Water1");
_windStatue = ObjectCache::find("Wind1");

_fireStatue->setMaterial(new StatueMaterial(nullptr, glm::vec3(1, 0, 0)));
_waterStatue->setMaterial(new StatueMaterial(nullptr, glm::vec3(0, 0, 1)));
_earthStatue->setMaterial(new StatueMaterial(nullptr, glm::vec3(0.5f, 0.5f, 0)));
_windStatue->setMaterial(new StatueMaterial(nullptr, glm::vec3(1, 1, 1)));
std::string path = config::MGE_TEXTURE_PATH + "statues/";

_fireStatue->setMaterial(new StatueMaterial(nullptr, nullptr, glm::vec3(1, 0, 0)));
_waterStatue->setMaterial(new StatueMaterial(Texture::load(path + "statue_water_diffuse.png"), Texture::load(path + "statue_water_emission2.png"), glm::vec3(0, 0, 1)));
_earthStatue->setMaterial(new StatueMaterial(nullptr, nullptr, glm::vec3(0.5f, 0.5f, 0)));
_windStatue->setMaterial(new StatueMaterial(nullptr, nullptr, glm::vec3(1, 1, 1)));
World::add(this);
}

@@ -15,9 +15,7 @@ Tile::Tile(glm::vec3 pPosition, Mesh* pMesh) : GameObject("tile")
this->setLocalPosition(pPosition);
_boardPos = glm::vec2(pPosition.x, pPosition.z);

Texture * texture = Texture::load(config::MGE_TEXTURE_PATH + "playfield_tile_sg_Ambient_occlusion.png");
//_material = new TextureMaterial(texture);
_material = new LitMaterial();
_material = new ChangeColorMaterial(Texture::load(config::MGE_TEXTURE_PATH + "tile_diffuse.png"), Texture::load(config::MGE_TEXTURE_PATH + "tile_highlight.png"));
this->setMaterial(_material);
this->setMesh(pMesh);
}
@@ -71,7 +69,7 @@ void Tile::setOwner(Id pPlayer)
switch (pPlayer)
{
case Id::empty:
_material->setColor(glm::vec3(1));
_material->setColor(glm::vec3(0));
break;

case Id::p1:
@@ -2,7 +2,7 @@
#define TILE_H

#include "mge/core/GameObject.hpp"
#include "mge/materials/TextureMaterial.hpp"
#include "mge/materials/ChangeColorMaterial.hpp"
#include "Enums.hpp"

class Tile : public GameObject
@@ -17,7 +17,7 @@ class Tile : public GameObject

vector<Tile*> getConnections();

LitMaterial* _material;
AbstractMaterial* _material;

//loop fill
bool _connected = true;
@@ -120,7 +120,7 @@ void AbstractGame::run()
//Bloom::renderToFBO();
Skybox::render();
_render();
//Bloom::blur(2);
//Bloom::blur(4);
_window->display();

float timeSinceLastRender = renderClock.restart().asSeconds();
@@ -136,7 +136,7 @@ void Bloom::blur(int amount)
for (GLuint i = 0; i < amount; i++)
{
glUniform1i(bloom->_uHorizontal, horizontal);
glUniform1f(bloom->_uMultiplier, 1.2f);
glUniform1f(bloom->_uMultiplier, 1.f);

glBindFramebuffer(GL_FRAMEBUFFER, bloom->_pingpongFBO[horizontal]);
glBindTexture(GL_TEXTURE_2D, first_iteration ? bloom->_colorBuffers[1] : bloom->_pingpongBuffers[!horizontal]);
@@ -9,7 +9,6 @@

Skybox* Skybox::_skybox = NULL;


Skybox::Skybox() : GameObject("skybox")
{
setMesh(Mesh::load(config::MGE_MODEL_PATH + "skybox_cube.obj"));
@@ -0,0 +1,163 @@
#include "mge/materials/ChangeColorMaterial.hpp"
#include "mge/core/Mesh.hpp"
#include "mge/core/GameObject.hpp"
#include "mge/config.hpp"

#include "mge/behaviours/DirectionalLight.hpp"
#include "mge/behaviours/PointLight.hpp"
#include "mge/behaviours/SpotLight.hpp"

#include <string>

//shader
ShaderProgram* ChangeColorMaterial::_shader = NULL;

//vertex uniforms
GLint ChangeColorMaterial::_uMVPMatrix = 0;
GLint ChangeColorMaterial::_uModelMatrix = 0;

//fragment uniforms
GLint ChangeColorMaterial::_uModelColor = 0;
GLint ChangeColorMaterial::_uShininess = 0;
GLint ChangeColorMaterial::_uCameraPos = 0;
GLint ChangeColorMaterial::_uTexture = 0;
GLint ChangeColorMaterial::_uHighlight = 0;

//vertex attributes
GLint ChangeColorMaterial::_aVertex = 0;
GLint ChangeColorMaterial::_aNormal = 0;
GLint ChangeColorMaterial::_aUv = 0;

ChangeColorMaterial::ChangeColorMaterial(Texture* pTexture, Texture* pHighlight, glm::vec3 pModelColor, float pShininess, std::vector<AbstractLight*>* pLights)
: _texture(pTexture), _highlight(pHighlight), _modelColor(pModelColor), _shininess(pShininess), _lights(pLights)
{
_lazyInitializeShader();
}

void ChangeColorMaterial::_lazyInitializeShader()
{
if (!_shader)
{
_shader = new ShaderProgram();

_shader->addShader(GL_VERTEX_SHADER, config::MGE_SHADER_PATH + "litColorChange.vs");
_shader->addShader(GL_FRAGMENT_SHADER, config::MGE_SHADER_PATH + "litColorChange.fs");
_shader->finalize();

//vertex uniforms
_uMVPMatrix = _shader->getUniformLocation("mvpMatrix");
_uModelMatrix = _shader->getUniformLocation("modelMatrix");

//fragment uniforms
_uModelColor = _shader->getUniformLocation("modelColor");
_uShininess = _shader->getUniformLocation("shininess");
_uCameraPos = _shader->getUniformLocation("cameraPos");
_uTexture = _shader->getUniformLocation("dTexture");
_uHighlight = _shader->getUniformLocation("highlight");

//vertex attributes
_aVertex = _shader->getAttribLocation("vertex");
_aNormal = _shader->getAttribLocation("normal");
_aUv = _shader->getAttribLocation("uv");
}
}

glm::vec3 ChangeColorMaterial::getColor() {
return _modelColor;
}
void ChangeColorMaterial::setColor(glm::vec3 newColor) {
_modelColor = newColor;
}

void ChangeColorMaterial::render(Mesh* pMesh, const glm::mat4& pModelMatrix, const glm::mat4& pViewMatrix, const glm::mat4& pProjectionMatrix)
{
_shader->use();

//uniforms
glm::mat4 mvpMatrix = pProjectionMatrix * pViewMatrix * pModelMatrix;
glUniformMatrix4fv(_uMVPMatrix, 1, GL_FALSE, glm::value_ptr(mvpMatrix));
glUniformMatrix4fv(_uModelMatrix, 1, GL_FALSE, glm::value_ptr(pModelMatrix));

glUniform3fv(_uCameraPos, 1, glm::value_ptr(((GameObject*)(World::get()->getMainCamera()))->getWorldPosition()));
glUniform1f(_uShininess, _shininess);
glUniform3fv(_uModelColor, 1, glm::value_ptr(_modelColor));

renderLights();
renderTextures();
pMesh->streamToOpenGL(_aVertex, _aNormal, _aUv);
}

void ChangeColorMaterial::renderTextures()
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, _texture->getId());
glUniform1i(_uTexture, 0);

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, _highlight->getId());
glUniform1i(_uHighlight, 1);
}

void ChangeColorMaterial::renderLights()
{
int dLights = 0;
int pLights = 0;
int sLights = 0;

for each (AbstractLight* abstractLight in *_lights)
{
std::string lType = "";
std::string num = "";

if (typeid(*abstractLight) == typeid(DirectionalLight))
{
num = std::to_string(dLights);
lType = "dirLight";

glUniform3fv(_shader->getUniformLocation("dirLight[" + num + "].direction"), 1, glm::value_ptr(abstractLight->getDirection()));

dLights++;
}
else if (typeid(*abstractLight) == typeid(PointLight))
{
num = std::to_string(pLights);
lType = "pointLight";

PointLight* light = static_cast<PointLight*>(abstractLight);

glUniform3fv(_shader->getUniformLocation("pointLight[" + num + "].position"), 1, glm::value_ptr(light->getWorldPosition()));

glUniform1f(_shader->getUniformLocation("pointLight[" + num + "].constant"), light->_constant);
glUniform1f(_shader->getUniformLocation("pointLight[" + num + "].linear"), light->_linear);
glUniform1f(_shader->getUniformLocation("pointLight[" + num + "].quadratic"), light->_quadratic);
pLights++;
}
else if (typeid(*abstractLight) == typeid(SpotLight))
{
num = std::to_string(sLights);
lType = "spotLight";

SpotLight* light = static_cast<SpotLight*>(abstractLight);

glUniform3fv(_shader->getUniformLocation("spotLight[" + num + "].direction"), 1, glm::value_ptr(light->getDirection()));
glUniform3fv(_shader->getUniformLocation("spotLight[" + num + "].position"), 1, glm::value_ptr(light->getWorldPosition()));

glUniform1f(_shader->getUniformLocation("spotLight[" + num + "].constant"), light->_constant);
glUniform1f(_shader->getUniformLocation("spotLight[" + num + "].linear"), light->_linear);
glUniform1f(_shader->getUniformLocation("spotLight[" + num + "].quadratic"), light->_quadratic);

glUniform1f(_shader->getUniformLocation("spotLight[" + num + "].cutOff"), 1 - glm::sin(light->_cutOff * (glm::pi<float>() / 180.0f)));
glUniform1f(_shader->getUniformLocation("spotLight[" + num + "].outerCutOff"), glm::sin(light->_outerCutOff * (glm::pi<float>() / 180.0f)));

sLights++;
}

//All lights have these values, so it's unnececary to cast
glUniform3fv(_shader->getUniformLocation(lType + "[" + num + "].ambient"), 1, glm::value_ptr(abstractLight->_ambient));
glUniform3fv(_shader->getUniformLocation(lType + "[" + num + "].diffuse"), 1, glm::value_ptr(abstractLight->_diffuse));
glUniform3fv(_shader->getUniformLocation(lType + "[" + num + "].specular"), 1, glm::value_ptr(abstractLight->_specular));
}
glUniform3fv(_shader->getUniformLocation("lightCount"), 1, glm::value_ptr(glm::vec3(dLights, pLights, sLights)));
}

ChangeColorMaterial::~ChangeColorMaterial() { }
@@ -0,0 +1,58 @@
#ifndef CHANGECOLORMATERIAL_H
#define CHANGECOLORMATERIAL_H

#include <vector>
#include <glm.hpp>

#include "mge/materials/AbstractMaterial.hpp"
#include "mge/core/ShaderProgram.hpp"
#include "mge/behaviours/AbstractLight.hpp"
#include "mge/core/World.hpp"
#include "mge/core/Texture.hpp"

class ChangeColorMaterial : public AbstractMaterial
{
public:
ChangeColorMaterial(Texture* pTexture, Texture* pHighlight, glm::vec3 pModelColor = glm::vec3(0), float pShininess = 10.0f, std::vector<AbstractLight*>* pLights = World::get()->GetLights());

virtual ~ChangeColorMaterial();

virtual void render(Mesh* pMesh, const glm::mat4& pModelMatrix, const glm::mat4& pViewMatrix, const glm::mat4& pProjectionMatrix) override;

glm::vec3 getColor();
void setColor(glm::vec3 pColor);

private:
static void _lazyInitializeShader();
void renderLights();
void renderTextures();

static ShaderProgram* _shader;

//vertex uniforms
static GLint _uMVPMatrix;
static GLint _uModelMatrix;

//fragment uniforms
static GLint _uModelColor;
static GLint _uShininess;
static GLint _uCameraPos;
static GLint _uTexture;
static GLint _uHighlight;

//vertex attributes
static GLint _aVertex;
static GLint _aNormal;
static GLint _aUv;

//lights
std::vector<AbstractLight*>* _lights;

//settings
glm::vec3 _modelColor;
Texture* _texture;
Texture*_highlight;
float _shininess;
};

#endif // LITMATERIAL_H
@@ -5,6 +5,9 @@
#include "mge/core/GameObject.hpp"
#include "mge/core/Mesh.hpp"

#include "mge/core/World.hpp"
#include "mge/core/Camera.hpp"

SkyMaterial::SkyMaterial(Texture* pTexture) : _texture(pTexture)
{
_shader = new ShaderProgram();
@@ -14,8 +17,8 @@ SkyMaterial::SkyMaterial(Texture* pTexture) : _texture(pTexture)

//attributes
_aVertex = _shader->getAttribLocation("vertex");
_aNormal = _shader->getAttribLocation("normal");
_aUV = _shader->getAttribLocation("uv");
//_aNormal = _shader->getAttribLocation("normal");
_aUV = _shader->getAttribLocation("uv");

//uniforms
_uMVmatrix = _shader->getUniformLocation("MVmatrix");
@@ -32,7 +35,8 @@ void SkyMaterial::render(Mesh* pMesh, const glm::mat4& pModelMatrix, const glm::
glDepthMask(GL_FALSE);
_shader->use();

glm::mat4 mvMatrix = pProjectionMatrix * pViewMatrix;

glm::mat4 mvMatrix = pProjectionMatrix * glm::mat4(glm::mat3(World::getMainCamera()->getWorldTransform()));
glUniformMatrix4fv(_uMVmatrix, 1, GL_FALSE, glm::value_ptr(mvMatrix));

glActiveTexture(GL_TEXTURE0);
@@ -8,6 +8,7 @@
#include "mge/behaviours/SpotLight.hpp"

#include <string>
#include "SFML/Window/Keyboard.hpp"

//shader
ShaderProgram* StatueMaterial::_shader = NULL;
@@ -22,7 +23,7 @@ GLint StatueMaterial::_uMVPMatrix = 0;
GLint StatueMaterial::_uModelMatrix = 0;

//fragment uniforms
GLint StatueMaterial::_uModelColor = 0;
GLint StatueMaterial::_uHighlight = 0;
GLint StatueMaterial::_uTexture = 0;
GLint StatueMaterial::_uShininess = 0;
GLint StatueMaterial::_uCameraPos = 0;
@@ -32,10 +33,14 @@ GLint StatueMaterial::_uScore = 0;
GLint StatueMaterial::_uMinHeight = 0;
GLint StatueMaterial::_uMaxHeight = 0;

StatueMaterial::StatueMaterial(Texture* pTexture, glm::vec3 pModelColor, float pShininess, std::vector<AbstractLight*>* pLights)
: _texture(pTexture), _modelColor(pModelColor), _shininess(pShininess), _lights(pLights)
StatueMaterial::StatueMaterial(Texture* pTexture, Texture* pHighLight, glm::vec3 pModelColor, float pShininess, std::vector<AbstractLight*>* pLights)
: _texture(pTexture), _highLight(pHighLight), _shininess(pShininess), _lights(pLights)
{
_lazyInitializeShader();

_relativeScore = 0.f;
_minHeight = 2.7f;
_maxHeight = 2.17f;
}

void StatueMaterial::_lazyInitializeShader()
@@ -58,8 +63,8 @@ void StatueMaterial::_lazyInitializeShader()
_uModelMatrix = _shader->getUniformLocation("modelMatrix");

//fragment uniforms
_uModelColor = _shader->getUniformLocation("modelColor");
_uTexture = _shader->getUniformLocation("dTexture");
_uHighlight = _shader->getUniformLocation("highlight");
_uShininess = _shader->getUniformLocation("shininess");
_uCameraPos = _shader->getUniformLocation("cameraPos");

@@ -74,9 +79,9 @@ void StatueMaterial::setTexture(Texture* pTexture)
{
_texture = pTexture;
}
void StatueMaterial::setSpecular(Texture* pSpecularTexture)
void StatueMaterial::setHighLight(Texture* pHighLight)
{
_specular = pSpecularTexture;
_highLight = pHighLight;
}

void StatueMaterial::setScore(float pScore)
@@ -87,6 +92,9 @@ void StatueMaterial::setScore(float pScore)
void StatueMaterial::render(Mesh* pMesh, const glm::mat4& pModelMatrix, const glm::mat4& pViewMatrix, const glm::mat4& pProjectionMatrix)
{
_shader->use();

if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::F))
_relativeScore += 0.005f;

//uniforms
glm::mat4 mvpMatrix = pProjectionMatrix * pViewMatrix * pModelMatrix;
@@ -96,25 +104,27 @@ void StatueMaterial::render(Mesh* pMesh, const glm::mat4& pModelMatrix, const gl
glUniform3fv(_uCameraPos, 1, glm::value_ptr(((GameObject*)(World::get()->getMainCamera()))->getWorldPosition()));
glUniform1f(_uShininess, _shininess);

glUniform3fv(_uModelColor, 1, glm::value_ptr(_modelColor));

//statue uniforms
glUniform1f(_uMinHeight, _minHeight);
glUniform1f(_uMaxHeight, _maxHeight);
glUniform1f(_uScore, _relativeScore);

if (_texture)
renderTexture();
if (_texture && _highLight)
renderTextures();

renderLights();
pMesh->streamToOpenGL(_aVertex, _aNormal, _aUV);
}

void StatueMaterial::renderTexture()
void StatueMaterial::renderTextures()
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, _texture->getId());
glUniform1i(_uTexture, 0);

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, _highLight->getId());
glUniform1i(_uHighlight, 1);
}

glm::vec3 StatueMaterial::getColor() {
@@ -9,11 +9,11 @@
class StatueMaterial : public AbstractMaterial
{
public:
StatueMaterial (Texture* pTexture, glm::vec3 pModelColor = glm::vec3(1), float pShininess = 10.0f, std::vector<AbstractLight*>* pLights = World::get()->GetLights());
StatueMaterial (Texture* pTexture, Texture* pHighLights, glm::vec3 pModelColor = glm::vec3(1), float pShininess = 10.0f, std::vector<AbstractLight*>* pLights = World::get()->GetLights());
virtual void render(Mesh* pMesh, const glm::mat4& pModelMatrix, const glm::mat4& pViewMatrix, const glm::mat4& pProjectionMatrix) override;

void setTexture (Texture* pDiffuseTexture);
void setSpecular(Texture* pSpecularTexture);
void setHighLight(Texture* pSpecularTexture);

glm::vec3 getColor();
void setColor(glm::vec3 pColor);
@@ -22,12 +22,12 @@ class StatueMaterial : public AbstractMaterial
private:
static void _lazyInitializeShader();
void renderLights();
void renderTexture();
void renderTextures();

//score floats
float _relativeScore = 0.5f;
float _minHeight = -1.f;
float _maxHeight = 10.f;
float _relativeScore;
float _minHeight;
float _maxHeight;


static ShaderProgram* _shader;
@@ -42,7 +42,7 @@ class StatueMaterial : public AbstractMaterial
static GLint _uModelMatrix;

//fragment uniforms
static GLint _uModelColor;
static GLint _uHighlight;
static GLint _uTexture;
static GLint _uShininess;
static GLint _uCameraPos;
@@ -58,7 +58,7 @@ class StatueMaterial : public AbstractMaterial
//settings
glm::vec3 _modelColor;
Texture* _texture;
Texture* _specular;
Texture* _highLight;
float _shininess;
};