making code for particle batch modular.

This commit is contained in:
Andreas Ortmann 2016-10-02 17:22:47 +02:00
parent a81b549126
commit 57e6e56217
4 changed files with 73 additions and 46 deletions

View file

@ -1,7 +1,8 @@
#version 120
attribute vec2 in_vertex;
attribute vec3 in_position;
attribute vec3 in_velocity;
attribute vec2 in_geometry;
attribute vec3 in_position;
attribute vec3 in_velocity;
attribute float in_maxDist;
uniform float age;
uniform float size;
@ -28,11 +29,17 @@ void main()
decay = ageMod / halfAge;
// faster particles are smaller
// TODO: scale by time too! scale down fast after 3 halfAges
float scaleBySpeed = (1.0 - 0.95*length(in_velocity)/maxVelocity);
float finalSize = size * scaleBySpeed;
vec2 base = in_vertex;
vec2 base = in_geometry;
vec3 p = finalSize*vec3(base, 0.0);
vec3 offset = (0.2*age + log(1.0+age*5.0)) * in_velocity + in_position;
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;
p += offset;
gl_Position = vec4(p, 1.0);