-
Notifications
You must be signed in to change notification settings - Fork 0
/
bezier.tesc
78 lines (61 loc) · 2.09 KB
/
bezier.tesc
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#version 460 core
layout (std140, binding = 0) uniform matrices
{
mat4 modelingMatrix;
mat4 viewingMatrix;
mat4 projectionMatrix;
vec3 eyePos;
};
layout (std140, binding = 1) uniform tessLevels
{
float tessInner;
float tessOuter;
float levelOfDetail;
int viewDependantTesselation;
float cameraFov;
};
layout (vertices = 16) out;
in VS_TESC_INTERFACE
{
vec3 fragWorldPos;
} tesc_in[];
out TESC_TESE_INTERFACE
{
vec3 fragWorldPos;
} tesc_out[];
bool isVisible(vec4 p);
float getLOD(vec4 p0, vec4 p1);
float LOD = 1.0f * levelOfDetail;
void main()
{
if(viewDependantTesselation == 0)
{
gl_TessLevelOuter[0] = tessOuter * LOD;
gl_TessLevelOuter[1] = tessOuter * LOD;
gl_TessLevelOuter[2] = tessOuter * LOD;
gl_TessLevelOuter[3] = tessOuter * LOD;
gl_TessLevelInner[0] = tessInner * LOD;
gl_TessLevelInner[1] = tessInner * LOD;
}
else
{
gl_TessLevelOuter[0] = LOD * getLOD(vec4(tesc_in[0].fragWorldPos, 1.f),
vec4(tesc_in[3].fragWorldPos, 1.f));
gl_TessLevelOuter[1] = LOD * getLOD(vec4(tesc_in[0].fragWorldPos, 1.f),
vec4(tesc_in[12].fragWorldPos, 1.f));
gl_TessLevelOuter[2] = LOD * getLOD(vec4(tesc_in[12].fragWorldPos, 1.f),
vec4(tesc_in[15].fragWorldPos, 1.f));
gl_TessLevelOuter[3] = LOD * getLOD(vec4(tesc_in[3].fragWorldPos, 1.f),
vec4(tesc_in[15].fragWorldPos, 1.f));
gl_TessLevelInner[0] = (gl_TessLevelOuter[1] + gl_TessLevelOuter[3])/2.f;
gl_TessLevelInner[1] = (gl_TessLevelOuter[0] + gl_TessLevelOuter[2])/2.f;
}
tesc_out[gl_InvocationID].fragWorldPos = tesc_in[gl_InvocationID].fragWorldPos;
gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
}
float getLOD(vec4 p0, vec4 p1)
{
precise float d1 = distance( (p0 + p1)/2.f, vec4(eyePos, 1.f));
precise float zoomScale = 90.f/cameraFov;
return ceil(40.f/(d1*d1)) * zoomScale;
}