From b3e0d5ca47467a83eea51e731b01bc6eb9587bb5 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Mon, 2 Feb 2015 19:58:16 +0100 Subject: [PATCH] Changed how depth values are written. Works even less than before. --- Shader/depth.fsh | 5 +++-- Shader/phong.fsh | 4 ++-- graphics.cc | 6 +++--- object.cc | 4 +++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Shader/depth.fsh b/Shader/depth.fsh index a2eab59..5c868ce 100644 --- a/Shader/depth.fsh +++ b/Shader/depth.fsh @@ -2,8 +2,9 @@ in vec4 fragPosition; -out float fragmentDepth; +out float gl_FragDepth; void main() { - fragmentDepth = fragPosition.z; + gl_FragDepth = fragPosition.z; + //gl_FragDepth = 0.0f; } diff --git a/Shader/phong.fsh b/Shader/phong.fsh index 978983b..93f00cb 100644 --- a/Shader/phong.fsh +++ b/Shader/phong.fsh @@ -73,7 +73,7 @@ float samplePointShadow(samplerCube shadowMap, vec3 lightDirection) { float bias = 0.005; //return texture(shadowMap, vec4(lightDirection , compValue - bias)); float value1 = texture(shadowMap, vec3(lightDirection)); - return value1 - compValue; + return value1 - length(lightDirection); } float distanceToBorder(vec2 vector) { @@ -116,7 +116,7 @@ void main() if (i == 0) { //visibility = samplePointShadow(shadowMap_cube, lightDirection); float value = samplePointShadow(shadowMap_cube, lightDirection); - if (abs(value) < 0.0001f) { + if (abs(value) < 0.1f) { oColor = vec4(0, 255, 0, 255); } else { diff --git a/graphics.cc b/graphics.cc index eb26598..2c36483 100644 --- a/graphics.cc +++ b/graphics.cc @@ -124,9 +124,9 @@ void Graphics::render(double time) viewMatrix[3][0], viewMatrix[3][1], viewMatrix[3][2], viewMatrix[3][3] ); } - std::vector vector = std::vector(); - vector.push_back(viewMatrix); - level->render(depthShader, false, &depthViewProjectionMatrix_face, &vector); + std::vector foovector = std::vector(); + foovector.push_back(viewMatrix); + level->render(depthShader, false, &depthViewProjectionMatrix_face, &foovector); 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 e6f7825..d3e156c 100644 --- a/object.cc +++ b/object.cc @@ -33,7 +33,9 @@ void Object::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass, sizeof(shadowMVPs), false, (GLfloat*) shadowMVPs); } else { - //shader->setUniform("modelViewMatrix", shadowVPs->at(0) * modelMatrix); + if (shadowVPs) { + shader->setUniform("modelViewMatrix", shadowVPs->at(0) * modelMatrix); + } } glm::mat4 mvp = (*viewProjectionMatrix) * modelMatrix; shader->setUniform("modelViewProjectionMatrix", mvp);