forked from przemyslawzaworski/Unity3D-CG-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtessellation.shader
77 lines (70 loc) · 1.86 KB
/
tessellation.shader
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
/*references: http://in2gpu.com/2014/07/12/tessellation-tutorial-opengl-4-3/
http://catlikecoding.com/unity/tutorials/advanced-rendering/tessellation/
https://github.com/Unity-Technologies/HLSLcc */
Shader "OpenGL4_triangle_tessellation"
{
Properties
{
_factor("Tessellation scale",Range(1.0,64.0)) = 4.0
}
SubShader
{
Pass
{
GLSLPROGRAM
#version 400
uniform float _factor;
#ifdef VERTEX
in vec4 in_POSITION0;
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * in_POSITION0;
}
#endif
#ifdef HULL //GLSL Tessellation Control Shader
layout (vertices = 3) out;
void main()
{
if (gl_InvocationID == 0)
{
gl_TessLevelInner[0] = _factor; //Inside tessellation factor
gl_TessLevelOuter[0] = _factor; //Edge tessellation factor
gl_TessLevelOuter[1] = _factor; //Edge tessellation factor
gl_TessLevelOuter[2] = _factor; //Edge tessellation factor
}
gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
}
#endif
#ifdef DOMAIN //GLSL Tessellation Evaluation Shader
layout (triangles, equal_spacing, cw) in;
void main()
{
gl_Position=(gl_TessCoord.x*gl_in[0].gl_Position+gl_TessCoord.y*gl_in[1].gl_Position+gl_TessCoord.z*gl_in[2].gl_Position);
}
#endif
#ifdef GEOMETRY //geometry shader for rendering wireframe
layout(triangles) in;
layout(line_strip, max_vertices = 3) out;
void main()
{
for(int i = 0; i < gl_in.length(); ++i)
{
gl_Position = gl_in[i].gl_Position;
EmitVertex();
}
gl_Position = gl_in[0].gl_Position;
EmitVertex();
EndPrimitive();
}
#endif
#ifdef FRAGMENT
out vec4 color;
void main()
{
color = vec4(0.0, 0.0, 0.0, 1.0);
}
#endif
ENDGLSL
}
}
}