diff --git a/Shader/phong.fsh b/Shader/phong.fsh index 4ce9816..7776aad 100644 --- a/Shader/phong.fsh +++ b/Shader/phong.fsh @@ -14,6 +14,9 @@ uniform float specularFactor; uniform vec3 camera; uniform float shininess; uniform int lightCount; +uniform vec3 directionalLightVector; +uniform vec3 directionalColor; +uniform float directionalIntensity; uniform vec3 lightSources[128]; uniform vec3 lightColors[128]; uniform float lightIntensities[128]; @@ -23,6 +26,15 @@ void main() vec3 ambientColor = ambientFactor * ambientColor; vec3 diffuseColor = vec3(0.0, 0.0, 0.0); vec3 specularColor = vec3(0.0, 0.0, 0.0); + + if(length(directionalLightVector)>0.0f) { + vec3 directionalVector = normalize(directionalLightVector); + diffuseColor += dot(normalize(vNormal), directionalVector) + *diffuseFactor*directionalIntensity*directionalColor; + vec3 cameraVector = normalize(camera - vec3(fragPosition)); + specularColor += clamp(pow((dot((cameraVector+directionalVector),normalize(vNormal))/(length(cameraVector+directionalVector)*length(normalize(vNormal)))),shininess), 0.0, 1.0) + *specularFactor*directionalIntensity*directionalColor; + } for(int i = 0; igetUniformLocation("lightIntensities"), sizeof(lightIntensities), (GLfloat*) lightIntensities); } + // set directional Light + if(level->getDirectionalLight()) { + shader->setUniform("directionalLightVector", + level->getDirectionalLight()->getPosition()); + shader->setUniform("directionalColor", + level->getDirectionalLight()->getColour()); + shader->setUniform("directionalIntensity", + level->getDirectionalLight()->getIntensity()); + } // set Material Parameters shader->setUniform("ambientColor", level->getAmbientLight()); diff --git a/level.cc b/level.cc index 7fca11c..5586ee2 100644 --- a/level.cc +++ b/level.cc @@ -44,25 +44,26 @@ void Level::load(ACGL::OpenGL::SharedShaderProgram shader) { Model blockModel = Model("Block.obj", 1.0f); Material blockMaterial = Material("blockTexture.png", 0.1f, 0.6, 0.4f, 2.0f); - Object blockObject = Object(blockModel, blockMaterial, glm::vec3(2.0f, 6.0f, 2.0f), + Object blockObject = Object(blockModel, blockMaterial, glm::vec3(2.0f, 7.0f, 2.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), shader); objects.push_back(blockObject); Model columnModel = Model("Column.obj", 1.0f); Material columnMaterial = Material("columnTexture.png", 0.1f, 0.6, 0.4f, 2.0f); - Object columnObject = Object(columnModel, columnMaterial, glm::vec3(-2.0f, 6.0f, -2.0f), + Object columnObject = Object(columnModel, columnMaterial, glm::vec3(-2.0f, 7.0f, -2.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), shader); objects.push_back(columnObject); //set lighting parameters ambientLight = glm::vec3(1.0f, 1.0f, 1.0f); - Light light = Light(glm::vec3(-3.0f, 7.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f), 10.0f); + directionalLight = Light(glm::vec3(-0.5f, 0.0f, -0.5f), glm::vec3(1.0f, 1.0f, 0.0f), 0.4f); + Light light = Light(glm::vec3(-3.0f, 7.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f), 10.0f); lights.push_back(light); - Light light2 = Light(glm::vec3(3.0f, 6.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f), 10.0f); + Light light2 = Light(glm::vec3(3.0f, 6.0f, 0.0f), glm::vec3(1.0f, 1.0f, 1.0f), 10.0f); lights.push_back(light2); - Light light3 = Light(glm::vec3(0.0f, 5.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.5f, 0.5f, 1.0f), 4.0f); + Light light3 = Light(glm::vec3(0.0f, 5.0f, 0.0f), glm::vec3(0.5f, 0.5f, 1.0f), 4.0f); lights.push_back(light3); @@ -137,3 +138,7 @@ Camera* Level::getCamera() { Object* Level::getCameraCenter() { return cameraCenter; } + +Light* Level::getDirectionalLight() { + return &directionalLight; +} diff --git a/level.hh b/level.hh index db6ab73..21d6d81 100644 --- a/level.hh +++ b/level.hh @@ -19,6 +19,7 @@ class Level { void update(float runTime, glm::vec2 mouseDelta,bool wPressed, bool aPressed,bool sPressed, bool dPressed); void render(); glm::vec3 getAmbientLight(); + Light* getDirectionalLight(); std::vector getLights(); Object* getCameraCenter(); Camera* getCamera(); @@ -27,6 +28,7 @@ class Level { std::vector objects; std::vector lights; glm::vec3 ambientLight; + Light directionalLight; Object* cameraCenter; Physics physics; Camera camera;