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->loadingScreenPath = screenPath;
this->loadingScreenContinuePath = screenContinuePath; this->loadingScreenContinuePath = screenContinuePath;
gameStart = false; gameStart = false;
renderShadows = true;
renderFlames = true;
} }
Graphics::Graphics() { Graphics::Graphics() {
@ -307,7 +309,10 @@ void Graphics::render(double time)
updateLights(); updateLights();
lastLightUpdate = time; lastLightUpdate = time;
} }
// At first render shadows // At first render shadows
std::vector<glm::mat4> depthViewProjectionMatrices = std::vector<glm::mat4>(framebuffer_directional.size());
if (renderShadows) {
depthCubeShader->use(); depthCubeShader->use();
depthCubeShader->setUniform("farPlane", farPlane); depthCubeShader->setUniform("farPlane", farPlane);
// render depth textures for point lights // render depth textures for point lights
@ -341,7 +346,7 @@ void Graphics::render(double time)
depthShader->use(); depthShader->use();
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());
float sunAngle = glm::dot(glm::vec3(0.0f, 1.0f, 0.0f), glm::normalize(level->getDirectionalLight()->getPosition())); 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());
@ -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) * 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)); glm::lookAt(sunVector, level->getCameraCenter()->getPosition(), glm::vec3(0,1,0));
level->render(depthShader, false, &depthViewProjectionMatrices.at(i)); 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");
} }
} }
}
}
// lighting render pass // lighting render pass
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
@ -422,12 +428,6 @@ void Graphics::render(double time)
lightingShader->use(); 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 // convert texture to homogenouse coordinates
glm::mat4 biasMatrix( glm::mat4 biasMatrix(
0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0,
@ -462,6 +462,7 @@ void Graphics::render(double time)
level->render(lightingShader, true, &lightingViewProjectionMatrix, &depthBiasVPs); level->render(lightingShader, true, &lightingViewProjectionMatrix, &depthBiasVPs);
// draw flames on top // draw flames on top
if (renderFlames) {
flameShader->use(); flameShader->use();
// cull faces to get consistent color while using alpha // cull faces to get consistent color while using alpha
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
@ -508,6 +509,7 @@ void Graphics::render(double time)
GL_COLOR_BUFFER_BIT, GL_NEAREST); GL_COLOR_BUFFER_BIT, GL_NEAREST);
} }
} }
}
bool Graphics::compareLightDistances(Light a, Light b) { bool Graphics::compareLightDistances(Light a, Light b) {
if (glm::distance(this->level->getCameraCenter()->getPosition(), a.getPosition()) < if (glm::distance(this->level->getCameraCenter()->getPosition(), a.getPosition()) <
@ -632,3 +634,31 @@ void Graphics::saveDepthBufferToDisk(int face, std::string filename) {
void Graphics::startGame() { void Graphics::startGame() {
gameStart = true; 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(); float getFarPlane();
void startGame(); void startGame();
void renderLoadingScreen(); void renderLoadingScreen();
void setRenderShadows(bool state);
void setRenderFlames(bool state);
bool getRenderShadows();
bool getRenderFlames();
private: private:
void bindTextureUnits(); void bindTextureUnits();
void updateLights(); void updateLights();
@ -71,6 +75,8 @@ class Graphics {
bool gameStart; bool gameStart;
float loadingScreenWidth; float loadingScreenWidth;
float loadingScreenHeight; float loadingScreenHeight;
bool renderShadows;
bool renderFlames;
}; };
#endif #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); glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
app.setCameraLock(false); 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) { static void mouseCallback(GLFWwindow* window, int button, int action, int) {