diff --git a/data/shader/skydome.fsh b/data/shader/skydome.fsh index 68f52d2..3ea54ca 100644 --- a/data/shader/skydome.fsh +++ b/data/shader/skydome.fsh @@ -22,7 +22,6 @@ void main() { vec4 dayColor = texture(uTexture, vTexCoord); if (sunAngle >= 0.0) { textureColor = mix(dayColor, texture(nightTexture, vTexCoord), sunAngle); - textureColor = mix(vec4(0.0, 0.0, 0.0, 1.0), textureColor, 1.0 - sunAngle); } else { textureColor = dayColor; diff --git a/graphics.cc b/graphics.cc index 65265ab..dcc945d 100644 --- a/graphics.cc +++ b/graphics.cc @@ -126,10 +126,6 @@ void Graphics::init(Level* level) { lightingShader->use(); - for (unsigned int i = 0; isetTexture("shadowMap_directional" + std::to_string(i), depth_directionalMaps.at(i), i+1); - } // always generate and bind 10 cube maps, because otherwise the shader won't work @@ -145,12 +141,6 @@ void Graphics::init(Level* level) { framebuffer_cube = SharedFrameBufferObject(new FrameBufferObject()); - if (level->getLights()->size() > 0) { - for(unsigned int i = 0; isetTexture("shadowMap_cube" + std::to_string(i), depth_cubeMaps.at(i), i+4); - } - } light_fbo_color_texture = SharedTexture2D(new Texture2D(windowSize, GL_RGBA8)); light_fbo_color_texture->setMinFilter(GL_NEAREST); @@ -169,12 +159,9 @@ void Graphics::init(Level* level) { framebuffer_light->validate(); flamePostShader->use(); - flamePostShader->setTexture("light_fbo", light_fbo_color_texture, 14); flamePostShader->setUniform("windowSizeX", int(windowSize.x)); flamePostShader->setUniform("windowSizeY", int(windowSize.y)); - skydomeShader->use(); - skydomeShader->setTexture("nightTexture", level->getSkydome()->getNightTexture()->getReference(), 15); flame_fbo_color_texture = SharedTexture2D(new Texture2D(windowSize, GL_RGBA8)); flame_fbo_color_texture->setMinFilter(GL_NEAREST); @@ -187,12 +174,7 @@ void Graphics::init(Level* level) { framebuffer_flame->setClearColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.0f)); framebuffer_flame->validate(); - mergeShader->use(); - mergeShader->setTexture("flame_fbo", flame_fbo_color_texture, 16); - mergeShader->setTexture("light_fbo", light_fbo_color_texture, 17); - - flameColorShader->use(); - flameColorShader->setTexture("flame_fbo", flame_fbo_color_texture, 18); + bindTextureUnits(); updateClosestLights(); } @@ -201,6 +183,30 @@ glm::uvec2 Graphics::getWindowSize() { return windowSize; } +void Graphics::bindTextureUnits() { + lightingShader->use(); + for (unsigned int i = 0; isetTexture("shadowMap_directional" + std::to_string(i), depth_directionalMaps.at(i), i+1); + } + if (level->getLights()->size() > 0) { + for(unsigned int i = 0; isetTexture("shadowMap_cube" + std::to_string(i), depth_cubeMaps.at(i), i+4); + } + } + flamePostShader->use(); + flamePostShader->setTexture("light_fbo", light_fbo_color_texture, 14); + skydomeShader->use(); + skydomeShader->setTexture("nightTexture", level->getSkydome()->getNightTexture()->getReference(), 15); + mergeShader->use(); + mergeShader->setTexture("flame_fbo", flame_fbo_color_texture, 16); + mergeShader->setTexture("light_fbo", light_fbo_color_texture, 17); + + flameColorShader->use(); + flameColorShader->setTexture("flame_fbo", flame_fbo_color_texture, 18); +} + void Graphics::render(double time) { // At first render shadows @@ -480,8 +486,10 @@ void Graphics::resize(glm::uvec2 windowSize) { } light_fbo_color_texture->resize(windowSize); light_fbo_depth_texture->resize(windowSize); + flame_fbo_color_texture->resize(windowSize); flamePostShader->setUniform("windowSizeX", int(windowSize.x)); flamePostShader->setUniform("windowSizeY", int(windowSize.y)); + bindTextureUnits(); } glm::mat4 Graphics::buildViewMatrix(Level* level) { diff --git a/graphics.hh b/graphics.hh index 2e63246..f054b17 100644 --- a/graphics.hh +++ b/graphics.hh @@ -21,6 +21,7 @@ class Graphics { void resize(glm::uvec2 windowSize); float getFarPlane(); private: + void bindTextureUnits(); void updateLights(); void updateClosestLights(); bool compareLightDistances(Light a, Light b);