Now also blurring the edges of the flames.
This commit is contained in:
parent
bb3267c72a
commit
f4b9d4dc38
@ -4,7 +4,14 @@ in vec3 fColor;
|
|||||||
|
|
||||||
out vec4 oColor;
|
out vec4 oColor;
|
||||||
|
|
||||||
|
uniform bool withColor;
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
if (withColor) {
|
||||||
oColor = vec4(fColor, 0.6);
|
oColor = vec4(fColor, 0.6);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
oColor = vec4(0.0, 0.0, 0.0, 0.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#version 150
|
#version 150
|
||||||
|
|
||||||
uniform mat4 viewProjectionMatrix;
|
uniform mat4 modelViewProjectionMatrix;
|
||||||
uniform float time;
|
uniform float time;
|
||||||
uniform bool bottom;
|
uniform bool bottom;
|
||||||
uniform bool left;
|
uniform bool left;
|
||||||
@ -62,19 +62,19 @@ void main() {
|
|||||||
float rightAngle = PI * 2.0 / resolution * (j+1);
|
float rightAngle = PI * 2.0 / resolution * (j+1);
|
||||||
|
|
||||||
vec4 offset = vec4(cos(rightAngle) * downRadius, i, -sin(rightAngle) * downRadius, 0.0);
|
vec4 offset = vec4(cos(rightAngle) * downRadius, i, -sin(rightAngle) * downRadius, 0.0);
|
||||||
gl_Position = gl_in[0].gl_Position + viewProjectionMatrix * offset;
|
gl_Position = gl_in[0].gl_Position + modelViewProjectionMatrix * offset;
|
||||||
EmitVertex();
|
EmitVertex();
|
||||||
|
|
||||||
offset = vec4(cos(rightAngle) * upRadius, i + step, -sin(rightAngle) * upRadius, 0.0);
|
offset = vec4(cos(rightAngle) * upRadius, i + step, -sin(rightAngle) * upRadius, 0.0);
|
||||||
gl_Position = gl_in[0].gl_Position + viewProjectionMatrix * offset;
|
gl_Position = gl_in[0].gl_Position + modelViewProjectionMatrix * offset;
|
||||||
EmitVertex();
|
EmitVertex();
|
||||||
|
|
||||||
offset = vec4(cos(leftAngle) * downRadius, i, -sin(leftAngle) * downRadius, 0.0);
|
offset = vec4(cos(leftAngle) * downRadius, i, -sin(leftAngle) * downRadius, 0.0);
|
||||||
gl_Position = gl_in[0].gl_Position + viewProjectionMatrix * offset;
|
gl_Position = gl_in[0].gl_Position + modelViewProjectionMatrix * offset;
|
||||||
EmitVertex();
|
EmitVertex();
|
||||||
|
|
||||||
offset = vec4(cos(leftAngle) * upRadius, i + step, -sin(leftAngle) * upRadius, 0.0);
|
offset = vec4(cos(leftAngle) * upRadius, i + step, -sin(leftAngle) * upRadius, 0.0);
|
||||||
gl_Position = gl_in[0].gl_Position + viewProjectionMatrix * offset;
|
gl_Position = gl_in[0].gl_Position + modelViewProjectionMatrix * offset;
|
||||||
EmitVertex();
|
EmitVertex();
|
||||||
|
|
||||||
EndPrimitive();
|
EndPrimitive();
|
||||||
|
42
graphics.cc
42
graphics.cc
@ -278,18 +278,16 @@ void Graphics::render(double time)
|
|||||||
level->render(lightingShader, true, &lightingViewProjectionMatrix, &depthBiasVPs);
|
level->render(lightingShader, true, &lightingViewProjectionMatrix, &depthBiasVPs);
|
||||||
|
|
||||||
// draw flames on top
|
// draw flames on top
|
||||||
|
flameShader->use();
|
||||||
// cull faces to get consistent color while using alpha
|
// cull faces to get consistent color while using alpha
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
glCullFace(GL_BACK);
|
glCullFace(GL_BACK);
|
||||||
glEnable(GL_STENCIL_TEST);
|
|
||||||
glStencilFunc(GL_ALWAYS, 1, 0xFF); //Set any stencil to 1
|
|
||||||
glStencilFunc(GL_ALWAYS, 1, 0xFF);
|
|
||||||
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
|
|
||||||
glStencilMask(0xFF);//write to stencil buffer
|
|
||||||
glClear(GL_STENCIL_BUFFER_BIT);//clear stencil buffer
|
|
||||||
|
|
||||||
flameShader->use();
|
|
||||||
|
// draw with colors
|
||||||
flameShader->setUniform("viewProjectionMatrix", lightingViewProjectionMatrix);
|
flameShader->setUniform("viewProjectionMatrix", lightingViewProjectionMatrix);
|
||||||
|
flameShader->setUniform("modelViewProjectionMatrix", lightingViewProjectionMatrix);
|
||||||
|
flameShader->setUniform("withColor", true);
|
||||||
flameShader->setUniform("time", (float) time);
|
flameShader->setUniform("time", (float) time);
|
||||||
flameShader->setUniform("bottom", true);
|
flameShader->setUniform("bottom", true);
|
||||||
flameShader->setUniform("left", true);
|
flameShader->setUniform("left", true);
|
||||||
@ -302,10 +300,36 @@ void Graphics::render(double time)
|
|||||||
flameShader->setUniform("left", false);
|
flameShader->setUniform("left", false);
|
||||||
flame_positions->render();
|
flame_positions->render();
|
||||||
|
|
||||||
glDisable(GL_CULL_FACE);
|
glDepthMask(GL_FALSE);
|
||||||
|
|
||||||
|
// draw slightly larger only for stencil buffer to blur edges
|
||||||
|
glEnable(GL_STENCIL_TEST);
|
||||||
|
glStencilFunc(GL_ALWAYS, 1, 0xFF); //Set any stencil to 1
|
||||||
|
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
|
||||||
|
glStencilMask(0xFF);//write to stencil buffer
|
||||||
|
glClear(GL_STENCIL_BUFFER_BIT);//clear stencil buffer
|
||||||
|
|
||||||
|
glm::mat4 modelMatrix = glm::scale(glm::vec3(1.1f));
|
||||||
|
flameShader->setUniform("viewProjectionMatrix", lightingViewProjectionMatrix);
|
||||||
|
flameShader->setUniform("modelViewProjectionMatrix", lightingViewProjectionMatrix * modelMatrix);
|
||||||
|
flameShader->setUniform("withColor", false);
|
||||||
|
flameShader->setUniform("time", (float) time);
|
||||||
|
flameShader->setUniform("bottom", true);
|
||||||
|
flameShader->setUniform("left", true);
|
||||||
|
flame_positions->render();
|
||||||
|
flameShader->setUniform("left", false);
|
||||||
|
flame_positions->render();
|
||||||
|
flameShader->setUniform("bottom", false);
|
||||||
|
flameShader->setUniform("left", true);
|
||||||
|
flame_positions->render();
|
||||||
|
flameShader->setUniform("left", false);
|
||||||
|
flame_positions->render();
|
||||||
|
|
||||||
glStencilFunc(GL_EQUAL, 1, 0xFF); //Pass test if stencil value is 1
|
glStencilFunc(GL_EQUAL, 1, 0xFF); //Pass test if stencil value is 1
|
||||||
glStencilMask(0x00); //don't write to stencil buffer
|
glStencilMask(0x00);// don't write to stencil buffer
|
||||||
|
|
||||||
|
glDepthMask(GL_TRUE);
|
||||||
|
glDisable(GL_CULL_FACE);
|
||||||
|
|
||||||
flamePostShader->use();
|
flamePostShader->use();
|
||||||
fullscreen_quad->render();
|
fullscreen_quad->render();
|
||||||
|
Loading…
Reference in New Issue
Block a user