Made first attempt at blurring flames. Conceptually bad, looks very bad.

This commit is contained in:
Faerbit 2015-03-04 00:55:01 +01:00
parent f34dbf891c
commit 2930a86959
4 changed files with 54 additions and 4 deletions

View File

@ -6,5 +6,5 @@ out vec4 oColor;
void main() {
oColor = vec4(fColor, 0.5);
oColor = vec4(fColor, 1.0);
}

View File

@ -3,9 +3,33 @@
in vec2 vTexCoord;
uniform sampler2D flame_fbo;
uniform sampler2D light_fbo;
uniform int windowSizeX;
uniform int windowSizeY;
out vec4 oColor;
const float lookup_offset = 4.0;
void main() {
oColor = texture(flame_fbo, vTexCoord).rgba;
vec4 color = texture(flame_fbo, vTexCoord).rgba;
if (color == vec4(0.0, 0.0, 0.0, 1.0)) {
oColor = texture(light_fbo, vTexCoord).rgba;
}
else {
vec4 sum = vec4(0.0);
for(float i = -lookup_offset; i<=lookup_offset; i+=1.0) {
for(float j = -lookup_offset; j<=lookup_offset; j+=1.0) {
vec4 flame_pixel = texture(flame_fbo, vec2(vTexCoord.x + i * 1.0/(windowSizeX/2.0), vTexCoord.y + j * 1.0/(windowSizeY/2.0)))/pow(lookup_offset*2+1, 2.0);
vec4 light_pixel = texture(light_fbo, vec2(vTexCoord.x + i * 1.0/(windowSizeX/2.0), vTexCoord.y + j * 1.0/(windowSizeY/2.0)))/pow(lookup_offset*2+1, 2.0);
if (flame_pixel == vec4(0.0, 0.0, 0.0, 1.0)) {
sum += light_pixel;
}
else {
sum += mix(flame_pixel, light_pixel, 0.7);
}
}
}
oColor = sum;
}
}

View File

@ -155,11 +155,30 @@ void Graphics::init(Level* level) {
framebuffer_flames = SharedFrameBufferObject(new FrameBufferObject());
framebuffer_flames->attachColorTexture("oColor", flame_fbo_color_texture);
framebuffer_flames->setDepthTexture(flame_fbo_depth_texture);
framebuffer_flames->setClearColor(glm::vec4(0.0f, 0.0f, 0.0f, 0.0f));
framebuffer_flames->setClearColor(glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
framebuffer_flames->validate();
light_fbo_color_texture = SharedTexture2D(new Texture2D(windowSize, GL_RGBA8));
light_fbo_color_texture->setMinFilter(GL_NEAREST);
light_fbo_color_texture->setMagFilter(GL_NEAREST);
light_fbo_color_texture->setWrapS(GL_CLAMP_TO_BORDER);
light_fbo_color_texture->setWrapT(GL_CLAMP_TO_BORDER);
light_fbo_depth_texture = SharedTexture2D(new Texture2D(windowSize, GL_DEPTH_COMPONENT24));
light_fbo_depth_texture->setMinFilter(GL_NEAREST);
light_fbo_depth_texture->setMagFilter(GL_NEAREST);
light_fbo_depth_texture->setWrapS(GL_CLAMP_TO_BORDER);
light_fbo_depth_texture->setWrapT(GL_CLAMP_TO_BORDER);
framebuffer_light = SharedFrameBufferObject(new FrameBufferObject());
framebuffer_light->attachColorTexture("oColor", light_fbo_color_texture);
framebuffer_light->setDepthTexture(light_fbo_depth_texture);
framebuffer_light->setClearColor(glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
framebuffer_light->validate();
flamePostShader->use();
flamePostShader->setTexture("flame_fbo", flame_fbo_color_texture, 15);
flamePostShader->setTexture("light_fbo", light_fbo_color_texture, 16);
flamePostShader->setUniform("windowSizeX", int(windowSize.x));
flamePostShader->setUniform("windowSizeY", int(windowSize.y));
updateClosestLights();
}
@ -229,7 +248,7 @@ void Graphics::render(double time)
}
// lighting render pass
glBindFramebuffer(GL_FRAMEBUFFER, 0);
framebuffer_light->bind();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
lightingShader->use();
@ -387,6 +406,10 @@ void Graphics::resize(glm::uvec2 windowSize) {
for (unsigned int i = 0; i<depth_directionalMaps.size(); i++) {
depth_directionalMaps.at(i)->resize(glm::vec2(windowSize.x, windowSize.y));
}
flame_fbo_color_texture->resize(windowSize);
flame_fbo_depth_texture->resize(windowSize);
flamePostShader->setUniform("windowSizeX", int(windowSize.x));
flamePostShader->setUniform("windowSizeY", int(windowSize.y));
}
glm::mat4 Graphics::buildViewMatrix(Level* level) {

View File

@ -42,6 +42,9 @@ class Graphics {
SharedFrameBufferObject framebuffer_flames;
SharedTexture2D flame_fbo_color_texture;
SharedTexture2D flame_fbo_depth_texture;
SharedFrameBufferObject framebuffer_light;
SharedTexture2D light_fbo_color_texture;
SharedTexture2D light_fbo_depth_texture;
SharedVertexArrayObject flame_positions;
SharedArrayBuffer flame_positions_ab;
SharedVertexArrayObject fullscreen_quad;