2016-09-29 02:24:14 +00:00
|
|
|
#version 120
|
2016-10-02 15:22:47 +00:00
|
|
|
attribute vec2 in_geometry;
|
|
|
|
attribute vec3 in_position;
|
|
|
|
attribute vec3 in_velocity;
|
|
|
|
attribute float in_maxDist;
|
2016-09-30 18:19:10 +00:00
|
|
|
|
2016-09-30 19:24:06 +00:00
|
|
|
uniform float age;
|
|
|
|
uniform float size;
|
|
|
|
uniform float maxVelocity;
|
2016-09-30 19:48:15 +00:00
|
|
|
uniform float halfAge;
|
2016-09-30 19:24:06 +00:00
|
|
|
uniform vec3 explCenter;
|
|
|
|
|
2016-09-30 18:19:10 +00:00
|
|
|
varying float decay;
|
2016-09-30 19:24:06 +00:00
|
|
|
varying vec3 velocity;
|
|
|
|
varying vec2 vertex;
|
|
|
|
varying float explCenterDist;
|
|
|
|
|
2016-10-02 09:00:03 +00:00
|
|
|
uniform float aspectRatio;
|
|
|
|
|
2016-09-30 19:24:06 +00:00
|
|
|
// TODO: rotate to face the user!
|
2016-09-29 02:24:14 +00:00
|
|
|
void main()
|
|
|
|
{
|
2016-09-30 20:25:37 +00:00
|
|
|
// add a bit variation to the decay compution by adding part of the initial
|
|
|
|
// position to the age
|
|
|
|
float ageMod = age + mod(20.0*in_position.z + 10.0*in_position.x + in_position.y, 0.5);
|
|
|
|
|
2016-09-30 19:48:15 +00:00
|
|
|
//decay = min(1.0, age+5.0*length(velocity)) / halfAge;
|
2016-09-30 18:19:10 +00:00
|
|
|
//decay = max(decay*decay, sqrt(decay));
|
2016-09-30 20:25:37 +00:00
|
|
|
decay = ageMod / halfAge;
|
2016-09-30 18:19:10 +00:00
|
|
|
|
2016-09-30 19:24:06 +00:00
|
|
|
// faster particles are smaller
|
2016-10-02 15:22:47 +00:00
|
|
|
// TODO: scale by time too! scale down fast after 3 halfAges
|
2016-09-30 20:30:50 +00:00
|
|
|
float scaleBySpeed = (1.0 - 0.95*length(in_velocity)/maxVelocity);
|
2016-10-02 18:10:43 +00:00
|
|
|
float finalSize = size * scaleBySpeed * (1.0-max(0.0, decay-3.0*halfAge)/2.0);
|
2016-10-02 15:22:47 +00:00
|
|
|
vec2 base = in_geometry;
|
2016-10-02 18:10:43 +00:00
|
|
|
vec3 p = vec3(finalSize*base, 0.0);
|
2016-10-02 15:22:47 +00:00
|
|
|
vec3 move = (0.2*age + log(1.0+age*5.0)) * in_velocity;
|
|
|
|
float md = length(move);
|
|
|
|
if (md > in_maxDist) {
|
|
|
|
move *= in_maxDist / md;
|
|
|
|
}
|
|
|
|
vec3 offset = move + in_position;
|
2016-09-30 19:24:06 +00:00
|
|
|
p += offset;
|
|
|
|
|
|
|
|
gl_Position = vec4(p, 1.0);
|
2016-09-29 07:05:35 +00:00
|
|
|
|
2016-09-30 19:24:06 +00:00
|
|
|
vertex = base.xy;
|
2016-09-29 07:05:35 +00:00
|
|
|
velocity = in_velocity;
|
2016-09-30 19:24:06 +00:00
|
|
|
|
2016-10-02 09:00:03 +00:00
|
|
|
explCenterDist = length(explCenter - offset);
|
2016-09-29 10:28:35 +00:00
|
|
|
}
|