Fixed mirroring of shadows by inverting coordinates instead of blitting framebuffers(performance...).
This commit is contained in:
parent
13df9c14a8
commit
8429280aee
@ -71,7 +71,8 @@ float samplePointShadow(samplerCubeShadow shadowMap, vec3 lightDirection) {
|
|||||||
float B = -2*(farPlane*nearPlane)/(farPlane - nearPlane);
|
float B = -2*(farPlane*nearPlane)/(farPlane - nearPlane);
|
||||||
float compValue = 0.5*(-A*length(lightDirection) + B)/length(lightDirection) + 0.5;
|
float compValue = 0.5*(-A*length(lightDirection) + B)/length(lightDirection) + 0.5;
|
||||||
float bias = 0.005;
|
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) {
|
float distanceToBorder(vec2 vector) {
|
||||||
|
10
graphics.cc
10
graphics.cc
@ -68,8 +68,6 @@ void Graphics::init(Level* level) {
|
|||||||
depthTexture_cube->setWrapS(GL_CLAMP_TO_EDGE);
|
depthTexture_cube->setWrapS(GL_CLAMP_TO_EDGE);
|
||||||
depthTexture_cube->setWrapT(GL_CLAMP_TO_EDGE);
|
depthTexture_cube->setWrapT(GL_CLAMP_TO_EDGE);
|
||||||
depthTexture_cube->setCompareMode(GL_COMPARE_REF_TO_TEXTURE);
|
depthTexture_cube->setCompareMode(GL_COMPARE_REF_TO_TEXTURE);
|
||||||
framebuffer_cube2 = SharedFrameBufferObject(new FrameBufferObject());
|
|
||||||
framebuffer_cube2->setDepthTexture(depthTexture_cube);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWwindow* Graphics::getWindow() {
|
GLFWwindow* Graphics::getWindow() {
|
||||||
@ -87,7 +85,7 @@ void Graphics::render()
|
|||||||
// render depth textures for point lights
|
// render depth textures for point lights
|
||||||
glViewport(0, 0, cube_size, cube_size);
|
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::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)};
|
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();
|
framebuffer_cube->bind();
|
||||||
@ -103,12 +101,6 @@ void Graphics::render()
|
|||||||
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,7 +32,6 @@ 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;
|
ACGL::OpenGL::SharedTexture2D depthTexture_cube;
|
||||||
static const int cube_size;
|
static const int cube_size;
|
||||||
Level* level;
|
Level* level;
|
||||||
|
Loading…
Reference in New Issue
Block a user