diff options
Diffstat (limited to 'gfx/gl')
-rw-r--r-- | gfx/gl/shaders/networkCommon.glsl | 41 | ||||
-rw-r--r-- | gfx/gl/shaders/networkCurve.gs | 10 | ||||
-rw-r--r-- | gfx/gl/shaders/networkCurve.vs | 10 | ||||
-rw-r--r-- | gfx/gl/shaders/networkStraight.gs | 38 |
4 files changed, 58 insertions, 41 deletions
diff --git a/gfx/gl/shaders/networkCommon.glsl b/gfx/gl/shaders/networkCommon.glsl new file mode 100644 index 0000000..2639eb1 --- /dev/null +++ b/gfx/gl/shaders/networkCommon.glsl @@ -0,0 +1,41 @@ +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); + +uniform mat4 viewProjection; +uniform ivec3 viewPoint; + +uniform float clipDistance = 5000000; +uniform float flatDistance = 1000000; + +out vec2 texCoord; +out vec3 rposition; + +void +doVertex(const ivec3 end, const int v, const float texY, const mat2 rot) +{ + rposition = vec3(rot * 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 +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) { + int vstep = (dist < flatDistance) ? 1 : profile.length() - 1; + for (int v = 0; v < profile.length(); v += vstep) { + doVertex(bpos, v, btexY, brot); + doVertex(apos, v, atexY, arot); + } + EndPrimitive(); + } +} diff --git a/gfx/gl/shaders/networkCurve.gs b/gfx/gl/shaders/networkCurve.gs index cf70b6e..c504df3 100644 --- a/gfx/gl/shaders/networkCurve.gs +++ b/gfx/gl/shaders/networkCurve.gs @@ -1,9 +1,19 @@ #version 330 core +flat in ivec3 apos[]; +flat in ivec3 bpos[]; +flat in ivec3 cpos[]; +flat in float reps[]; + layout(points) in; layout(triangle_strip, max_vertices = 255) out; +const mat2 rot = mat2(1); + +include(`networkCommon.glsl') + void main() { + doSeg(0, apos[0], bpos[0], 0.f, reps[0], rot, rot); } diff --git a/gfx/gl/shaders/networkCurve.vs b/gfx/gl/shaders/networkCurve.vs index b4324d6..d083765 100644 --- a/gfx/gl/shaders/networkCurve.vs +++ b/gfx/gl/shaders/networkCurve.vs @@ -5,16 +5,16 @@ layout(location = 1) in ivec3 v_bpos; layout(location = 2) in ivec3 v_centre; layout(location = 3) in float v_reps; -uniform mat4 viewProjection; - flat out ivec3 apos; flat out ivec3 bpos; -flat out mat2 rot; +flat out ivec3 cpos; flat out float reps; -flat out float dist; void main() { - dist = viewProjection[0][0]; + apos = v_apos; + bpos = v_bpos; + cpos = v_centre; + reps = v_reps; } diff --git a/gfx/gl/shaders/networkStraight.gs b/gfx/gl/shaders/networkStraight.gs index ccd456a..51df5fb 100644 --- a/gfx/gl/shaders/networkStraight.gs +++ b/gfx/gl/shaders/networkStraight.gs @@ -1,14 +1,5 @@ #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[]; @@ -17,35 +8,10 @@ flat in float dist[]; layout(points) in; 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(); -} +include(`networkCommon.glsl') 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(); - } + doSeg(dist[0], apos[0], bpos[0], 0.f, reps[0], rot[0], rot[0]); } |