summaryrefslogtreecommitdiff
path: root/gfx/gl/shaders/networkCurve.gs
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-01-24 00:46:57 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2024-01-24 00:46:57 +0000
commit17aa6053e641d006649f94bb60a834ce945f351e (patch)
treeb76f6fc642b749ee69d4be4b2e3f60e80c0ed7bc /gfx/gl/shaders/networkCurve.gs
parentAdd traits wrapper for setting uniforms (diff)
parentFix network population of position in gBuffer (diff)
downloadilt-17aa6053e641d006649f94bb60a834ce945f351e.tar.bz2
ilt-17aa6053e641d006649f94bb60a834ce945f351e.tar.xz
ilt-17aa6053e641d006649f94bb60a834ce945f351e.zip
Merge remote-tracking branch 'origin/instanced-networks'
Diffstat (limited to 'gfx/gl/shaders/networkCurve.gs')
-rw-r--r--gfx/gl/shaders/networkCurve.gs47
1 files changed, 47 insertions, 0 deletions
diff --git a/gfx/gl/shaders/networkCurve.gs b/gfx/gl/shaders/networkCurve.gs
new file mode 100644
index 0000000..7cb6c42
--- /dev/null
+++ b/gfx/gl/shaders/networkCurve.gs
@@ -0,0 +1,47 @@
+#version 330 core
+
+flat in ivec3 apos[];
+flat in ivec3 bpos[];
+flat in ivec3 cpos[];
+flat in float reps[];
+flat in float aangle[];
+flat in float bangle[];
+flat in float radius[];
+
+layout(points) in;
+layout(triangle_strip, max_vertices = GL_MAX_GEOMETRY_OUTPUT_VERTICES) out;
+
+const mat2 rot = mat2(1);
+
+include(`networkCommon.glsl')
+
+mat2
+getRot(float angle)
+{
+ return mat2(cos(angle), sin(angle), -sin(angle), cos(angle));
+}
+
+void
+main()
+{
+ float segs = clamp(
+ round(reps[0] * radius[0] / 1000), 4, floor(uint(GL_MAX_GEOMETRY_OUTPUT_VERTICES) / (profileLength * 2u)));
+ vec3 arcstep = vec3((bangle[0] - aangle[0]), // angle
+ reps[0], // texture
+ (bpos[0].z - apos[0].z)) // height
+ / segs;
+
+ ivec3 prevPos = apos[0];
+ mat2 prevRot = getRot(aangle[0]);
+ float prevTex = 0;
+ for (vec3 arc = arcstep; arc.y < reps[0] - 0.01; arc += arcstep) {
+ mat2 rot = getRot(arc.x + aangle[0]);
+ ivec3 pos = cpos[0] + ivec3(rot * vec2(radius[0], 0), arc.z);
+ float tex = arc.y;
+ doSeg(segDist(prevPos, pos), pos, prevPos, tex, prevTex, rot, prevRot);
+ prevPos = pos;
+ prevRot = rot;
+ prevTex = tex;
+ }
+ doSeg(segDist(prevPos, bpos[0]), bpos[0], prevPos, reps[0], prevTex, getRot(bangle[0]), prevRot);
+}