Gave the flames it's own framebuffer to be able to manipulate it's color.
This commit is contained in:
parent
8443ab789f
commit
a82ecad52f
@ -9,7 +9,7 @@ uniform bool withColor;
|
||||
|
||||
void main() {
|
||||
if (withColor) {
|
||||
oColor = vec4(fColor, 0.6);
|
||||
oColor = vec4(fColor, 1.0);
|
||||
}
|
||||
else {
|
||||
oColor = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
|
18
data/shader/merge.fsh
Normal file
18
data/shader/merge.fsh
Normal file
@ -0,0 +1,18 @@
|
||||
#version 150
|
||||
|
||||
in vec2 vTexCoord;
|
||||
|
||||
uniform sampler2D flame_fbo;
|
||||
uniform sampler2D light_fbo;
|
||||
|
||||
out vec4 oColor;
|
||||
|
||||
void main() {
|
||||
vec4 flameColor = texture(flame_fbo, vTexCoord);
|
||||
if (flameColor == vec4(0.0, 0.0, 0.0, 1.0)) {
|
||||
oColor = texture(light_fbo, vTexCoord);
|
||||
}
|
||||
else {
|
||||
oColor = mix(flameColor, texture(light_fbo, vTexCoord), 0.4);
|
||||
}
|
||||
}
|
11
data/shader/merge.vsh
Normal file
11
data/shader/merge.vsh
Normal 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);
|
||||
}
|
37
graphics.cc
37
graphics.cc
@ -32,6 +32,7 @@ void Graphics::init(Level* level) {
|
||||
glClearColor( 0.0, 0.0, 0.0, 1.0 );
|
||||
glEnable( GL_DEPTH_TEST );
|
||||
glEnable(GL_BLEND);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
|
||||
//glEnable(GL_MULTISAMPLE);
|
||||
@ -92,11 +93,14 @@ void Graphics::init(Level* level) {
|
||||
flamePostShader = ShaderProgramCreator("flame_post")
|
||||
.attributeLocations(fullscreen_quad->getAttributeLocations()).create();
|
||||
|
||||
mergeShader = ShaderProgramCreator("merge")
|
||||
.attributeLocations(fullscreen_quad->getAttributeLocations()).create();
|
||||
|
||||
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 < 16) {
|
||||
printf("You need at least 16 texture units to run this application. Exiting\n");
|
||||
if (number_of_texture_units < 18) {
|
||||
printf("You need at least 18 texture units to run this application. Exiting\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
@ -169,6 +173,21 @@ void Graphics::init(Level* level) {
|
||||
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);
|
||||
flame_fbo_color_texture->setMagFilter(GL_NEAREST);
|
||||
flame_fbo_color_texture->setWrapS(GL_CLAMP_TO_BORDER);
|
||||
flame_fbo_color_texture->setWrapT(GL_CLAMP_TO_BORDER);
|
||||
framebuffer_flame = SharedFrameBufferObject(new FrameBufferObject());
|
||||
framebuffer_flame->attachColorTexture("oColor", flame_fbo_color_texture);
|
||||
framebuffer_flame->setDepthTexture(light_fbo_depth_texture);
|
||||
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);
|
||||
|
||||
updateClosestLights();
|
||||
}
|
||||
|
||||
@ -298,6 +317,8 @@ void Graphics::render(double time)
|
||||
|
||||
// draw flames on top
|
||||
flameShader->use();
|
||||
framebuffer_flame->bind();
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
// cull faces to get consistent color while using alpha
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
@ -317,10 +338,18 @@ void Graphics::render(double time)
|
||||
flame_positions->render();
|
||||
flameShader->setUniform("left", false);
|
||||
flame_positions->render();
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
framebuffer_light->bind();
|
||||
glDepthMask(GL_FALSE);
|
||||
mergeShader->use();
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
fullscreen_quad->render();
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
|
||||
// draw slightly larger only for stencil buffer to blur edges
|
||||
flameShader->use();
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
glStencilFunc(GL_ALWAYS, 1, 0xFF); //Set any stencil to 1
|
||||
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
|
||||
@ -346,11 +375,9 @@ void Graphics::render(double time)
|
||||
glStencilFunc(GL_EQUAL, 1, 0xFF); //Pass test if stencil value is 1
|
||||
glStencilMask(0x00);// don't write to stencil buffer
|
||||
|
||||
glDepthMask(GL_TRUE);
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
flamePostShader->use();
|
||||
fullscreen_quad->render();
|
||||
glDepthMask(GL_TRUE);
|
||||
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
|
||||
|
@ -36,11 +36,14 @@ class Graphics {
|
||||
SharedShaderProgram depthShader;
|
||||
SharedShaderProgram flameShader;
|
||||
SharedShaderProgram flamePostShader;
|
||||
SharedShaderProgram mergeShader;
|
||||
std::vector<SharedTexture2D> depth_directionalMaps;
|
||||
std::vector<SharedFrameBufferObject> framebuffer_directional;
|
||||
std::vector<SharedTextureCubeMap> depth_cubeMaps;
|
||||
SharedFrameBufferObject framebuffer_cube;
|
||||
SharedFrameBufferObject framebuffer_light;
|
||||
SharedFrameBufferObject framebuffer_flame;
|
||||
SharedTexture2D flame_fbo_color_texture;
|
||||
SharedTexture2D light_fbo_color_texture;
|
||||
SharedTexture2D light_fbo_depth_texture;
|
||||
SharedVertexArrayObject flame_positions;
|
||||
|
Loading…
Reference in New Issue
Block a user