From f9ad6fa902c1167d7622ee7af2617d14b62bee21 Mon Sep 17 00:00:00 2001 From: pryazha Date: Wed, 19 Feb 2025 22:26:48 +0500 Subject: quite a lot of changes that I, of course, are not going to describe;) --- .../8.geometry_shader/shaders/explosion.geom | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 advanced_opengl/8.geometry_shader/shaders/explosion.geom (limited to 'advanced_opengl/8.geometry_shader/shaders/explosion.geom') diff --git a/advanced_opengl/8.geometry_shader/shaders/explosion.geom b/advanced_opengl/8.geometry_shader/shaders/explosion.geom new file mode 100644 index 0000000..e708591 --- /dev/null +++ b/advanced_opengl/8.geometry_shader/shaders/explosion.geom @@ -0,0 +1,41 @@ +#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.2; + vec3 direction = normal*magnitude*((sin(time)+1.0)/2.0); + vec4 result = position+vec4(direction, 0.0); + 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