summaryrefslogtreecommitdiff
path: root/gfx/gl/shaders/pointLight.gs
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-11-23 19:07:18 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2022-11-23 19:07:18 +0000
commit50d6f63fb28c82a35e68914fe941b685d26f6e89 (patch)
tree4a86d800d36341aedee7319307675cd1e6e5b784 /gfx/gl/shaders/pointLight.gs
parentSupport setting a viewPort uniform for those shaders which need it (diff)
downloadilt-50d6f63fb28c82a35e68914fe941b685d26f6e89.tar.bz2
ilt-50d6f63fb28c82a35e68914fe941b685d26f6e89.tar.xz
ilt-50d6f63fb28c82a35e68914fe941b685d26f6e89.zip
Add rendering support for point lights
Diffstat (limited to 'gfx/gl/shaders/pointLight.gs')
-rw-r--r--gfx/gl/shaders/pointLight.gs44
1 files changed, 44 insertions, 0 deletions
diff --git a/gfx/gl/shaders/pointLight.gs b/gfx/gl/shaders/pointLight.gs
new file mode 100644
index 0000000..2bd71e9
--- /dev/null
+++ b/gfx/gl/shaders/pointLight.gs
@@ -0,0 +1,44 @@
+#version 330 core
+#extension GL_ARB_enhanced_layouts : enable
+#extension GL_ARB_shading_language_420pack : enable
+
+const int maxv = 128;
+const int maxarcs = (maxv / 2) - 1;
+const int minarcs = 10;
+const float tau = radians(360);
+const float scale = 150;
+uniform ivec4 viewPort;
+
+in vec3 centre[];
+in float size[];
+layout(points) in;
+
+layout(triangle_strip, max_vertices = maxv) out;
+out vec3 geo_centre;
+
+void
+doSeg(float arc, vec2 radius)
+{
+ gl_Position = gl_in[0].gl_Position;
+ geo_centre = centre[0];
+ EmitVertex();
+
+ const vec2 off = vec2(cos(arc), sin(arc)) * radius;
+ gl_Position.xy = gl_in[0].gl_Position.xy + off;
+ geo_centre = centre[0];
+ EmitVertex();
+}
+
+void
+main()
+{
+ const vec2 display = viewPort.zw;
+ const vec2 ratio = vec2(1, display.x / display.y);
+ const vec2 radius = (size[0] * ratio * scale) / gl_in[0].gl_Position.w;
+ const float step = tau / clamp(radius.x, minarcs, maxarcs);
+ for (float arc = 0; arc < tau; arc += step) {
+ doSeg(arc, radius);
+ }
+ doSeg(tau, radius);
+ EndPrimitive();
+}