Added shader which could manipulate the color of the flames.

This commit is contained in:
Faerbit 2015-03-06 09:21:38 +01:00
parent 00506c6b3e
commit 1b8b8125f4
4 changed files with 35 additions and 3 deletions

View File

@ -0,0 +1,11 @@
#version 150
in vec2 vTexCoord;
uniform sampler2D flame_fbo;
out vec4 oColor;
void main() {
oColor = texture(flame_fbo, vTexCoord);
}

View File

@ -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);
}

View File

@ -90,6 +90,9 @@ void Graphics::init(Level* level) {
flameShader = ShaderProgramCreator("flame") flameShader = ShaderProgramCreator("flame")
.attributeLocations(flame_positions->getAttributeLocations()).create(); .attributeLocations(flame_positions->getAttributeLocations()).create();
flameColorShader = ShaderProgramCreator("flame_color")
.attributeLocations(fullscreen_quad->getAttributeLocations()).create();
flamePostShader = ShaderProgramCreator("flame_post") flamePostShader = ShaderProgramCreator("flame_post")
.attributeLocations(fullscreen_quad->getAttributeLocations()).create(); .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); glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &number_of_texture_units);
printf("Your graphics card supports %d texture units.\n", number_of_texture_units); printf("Your graphics card supports %d texture units.\n", number_of_texture_units);
// Exit if we need more texture units // Exit if we need more texture units
if (number_of_texture_units < 18) { if (number_of_texture_units < 19) {
printf("You need at least 18 texture units to run this application. Exiting\n"); printf("You need at least 19 texture units to run this application. Exiting\n");
exit(-1); exit(-1);
} }
@ -188,6 +191,9 @@ void Graphics::init(Level* level) {
mergeShader->setTexture("flame_fbo", flame_fbo_color_texture, 16); mergeShader->setTexture("flame_fbo", flame_fbo_color_texture, 16);
mergeShader->setTexture("light_fbo", light_fbo_color_texture, 17); mergeShader->setTexture("light_fbo", light_fbo_color_texture, 17);
flameColorShader->use();
flameColorShader->setTexture("flame_fbo", flame_fbo_color_texture, 18);
updateClosestLights(); updateClosestLights();
} }
@ -340,8 +346,11 @@ void Graphics::render(double time)
flame_positions->render(); flame_positions->render();
glDisable(GL_CULL_FACE); glDisable(GL_CULL_FACE);
framebuffer_light->bind();
glDepthMask(GL_FALSE); glDepthMask(GL_FALSE);
flameColorShader->use();
fullscreen_quad->render();
framebuffer_light->bind();
mergeShader->use(); mergeShader->use();
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
fullscreen_quad->render(); fullscreen_quad->render();

View File

@ -35,6 +35,7 @@ class Graphics {
SharedShaderProgram depthCubeShader; SharedShaderProgram depthCubeShader;
SharedShaderProgram depthShader; SharedShaderProgram depthShader;
SharedShaderProgram flameShader; SharedShaderProgram flameShader;
SharedShaderProgram flameColorShader;
SharedShaderProgram flamePostShader; SharedShaderProgram flamePostShader;
SharedShaderProgram mergeShader; SharedShaderProgram mergeShader;
std::vector<SharedTexture2D> depth_directionalMaps; std::vector<SharedTexture2D> depth_directionalMaps;