diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-01-20 13:00:49 +0000 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-01-20 15:08:43 +0000 |
commit | d1d1a4e349f18cd36406f75170dad87fbad2722a (patch) | |
tree | d950e7462e6718360c8a048e87ca7b14fe0258c1 /gfx/gl/shaders/networkCommon.glsl | |
parent | Implement complete network straight part shader (diff) | |
download | ilt-d1d1a4e349f18cd36406f75170dad87fbad2722a.tar.bz2 ilt-d1d1a4e349f18cd36406f75170dad87fbad2722a.tar.xz ilt-d1d1a4e349f18cd36406f75170dad87fbad2722a.zip |
Common code between straight/curve network geometry shaders
Diffstat (limited to 'gfx/gl/shaders/networkCommon.glsl')
-rw-r--r-- | gfx/gl/shaders/networkCommon.glsl | 41 |
1 files changed, 41 insertions, 0 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(); + } +} |