summaryrefslogtreecommitdiff
path: root/geometry_shader/shaders/explosion.gs
blob: 1883ad2c4811037866d3add5043c8bd4ba09cd5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#version 330 core
layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;

in VS_OUT {
    vec2 gtex_coords;
} gs_in[];

out vec2 ftex_coords;

uniform float time;

vec3
get_normal(void)
{
    vec3 a = vec3(gl_in[0].gl_Position)-vec3(gl_in[1].gl_Position);
    vec3 b = vec3(gl_in[2].gl_Position)-vec3(gl_in[1].gl_Position);
    return(normalize(cross(a, b)));
}

vec4
explode(vec4 position, vec3 normal)
{
    float magnitude = 0.2f;
    vec3 direction = normal*magnitude*((sin(time)+1.0f)/2.0f);
    vec4 result = position+vec4(direction, 0.0f);
    return(result);
}

void
main(void)
{
    vec3 normal = get_normal();
    gl_Position = explode(gl_in[0].gl_Position, normal);
    ftex_coords = gs_in[0].gtex_coords;
    EmitVertex();
    gl_Position = explode(gl_in[1].gl_Position, normal);
    ftex_coords = gs_in[1].gtex_coords;
    EmitVertex();
    gl_Position = explode(gl_in[2].gl_Position, normal);
    ftex_coords = gs_in[2].gtex_coords;
    EmitVertex();
    EndPrimitive();
}