very nice particles with heat in the center of the explosion and moving in 3d space.

This commit is contained in:
Andreas Ortmann 2016-09-30 21:24:06 +02:00
parent 067cfb6203
commit a6b9078c21
6 changed files with 97 additions and 37 deletions

View file

@ -1,8 +1,11 @@
#version 120
varying vec2 vertex;
varying vec2 velocity;
varying vec2 vertex;
varying vec3 velocity;
varying float decay;
varying float explCenterDist;
uniform vec3 explCenter;
vec3 hsv2rgb(vec3 c)
{
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
@ -17,10 +20,16 @@ void main()
if (r > 1.0) {
discard;
}
float d = decay;
float d = decay/(1.0+max(0.0, 1.0-explCenterDist));
float h = (1.0-d)/6.0;
float v = max(0.0, (1.0-d/2.0) - 0.1*(d*d*d));
float v = max(0.0, (1.0-log(d)));
float s = 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)) * 15.0 * explCenterDist;
gl_FragColor = vec4(hsv2rgb(vec3(h, s, v)), 1.0);
//gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0);

View file

@ -1,26 +1,37 @@
#version 120
attribute vec2 in_vertex;
attribute vec2 in_position;
attribute vec2 in_velocity;
attribute vec3 in_position;
attribute vec3 in_velocity;
uniform float maxAge;
varying float decay;
varying vec2 velocity;
varying vec2 vertex;
uniform float time;
uniform float age;
uniform float size;
uniform float maxVelocity;
uniform float maxAge;
uniform vec3 explCenter;
varying float decay;
varying vec3 velocity;
varying vec2 vertex;
varying float explCenterDist;
// TODO: rotate to face the user!
void main()
{
//decay = min(1.0, time+5.0*length(velocity)) / maxAge;
//decay = min(1.0, age+5.0*length(velocity)) / maxAge;
//decay = max(decay*decay, sqrt(decay));
decay = time / maxAge;
decay = age / maxAge;
// faster particles are smaller
float s = size * (1.0-length(in_velocity)/maxVelocity);
vec2 base = in_vertex;
vec2 p = size*base;
p += log(1.0+time) * in_velocity;
p += in_position;
gl_Position = vec4(p, 0.0, 1.0);
vec3 p = s*vec3(base, 0.0);
vec3 offset = log(1.0+age) * in_velocity + in_position;
p += offset;
vertex = base;
gl_Position = vec4(p, 1.0);
vertex = base.xy;
velocity = in_velocity;
explCenterDist = length(explCenter-offset);
}