From 1b8b8125f4379d3efcc517ec9932a6e06e13e110 Mon Sep 17 00:00:00 2001 From: Faerbit Date: Fri, 6 Mar 2015 09:21:38 +0100 Subject: [PATCH] Added shader which could manipulate the color of the flames. --- data/shader/flame_color.fsh | 11 +++++++++++ data/shader/flame_color.vsh | 11 +++++++++++ graphics.cc | 15 ++++++++++++--- graphics.hh | 1 + 4 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 data/shader/flame_color.fsh create mode 100644 data/shader/flame_color.vsh diff --git a/data/shader/flame_color.fsh b/data/shader/flame_color.fsh new file mode 100644 index 0000000..6e36a05 --- /dev/null +++ b/data/shader/flame_color.fsh @@ -0,0 +1,11 @@ +#version 150 + +in vec2 vTexCoord; + +uniform sampler2D flame_fbo; + +out vec4 oColor; + +void main() { + oColor = texture(flame_fbo, vTexCoord); +} diff --git a/data/shader/flame_color.vsh b/data/shader/flame_color.vsh new file mode 100644 index 0000000..f3e6540 --- /dev/null +++ b/data/shader/flame_color.vsh @@ -0,0 +1,11 @@ +#version 150 + +in vec2 aPosition; +in vec2 aTexCoord; + +out vec2 vTexCoord; + +void main() { + vTexCoord = aTexCoord; + gl_Position = vec4(aPosition, 0.0, 1.0); +} diff --git a/graphics.cc b/graphics.cc index ee660c3..65265ab 100644 --- a/graphics.cc +++ b/graphics.cc @@ -90,6 +90,9 @@ void Graphics::init(Level* level) { flameShader = ShaderProgramCreator("flame") .attributeLocations(flame_positions->getAttributeLocations()).create(); + flameColorShader = ShaderProgramCreator("flame_color") + .attributeLocations(fullscreen_quad->getAttributeLocations()).create(); + flamePostShader = ShaderProgramCreator("flame_post") .attributeLocations(fullscreen_quad->getAttributeLocations()).create(); @@ -99,8 +102,8 @@ void Graphics::init(Level* level) { glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &number_of_texture_units); printf("Your graphics card supports %d texture units.\n", number_of_texture_units); // Exit if we need more texture units - if (number_of_texture_units < 18) { - printf("You need at least 18 texture units to run this application. Exiting\n"); + if (number_of_texture_units < 19) { + printf("You need at least 19 texture units to run this application. Exiting\n"); exit(-1); } @@ -188,6 +191,9 @@ void Graphics::init(Level* level) { 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); + updateClosestLights(); } @@ -340,8 +346,11 @@ void Graphics::render(double time) flame_positions->render(); glDisable(GL_CULL_FACE); - framebuffer_light->bind(); glDepthMask(GL_FALSE); + flameColorShader->use(); + fullscreen_quad->render(); + + framebuffer_light->bind(); mergeShader->use(); glDisable(GL_DEPTH_TEST); fullscreen_quad->render(); diff --git a/graphics.hh b/graphics.hh index 999e157..2e63246 100644 --- a/graphics.hh +++ b/graphics.hh @@ -35,6 +35,7 @@ class Graphics { SharedShaderProgram depthCubeShader; SharedShaderProgram depthShader; SharedShaderProgram flameShader; + SharedShaderProgram flameColorShader; SharedShaderProgram flamePostShader; SharedShaderProgram mergeShader; std::vector depth_directionalMaps;