From 8429280aee0fe7d163cf896be9e44db4e8196c89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20F=C3=BCndgens?= Date: Fri, 23 Jan 2015 14:00:26 +0100 Subject: [PATCH] Fixed mirroring of shadows by inverting coordinates instead of blitting framebuffers(performance...). --- Shader/phong.fsh | 3 ++- graphics.cc | 10 +--------- graphics.hh | 1 - 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/Shader/phong.fsh b/Shader/phong.fsh index 67c7679..447b1fe 100644 --- a/Shader/phong.fsh +++ b/Shader/phong.fsh @@ -71,7 +71,8 @@ float samplePointShadow(samplerCubeShadow shadowMap, vec3 lightDirection) { float B = -2*(farPlane*nearPlane)/(farPlane - nearPlane); float compValue = 0.5*(-A*length(lightDirection) + B)/length(lightDirection) + 0.5; float bias = 0.005; - return texture(shadowMap, vec4(lightDirection.xyz , compValue - bias)); + vec3 vector = vec3(-lightDirection.x, -lightDirection.y, lightDirection.z); + return texture(shadowMap, vec4(vector , compValue - bias)); } float distanceToBorder(vec2 vector) { diff --git a/graphics.cc b/graphics.cc index f264a3f..d6820b8 100644 --- a/graphics.cc +++ b/graphics.cc @@ -68,8 +68,6 @@ void Graphics::init(Level* level) { depthTexture_cube->setWrapS(GL_CLAMP_TO_EDGE); depthTexture_cube->setWrapT(GL_CLAMP_TO_EDGE); depthTexture_cube->setCompareMode(GL_COMPARE_REF_TO_TEXTURE); - framebuffer_cube2 = SharedFrameBufferObject(new FrameBufferObject()); - framebuffer_cube2->setDepthTexture(depthTexture_cube); } GLFWwindow* Graphics::getWindow() { @@ -87,7 +85,7 @@ void Graphics::render() // 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::vec3(0.0f, 1.0f, 0.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)}; framebuffer_cube->bind(); @@ -103,12 +101,6 @@ void Graphics::render() glm::mat4 depthViewProjectionMatrix_face = depthProjectionMatrix_pointlights * glm::lookAt(level->getLights()->at(i_pointlight).getPosition(), level->getLights()->at(i_pointlight).getPosition() + looking_directions[i_face], glm::vec3(0.0f, 1.0f, 0.0f)); level->render(depthShader, false, &depthViewProjectionMatrix_face); - glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer_cube->getObjectName()); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer_cube2->getObjectName()); - glBlitFramebuffer(0, 0, cube_size, cube_size, cube_size, cube_size, 0, 0, GL_DEPTH_BUFFER_BIT, GL_NEAREST); - glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer_cube2->getObjectName()); - glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer_cube->getObjectName()); - glBlitFramebuffer(0, 0, cube_size, cube_size, 0, 0, cube_size, cube_size, GL_DEPTH_BUFFER_BIT, GL_NEAREST); if (!framebuffer_cube->isFrameBufferObjectComplete()) { printf("Framebuffer incomplete, unknown error occured during shadow generation!\n"); } diff --git a/graphics.hh b/graphics.hh index d9f92a3..71d3d97 100644 --- a/graphics.hh +++ b/graphics.hh @@ -32,7 +32,6 @@ class Graphics { ACGL::OpenGL::SharedFrameBufferObject framebuffer; std::vector depth_cubeMaps; ACGL::OpenGL::SharedFrameBufferObject framebuffer_cube; - ACGL::OpenGL::SharedFrameBufferObject framebuffer_cube2; ACGL::OpenGL::SharedTexture2D depthTexture_cube; static const int cube_size; Level* level;