From fd1f32be6ae164fe06575bf623ada3311d2d2476 Mon Sep 17 00:00:00 2001 From: Fabian Klemp Date: Fri, 13 Feb 2015 17:09:25 +0100 Subject: [PATCH] maxShadowRenderCount now works correctly. --- Shader/phong.fsh | 31 ++++++++++++------------------- graphics.cc | 47 +++++++++++++++++++++-------------------------- graphics.hh | 3 +-- 3 files changed, 34 insertions(+), 47 deletions(-) diff --git a/Shader/phong.fsh b/Shader/phong.fsh index e9a7f13..08a6bf0 100644 --- a/Shader/phong.fsh +++ b/Shader/phong.fsh @@ -26,6 +26,7 @@ uniform float specularFactor; uniform vec3 camera; uniform float shininess; uniform int lightCount; +uniform int maxShadowRenderCount; uniform vec3 directionalLightVector; uniform vec3 directionalColor; uniform float directionalIntensity; @@ -115,45 +116,37 @@ void main() for(int i = 0; ibind(); - for (unsigned int i_pointlight = 0; i_pointlightsize() && i_pointlight < maxShadowRenderCount; i_pointlight++) { + for (unsigned int i_pointlight = 0; i_pointlightgetObjectName(), 0); glClear(GL_DEPTH_BUFFER_BIT); - glm::mat4 viewMatrix = glm::lookAt(closestLights->at(i_pointlight).getPosition(), - closestLights->at(i_pointlight).getPosition() + looking_directions[i_face], upvectors[i_face]); + glm::mat4 viewMatrix = glm::lookAt(closestLights.at(i_pointlight).getPosition(), + closestLights.at(i_pointlight).getPosition() + looking_directions[i_face], upvectors[i_face]); glm::mat4 depthViewProjectionMatrix_face = depthProjectionMatrix_pointlights * viewMatrix; std::vector viewMatrixVector = std::vector(); viewMatrixVector.push_back(viewMatrix); @@ -200,43 +200,38 @@ bool Graphics::compareLightDistances(Light a, Light b) { } void Graphics::updateClosestLights() { - if (level->getLights()->size() <= 32) { - this->closestLights = level->getLights(); - } - else { - closestLightsVector = std::vector(*level->getLights()); - std::sort(closestLightsVector.begin(), - closestLightsVector.end(), - [this](Light a, Light b) {return compareLightDistances(a, b); }); - closestLightsVector = std::vector(&closestLightsVector[0], - &closestLightsVector[31]); - closestLights = &closestLightsVector; - } + closestLights = std::vector(*level->getLights()); + std::sort(closestLights.begin(), + closestLights.end(), + [this](Light a, Light b) {return compareLightDistances(a, b); }); + closestLights = std::vector(&closestLights[0], + &closestLights[31]); } void Graphics::updateShaderLights() { updateClosestLights(); - if (closestLights->size() > 0) { - lightingShader->setUniform("lightCount", (int) closestLights->size()); + if (closestLights.size() > 0) { + lightingShader->setUniform("lightCount", (int) closestLights.size()); + lightingShader->setUniform("maxShadowRenderCount", std::min((int) closestLights.size(), (int)maxShadowRenderCount)); // Build light position array - glm::vec3 lightSources[closestLights->size()]; - for(unsigned int i = 0; isize(); i++) { - lightSources[i] = closestLights->at(i).getPosition(); + glm::vec3 lightSources[closestLights.size()]; + for(unsigned int i = 0; igetUniformLocation("lightSources"), sizeof(lightSources), (GLfloat*) lightSources); // Build light colour array - glm::vec3 lightColours[closestLights->size()]; - for(unsigned int i = 0; isize(); i++) { - lightColours[i] = closestLights->at(i).getColour(); + glm::vec3 lightColours[closestLights.size()]; + for(unsigned int i = 0; igetUniformLocation("lightColors"), sizeof(lightColours), (GLfloat*) lightColours); // Build light attenuation array - float lightIntensities[closestLights->size()]; - for(unsigned int i = 0; isize(); i++) { - lightIntensities[i] = closestLights->at(i).getIntensity(); + float lightIntensities[closestLights.size()]; + for(unsigned int i = 0; igetUniformLocation("lightIntensities"), sizeof(lightIntensities), (GLfloat*) lightIntensities); diff --git a/graphics.hh b/graphics.hh index 1876899..ec348f2 100644 --- a/graphics.hh +++ b/graphics.hh @@ -28,8 +28,7 @@ class Graphics { float nearPlane; float farPlane; // pointer to either use the vector from the level or from here - std::vector* closestLights; - std::vector closestLightsVector; // contains the 32 closest lights + std::vector closestLights; ACGL::OpenGL::SharedShaderProgram lightingShader; ACGL::OpenGL::SharedShaderProgram depthCubeShader; ACGL::OpenGL::SharedShaderProgram depthShader;