Additional debug stuff.

This commit is contained in:
Fabian Klemp 2015-01-30 15:47:07 +01:00
parent 60372cf1a1
commit 2ddd753575
3 changed files with 25 additions and 11 deletions

View File

@ -9,7 +9,7 @@ out vec4 oColor;
uniform sampler2D uTexture; uniform sampler2D uTexture;
uniform sampler2DShadow shadowMap; uniform sampler2DShadow shadowMap;
uniform samplerCubeShadow shadowMap_cube; uniform samplerCube shadowMap_cube;
uniform vec3 ambientColor; uniform vec3 ambientColor;
uniform float ambientFactor; uniform float ambientFactor;
uniform float diffuseFactor; uniform float diffuseFactor;
@ -65,13 +65,15 @@ float sampleDirectionalShadow(sampler2DShadow shadowMap, vec4 shadowCoord) {
return visibility; return visibility;
} }
float samplePointShadow(samplerCubeShadow shadowMap, vec3 lightDirection) { float samplePointShadow(samplerCube shadowMap, vec3 lightDirection) {
float nearPlane = 0.1; float nearPlane = 0.1;
float A = -(farPlane+nearPlane)/(farPlane-nearPlane); float A = -(farPlane+nearPlane)/(farPlane-nearPlane);
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 , compValue - bias)); //return texture(shadowMap, vec4(lightDirection , compValue - bias));
float value1 = texture(shadowMap, vec3(lightDirection));
return value1 - compValue;
} }
float distanceToBorder(vec2 vector) { 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) specularColor += clamp(pow((dot((cameraVector+lightVector),normalize(vNormal))/(length(cameraVector+lightVector)*length(normalize(vNormal)))),shininess), 0.0, 1.0)
*specularFactor*intensity*lightColors[i]; *specularFactor*intensity*lightColors[i];
if (i == 0) { 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); /*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); fogFactor *= clamp((1.0-((fragPosition.y-40.0)/30.0)), 0.0, 1.0);
vec4 texture = texture(uTexture, vTexCoord).rgba; vec4 texture = texture(uTexture, vTexCoord).rgba;
oColor = vec4(finalColor, 1.0f)*texture; //oColor = vec4(finalColor, 1.0f)*texture;
oColor = mix(oColor, fogColor, fogFactor); //oColor = mix(oColor, fogColor, fogFactor);
} }

View File

@ -2,7 +2,7 @@
Application::Application() { 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() void Application::init()

View File

@ -62,7 +62,7 @@ void Graphics::init(Level* level) {
depth_cubeMaps.at(i)->setMagFilter(GL_NEAREST); depth_cubeMaps.at(i)->setMagFilter(GL_NEAREST);
depth_cubeMaps.at(i)->setWrapS(GL_CLAMP_TO_EDGE); depth_cubeMaps.at(i)->setWrapS(GL_CLAMP_TO_EDGE);
depth_cubeMaps.at(i)->setWrapT(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()); framebuffer_cube = SharedFrameBufferObject(new FrameBufferObject());
@ -72,7 +72,7 @@ void Graphics::init(Level* level) {
depthTexture_cube->setMagFilter(GL_NEAREST); depthTexture_cube->setMagFilter(GL_NEAREST);
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_cube_mirror = SharedFrameBufferObject(new FrameBufferObject()); framebuffer_cube_mirror = SharedFrameBufferObject(new FrameBufferObject());
framebuffer_cube_mirror->setDepthTexture(depthTexture_cube); framebuffer_cube_mirror->setDepthTexture(depthTexture_cube);
@ -100,6 +100,7 @@ void Graphics::render(double time)
framebuffer_cube->bind(); framebuffer_cube->bind();
static bool printed = false; static bool printed = false;
glm::mat4 reproduceMatrix;
//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++) {
// render each side of the cube // 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(), 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)); 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; glm::mat4 depthViewProjectionMatrix_face = depthProjectionMatrix_pointlights * viewMatrix;
if (i_face == 0) {
reproduceMatrix = depthViewProjectionMatrix_face;
}
if (!printed) { 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", 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], 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 // render depth texture for sun
glViewport(0, 0, windowSize.x, windowSize.y); //glViewport(0, 0, windowSize.x, windowSize.y);
// far pass // far pass
framebuffer->bind(); framebuffer->bind();
@ -202,7 +206,8 @@ void Graphics::render(double time)
shadowVPs.push_back(depthBiasVP); shadowVPs.push_back(depthBiasVP);
// render the level // render the level
level->render(lightingShader, true, &lightingViewProjectionMatrix, &shadowVPs); //level->render(lightingShader, true, &lightingViewProjectionMatrix, &shadowVPs);
level->render(lightingShader, true, &reproduceMatrix, &shadowVPs);
} }
void Graphics::updateLights() { void Graphics::updateLights() {