Tried some stuff(tried doing depth buffer calculation in world space) nothing works.
This commit is contained in:
parent
812321edec
commit
30320a16ef
@ -1,7 +1,11 @@
|
|||||||
#version 150
|
#version 150
|
||||||
|
|
||||||
|
in vec4 fragPosition;
|
||||||
|
|
||||||
out float fragmentDepth;
|
out float fragmentDepth;
|
||||||
|
|
||||||
|
uniform vec3 cameraPosition;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
fragmentDepth = gl_FragCoord.z;
|
fragmentDepth = length(vec3(fragPosition) - cameraPosition);
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,12 @@ in vec3 aPosition;
|
|||||||
in vec3 aNormal;
|
in vec3 aNormal;
|
||||||
in vec3 aTexcoord;
|
in vec3 aTexcoord;
|
||||||
|
|
||||||
|
out vec4 fragPosition;
|
||||||
|
|
||||||
|
uniform mat4 modelMatrix;
|
||||||
uniform mat4 modelViewProjectionMatrix;
|
uniform mat4 modelViewProjectionMatrix;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
fragPosition = modelMatrix * vec4(aPosition, 1.0);
|
||||||
gl_Position = modelViewProjectionMatrix * vec4(aPosition, 1.0);
|
gl_Position = modelViewProjectionMatrix * vec4(aPosition, 1.0);
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,9 @@ float sampleDirectionalShadow(sampler2DShadow shadowMap, vec4 shadowCoord) {
|
|||||||
|
|
||||||
float samplePointShadow(samplerCubeShadow shadowMap, vec3 lightDirection) {
|
float samplePointShadow(samplerCubeShadow shadowMap, vec3 lightDirection) {
|
||||||
float bias = 0.005;
|
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) {
|
float distanceToBorder(vec2 vector) {
|
||||||
|
@ -86,13 +86,14 @@ void Graphics::render()
|
|||||||
depthShader->use();
|
depthShader->use();
|
||||||
// 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.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 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();
|
||||||
//for (unsigned int i_pointlight = 0; i_pointlight<level->getLights()->size(); i_pointlight++) {
|
//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++) {
|
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
|
// 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();
|
framebuffer_cube2->bind();
|
||||||
@ -162,6 +163,8 @@ void Graphics::render()
|
|||||||
glUniform1fv(lightingShader->getUniformLocation("lightIntensities"),
|
glUniform1fv(lightingShader->getUniformLocation("lightIntensities"),
|
||||||
sizeof(lightIntensities), (GLfloat*) lightIntensities);
|
sizeof(lightIntensities), (GLfloat*) lightIntensities);
|
||||||
|
|
||||||
|
// Calculate light source position in camera screen space
|
||||||
|
|
||||||
lightingShader->setTexture("shadowMap_cube", depth_cubeMaps.at(0), 4);
|
lightingShader->setTexture("shadowMap_cube", depth_cubeMaps.at(0), 4);
|
||||||
}
|
}
|
||||||
// set directional Light
|
// set directional Light
|
||||||
|
@ -22,8 +22,6 @@ void Object::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
|
|||||||
shader->setUniform("specularFactor", material.getSpecularFactor());
|
shader->setUniform("specularFactor", material.getSpecularFactor());
|
||||||
shader->setUniform("shininess", material.getShininess());
|
shader->setUniform("shininess", material.getShininess());
|
||||||
shader->setTexture("uTexture", material.getReference(), 0);
|
shader->setTexture("uTexture", material.getReference(), 0);
|
||||||
// set model matrix
|
|
||||||
shader->setUniform( "modelMatrix", modelMatrix);
|
|
||||||
// set shadowMVPs
|
// set shadowMVPs
|
||||||
glm::mat4 shadowMVPs[5];
|
glm::mat4 shadowMVPs[5];
|
||||||
for(unsigned int i = 0; (i<shadowVPs->size() && i<5); i++) {
|
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"),
|
glUniformMatrix4fv(shader->getUniformLocation("shadowMVPs"),
|
||||||
sizeof(shadowMVPs), false, (GLfloat*) shadowMVPs);
|
sizeof(shadowMVPs), false, (GLfloat*) shadowMVPs);
|
||||||
}
|
}
|
||||||
|
// set model matrix
|
||||||
|
shader->setUniform( "modelMatrix", modelMatrix);
|
||||||
glm::mat4 mvp = (*viewProjectionMatrix) * modelMatrix;
|
glm::mat4 mvp = (*viewProjectionMatrix) * modelMatrix;
|
||||||
shader->setUniform("modelViewProjectionMatrix", mvp);
|
shader->setUniform("modelViewProjectionMatrix", mvp);
|
||||||
// draw
|
// draw
|
||||||
|
Loading…
Reference in New Issue
Block a user