Only rendering sun shadows when the sun is actually shining.
This commit is contained in:
parent
93f87cc9c5
commit
185371d78c
31
graphics.cc
31
graphics.cc
@ -253,26 +253,29 @@ void Graphics::render(double time)
|
|||||||
glViewport(0, 0, windowSize.x, windowSize.y);
|
glViewport(0, 0, windowSize.x, windowSize.y);
|
||||||
|
|
||||||
std::vector<glm::mat4> depthViewProjectionMatrices = std::vector<glm::mat4>(framebuffer_directional.size());
|
std::vector<glm::mat4> depthViewProjectionMatrices = std::vector<glm::mat4>(framebuffer_directional.size());
|
||||||
|
float sunAngle = glm::dot(glm::vec3(0.0f, 1.0f, 0.0f), glm::normalize(level->getDirectionalLight()->getPosition()));
|
||||||
glm::vec3 sunVector = (level->getCameraCenter()->getPosition() + level->getDirectionalLight()->getPosition());
|
glm::vec3 sunVector = (level->getCameraCenter()->getPosition() + level->getDirectionalLight()->getPosition());
|
||||||
|
|
||||||
for (unsigned int i = 0; i<framebuffer_directional.size(); i++) {
|
for (unsigned int i = 0; i<framebuffer_directional.size(); i++) {
|
||||||
framebuffer_directional.at(i)->bind();
|
framebuffer_directional.at(i)->bind();
|
||||||
glClear(GL_DEPTH_BUFFER_BIT);
|
glClear(GL_DEPTH_BUFFER_BIT);
|
||||||
float projection_size = 0.0f;
|
if (sunAngle > 0.0f) {
|
||||||
switch(i) {
|
float projection_size = 0.0f;
|
||||||
case 0:
|
switch(i) {
|
||||||
projection_size = 10.0f;
|
case 0:
|
||||||
break;
|
projection_size = 10.0f;
|
||||||
case 1:
|
break;
|
||||||
projection_size = 30.0f;
|
case 1:
|
||||||
break;
|
projection_size = 30.0f;
|
||||||
case 2:
|
break;
|
||||||
projection_size = farPlane/1.5f;
|
case 2:
|
||||||
break;
|
projection_size = farPlane/1.5f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
depthViewProjectionMatrices.at(i) = glm::ortho<float>(-projection_size, projection_size, -projection_size, projection_size, -farPlane/1.5f, farPlane/1.5f) *
|
||||||
|
glm::lookAt(sunVector, level->getCameraCenter()->getPosition(), glm::vec3(0,1,0));
|
||||||
|
level->render(depthShader, false, &depthViewProjectionMatrices.at(i));
|
||||||
}
|
}
|
||||||
depthViewProjectionMatrices.at(i) = glm::ortho<float>(-projection_size, projection_size, -projection_size, projection_size, -farPlane/1.5f, farPlane/1.5f) *
|
|
||||||
glm::lookAt(sunVector, level->getCameraCenter()->getPosition(), glm::vec3(0,1,0));
|
|
||||||
level->render(depthShader, false, &depthViewProjectionMatrices.at(i));
|
|
||||||
if (!framebuffer_directional.at(i)->isFrameBufferObjectComplete()) {
|
if (!framebuffer_directional.at(i)->isFrameBufferObjectComplete()) {
|
||||||
printf("Framebuffer incomplete, unknown error occured during shadow generation!\n");
|
printf("Framebuffer incomplete, unknown error occured during shadow generation!\n");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user