diff --git a/Shader/depth.fsh b/Shader/depth.fsh index b236c6a..a2eab59 100644 --- a/Shader/depth.fsh +++ b/Shader/depth.fsh @@ -1,7 +1,9 @@ #version 150 +in vec4 fragPosition; + out float fragmentDepth; void main() { - fragmentDepth = gl_FragCoord.z; + fragmentDepth = fragPosition.z; } diff --git a/Shader/depth.vsh b/Shader/depth.vsh index f84c3cf..2618bfa 100644 --- a/Shader/depth.vsh +++ b/Shader/depth.vsh @@ -5,7 +5,11 @@ in vec3 aNormal; in vec3 aTexcoord; uniform mat4 modelViewProjectionMatrix; +uniform mat4 modelViewMatrix; + +out vec4 fragPosition; void main() { + fragPosition = modelViewMatrix * vec4(aPosition, 1.0); gl_Position = modelViewProjectionMatrix * vec4(aPosition, 1.0); } diff --git a/graphics.cc b/graphics.cc index 8422f49..f21457e 100644 --- a/graphics.cc +++ b/graphics.cc @@ -120,7 +120,9 @@ void Graphics::render(double time) viewMatrix[3][0], viewMatrix[3][1], viewMatrix[3][2], viewMatrix[3][3] ); } - level->render(depthShader, false, &depthViewProjectionMatrix_face); + std::vector vector = std::vector(); + vector.push_back(viewMatrix); + level->render(depthShader, false, &depthViewProjectionMatrix_face, &vector); glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer_cube->getObjectName()); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer_cube_mirror->getObjectName()); glBlitFramebuffer(0, 0, cube_size, cube_size, cube_size, cube_size, 0, 0, GL_DEPTH_BUFFER_BIT, GL_NEAREST); diff --git a/object.cc b/object.cc index 9d1f339..e6f7825 100644 --- a/object.cc +++ b/object.cc @@ -23,7 +23,7 @@ void Object::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass, shader->setUniform("shininess", material.getShininess()); shader->setTexture("uTexture", material.getReference(), 0); // set model matrix - shader->setUniform( "modelMatrix", modelMatrix); + shader->setUniform("modelMatrix", modelMatrix); // set shadowMVPs glm::mat4 shadowMVPs[5]; for(unsigned int i = 0; (isize() && i<5); i++) { @@ -32,6 +32,9 @@ void Object::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass, glUniformMatrix4fv(shader->getUniformLocation("shadowMVPs"), sizeof(shadowMVPs), false, (GLfloat*) shadowMVPs); } + else { + //shader->setUniform("modelViewMatrix", shadowVPs->at(0) * modelMatrix); + } glm::mat4 mvp = (*viewProjectionMatrix) * modelMatrix; shader->setUniform("modelViewProjectionMatrix", mvp); // draw