1
1
#shader vertex
2
2
#version 430 core
3
3
layout (location = 0 ) in vec4 a_position;
4
+ layout (location = 1 ) in vec4 a_normal;
4
5
layout (location = 2 ) in vec2 a_texCoord;
5
6
6
7
uniform mat4 u_modelMat;
7
8
uniform mat4 u_viewMat;
9
+ uniform mat4 u_normalMat;
8
10
uniform mat4 u_projectionMat;
9
11
10
-
11
12
out VS_OUT {
12
13
vec2 v_texCoord;
14
+ vec3 v_normal;
13
15
};
14
16
15
17
void main() {
16
18
gl_Position = u_projectionMat * u_viewMat * u_modelMat * a_position;
17
19
v_texCoord = a_texCoord;
20
+ v_normal = vec3 (normalize (a_normal));
18
21
}
19
22
20
23
#shader geometry
21
24
#version 430 core
22
25
23
26
in VS_OUT {
24
27
vec2 v_texCoord;
28
+ vec3 v_normal;
25
29
} gs_in[];
26
30
out GS_OUT {
27
31
vec2 v_texCoord;
28
32
};
29
33
34
+ uniform float u_timepoint;
35
+
30
36
layout (triangles) in ;
31
37
layout (triangle_strip, max_vertices= 3 ) out ;
38
+ vec4 explode(vec4 position, vec3 normal)
39
+ {
40
+ float magnitude = 2.0 ;
41
+ vec3 direction = normal * ((sin (u_timepoint) + 1.0 ) / 2 ) * magnitude;
42
+ return position + vec4 (direction, 0.0 );
43
+ }
44
+
45
+ vec3 GetNormal()
46
+ {
47
+ vec3 a = vec3 (gl_in[0 ].gl_Position ) - vec3 (gl_in[1 ].gl_Position );
48
+ vec3 b = vec3 (gl_in[2 ].gl_Position ) - vec3 (gl_in[1 ].gl_Position );
49
+ return normalize (cross (a, b));
50
+ }
32
51
void main() {
52
+ vec3 normal = GetNormal(); // FIXME: gs_in[0].v_normal is wrong
53
+
54
+ gl_Position = explode(gl_in[0 ].gl_Position , normal);
33
55
v_texCoord = gs_in[0 ].v_texCoord;
34
- gl_Position = gl_in[0 ].gl_Position ;
35
56
EmitVertex();
36
-
57
+ gl_Position = explode(gl_in[ 1 ]. gl_Position , normal);
37
58
v_texCoord = gs_in[1 ].v_texCoord;
38
- gl_Position = gl_in[1 ].gl_Position ;
39
59
EmitVertex();
40
-
60
+ gl_Position = explode(gl_in[ 2 ]. gl_Position , normal);
41
61
v_texCoord = gs_in[2 ].v_texCoord;
42
- gl_Position = gl_in[2 ].gl_Position ;
43
62
EmitVertex();
44
-
45
63
EndPrimitive();
46
64
}
47
65
@@ -59,6 +77,6 @@ in GS_OUT {
59
77
uniform Material u_material;
60
78
61
79
void main() {
62
- // o_color = texture(u_material.diffuse, v_texCoord);
63
- o_color = vec4 (1 );
80
+ o_color = texture(u_material.diffuse, v_texCoord);
81
+ // o_color = vec4(1);
64
82
}
0 commit comments