Mirrored rendering of pointlight shadows, so that they are at the correct positions now, but occlude everything. -- Fabian
This commit is contained in:
parent
1940b72b00
commit
cf836b151a
20
graphics.cc
20
graphics.cc
@ -61,6 +61,15 @@ void Graphics::init(Level* level) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
framebuffer_cube = SharedFrameBufferObject(new FrameBufferObject());
|
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() {
|
GLFWwindow* Graphics::getWindow() {
|
||||||
@ -86,11 +95,20 @@ void Graphics::render()
|
|||||||
for (unsigned int i_pointlight = 0; i_pointlight<1 && i_pointlight<level->getLights()->size(); i_pointlight++) {
|
for (unsigned int i_pointlight = 0; i_pointlight<1 && i_pointlight<level->getLights()->size(); i_pointlight++) {
|
||||||
// render each side of the cube
|
// render each side of the cube
|
||||||
for (int i_face = 0; i_face<6; i_face++) {
|
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);
|
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);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
glm::mat4 depthViewProjectionMatrix_face = depthProjectionMatrix_pointlights * glm::lookAt(level->getLights()->at(i_pointlight).getPosition(),
|
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->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()) {
|
if (!framebuffer_cube->isFrameBufferObjectComplete()) {
|
||||||
printf("Framebuffer incomplete, unknown error occured during shadow generation!\n");
|
printf("Framebuffer incomplete, unknown error occured during shadow generation!\n");
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,8 @@ class Graphics {
|
|||||||
ACGL::OpenGL::SharedFrameBufferObject framebuffer;
|
ACGL::OpenGL::SharedFrameBufferObject framebuffer;
|
||||||
std::vector<ACGL::OpenGL::SharedTextureCubeMap> depth_cubeMaps;
|
std::vector<ACGL::OpenGL::SharedTextureCubeMap> depth_cubeMaps;
|
||||||
ACGL::OpenGL::SharedFrameBufferObject framebuffer_cube;
|
ACGL::OpenGL::SharedFrameBufferObject framebuffer_cube;
|
||||||
|
ACGL::OpenGL::SharedFrameBufferObject framebuffer_cube2;
|
||||||
|
ACGL::OpenGL::SharedTexture2D depthTexture_cube;
|
||||||
static const int cube_size;
|
static const int cube_size;
|
||||||
Level* level;
|
Level* level;
|
||||||
};
|
};
|
||||||
|
2
level.cc
2
level.cc
@ -422,7 +422,7 @@ void Level::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
|
|||||||
glm::mat4* viewProjectionMatrix, std::vector<glm::mat4>* shadowVPs) {
|
glm::mat4* viewProjectionMatrix, std::vector<glm::mat4>* shadowVPs) {
|
||||||
for(unsigned int i = 0; i<objects.size(); i++) {
|
for(unsigned int i = 0; i<objects.size(); i++) {
|
||||||
// do not project shadow of skydome
|
// do not project shadow of skydome
|
||||||
if(lightingPass || objects.at(i) != skydome) {
|
if(lightingPass || (objects.at(i) != skydome && i!=0)) {
|
||||||
objects.at(i)->render(shader, lightingPass, viewProjectionMatrix, shadowVPs);
|
objects.at(i)->render(shader, lightingPass, viewProjectionMatrix, shadowVPs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user