diff --git a/data/levels/Compositions.xml b/data/levels/Compositions.xml index b377569..7bb9ec6 100644 --- a/data/levels/Compositions.xml +++ b/data/levels/Compositions.xml @@ -75,7 +75,7 @@ 1.0 1.0 4.0 - 0.5 + -1.2 diff --git a/data/shader/flame.fsh b/data/shader/flame.fsh new file mode 100644 index 0000000..6f8ab8c --- /dev/null +++ b/data/shader/flame.fsh @@ -0,0 +1,7 @@ +#version 150 + +out vec4 oColor; + +void main() { + oColor = vec4(1.0, 0.0, 0.0, 0.5); +} diff --git a/data/shader/flame.gsh b/data/shader/flame.gsh new file mode 100644 index 0000000..96b2d1f --- /dev/null +++ b/data/shader/flame.gsh @@ -0,0 +1,20 @@ +#version 150 + +uniform mat4 viewProjectionMatrix; +uniform float time; + +layout(points) in; +layout(triangle_strip, max_vertices = 3) out; + +void main() { + gl_Position = gl_in[0].gl_Position + viewProjectionMatrix * vec4(-0.5, 0.0, 0.0, 0.0); + EmitVertex(); + + gl_Position = gl_in[0].gl_Position + viewProjectionMatrix * vec4(0.5, 0.0, 0.0, 0.0); + EmitVertex(); + + gl_Position = gl_in[0].gl_Position + viewProjectionMatrix * vec4(0.0, 2.0 + sin(time), 0.0, 0.0); + EmitVertex(); + + EndPrimitive(); +} diff --git a/data/shader/flame.vsh b/data/shader/flame.vsh new file mode 100644 index 0000000..09df02a --- /dev/null +++ b/data/shader/flame.vsh @@ -0,0 +1,9 @@ +#version 150 + +uniform mat4 viewProjectionMatrix; + +in vec3 aPosition; + +void main () { + gl_Position = viewProjectionMatrix * vec4(aPosition, 1.0); +} diff --git a/graphics.cc b/graphics.cc index a4da883..ec2dcba 100644 --- a/graphics.cc +++ b/graphics.cc @@ -49,6 +49,15 @@ void Graphics::init(Level* level) { depthCubeShader = ShaderProgramCreator("depth_cube") .attributeLocations(vao->getAttributeLocations()).create(); + flame_positions_ab = SharedArrayBuffer(new ArrayBuffer()); + flame_positions_ab->defineAttribute("aPosition", GL_FLOAT, 3); + flame_positions = SharedVertexArrayObject(new VertexArrayObject()); + flame_positions->setMode(GL_POINTS); + flame_positions->attachAllAttributes(flame_positions_ab); + + flameShader = ShaderProgramCreator("flame") + .attributeLocations(flame_positions->getAttributeLocations()).create(); + depthTexture = SharedTexture2D( new Texture2D(windowSize, GL_DEPTH_COMPONENT24)); depthTexture->setMinFilter(GL_NEAREST); depthTexture->setMagFilter(GL_NEAREST); @@ -157,7 +166,7 @@ void Graphics::render(double time) double nextUpdate = lastUpdate + lightUpdateDelay; if (time >= nextUpdate) { - updateShaderLights(); + updateLights(); lastUpdate = time; } @@ -187,6 +196,12 @@ void Graphics::render(double time) // render the level level->render(lightingShader, true, &lightingViewProjectionMatrix, &shadowVPs); + + // draw flames on top + flameShader->use(); + flameShader->setUniform("viewProjectionMatrix", lightingViewProjectionMatrix); + flameShader->setUniform("time", (float) time); + flame_positions->render(); } bool Graphics::compareLightDistances(Light a, Light b) { @@ -210,7 +225,7 @@ void Graphics::updateClosestLights() { } } -void Graphics::updateShaderLights() { +void Graphics::updateLights() { updateClosestLights(); if (closestLights.size() > 0) { lightingShader->setUniform("lightCount", (int) closestLights.size()); @@ -247,6 +262,17 @@ void Graphics::updateShaderLights() { lightingShader->setUniform("directionalIntensity", level->getDirectionalLight()->getIntensity()); } + float flamePositionsData[closestLights.size() * 3] = {}; + int flameIndex = 0; + for (unsigned int i = 0; isetDataElements(flameIndex, flamePositionsData); } void Graphics::resize(glm::uvec2 windowSize) { diff --git a/graphics.hh b/graphics.hh index a5b43ab..c3f4ff6 100644 --- a/graphics.hh +++ b/graphics.hh @@ -19,7 +19,7 @@ class Graphics { void resize(glm::uvec2 windowSize); float getFarPlane(); private: - void updateShaderLights(); + void updateLights(); void updateClosestLights(); bool compareLightDistances(Light a, Light b); void saveDepthBufferToDisk(int face, std::string); @@ -31,10 +31,13 @@ class Graphics { ACGL::OpenGL::SharedShaderProgram lightingShader; ACGL::OpenGL::SharedShaderProgram depthCubeShader; ACGL::OpenGL::SharedShaderProgram depthShader; + ACGL::OpenGL::SharedShaderProgram flameShader; ACGL::OpenGL::SharedTexture2D depthTexture; ACGL::OpenGL::SharedFrameBufferObject framebuffer; std::vector depth_cubeMaps; ACGL::OpenGL::SharedFrameBufferObject framebuffer_cube; + ACGL::OpenGL::SharedVertexArrayObject flame_positions; + ACGL::OpenGL::SharedArrayBuffer flame_positions_ab; int cube_size; unsigned int maxShadowRenderCount; Level* level;