Removed Cascaded Shadow Mapping because it is not realistic to get it working in the remaining time.
This commit is contained in:
parent
d26722595e
commit
6210d2e35b
@ -3,16 +3,12 @@
|
||||
in vec3 vNormal;
|
||||
in vec2 vTexCoord;
|
||||
in vec4 fragPosition;
|
||||
in vec4 shadowCoord_near;
|
||||
in vec4 shadowCoord_middle;
|
||||
in vec4 shadowCoord_far;
|
||||
in vec4 shadowCoord;
|
||||
|
||||
out vec4 oColor;
|
||||
|
||||
uniform sampler2D uTexture;
|
||||
uniform sampler2DShadow shadowMap_near;
|
||||
uniform sampler2DShadow shadowMap_middle;
|
||||
uniform sampler2DShadow shadowMap_far;
|
||||
uniform sampler2DShadow shadowMap;
|
||||
uniform samplerCubeShadow shadowMap_cube;
|
||||
uniform vec3 ambientColor;
|
||||
uniform float ambientFactor;
|
||||
@ -116,17 +112,7 @@ void main()
|
||||
}
|
||||
|
||||
// shadows
|
||||
if (distanceToBorder(shadowCoord_middle.xy) <= 0.5 && distanceToBorder(shadowCoord_middle.xy) > 0.0) {
|
||||
if (distanceToBorder(shadowCoord_near.xy) <= 0.5 && distanceToBorder(shadowCoord_near.xy) > 0.0) {
|
||||
visibility *= sampleDirectionalShadow(shadowMap_near, shadowCoord_near);
|
||||
}
|
||||
else {
|
||||
visibility *= sampleDirectionalShadow(shadowMap_middle, shadowCoord_middle);
|
||||
}
|
||||
}
|
||||
else {
|
||||
visibility *= sampleDirectionalShadow(shadowMap_far, shadowCoord_far);
|
||||
}
|
||||
visibility *= sampleDirectionalShadow(shadowMap, shadowCoord);
|
||||
|
||||
specularColor *= visibility;
|
||||
diffuseColor *= visibility;
|
||||
|
@ -11,17 +11,13 @@ in vec2 aTexCoord;
|
||||
out vec3 vNormal;
|
||||
out vec2 vTexCoord;
|
||||
out vec4 fragPosition;
|
||||
out vec4 shadowCoord_near;
|
||||
out vec4 shadowCoord_middle;
|
||||
out vec4 shadowCoord_far;
|
||||
out vec4 shadowCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
fragPosition = modelMatrix * vec4(aPosition, 1.0);
|
||||
vNormal = inverse(transpose(mat3(modelMatrix))) * aNormal;
|
||||
vTexCoord = aTexCoord;
|
||||
shadowCoord_near = shadowMVPs[0] * vec4(aPosition, 1.0);
|
||||
shadowCoord_middle = shadowMVPs[1] * vec4(aPosition, 1.0);
|
||||
shadowCoord_far = shadowMVPs[2] * vec4(aPosition, 1.0);
|
||||
shadowCoord = shadowMVPs[0] * vec4(aPosition, 1.0);
|
||||
gl_Position = modelViewProjectionMatrix * vec4(aPosition, 1.0);
|
||||
}
|
||||
|
85
graphics.cc
85
graphics.cc
@ -37,38 +37,16 @@ void Graphics::init(Level* level) {
|
||||
depthShader = ShaderProgramCreator("depth")
|
||||
.attributeLocations(vao->getAttributeLocations()).create();
|
||||
|
||||
depthTexture_near = SharedTexture2D( new Texture2D(windowSize, GL_DEPTH_COMPONENT16));
|
||||
depthTexture_near->setMinFilter(GL_NEAREST);
|
||||
depthTexture_near->setMagFilter(GL_NEAREST);
|
||||
depthTexture_near->setWrapS(GL_CLAMP_TO_EDGE);
|
||||
depthTexture_near->setWrapT(GL_CLAMP_TO_EDGE);
|
||||
depthTexture_near->setCompareMode(GL_COMPARE_REF_TO_TEXTURE);
|
||||
depthTexture = SharedTexture2D( new Texture2D(windowSize, GL_DEPTH_COMPONENT16));
|
||||
depthTexture->setMinFilter(GL_NEAREST);
|
||||
depthTexture->setMagFilter(GL_NEAREST);
|
||||
depthTexture->setWrapS(GL_CLAMP_TO_EDGE);
|
||||
depthTexture->setWrapT(GL_CLAMP_TO_EDGE);
|
||||
depthTexture->setCompareMode(GL_COMPARE_REF_TO_TEXTURE);
|
||||
|
||||
framebuffer_near = SharedFrameBufferObject(new FrameBufferObject());
|
||||
framebuffer_near->setDepthTexture(depthTexture_near);
|
||||
framebuffer_near->validate();
|
||||
|
||||
depthTexture_middle = SharedTexture2D( new Texture2D(windowSize, GL_DEPTH_COMPONENT16));
|
||||
depthTexture_middle->setMinFilter(GL_NEAREST);
|
||||
depthTexture_middle->setMagFilter(GL_NEAREST);
|
||||
depthTexture_middle->setWrapS(GL_CLAMP_TO_EDGE);
|
||||
depthTexture_middle->setWrapT(GL_CLAMP_TO_EDGE);
|
||||
depthTexture_middle->setCompareMode(GL_COMPARE_REF_TO_TEXTURE);
|
||||
|
||||
framebuffer_middle = SharedFrameBufferObject(new FrameBufferObject());
|
||||
framebuffer_middle->setDepthTexture(depthTexture_middle);
|
||||
framebuffer_middle->validate();
|
||||
|
||||
depthTexture_far = SharedTexture2D( new Texture2D(windowSize, GL_DEPTH_COMPONENT16));
|
||||
depthTexture_far->setMinFilter(GL_NEAREST);
|
||||
depthTexture_far->setMagFilter(GL_NEAREST);
|
||||
depthTexture_far->setWrapS(GL_CLAMP_TO_EDGE);
|
||||
depthTexture_far->setWrapT(GL_CLAMP_TO_EDGE);
|
||||
depthTexture_far->setCompareMode(GL_COMPARE_REF_TO_TEXTURE);
|
||||
|
||||
framebuffer_far = SharedFrameBufferObject(new FrameBufferObject());
|
||||
framebuffer_far->setDepthTexture(depthTexture_far);
|
||||
framebuffer_far->validate();
|
||||
framebuffer = SharedFrameBufferObject(new FrameBufferObject());
|
||||
framebuffer->setDepthTexture(depthTexture);
|
||||
framebuffer->validate();
|
||||
|
||||
/*depth_cubeMaps = std::vector<ACGL::OpenGL::SharedTextureCubeMap>(level->getLights()->size());
|
||||
for (unsigned int i = 0; i<depth_cubeMaps.size(); i++) {*/
|
||||
@ -120,34 +98,15 @@ void Graphics::render()
|
||||
}
|
||||
// render depth texture for sun
|
||||
glViewport(0, 0, windowSize.x, windowSize.y);
|
||||
// near pass
|
||||
framebuffer_near->bind();
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
glm::vec3 sunVector = (level->getCameraCenter()->getPosition() + level->getDirectionalLight()->getPosition());
|
||||
glm::mat4 depthViewProjectionMatrix_near = glm::ortho<float>(-5, 5, -5, 5, -5, 5) *
|
||||
glm::lookAt(sunVector, level->getCameraCenter()->getPosition(), glm::vec3(0,1,0));
|
||||
level->render(depthShader, false, &depthViewProjectionMatrix_near);
|
||||
if (!framebuffer_near->isFrameBufferObjectComplete()) {
|
||||
printf("Framebuffer incomplete, unknown error occured during shadow generation!\n");
|
||||
}
|
||||
|
||||
// middle pass
|
||||
framebuffer_middle->bind();
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
glm::mat4 depthViewProjectionMatrix_middle = glm::ortho<float>(-20, 20, -20, 20, -20, 20) *
|
||||
glm::lookAt(sunVector, level->getCameraCenter()->getPosition(), glm::vec3(0,1,0));
|
||||
level->render(depthShader, false, &depthViewProjectionMatrix_middle);
|
||||
if (!framebuffer_middle->isFrameBufferObjectComplete()) {
|
||||
printf("Framebuffer incomplete, unknown error occured during shadow generation!\n");
|
||||
}
|
||||
|
||||
// far pass
|
||||
framebuffer_far->bind();
|
||||
framebuffer->bind();
|
||||
glClear(GL_DEPTH_BUFFER_BIT);
|
||||
glm::mat4 depthViewProjectionMatrix_far = glm::ortho<float>(-farPlane/2.0f, farPlane/2.0f, -farPlane/2.0f, farPlane/2.0f, -farPlane/2.0f, farPlane/2.0f) *
|
||||
glm::vec3 sunVector = (level->getCameraCenter()->getPosition() + level->getDirectionalLight()->getPosition());
|
||||
glm::mat4 depthViewProjectionMatrix = glm::ortho<float>(-farPlane/2.0f, farPlane/2.0f, -farPlane/2.0f, farPlane/2.0f, -farPlane/2.0f, farPlane/2.0f) *
|
||||
glm::lookAt(sunVector, level->getCameraCenter()->getPosition(), glm::vec3(0,1,0));
|
||||
level->render(depthShader, false, &depthViewProjectionMatrix_far);
|
||||
if (!framebuffer_far->isFrameBufferObjectComplete()) {
|
||||
level->render(depthShader, false, &depthViewProjectionMatrix);
|
||||
if (!framebuffer->isFrameBufferObjectComplete()) {
|
||||
printf("Framebuffer incomplete, unknown error occured during shadow generation!\n");
|
||||
}
|
||||
|
||||
@ -204,13 +163,9 @@ void Graphics::render()
|
||||
0.0, 0.0, 0.5, 0.0,
|
||||
0.5, 0.5, 0.5, 1.0
|
||||
);
|
||||
glm::mat4 depthBiasVP_near = biasMatrix*depthViewProjectionMatrix_near;
|
||||
glm::mat4 depthBiasVP_middle = biasMatrix*depthViewProjectionMatrix_middle;
|
||||
glm::mat4 depthBiasVP_far = biasMatrix*depthViewProjectionMatrix_far;
|
||||
glm::mat4 depthBiasVP = biasMatrix*depthViewProjectionMatrix;
|
||||
|
||||
lightingShader->setTexture("shadowMap_near", depthTexture_near, 1);
|
||||
lightingShader->setTexture("shadowMap_middle", depthTexture_middle, 2);
|
||||
lightingShader->setTexture("shadowMap_far", depthTexture_far, 3);
|
||||
lightingShader->setTexture("shadowMap", depthTexture, 1);
|
||||
|
||||
lightingShader->setUniform("farPlane", farPlane);
|
||||
|
||||
@ -226,9 +181,7 @@ void Graphics::render()
|
||||
glm::mat4 lightingViewProjectionMatrix = glm::perspective(1.571f, (float)windowSize.x/(float)windowSize.y, 0.1f, farPlane) * buildViewMatrix(level);
|
||||
|
||||
std::vector<glm::mat4> shadowVPs = std::vector<glm::mat4>();
|
||||
shadowVPs.push_back(depthBiasVP_near);
|
||||
shadowVPs.push_back(depthBiasVP_middle);
|
||||
shadowVPs.push_back(depthBiasVP_far);
|
||||
shadowVPs.push_back(depthBiasVP);
|
||||
|
||||
// render the level
|
||||
level->render(lightingShader, true, &lightingViewProjectionMatrix, &shadowVPs);
|
||||
@ -236,9 +189,7 @@ void Graphics::render()
|
||||
|
||||
void Graphics::resize(glm::uvec2 windowSize) {
|
||||
this->windowSize = windowSize;
|
||||
depthTexture_near->resize(glm::vec2(windowSize.x, windowSize.y));
|
||||
depthTexture_middle->resize(glm::vec2(windowSize.x, windowSize.y));
|
||||
depthTexture_far->resize(glm::vec2(windowSize.x, windowSize.y));
|
||||
depthTexture->resize(glm::vec2(windowSize.x, windowSize.y));
|
||||
}
|
||||
|
||||
glm::mat4 Graphics::buildViewMatrix(Level* level) {
|
||||
|
@ -28,12 +28,8 @@ class Graphics {
|
||||
GLFWwindow* window;
|
||||
ACGL::OpenGL::SharedShaderProgram lightingShader;
|
||||
ACGL::OpenGL::SharedShaderProgram depthShader;
|
||||
ACGL::OpenGL::SharedTexture2D depthTexture_near;
|
||||
ACGL::OpenGL::SharedFrameBufferObject framebuffer_near;
|
||||
ACGL::OpenGL::SharedTexture2D depthTexture_middle;
|
||||
ACGL::OpenGL::SharedFrameBufferObject framebuffer_middle;
|
||||
ACGL::OpenGL::SharedTexture2D depthTexture_far;
|
||||
ACGL::OpenGL::SharedFrameBufferObject framebuffer_far;
|
||||
ACGL::OpenGL::SharedTexture2D depthTexture;
|
||||
ACGL::OpenGL::SharedFrameBufferObject framebuffer;
|
||||
std::vector<ACGL::OpenGL::SharedTextureCubeMap> depth_cubeMaps;
|
||||
ACGL::OpenGL::SharedFrameBufferObject framebuffer_cube;
|
||||
static const int cube_size;
|
||||
|
Loading…
Reference in New Issue
Block a user