From c950d6a54d301e685a3dcdbbc27df7c3aa74570d Mon Sep 17 00:00:00 2001 From: Andreas Ortmann Date: Fri, 30 Sep 2016 22:04:14 +0200 Subject: [PATCH] particles are even nicer now. --- data/shader/particle.frag | 3 --- data/shader/particle.vert | 8 ++++---- game/main.cpp | 3 ++- game/renderer_polygon_3d/particle_batch.cpp | 4 ++-- game/renderer_polygon_3d/renderer_polygon_3d.cpp | 10 +++++----- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/data/shader/particle.frag b/data/shader/particle.frag index f492427..1c3307e 100644 --- a/data/shader/particle.frag +++ b/data/shader/particle.frag @@ -15,7 +15,6 @@ vec3 hsv2rgb(vec3 c) void main() { - gl_FragColor = vec4(0.5+0.5*vertex.x, 0.5+0.5*vertex.y, 0.0, 1.0); float r = length(vertex); if (r > 1.0) { discard; @@ -26,8 +25,6 @@ void main() float v = max(0.0, (1.0-log(d))); float s = max(0.0, min(30.0 * sqrt(decay) * explCenterDist, 1.0)); - //v /= decay * 10.0*length(vertex-explCenter); - //v /= 1.0+2.0*length(vertex-explCenter); //v /= 1.0 + max(0.0, min(35.0*(decay-0.2), 1.0)) + 10.0 * explCenterDist; v /= 1.0 + 10.0 * explCenterDist; diff --git a/data/shader/particle.vert b/data/shader/particle.vert index 641d628..aecc600 100644 --- a/data/shader/particle.vert +++ b/data/shader/particle.vert @@ -22,11 +22,11 @@ void main() decay = age / halfAge; // faster particles are smaller - //float s = size * (1.0-length(in_velocity)/maxVelocity); - float s = size; + float speedScale = (1.0 - 0.8*length(in_velocity)/maxVelocity); + float finalSize = size * speedScale; vec2 base = in_vertex; - vec3 p = s*vec3(base, 0.0); - vec3 offset = (0.1*age + log(1.0+age*5.0)) * in_velocity + in_position; + vec3 p = finalSize*vec3(base, 0.0); + vec3 offset = (0.2*age + log(1.0+age*5.0)) * in_velocity + in_position; p += offset; gl_Position = vec4(p, 1.0); diff --git a/game/main.cpp b/game/main.cpp index d28c5e6..da4a2cf 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -77,7 +77,8 @@ int main(int argc, char *argv[]) asio::io_service io_service; Server s(io_service, game.state(), atoi(port) ); - GameWindow window(500, 500, &game); + //GameWindow window(500, 500, &game); + GameWindow window(750, 750, &game); window.set_maxfps(60.0); window.open(); diff --git a/game/renderer_polygon_3d/particle_batch.cpp b/game/renderer_polygon_3d/particle_batch.cpp index 70d366f..7d63ab4 100644 --- a/game/renderer_polygon_3d/particle_batch.cpp +++ b/game/renderer_polygon_3d/particle_batch.cpp @@ -137,9 +137,9 @@ namespace endofthejedi { glUniform1f(m_shader.location("age"), m_age); glUniform1f(m_shader.location("maxVelocity"), m_maxVelocity); - glUniform1f(m_shader.location("halfAge"), m_halfAge); + glUniform1f(m_shader.location("halfAge"), m_halfAge); glUniform1f(m_shader.location("size"), m_particleRadius); - glUniform3f(m_shader.location("center"), m_center.x, m_center.y, m_center.z); + glUniform3f(m_shader.location("explCenter"), m_center.x, m_center.y, m_center.z); bind(); diff --git a/game/renderer_polygon_3d/renderer_polygon_3d.cpp b/game/renderer_polygon_3d/renderer_polygon_3d.cpp index f7616cb..25b996b 100644 --- a/game/renderer_polygon_3d/renderer_polygon_3d.cpp +++ b/game/renderer_polygon_3d/renderer_polygon_3d.cpp @@ -95,7 +95,7 @@ namespace endofthejedi { { //float particleRadius = 0.005; //float particleRadius = 0.003; - float particleRadius = 0.01; + float particleRadius = 0.007; // TODO: use this as shader input too and make the area 2x around this // so that it stays hot/yellow for 2/3 of the time @@ -119,7 +119,7 @@ namespace endofthejedi { //glm::vec3 v = 0.5f*glm::vec3(sin(t), cos(t), util::randf_m1_1()); glm::vec3 v = glm::ballRand(maxVelocity); - v *= util::randf_0_1() * util::randf_0_1(); + v *= util::randf_0_1() * util::randf_0_1() * util::randf_0_1(); batch->setParticle(i, glm::vec3(pos, 0.0) + glm::ballRand(explSize), v); } @@ -141,12 +141,12 @@ namespace endofthejedi { } if (!gotIt) { - addExplosionEffect(expl->id, expl->position, 500, 5.0); + addExplosionEffect(expl->id, expl->position, 1000, 2.0); } } if (m_particles.size() == 0) { - addExplosionEffect(0, glm::vec2(0.0, 0.0), 1000, 5.0); + addExplosionEffect(0, glm::vec2(0.0, 0.0), 1000, 2.0); } std::vector rm; @@ -284,7 +284,7 @@ namespace endofthejedi { fade_out = 1.0 - (trace->age / trace->maxAge); } - glColor3f(0.0, 0.0, 1.0*fade_out); + glColor3f(0.0, 0.5*fade_out, 0.5*fade_out); glBegin(GL_LINE_STRIP); for (const game::Trace::TracePoint &tp : trace->points) { glVertex2f(tp.position.x, tp.position.y);