From f45603fe4ce46c7e3617b5f0370a5fd7348fdaec Mon Sep 17 00:00:00 2001 From: Faerbit Date: Wed, 4 Feb 2015 22:54:40 +0100 Subject: [PATCH] Did a little bit of cleanup. --- Shader/depth.fsh | 1 - graphics.cc | 48 +++++++----------------------------------------- object.cc | 10 +++++----- object.hh | 2 +- 4 files changed, 13 insertions(+), 48 deletions(-) diff --git a/Shader/depth.fsh b/Shader/depth.fsh index 0fcb690..79e5487 100644 --- a/Shader/depth.fsh +++ b/Shader/depth.fsh @@ -8,5 +8,4 @@ out float gl_FragDepth; void main() { gl_FragDepth = length(fragPosition)/farPlane; - //gl_FragDepth = 1.5f; } diff --git a/graphics.cc b/graphics.cc index 941b27c..635fe1c 100644 --- a/graphics.cc +++ b/graphics.cc @@ -96,14 +96,12 @@ void Graphics::render(double time) // render depth textures for point lights glViewport(0, 0, cube_size, cube_size); glm::mat4 depthProjectionMatrix_pointlights = glm::perspective(1.571f, (float)cube_size/(float)cube_size, 0.1f, farPlane); - glm::vec3 looking_directions[6] = {glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(-1.0f, 0.0f, 0.0f), glm::normalize(glm::vec3(0.0f, 1.0f, 0.0f)), - glm::normalize(glm::vec3(0.0f, -1.0f, 0.0f)), glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.0f, 0.0f, -1.0f)}; + glm::vec3 looking_directions[6] = {glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(-1.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f), + glm::vec3(0.0f, -1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f), glm::vec3(0.0f, 0.0f, -1.0f)}; glm::vec3 upvectors[6] = {glm::vec3(0.0f, -1.0f, 0.0f),glm::vec3(0.0f, -1.0f, 0.0f),glm::vec3(0.0f, 0.0f, -1.0f), glm::vec3(0.0f, 0.0f, -1.0f),glm::vec3(0.0f, -1.0f, 0.0f),glm::vec3(0.0f, -1.0f, 0.0f)}; framebuffer_cube->bind(); - static bool printed = false; - glm::mat4 reproduceMatrix; //for (unsigned int i_pointlight = 0; i_pointlightgetLights()->size(); i_pointlight++) { for (unsigned int i_pointlight = 0; i_pointlight<1 && i_pointlightgetLights()->size(); i_pointlight++) { // render each side of the cube @@ -116,32 +114,13 @@ void Graphics::render(double time) glm::mat4 viewMatrix = glm::lookAt(level->getLights()->at(i_pointlight).getPosition(), level->getLights()->at(i_pointlight).getPosition() + looking_directions[i_face], upvectors[i_face]); glm::mat4 depthViewProjectionMatrix_face = depthProjectionMatrix_pointlights * viewMatrix; - if (i_face == 0) { - reproduceMatrix = depthViewProjectionMatrix_face; - } - if (!printed) { - printf("\n\nView matrix:\n %2.10f, %2.10f, %2.10f, %2.10f\n%2.10f, %2.10f, %2.10f, %2.10f\n%2.10f, %2.10f, %2.10f, %2.10f\n%2.10f, %2.10f, %2.10f, %2.10f\n\n\n", - viewMatrix[0][0], viewMatrix[1][0], viewMatrix[2][0], viewMatrix[3][0], - viewMatrix[0][1], viewMatrix[1][1], viewMatrix[2][1], viewMatrix[3][1], - viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2], viewMatrix[3][2], - viewMatrix[0][3], viewMatrix[1][3], viewMatrix[2][3], viewMatrix[3][3] - ); - - //std::cout<<"View matrix:" < foovector = std::vector(); - foovector.push_back(viewMatrix); - level->render(depthShader, false, &depthViewProjectionMatrix_face, &foovector); + std::vector viewMatrixVector = std::vector(); + viewMatrixVector.push_back(viewMatrix); + level->render(depthShader, false, &depthViewProjectionMatrix_face, &viewMatrixVector); + level->render(depthShader, false, &viewMatrix); if (!framebuffer_cube->isFrameBufferObjectComplete()) { printf("Framebuffer incomplete, unknown error occured during shadow generation!\n"); } - if (saveDepthBufferBool && i_face == 3) { - saveDepthBufferToDisk(3, "face.png"); - saveDepthBufferBool = false; - } - } - if (!printed) { - printed = true; } } // render depth texture for sun @@ -208,7 +187,6 @@ void Graphics::render(double time) // render the level level->render(lightingShader, true, &lightingViewProjectionMatrix, &shadowVPs); - //level->render(lightingShader, true, &reproduceMatrix, &shadowVPs); } void Graphics::updateLights() { @@ -257,20 +235,8 @@ glm::mat4 Graphics::buildViewMatrix(Level* level) { //construct lookAt (cameraPosition = cameraCenter + cameraVector) //return glm::lookAt(level->getCamera()->getPosition(), level->getCamera()->getPosition() + level->getCamera()->getDirection(), glm::vec3(0.0f, 1.0f, 0.0f)); - glm::mat4 depthViewProjectionMatrix_face = glm::lookAt((level->getCameraCenter()->getPosition() + level->getCamera()->getVector()), + return glm::lookAt((level->getCameraCenter()->getPosition() + level->getCamera()->getVector()), level->getCameraCenter()->getPosition(), glm::vec3(0.0f, 1.0f, 0.0f)); - static int i = 5; - if (i == 0) { - printf("\n\nView matrix Camera:\n %2.2f, %2.2f, %2.2f, %2.2f\n%2.2f, %2.2f, %2.2f, %2.2f\n%2.2f, %2.2f, %2.2f, %2.2f\n%2.2f, %2.2f, %2.2f, %2.2f\n\n\n", - depthViewProjectionMatrix_face[0][0], depthViewProjectionMatrix_face[0][1], depthViewProjectionMatrix_face[0][2], depthViewProjectionMatrix_face[0][3], - depthViewProjectionMatrix_face[1][0], depthViewProjectionMatrix_face[1][1], depthViewProjectionMatrix_face[1][2], depthViewProjectionMatrix_face[1][3], - depthViewProjectionMatrix_face[2][0], depthViewProjectionMatrix_face[2][1], depthViewProjectionMatrix_face[2][2], depthViewProjectionMatrix_face[2][3], - depthViewProjectionMatrix_face[3][0], depthViewProjectionMatrix_face[3][1], depthViewProjectionMatrix_face[3][2], depthViewProjectionMatrix_face[3][3] - ); - } - i--; - return depthViewProjectionMatrix_face; - } float Graphics::getFarPlane() { diff --git a/object.cc b/object.cc index d3e156c..94ecf97 100644 --- a/object.cc +++ b/object.cc @@ -13,7 +13,7 @@ Object::~Object() { } void Object::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass, - glm::mat4* viewProjectionMatrix, std::vector* shadowVPs) { + glm::mat4* viewProjectionMatrix, std::vector* additionalMatrices) { glm::mat4 modelMatrix = glm::translate(getPosition()) * getRotation() * glm::scale(glm::vec3(model.getScale())); if (lightingPass) { // set lightning parameters for this object @@ -26,15 +26,15 @@ void Object::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass, shader->setUniform("modelMatrix", modelMatrix); // set shadowMVPs glm::mat4 shadowMVPs[5]; - for(unsigned int i = 0; (isize() && i<5); i++) { - shadowMVPs[i] = shadowVPs->at(i) * modelMatrix; + for(unsigned int i = 0; (isize() && i<5); i++) { + shadowMVPs[i] = additionalMatrices->at(i) * modelMatrix; } glUniformMatrix4fv(shader->getUniformLocation("shadowMVPs"), sizeof(shadowMVPs), false, (GLfloat*) shadowMVPs); } else { - if (shadowVPs) { - shader->setUniform("modelViewMatrix", shadowVPs->at(0) * modelMatrix); + if (additionalMatrices) { + shader->setUniform("modelViewMatrix", additionalMatrices->at(0) * modelMatrix); } } glm::mat4 mvp = (*viewProjectionMatrix) * modelMatrix; diff --git a/object.hh b/object.hh index 321e9a0..4713202 100644 --- a/object.hh +++ b/object.hh @@ -16,7 +16,7 @@ class Object : public Entity { Object(); ~Object(); void render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass, - glm::mat4* viewProjcetionMatrix, std::vector* shadowVPs); + glm::mat4* viewProjcetionMatrix, std::vector* additionalMatrices); private: Model model; Material material;