KlassischeKeplerKriege/data/shader/particle.vert

37 lines
No EOL
830 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 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, age+5.0*length(velocity)) / maxAge;
//decay = max(decay*decay, sqrt(decay));
decay = age / maxAge;
// faster particles are smaller
float s = size * (1.0-length(in_velocity)/maxVelocity);
vec2 base = in_vertex;
vec3 p = s*vec3(base, 0.0);
vec3 offset = log(1.0+age) * in_velocity + in_position;
p += offset;
gl_Position = vec4(p, 1.0);
vertex = base.xy;
velocity = in_velocity;
explCenterDist = length(explCenter-offset);
}