From cf836b151af4d20af69cfb67d087c0185f751bcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20F=C3=BCndgens?= Date: Mon, 19 Jan 2015 18:22:25 +0100 Subject: [PATCH] Mirrored rendering of pointlight shadows, so that they are at the correct positions now, but occlude everything. -- Fabian --- graphics.cc | 20 +++++++++++++++++++- graphics.hh | 2 ++ level.cc | 2 +- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/graphics.cc b/graphics.cc index f3be9d8..0f5fc6f 100644 --- a/graphics.cc +++ b/graphics.cc @@ -61,6 +61,15 @@ void Graphics::init(Level* level) { } framebuffer_cube = SharedFrameBufferObject(new FrameBufferObject()); + + depthTexture_cube = SharedTexture2D( new Texture2D(windowSize, GL_DEPTH_COMPONENT16)); + depthTexture_cube->setMinFilter(GL_NEAREST); + depthTexture_cube->setMagFilter(GL_NEAREST); + 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() { @@ -86,11 +95,20 @@ void Graphics::render() for (unsigned int i_pointlight = 0; i_pointlight<1 && i_pointlightgetLights()->size(); i_pointlight++) { // render each side of the cube for (int i_face = 0; i_face<6; i_face++) { + framebuffer_cube2->bind(); + glClear(GL_DEPTH_BUFFER_BIT); + framebuffer_cube->bind(); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i_face, depth_cubeMaps.at(i_pointlight)->getObjectName(), 0); glClear(GL_DEPTH_BUFFER_BIT); 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); + 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 bb37a19..d9f92a3 100644 --- a/graphics.hh +++ b/graphics.hh @@ -32,6 +32,8 @@ 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; }; diff --git a/level.cc b/level.cc index d6b90ca..b89610a 100644 --- a/level.cc +++ b/level.cc @@ -422,7 +422,7 @@ void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass, glm::mat4* viewProjectionMatrix, std::vector* shadowVPs) { for(unsigned int i = 0; irender(shader, lightingPass, viewProjectionMatrix, shadowVPs); } }