KlassischeKeplerKriege/data/shader/particle.vert
2016-09-30 22:04:14 +02:00

38 lines
No EOL
904 B
GLSL

#version 120
attribute vec2 in_vertex;
attribute vec3 in_position;
attribute vec3 in_velocity;
uniform float age;
uniform float size;
uniform float maxVelocity;
uniform float halfAge;
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, age+5.0*length(velocity)) / halfAge;
//decay = max(decay*decay, sqrt(decay));
decay = age / halfAge;
// faster particles are smaller
float speedScale = (1.0 - 0.8*length(in_velocity)/maxVelocity);
float finalSize = size * speedScale;
vec2 base = in_vertex;
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);
vertex = base.xy;
velocity = in_velocity;
explCenterDist = length(explCenter-offset);
}