Adding debug switchtes for flames and shadows.

This commit is contained in:
Faerbit 2015-03-12 19:24:10 +01:00
parent 9a54c033c0
commit e2e343db1a
3 changed files with 145 additions and 103 deletions

View File

@ -25,6 +25,8 @@ Graphics::Graphics(glm::uvec2 windowSize, float nearPlane,
this->loadingScreenPath = screenPath;
this->loadingScreenContinuePath = screenContinuePath;
gameStart = false;
renderShadows = true;
renderFlames = true;
}
Graphics::Graphics() {
@ -307,7 +309,10 @@ void Graphics::render(double time)
updateLights();
lastLightUpdate = time;
}
// At first render shadows
std::vector<glm::mat4> depthViewProjectionMatrices = std::vector<glm::mat4>(framebuffer_directional.size());
if (renderShadows) {
depthCubeShader->use();
depthCubeShader->setUniform("farPlane", farPlane);
// render depth textures for point lights
@ -341,7 +346,7 @@ void Graphics::render(double time)
depthShader->use();
glViewport(0, 0, windowSize.x, windowSize.y);
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());
@ -364,11 +369,12 @@ void Graphics::render(double time)
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()) {
printf("Framebuffer incomplete, unknown error occured during shadow generation!\n");
}
}
}
}
// lighting render pass
glBindFramebuffer(GL_FRAMEBUFFER, 0);
@ -422,12 +428,6 @@ void Graphics::render(double time)
lightingShader->use();
//set lighting parameters
// TODO look into doing this less often, offload to another thread?
// TODO figure out how to deal with bigger numbers of lights. load the nearest on demand?
// convert texture to homogenouse coordinates
glm::mat4 biasMatrix(
0.5, 0.0, 0.0, 0.0,
@ -462,6 +462,7 @@ void Graphics::render(double time)
level->render(lightingShader, true, &lightingViewProjectionMatrix, &depthBiasVPs);
// draw flames on top
if (renderFlames) {
flameShader->use();
// cull faces to get consistent color while using alpha
glEnable(GL_CULL_FACE);
@ -507,6 +508,7 @@ void Graphics::render(double time)
glBlitFramebuffer(0, 0, windowSize.x, windowSize.y, 0, 0, windowSize.x, windowSize.y,
GL_COLOR_BUFFER_BIT, GL_NEAREST);
}
}
}
bool Graphics::compareLightDistances(Light a, Light b) {
@ -632,3 +634,31 @@ void Graphics::saveDepthBufferToDisk(int face, std::string filename) {
void Graphics::startGame() {
gameStart = true;
}
void Graphics::setRenderShadows(bool state) {
if(!state) {
for(unsigned int i = 0; i<framebuffer_directional.size(); i++) {
framebuffer_directional.at(i)->bind();
glClear(GL_DEPTH_BUFFER_BIT);
}
for(unsigned int i_pointlight = 0; i_pointlight<depth_cubeMaps.size(); i_pointlight++) {
for(int i_face = 0; i_face<6; i_face++) {
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i_face, depth_cubeMaps.at(i_pointlight)->getObjectName(), 0);
glClear(GL_DEPTH_BUFFER_BIT);
}
}
}
renderShadows = state;
}
void Graphics::setRenderFlames(bool state) {
renderFlames = state;
}
bool Graphics::getRenderShadows() {
return renderShadows;
}
bool Graphics::getRenderFlames() {
return renderFlames;
}

View File

@ -24,6 +24,10 @@ class Graphics {
float getFarPlane();
void startGame();
void renderLoadingScreen();
void setRenderShadows(bool state);
void setRenderFlames(bool state);
bool getRenderShadows();
bool getRenderFlames();
private:
void bindTextureUnits();
void updateLights();
@ -71,6 +75,8 @@ class Graphics {
bool gameStart;
float loadingScreenWidth;
float loadingScreenHeight;
bool renderShadows;
bool renderFlames;
};
#endif

View File

@ -23,6 +23,12 @@ static void keyCallback(GLFWwindow* _window, int _key, int, int _action, int)
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
app.setCameraLock(false);
}
if (_key == GLFW_KEY_F5 && _action == GLFW_PRESS) {
app.getGraphics()->setRenderShadows(!app.getGraphics()->getRenderShadows());
}
if (_key == GLFW_KEY_F6 && _action == GLFW_PRESS) {
app.getGraphics()->setRenderFlames(!app.getGraphics()->getRenderFlames());
}
}
static void mouseCallback(GLFWwindow* window, int button, int action, int) {