summaryrefslogtreecommitdiff
path: root/advanced_opengl/8.geometry_shader/shaders/explosion.gs
diff options
context:
space:
mode:
authorpryazha <pryadeiniv@mail.ru>2025-01-23 19:39:54 +0500
committerpryazha <pryadeiniv@mail.ru>2025-01-23 19:39:54 +0500
commitbf1c59565096ac9774493846cfb15e259d3b0e66 (patch)
tree82e8182af128580b6f38437feccba8c0f48abdc1 /advanced_opengl/8.geometry_shader/shaders/explosion.gs
parent1ee094199af9c169e1ccaa53c7b0c186c4a3639e (diff)
restructure
Diffstat (limited to 'advanced_opengl/8.geometry_shader/shaders/explosion.gs')
-rw-r--r--advanced_opengl/8.geometry_shader/shaders/explosion.gs44
1 files changed, 44 insertions, 0 deletions
diff --git a/advanced_opengl/8.geometry_shader/shaders/explosion.gs b/advanced_opengl/8.geometry_shader/shaders/explosion.gs
new file mode 100644
index 0000000..1883ad2
--- /dev/null
+++ b/advanced_opengl/8.geometry_shader/shaders/explosion.gs
@@ -0,0 +1,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();
+}