From afbf41ea0d37e537526d9867c4e801fe55a487ea Mon Sep 17 00:00:00 2001 From: Faerbit Date: Mon, 3 Nov 2014 23:54:35 +0100 Subject: [PATCH] Shading now respects colours. --- Shader/phong.fsh | 9 +++++---- graphics.cc | 19 +++++++++++++------ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Shader/phong.fsh b/Shader/phong.fsh index abf82b5..8e2b5f5 100644 --- a/Shader/phong.fsh +++ b/Shader/phong.fsh @@ -8,17 +8,18 @@ out vec4 oColor; uniform sampler2D uTexture; uniform int lightCount; uniform vec3 lightSources[128]; -uniform vec3 ambientIntensity; +uniform vec3 ambientColor; uniform float ambientFactor; -uniform vec3 diffuseIntensity; +uniform vec3 lightColors[128]; uniform float diffuseFactor; void main() { - vec3 ambientColor = ambientFactor * ambientIntensity; + vec3 ambientColor = ambientFactor * ambientColor; vec3 diffuseColor = vec3(0.0, 0.0, 0.0); for(int i = 0; isetUniform( "uProjectionMatrix", buildFrustum(75.0, 0.1, 100.0, (float)g_windowSize.x/(float)g_windowSize.y) ); //set lighting parameters - shader.getReference()->setUniform("ambientIntensity", level.getAmbientLight()); + shader.getReference()->setUniform("ambientColor", level.getAmbientLight()); shader.getReference()->setUniform("ambientFactor", 1.0f); if (level.getLights().size() > 0) { - shader.getReference()->setUniform("diffuseIntensity", glm::vec3(1.0f, 1.0f, 1.0f)); - shader.getReference()->setUniform("diffuseFactor", 1.0f); + shader.getReference()->setUniform("diffuseFactor", 0.7f); shader.getReference()->setUniform("lightCount", (int) level.getLights().size()); // TODO look into doing this less often // Build light position array - glm::vec3 lights[level.getLights().size()]; + glm::vec3 lightSources[level.getLights().size()]; for(int i = 0; igetUniformLocation("lightSources"), sizeof(lights), (GLfloat*) lights); + glUniform3fv(shader.getReference()->getUniformLocation("lightSources"), + sizeof(lightSources), (GLfloat*) lightSources); + // Build light colour array + glm::vec3 lightColours[level.getLights().size()]; + for(int i = 0; igetUniformLocation("lightColors"), + sizeof(lightColours), (GLfloat*) lightColours); } // render the level(currently only a bunny):