diff --git a/Shader/HelloWorld.fsh b/Shader/HelloWorld.fsh index 06e02b5..abf82b5 100644 --- a/Shader/HelloWorld.fsh +++ b/Shader/HelloWorld.fsh @@ -6,6 +6,7 @@ in vec2 vTexCoord; out vec4 oColor; uniform sampler2D uTexture; +uniform int lightCount; uniform vec3 lightSources[128]; uniform vec3 ambientIntensity; uniform float ambientFactor; @@ -15,7 +16,10 @@ uniform float diffuseFactor; void main() { vec3 ambientColor = ambientFactor * ambientIntensity; - vec3 diffuseColor = dot(normalize(vNormal),vec3(0,0,1))*diffuseFactor*diffuseIntensity; + vec3 diffuseColor = vec3(0.0, 0.0, 0.0); + for(int i = 0; isetUniform("ambientIntensity", level.getAmbientLight()); shader.getReference()->setUniform("ambientFactor", 1.0f); - shader.getReference()->setUniform("diffuseIntensity", glm::vec3(1.0f, 1.0f, 1.0f)); - shader.getReference()->setUniform("diffuseFactor", 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("lightCount", (int) level.getLights().size()); - - // TODO look into doing this less often - // Build light position array - glm::vec3 lights[level.getLights().size()]; - for(int i = 0; igetUniformLocation("lightSources"), sizeof(lights), (GLfloat*) lights); } - - shader.getReference()->setUniform("lightSources", lights); - //glUniform1fv(glGetUniformLocation(shader.getReference(), "lightSources", 128, lights); // render the level(currently only a bunny): level.render(); diff --git a/level.cc b/level.cc index 51f6870..fe66376 100644 --- a/level.cc +++ b/level.cc @@ -23,6 +23,10 @@ void Level::load(Shader shader) { objects.push_back(object); //set lighting parameters ambientLight = glm::vec3(0.1f, 0.1f, 0.1f); + Light light = Light(glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f), 1.0f); + lights.push_back(light); + Light light2 = Light(glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 0.0f, 0.0f), 1.0f); + lights.push_back(light2); } void Level::render() {