vertex_shader_v5.glsl Full Listing#

vertex_shader_v5.glsl#
 1#version 330
 2
 3// Time since burst start
 4uniform float time;
 5
 6// (x, y) position passed in
 7in vec2 in_pos;
 8
 9// Velocity of particle
10in vec2 in_vel;
11
12// Color of particle
13in vec3 in_color;
14
15// Fade rate
16in float in_fade_rate;
17
18// Output the color to the fragment shader
19out vec4 color;
20
21void main() {
22
23    // Calculate alpha based on time and fade rate
24    float alpha = 1.0 - (in_fade_rate * time);
25    if(alpha < 0.0) alpha = 0;
26
27    // Set the RGBA color
28    color = vec4(in_color[0], in_color[1], in_color[2], alpha);
29
30    // Adjust velocity based on gravity
31    vec2 new_vel = in_vel;
32    new_vel[1] -= time * 1.1;
33
34    // Calculate a new position
35    vec2 new_pos = in_pos + (time * new_vel);
36
37    // Set the position. (x, y, z, w)
38    gl_Position = vec4(new_pos, 0.0, 1);
39}