Tried some stuff(tried doing depth buffer calculation in world space) nothing works.

This commit is contained in:
Steffen Fündgens 2015-01-20 13:11:43 +01:00
parent 812321edec
commit 30320a16ef
5 changed files with 18 additions and 5 deletions

View File

@ -1,7 +1,11 @@
#version 150
in vec4 fragPosition;
out float fragmentDepth;
uniform vec3 cameraPosition;
void main() {
fragmentDepth = gl_FragCoord.z;
fragmentDepth = length(vec3(fragPosition) - cameraPosition);
}

View File

@ -4,8 +4,12 @@ in vec3 aPosition;
in vec3 aNormal;
in vec3 aTexcoord;
out vec4 fragPosition;
uniform mat4 modelMatrix;
uniform mat4 modelViewProjectionMatrix;
void main() {
fragPosition = modelMatrix * vec4(aPosition, 1.0);
gl_Position = modelViewProjectionMatrix * vec4(aPosition, 1.0);
}

View File

@ -67,7 +67,9 @@ float sampleDirectionalShadow(sampler2DShadow shadowMap, vec4 shadowCoord) {
float samplePointShadow(samplerCubeShadow shadowMap, vec3 lightDirection) {
float bias = 0.005;
return texture(shadowMap, vec4(lightDirection.xyz , length(lightDirection) - bias));
float nearPlane = 0.1;
float linValue = (2.0*nearPlane) / (farPlane + nearPlane - (length(lightDirection)-nearPlane)/(farPlane-nearPlane) * (farPlane - nearPlane));
return texture(shadowMap, vec4(lightDirection.xyz , 0.5/*length(lightDirection)-bias*/));
}
float distanceToBorder(vec2 vector) {

View File

@ -86,13 +86,14 @@ void Graphics::render()
depthShader->use();
// 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::mat4 depthProjectionMatrix_pointlights = glm::perspective(1.571f, (float)cube_size/(float)cube_size, 0.01f, 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(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();
//for (unsigned int i_pointlight = 0; i_pointlight<level->getLights()->size(); i_pointlight++) {
for (unsigned int i_pointlight = 0; i_pointlight<1 && i_pointlight<level->getLights()->size(); i_pointlight++) {
depthShader->setUniform("cameraPosition", level->getLights()->at(i_pointlight).getPosition());
// render each side of the cube
for (int i_face = 0; i_face<6; i_face++) {
framebuffer_cube2->bind();
@ -162,6 +163,8 @@ void Graphics::render()
glUniform1fv(lightingShader->getUniformLocation("lightIntensities"),
sizeof(lightIntensities), (GLfloat*) lightIntensities);
// Calculate light source position in camera screen space
lightingShader->setTexture("shadowMap_cube", depth_cubeMaps.at(0), 4);
}
// set directional Light

View File

@ -22,8 +22,6 @@ void Object::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
shader->setUniform("specularFactor", material.getSpecularFactor());
shader->setUniform("shininess", material.getShininess());
shader->setTexture("uTexture", material.getReference(), 0);
// set model matrix
shader->setUniform( "modelMatrix", modelMatrix);
// set shadowMVPs
glm::mat4 shadowMVPs[5];
for(unsigned int i = 0; (i<shadowVPs->size() && i<5); i++) {
@ -32,6 +30,8 @@ void Object::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
glUniformMatrix4fv(shader->getUniformLocation("shadowMVPs"),
sizeof(shadowMVPs), false, (GLfloat*) shadowMVPs);
}
// set model matrix
shader->setUniform( "modelMatrix", modelMatrix);
glm::mat4 mvp = (*viewProjectionMatrix) * modelMatrix;
shader->setUniform("modelViewProjectionMatrix", mvp);
// draw