summaryrefslogtreecommitdiff
path: root/gfx/gl/shaders/networkCommon.glsl
blob: faa95ec55b860fddbd16686b0896a34b2da1e836 (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
47
48
49
50
51
52
53
54
55
56
57
#ifndef NETWORK_COMMON_INCLUDED
#define NETWORK_COMMON_INCLUDED

uniform vec3[10] profile;
uniform float[10] texturePos;
uniform uint profileLength;

uniform mat4 viewProjection;
uniform ivec3 viewPoint;

uniform float clipDistance = 5000000;
uniform float flatDistance = 1000000;

out vec2 texCoord;
out vec3 rposition;

float
viewPointDist(const ivec3 position)
{
	return length(vec3(viewPoint - position));
}

float
segDist(const ivec3 a, const ivec3 b)
{
	return min(viewPointDist(a), viewPointDist(b));
}

#ifdef GL_GEOMETRY_SHADER // Begin: Geometry shader only function

void
doVertex(const ivec3 end, const uint v, const float texY, const mat2 rot)
{
	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();
}

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) {
		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);
		}
		EndPrimitive();
	}
}

#endif // End: Geometry shader only function

#endif