Merge branch 'debug-shadows' of github.com:Faerbit/swp into debug-shadows
This commit is contained in:
commit
c757b80fa9
@ -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) {
|
||||
@ -111,7 +113,16 @@ 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 = 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);
|
||||
oColor = vec4(value, value, value, 255);*/
|
||||
@ -129,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);
|
||||
}
|
||||
|
@ -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()
|
||||
|
13
graphics.cc
13
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_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
|
||||
@ -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],
|
||||
@ -142,7 +146,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();
|
||||
@ -204,7 +208,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() {
|
||||
|
Loading…
Reference in New Issue
Block a user