summaryrefslogtreecommitdiff
path: root/gfx/gl/shaders/networkCommon.glsl
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/networkCommon.glsl
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/networkCommon.glsl')
-rw-r--r--gfx/gl/shaders/networkCommon.glsl43
1 files changed, 43 insertions, 0 deletions
diff --git a/gfx/gl/shaders/networkCommon.glsl b/gfx/gl/shaders/networkCommon.glsl
new file mode 100644
index 0000000..0bc3c1c
--- /dev/null
+++ b/gfx/gl/shaders/networkCommon.glsl
@@ -0,0 +1,43 @@
+uniform vec3[10] profile;
+uniform float[10] texturePos;
+uniform uint profileLength;
+
+uniform mat4 viewProjection;
+uniform ivec3 viewPoint;
+
+uniform float clipDistance = 5000000;
+uniform float flatDistance = 1000000;
+
+out vec2 texCoord;
+out vec3 rposition;
+
+float
+segDist(const ivec3 a, const ivec3 b)
+{
+ return min(distance(viewPoint, a), distance(viewPoint, b));
+}
+
+ifelse(
+ TYPE, .gs,
+ // Begin: Geometry shader only function
+ void doVertex(const ivec3 end, const uint v, const float texY, const mat2 rot) {
+ ivec3 vpos = end + ivec3(rot * profile[v].xy, profile[v].z);
+ rposition = vpos - viewPoint;
+ gl_Position = viewProjection * vec4(rposition, 1);
+ texCoord = vec2(texturePos[v], texY);
+ EmitVertex();
+ }
+
+ void doSeg(const float dist, const ivec3 apos, const ivec3 bpos, const float atexY, const float btexY,
+ const mat2 arot, const mat2 brot) {
+ if (dist < clipDistance) {
+ uint vstep = (dist < flatDistance) ? 1u : profileLength - 1u;
+ for (uint v = 0u; v < profileLength; v += vstep) {
+ doVertex(bpos, v, btexY, brot);
+ doVertex(apos, v, atexY, arot);
+ }
+ EndPrimitive();
+ }
+ }
+ // End: Geometry shader only function
+)