summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-01-20 12:05:53 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2024-01-20 15:08:43 +0000
commit7f852de673bb687c5721c6a74367278f8ba62f56 (patch)
tree40b4e903854f4457191af6a4bb28abfd18b69fc7 /gfx
parentUpdate network with vertex array (diff)
downloadilt-7f852de673bb687c5721c6a74367278f8ba62f56.tar.bz2
ilt-7f852de673bb687c5721c6a74367278f8ba62f56.tar.xz
ilt-7f852de673bb687c5721c6a74367278f8ba62f56.zip
Implement complete network straight part shader
Diffstat (limited to 'gfx')
-rw-r--r--gfx/gl/shaders/network.fs11
-rw-r--r--gfx/gl/shaders/networkStraight.gs38
-rw-r--r--gfx/gl/shaders/networkStraight.vs8
3 files changed, 54 insertions, 3 deletions
diff --git a/gfx/gl/shaders/network.fs b/gfx/gl/shaders/network.fs
index d427da2..e7d15b3 100644
--- a/gfx/gl/shaders/network.fs
+++ b/gfx/gl/shaders/network.fs
@@ -1,6 +1,17 @@
#version 330 core
+#extension GL_ARB_shading_language_420pack : enable
+
+include(`materialOut.glsl')
+in vec3 rposition;
+in vec2 texCoord;
+
+layout(binding = 0) uniform sampler2D texture0;
+uniform ivec3 viewPoint;
void
main()
{
+ gPosition = ivec4(viewPoint + rposition, 0);
+ gNormal = vec4(0, 0, 1, 1);
+ gAlbedoSpec = texture(texture0, texCoord);
}
diff --git a/gfx/gl/shaders/networkStraight.gs b/gfx/gl/shaders/networkStraight.gs
index c2bfe3f..ccd456a 100644
--- a/gfx/gl/shaders/networkStraight.gs
+++ b/gfx/gl/shaders/networkStraight.gs
@@ -1,5 +1,14 @@
#version 330 core
+const float RAIL_HEIGHT = 250;
+const vec3[] profile = vec3[]( //
+ vec3(-1900.F, 0.F, 0.F), //
+ vec3(-608.F, 0.F, RAIL_HEIGHT), //
+ vec3(0, 0.F, RAIL_HEIGHT * .7F), //
+ vec3(608.F, 0.F, RAIL_HEIGHT), //
+ vec3(1900.F, 0.F, 0.F));
+const float[profile.length()] texturePos = float[](0, 0.34, 0.5, 0.65, 1);
+
flat in ivec3 apos[];
flat in ivec3 bpos[];
flat in mat2 rot[];
@@ -7,9 +16,36 @@ flat in float reps[];
flat in float dist[];
layout(points) in;
-layout(triangle_strip, max_vertices = 20) out;
+layout(triangle_strip, max_vertices = 10) out;
+
+uniform mat4 viewProjection;
+uniform ivec3 viewPoint;
+
+uniform int clipDistance = 5000000;
+uniform int flatDistance = 1000000;
+
+out vec2 texCoord;
+out vec3 rposition;
+
+void
+doEnd(const ivec3 end, int v, float texY)
+{
+ rposition = vec3(rot[0] * profile[v].xy, profile[v].z);
+ ivec3 vpos = end + ivec3(rposition);
+ gl_Position = viewProjection * vec4(vpos - viewPoint, 1);
+ texCoord = vec2(texturePos[v], texY);
+ EmitVertex();
+}
void
main()
{
+ if (dist[0] < clipDistance) {
+ int vstep = (dist[0] < flatDistance) ? 1 : profile.length() - 1;
+ for (int v = 0; v < profile.length(); v += vstep) {
+ doEnd(bpos[0], v, reps[0]);
+ doEnd(apos[0], v, 0);
+ }
+ EndPrimitive();
+ }
}
diff --git a/gfx/gl/shaders/networkStraight.vs b/gfx/gl/shaders/networkStraight.vs
index 025ae8f..a0fa437 100644
--- a/gfx/gl/shaders/networkStraight.vs
+++ b/gfx/gl/shaders/networkStraight.vs
@@ -5,7 +5,7 @@ layout(location = 1) in ivec3 v_bpos;
layout(location = 2) in mat2 v_rot;
layout(location = 4) in float v_reps;
-uniform mat4 viewProjection;
+uniform ivec3 viewPoint;
flat out ivec3 apos;
flat out ivec3 bpos;
@@ -16,5 +16,9 @@ flat out float dist;
void
main()
{
- dist = viewProjection[0][0];
+ apos = v_apos;
+ bpos = v_bpos;
+ rot = v_rot;
+ reps = v_reps;
+ dist = min(distance(viewPoint, v_apos), distance(viewPoint, v_bpos));
}