summaryrefslogtreecommitdiff
path: root/gfx/gl/shaders/networkCurve.gs
blob: 326e8b62b34426ebd14d44ef410ea4423ef9aa8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#version 330 core

flat in ivec3 apos[];
flat in ivec3 bpos[];
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 = GL_MAX_GEOMETRY_OUTPUT_VERTICES) out;

const mat2 rot = mat2(1);

include(`networkCommon.glsl')

mat2
getRot(float angle)
{
	return mat2(cos(angle), sin(angle), -sin(angle), cos(angle));
}

void
main()
{
	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
			/ 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], 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);
}