From bd49bd525f4c6c6c15c4142bf42d1dd38be6fc16 Mon Sep 17 00:00:00 2001 From: pryazha Date: Sun, 19 Jan 2025 17:33:44 +0500 Subject: initial commit --- geometry_shader/shaders/explosion.gs | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 geometry_shader/shaders/explosion.gs (limited to 'geometry_shader/shaders/explosion.gs') diff --git a/geometry_shader/shaders/explosion.gs b/geometry_shader/shaders/explosion.gs new file mode 100644 index 0000000..1883ad2 --- /dev/null +++ b/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(); +} -- cgit v1.2.3