diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2026-01-31 02:51:16 +0000 |
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2026-01-31 02:51:16 +0000 |
| commit | bc0958cc863083b4082161bf12456fdf28ab1c77 (patch) | |
| tree | f970782f232d86325f14a36b83125791f24335af /gfx/gl/shaders/spotLight.geom | |
| parent | Initial commit using tesselation shader to create curves (diff) | |
| download | ilt-bc0958cc863083b4082161bf12456fdf28ab1c77.tar.bz2 ilt-bc0958cc863083b4082161bf12456fdf28ab1c77.tar.xz ilt-bc0958cc863083b4082161bf12456fdf28ab1c77.zip | |
Rename shader source in keeping with glsl expectations
Swaps name/type of generated files to match class names and source
files.
Diffstat (limited to 'gfx/gl/shaders/spotLight.geom')
| -rw-r--r-- | gfx/gl/shaders/spotLight.geom | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/gfx/gl/shaders/spotLight.geom b/gfx/gl/shaders/spotLight.geom new file mode 100644 index 0000000..fec191e --- /dev/null +++ b/gfx/gl/shaders/spotLight.geom @@ -0,0 +1,66 @@ +#version 460 core + +const vec3[] pyramid = vec3[]( // four-sided + vec3(0, 0, 0), // Apex + vec3(-1, 1, 1), // Back-left + vec3(-1, -1, 1), // Front-left + vec3(1, 1, 1), // Back-right + vec3(1, -1, 1) // Front-right +); +uniform mat4 viewProjection; +uniform ivec3 viewPoint; +flat in ivec3 position[]; +flat in vec3 direction[]; +flat in vec3 colour[]; +flat in float size[]; +flat in float kq[]; +flat in vec2 arc[]; +layout(points) in; + +layout(triangle_strip, max_vertices = 8) out; +flat out vec4 geo_centre; +flat out vec4 geo_direction; +flat out vec3 geo_colour; +flat out float geo_kq; + +vec3 +perp(vec3 a) +{ + return normalize(a.x != 0 ? vec3((a.y + a.z) / -a.x, 1, 1) + : a.y != 0 ? vec3(1, (a.x + a.z) / -a.y, 1) + : vec3(1, 1, (a.x + a.y) / -a.z)); +} + +void +doVertex(vec4 ndcpos) +{ + gl_Position = ndcpos; + geo_centre = vec4(position[0], size[0]); + geo_direction = vec4(direction[0], arc[0].x); + geo_colour = colour[0]; + geo_kq = kq[0]; + EmitVertex(); +} + +void +main() +{ + const float base = size[0] * arc[0].y; + const vec3 offx = perp(direction[0]); + const vec3 offy = cross(direction[0], offx); + vec4 out_py[pyramid.length()]; + for (int i = 0; i < pyramid.length(); ++i) { + const vec3 p = pyramid[i]; + const vec3 edge = (offx * base * p.x) + (offy * base * p.y) + (direction[0] * size[0] * p.z); + out_py[i] = viewProjection * (gl_in[0].gl_Position + vec4(edge, 1)); + } + doVertex(out_py[3]); + doVertex(out_py[0]); + doVertex(out_py[1]); + doVertex(out_py[2]); + doVertex(out_py[3]); + doVertex(out_py[4]); + doVertex(out_py[0]); + doVertex(out_py[2]); + EndPrimitive(); +} |
