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/network.fs | 6 ++++++ gfx/gl/shaders/networkCurve.gs | 9 +++++++++ gfx/gl/shaders/networkCurve.vs | 20 ++++++++++++++++++++ gfx/gl/shaders/networkStraight.gs | 15 +++++++++++++++ gfx/gl/shaders/networkStraight.vs | 20 ++++++++++++++++++++ 5 files changed, 70 insertions(+) create mode 100644 gfx/gl/shaders/network.fs create mode 100644 gfx/gl/shaders/networkCurve.gs create mode 100644 gfx/gl/shaders/networkCurve.vs create mode 100644 gfx/gl/shaders/networkStraight.gs create mode 100644 gfx/gl/shaders/networkStraight.vs (limited to 'gfx/gl/shaders') diff --git a/gfx/gl/shaders/network.fs b/gfx/gl/shaders/network.fs new file mode 100644 index 0000000..d427da2 --- /dev/null +++ b/gfx/gl/shaders/network.fs @@ -0,0 +1,6 @@ +#version 330 core + +void +main() +{ +} 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() +{ +} diff --git a/gfx/gl/shaders/networkCurve.vs b/gfx/gl/shaders/networkCurve.vs new file mode 100644 index 0000000..b4324d6 --- /dev/null +++ b/gfx/gl/shaders/networkCurve.vs @@ -0,0 +1,20 @@ +#version 330 core + +layout(location = 0) in ivec3 v_apos; +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 float reps; +flat out float dist; + +void +main() +{ + dist = viewProjection[0][0]; +} diff --git a/gfx/gl/shaders/networkStraight.gs b/gfx/gl/shaders/networkStraight.gs new file mode 100644 index 0000000..c2bfe3f --- /dev/null +++ b/gfx/gl/shaders/networkStraight.gs @@ -0,0 +1,15 @@ +#version 330 core + +flat in ivec3 apos[]; +flat in ivec3 bpos[]; +flat in mat2 rot[]; +flat in float reps[]; +flat in float dist[]; + +layout(points) in; +layout(triangle_strip, max_vertices = 20) out; + +void +main() +{ +} diff --git a/gfx/gl/shaders/networkStraight.vs b/gfx/gl/shaders/networkStraight.vs new file mode 100644 index 0000000..025ae8f --- /dev/null +++ b/gfx/gl/shaders/networkStraight.vs @@ -0,0 +1,20 @@ +#version 330 core + +layout(location = 0) in ivec3 v_apos; +layout(location = 1) in ivec3 v_bpos; +layout(location = 2) in mat2 v_rot; +layout(location = 4) in float v_reps; + +uniform mat4 viewProjection; + +flat out ivec3 apos; +flat out ivec3 bpos; +flat out mat2 rot; +flat out float reps; +flat out float dist; + +void +main() +{ + dist = viewProjection[0][0]; +} -- cgit v1.2.3 From 7f852de673bb687c5721c6a74367278f8ba62f56 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 20 Jan 2024 12:05:53 +0000 Subject: Implement complete network straight part shader --- gfx/gl/shaders/network.fs | 11 +++++++++++ gfx/gl/shaders/networkStraight.gs | 38 +++++++++++++++++++++++++++++++++++++- gfx/gl/shaders/networkStraight.vs | 8 ++++++-- 3 files changed, 54 insertions(+), 3 deletions(-) (limited to 'gfx/gl/shaders') 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)); } -- 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/networkCommon.glsl | 41 +++++++++++++++++++++++++++++++++++++++ gfx/gl/shaders/networkCurve.gs | 10 ++++++++++ gfx/gl/shaders/networkCurve.vs | 10 +++++----- gfx/gl/shaders/networkStraight.gs | 38 ++---------------------------------- 4 files changed, 58 insertions(+), 41 deletions(-) create mode 100644 gfx/gl/shaders/networkCommon.glsl (limited to 'gfx/gl/shaders') 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]); } -- 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/networkCommon.glsl | 45 ++++++++++++++++++++++----------------- gfx/gl/shaders/networkCurve.gs | 29 ++++++++++++++++++++++++- gfx/gl/shaders/networkCurve.vs | 6 ++++++ gfx/gl/shaders/networkStraight.vs | 6 +++--- 4 files changed, 63 insertions(+), 23 deletions(-) (limited to 'gfx/gl/shaders') diff --git a/gfx/gl/shaders/networkCommon.glsl b/gfx/gl/shaders/networkCommon.glsl index 2639eb1..e1811bc 100644 --- a/gfx/gl/shaders/networkCommon.glsl +++ b/gfx/gl/shaders/networkCommon.glsl @@ -16,26 +16,33 @@ uniform float flatDistance = 1000000; out vec2 texCoord; out vec3 rposition; -void -doVertex(const ivec3 end, const int v, const float texY, const mat2 rot) +float +segDist(const ivec3 a, const ivec3 b) { - 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(); + return min(distance(viewPoint, a), distance(viewPoint, b)); } -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); +ifelse( + TYPE, .gs, + // Begin: Geometry shader only function + 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(); } - EndPrimitive(); - } -} + + 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(); + } + } + // End: Geometry shader only function +) 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); } diff --git a/gfx/gl/shaders/networkCurve.vs b/gfx/gl/shaders/networkCurve.vs index d083765..6c56e93 100644 --- a/gfx/gl/shaders/networkCurve.vs +++ b/gfx/gl/shaders/networkCurve.vs @@ -4,11 +4,15 @@ layout(location = 0) in ivec3 v_apos; layout(location = 1) in ivec3 v_bpos; layout(location = 2) in ivec3 v_centre; layout(location = 3) in float v_reps; +layout(location = 4) in float v_aangle; +layout(location = 5) in float v_bangle; flat out ivec3 apos; flat out ivec3 bpos; flat out ivec3 cpos; flat out float reps; +flat out float aangle; +flat out float bangle; void main() @@ -17,4 +21,6 @@ main() bpos = v_bpos; cpos = v_centre; reps = v_reps; + aangle = v_aangle; + bangle = v_bangle; } diff --git a/gfx/gl/shaders/networkStraight.vs b/gfx/gl/shaders/networkStraight.vs index a0fa437..55f9c4f 100644 --- a/gfx/gl/shaders/networkStraight.vs +++ b/gfx/gl/shaders/networkStraight.vs @@ -5,14 +5,14 @@ layout(location = 1) in ivec3 v_bpos; layout(location = 2) in mat2 v_rot; layout(location = 4) in float v_reps; -uniform ivec3 viewPoint; - flat out ivec3 apos; flat out ivec3 bpos; flat out mat2 rot; flat out float reps; flat out float dist; +include(`networkCommon.glsl') + void main() { @@ -20,5 +20,5 @@ main() bpos = v_bpos; rot = v_rot; reps = v_reps; - dist = min(distance(viewPoint, v_apos), distance(viewPoint, v_bpos)); + dist = segDist(v_apos, v_bpos); } -- 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 ++-- gfx/gl/shaders/networkCurve.vs | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'gfx/gl/shaders') 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; diff --git a/gfx/gl/shaders/networkCurve.vs b/gfx/gl/shaders/networkCurve.vs index 6c56e93..f51bb87 100644 --- a/gfx/gl/shaders/networkCurve.vs +++ b/gfx/gl/shaders/networkCurve.vs @@ -6,6 +6,7 @@ layout(location = 2) in ivec3 v_centre; layout(location = 3) in float v_reps; layout(location = 4) in float v_aangle; layout(location = 5) in float v_bangle; +layout(location = 6) in float v_radius; flat out ivec3 apos; flat out ivec3 bpos; @@ -13,6 +14,7 @@ flat out ivec3 cpos; flat out float reps; flat out float aangle; flat out float bangle; +flat out float radius; void main() @@ -23,4 +25,5 @@ main() reps = v_reps; aangle = v_aangle; bangle = v_bangle; + radius = v_radius; } -- 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') 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') 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/networkCommon.glsl | 17 ++++++----------- gfx/gl/shaders/networkCurve.gs | 2 +- 2 files changed, 7 insertions(+), 12 deletions(-) (limited to 'gfx/gl/shaders') diff --git a/gfx/gl/shaders/networkCommon.glsl b/gfx/gl/shaders/networkCommon.glsl index e1811bc..7b55cad 100644 --- a/gfx/gl/shaders/networkCommon.glsl +++ b/gfx/gl/shaders/networkCommon.glsl @@ -1,11 +1,6 @@ -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 vec3[10] profile; +uniform float[10] texturePos; +uniform uint profileLength; uniform mat4 viewProjection; uniform ivec3 viewPoint; @@ -25,7 +20,7 @@ segDist(const ivec3 a, const ivec3 b) ifelse( TYPE, .gs, // Begin: Geometry shader only function - void doVertex(const ivec3 end, const int v, const float texY, const mat2 rot) { + void doVertex(const ivec3 end, const uint 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); @@ -36,8 +31,8 @@ ifelse( 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) { + 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); } 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 From 8391c63472641c67f59723d0a6706efff6fb17d4 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 23 Jan 2024 23:50:46 +0000 Subject: Fix network population of position in gBuffer Adds some rails to the basic test highlighting broken shadows --- gfx/gl/shaders/network.fs | 2 +- gfx/gl/shaders/networkCommon.glsl | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'gfx/gl/shaders') diff --git a/gfx/gl/shaders/network.fs b/gfx/gl/shaders/network.fs index e7d15b3..4e347b4 100644 --- a/gfx/gl/shaders/network.fs +++ b/gfx/gl/shaders/network.fs @@ -11,7 +11,7 @@ uniform ivec3 viewPoint; void main() { - gPosition = ivec4(viewPoint + rposition, 0); + gPosition = ivec4(viewPoint + rposition, 1); gNormal = vec4(0, 0, 1, 1); gAlbedoSpec = texture(texture0, texCoord); } diff --git a/gfx/gl/shaders/networkCommon.glsl b/gfx/gl/shaders/networkCommon.glsl index 7b55cad..0bc3c1c 100644 --- a/gfx/gl/shaders/networkCommon.glsl +++ b/gfx/gl/shaders/networkCommon.glsl @@ -21,9 +21,9 @@ ifelse( TYPE, .gs, // Begin: Geometry shader only function void doVertex(const ivec3 end, const uint 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); + 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(); } -- cgit v1.2.3