From 45ae4a2c662ba6aea159523dc5d1a479c81a5516 Mon Sep 17 00:00:00 2001 From: Fabian Klemp Date: Fri, 30 Jan 2015 15:11:00 +0100 Subject: [PATCH 1/2] Only sample shadows from the first light source. --- Shader/phong.fsh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Shader/phong.fsh b/Shader/phong.fsh index f2756d4..337fc63 100644 --- a/Shader/phong.fsh +++ b/Shader/phong.fsh @@ -111,7 +111,9 @@ void main() vec3 cameraVector = normalize(camera - vec3(fragPosition)); specularColor += clamp(pow((dot((cameraVector+lightVector),normalize(vNormal))/(length(cameraVector+lightVector)*length(normalize(vNormal)))),shininess), 0.0, 1.0) *specularFactor*intensity*lightColors[i]; - visibility = samplePointShadow(shadowMap_cube, lightDirection); + if (i == 0) { + visibility = samplePointShadow(shadowMap_cube, lightDirection); + } } /*float value = texture(shadowMap_cube, lightDirection); oColor = vec4(value, value, value, 255);*/ From e5e75fc7e6fa8981bd0f81f3f7719dd949044231 Mon Sep 17 00:00:00 2001 From: Fabian Klemp Date: Fri, 30 Jan 2015 15:47:07 +0100 Subject: [PATCH 2/2] Additional debug stuff. --- Shader/phong.fsh | 21 +++++++++++++++------ application.cc | 2 +- graphics.cc | 13 +++++++++---- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Shader/phong.fsh b/Shader/phong.fsh index 337fc63..978983b 100644 --- a/Shader/phong.fsh +++ b/Shader/phong.fsh @@ -9,7 +9,7 @@ out vec4 oColor; uniform sampler2D uTexture; uniform sampler2DShadow shadowMap; -uniform samplerCubeShadow shadowMap_cube; +uniform samplerCube shadowMap_cube; uniform vec3 ambientColor; uniform float ambientFactor; uniform float diffuseFactor; @@ -65,13 +65,15 @@ float sampleDirectionalShadow(sampler2DShadow shadowMap, vec4 shadowCoord) { return visibility; } -float samplePointShadow(samplerCubeShadow shadowMap, vec3 lightDirection) { +float samplePointShadow(samplerCube shadowMap, vec3 lightDirection) { float nearPlane = 0.1; float A = -(farPlane+nearPlane)/(farPlane-nearPlane); float B = -2*(farPlane*nearPlane)/(farPlane - nearPlane); float compValue = 0.5*(-A*length(lightDirection) + B)/length(lightDirection) + 0.5; float bias = 0.005; - return texture(shadowMap, vec4(lightDirection , compValue - bias)); + //return texture(shadowMap, vec4(lightDirection , compValue - bias)); + float value1 = texture(shadowMap, vec3(lightDirection)); + return value1 - compValue; } float distanceToBorder(vec2 vector) { @@ -112,7 +114,14 @@ void main() specularColor += clamp(pow((dot((cameraVector+lightVector),normalize(vNormal))/(length(cameraVector+lightVector)*length(normalize(vNormal)))),shininess), 0.0, 1.0) *specularFactor*intensity*lightColors[i]; if (i == 0) { - visibility = samplePointShadow(shadowMap_cube, lightDirection); + //visibility = samplePointShadow(shadowMap_cube, lightDirection); + float value = samplePointShadow(shadowMap_cube, lightDirection); + if (abs(value) < 0.0001f) { + oColor = vec4(0, 255, 0, 255); + } + else { + oColor = vec4(255, 0, 0, 255); + } } } /*float value = texture(shadowMap_cube, lightDirection); @@ -131,6 +140,6 @@ void main() fogFactor *= clamp((1.0-((fragPosition.y-40.0)/30.0)), 0.0, 1.0); vec4 texture = texture(uTexture, vTexCoord).rgba; - oColor = vec4(finalColor, 1.0f)*texture; - oColor = mix(oColor, fogColor, fogFactor); + //oColor = vec4(finalColor, 1.0f)*texture; + //oColor = mix(oColor, fogColor, fogFactor); } diff --git a/application.cc b/application.cc index ff80cac..b2b00f9 100644 --- a/application.cc +++ b/application.cc @@ -2,7 +2,7 @@ Application::Application() { - graphics = Graphics(glm::uvec2(1024, 786), 0.1f, 150.0f); + graphics = Graphics(glm::uvec2(1024, 1024), 0.1f, 150.0f); } void Application::init() diff --git a/graphics.cc b/graphics.cc index 8422f49..81fbb71 100644 --- a/graphics.cc +++ b/graphics.cc @@ -62,7 +62,7 @@ void Graphics::init(Level* level) { depth_cubeMaps.at(i)->setMagFilter(GL_NEAREST); depth_cubeMaps.at(i)->setWrapS(GL_CLAMP_TO_EDGE); depth_cubeMaps.at(i)->setWrapT(GL_CLAMP_TO_EDGE); - depth_cubeMaps.at(i)->setCompareMode(GL_COMPARE_REF_TO_TEXTURE); + //depth_cubeMaps.at(i)->setCompareMode(GL_COMPARE_REF_TO_TEXTURE); } framebuffer_cube = SharedFrameBufferObject(new FrameBufferObject()); @@ -72,7 +72,7 @@ void Graphics::init(Level* level) { 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); + //depthTexture_cube->setCompareMode(GL_COMPARE_REF_TO_TEXTURE); framebuffer_cube_mirror = SharedFrameBufferObject(new FrameBufferObject()); framebuffer_cube_mirror->setDepthTexture(depthTexture_cube); @@ -100,6 +100,7 @@ void Graphics::render(double time) framebuffer_cube->bind(); static bool printed = false; + glm::mat4 reproduceMatrix; //for (unsigned int i_pointlight = 0; i_pointlightgetLights()->size(); i_pointlight++) { for (unsigned int i_pointlight = 0; i_pointlight<1 && i_pointlightgetLights()->size(); i_pointlight++) { // render each side of the cube @@ -112,6 +113,9 @@ void Graphics::render(double time) glm::mat4 viewMatrix = 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)); glm::mat4 depthViewProjectionMatrix_face = depthProjectionMatrix_pointlights * viewMatrix; + if (i_face == 0) { + reproduceMatrix = depthViewProjectionMatrix_face; + } if (!printed) { printf("\n\nView matrix:\n %2.2f, %2.2f, %2.2f, %2.2f\n%2.2f, %2.2f, %2.2f, %2.2f\n%2.2f, %2.2f, %2.2f, %2.2f\n%2.2f, %2.2f, %2.2f, %2.2f\n\n\n", viewMatrix[0][0], viewMatrix[0][1], viewMatrix[0][2], viewMatrix[0][3], @@ -140,7 +144,7 @@ void Graphics::render(double time) } } // render depth texture for sun - glViewport(0, 0, windowSize.x, windowSize.y); + //glViewport(0, 0, windowSize.x, windowSize.y); // far pass framebuffer->bind(); @@ -202,7 +206,8 @@ void Graphics::render(double time) shadowVPs.push_back(depthBiasVP); // render the level - level->render(lightingShader, true, &lightingViewProjectionMatrix, &shadowVPs); + //level->render(lightingShader, true, &lightingViewProjectionMatrix, &shadowVPs); + level->render(lightingShader, true, &reproduceMatrix, &shadowVPs); } void Graphics::updateLights() {