From c7af64b7061c59c987958d0830838f1c05caeb29 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 19 Jan 2024 00:23:56 +0000 Subject: Render rail network using new shaders Non-functional, totally unimplemented at this stage --- gfx/gl/shaders/networkCurve.gs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 gfx/gl/shaders/networkCurve.gs (limited to 'gfx/gl/shaders/networkCurve.gs') diff --git a/gfx/gl/shaders/networkCurve.gs b/gfx/gl/shaders/networkCurve.gs new file mode 100644 index 0000000..cf70b6e --- /dev/null +++ b/gfx/gl/shaders/networkCurve.gs @@ -0,0 +1,9 @@ +#version 330 core + +layout(points) in; +layout(triangle_strip, max_vertices = 255) out; + +void +main() +{ +} -- cgit v1.2.3 From d1d1a4e349f18cd36406f75170dad87fbad2722a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 20 Jan 2024 13:00:49 +0000 Subject: Common code between straight/curve network geometry shaders --- gfx/gl/shaders/networkCurve.gs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gfx/gl/shaders/networkCurve.gs') 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); } -- cgit v1.2.3 From a19011b730ac6d770e3b42cde3a10961495a417d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 20 Jan 2024 20:10:12 +0000 Subject: Implement basic network curve part shader --- gfx/gl/shaders/networkCurve.gs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'gfx/gl/shaders/networkCurve.gs') diff --git a/gfx/gl/shaders/networkCurve.gs b/gfx/gl/shaders/networkCurve.gs index c504df3..82d8c59 100644 --- a/gfx/gl/shaders/networkCurve.gs +++ b/gfx/gl/shaders/networkCurve.gs @@ -4,6 +4,8 @@ flat in ivec3 apos[]; flat in ivec3 bpos[]; flat in ivec3 cpos[]; flat in float reps[]; +flat in float aangle[]; +flat in float bangle[]; layout(points) in; layout(triangle_strip, max_vertices = 255) out; @@ -12,8 +14,33 @@ const mat2 rot = mat2(1); include(`networkCommon.glsl') +mat2 +getRot(float angle) +{ + return mat2(cos(angle), sin(angle), -sin(angle), cos(angle)); +} + void main() { - doSeg(0, apos[0], bpos[0], 0.f, reps[0], rot, rot); + float segs = floor(255 / (profile.length() * 2)); + float radius = distance(cpos[0], apos[0]); + 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), 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); } -- cgit v1.2.3 From 35a9f035963458156c719dc16f4073b8244d66eb Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 20 Jan 2024 23:27:01 +0000 Subject: Pass curve link radius, no recalculate, its constant --- gfx/gl/shaders/networkCurve.gs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gfx/gl/shaders/networkCurve.gs') diff --git a/gfx/gl/shaders/networkCurve.gs b/gfx/gl/shaders/networkCurve.gs index 82d8c59..d373c0c 100644 --- a/gfx/gl/shaders/networkCurve.gs +++ b/gfx/gl/shaders/networkCurve.gs @@ -6,6 +6,7 @@ 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 = 255) out; @@ -24,7 +25,6 @@ void main() { float segs = floor(255 / (profile.length() * 2)); - float radius = distance(cpos[0], apos[0]); vec3 arcstep = vec3((bangle[0] - aangle[0]), // angle reps[0], // texture (bpos[0].z - apos[0].z)) // height @@ -35,7 +35,7 @@ main() 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), arc.z); + 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; -- cgit v1.2.3 From 7ce3368e918b085ef8894fb7aa68e36b07984b1d Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 21 Jan 2024 03:04:57 +0000 Subject: Use symbol GL_MAX_GEOMETRY_OUTPUT_VERTICES to lookup the implementation limit at runtime --- gfx/gl/shaders/networkCurve.gs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gfx/gl/shaders/networkCurve.gs') diff --git a/gfx/gl/shaders/networkCurve.gs b/gfx/gl/shaders/networkCurve.gs index d373c0c..326e8b6 100644 --- a/gfx/gl/shaders/networkCurve.gs +++ b/gfx/gl/shaders/networkCurve.gs @@ -9,7 +9,7 @@ flat in float bangle[]; flat in float radius[]; layout(points) in; -layout(triangle_strip, max_vertices = 255) out; +layout(triangle_strip, max_vertices = GL_MAX_GEOMETRY_OUTPUT_VERTICES) out; const mat2 rot = mat2(1); @@ -24,7 +24,7 @@ getRot(float angle) void main() { - float segs = floor(255 / (profile.length() * 2)); + float segs = floor(GL_MAX_GEOMETRY_OUTPUT_VERTICES / (profile.length() * 2)); vec3 arcstep = vec3((bangle[0] - aangle[0]), // angle reps[0], // texture (bpos[0].z - apos[0].z)) // height -- cgit v1.2.3 From fb3e42e2d13138865d5eb40a0f65ef14e67f995b Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 21 Jan 2024 03:27:01 +0000 Subject: Dynamic number of segments into curve render Simpler formula than the old one, neither scientific, needs to tests to demonstrate a decent result for whatever formula we use. --- gfx/gl/shaders/networkCurve.gs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'gfx/gl/shaders/networkCurve.gs') diff --git a/gfx/gl/shaders/networkCurve.gs b/gfx/gl/shaders/networkCurve.gs index 326e8b6..619625f 100644 --- a/gfx/gl/shaders/networkCurve.gs +++ b/gfx/gl/shaders/networkCurve.gs @@ -24,7 +24,8 @@ getRot(float angle) void main() { - float segs = floor(GL_MAX_GEOMETRY_OUTPUT_VERTICES / (profile.length() * 2)); + float segs = clamp( + round(reps[0] * radius[0] / 1000), 4, floor(GL_MAX_GEOMETRY_OUTPUT_VERTICES / (profile.length() * 2))); vec3 arcstep = vec3((bangle[0] - aangle[0]), // angle reps[0], // texture (bpos[0].z - apos[0].z)) // height -- cgit v1.2.3 From 961f69d8cda0364c04ec98efc70a6f21e0a091e6 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 22 Jan 2024 02:25:47 +0000 Subject: Bind the network profile in as uniforms Makes the network shaders generic to network type --- gfx/gl/shaders/networkCurve.gs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gfx/gl/shaders/networkCurve.gs') diff --git a/gfx/gl/shaders/networkCurve.gs b/gfx/gl/shaders/networkCurve.gs index 619625f..7cb6c42 100644 --- a/gfx/gl/shaders/networkCurve.gs +++ b/gfx/gl/shaders/networkCurve.gs @@ -25,7 +25,7 @@ void main() { float segs = clamp( - round(reps[0] * radius[0] / 1000), 4, floor(GL_MAX_GEOMETRY_OUTPUT_VERTICES / (profile.length() * 2))); + 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 -- cgit v1.2.3