2 # * tessellation of quads
3 # * different number of input (pre-TCS) and output (post-TCS) control points
4 # * all inputs are read in each shader
5 # * gl_PatchVerticesIn in TCS and TES
8 # * There is a patch with 4 control points on the input (quad).
9 # * The TCS subdivides the patch into 9 control points (4 tiles in a 2x2 pattern).
10 # * A color is assigned to each tile, which is held in the upper-left corner
12 # * The 2x2 pattern is still a single quad from the tessellator point of view.
13 # * The tessellator should create 21*21 quads (21*21*2 triangles).
14 # * The quad should be tessellated such that you can clearly see 4 tiles that
15 # have different colors. The triangles in the middle should smoothly blend
16 # colors from both tiles (caused by interpolation of varyings).
21 GL_ARB_tessellation_shader
29 gl_Position = vec4(vertex.xy, 0, 1);
32 [tessellation control shader]
34 #extension GL_ARB_tessellation_shader : require
36 layout(vertices = 9) out;
44 gl_TessLevelInner[0] = t;
45 gl_TessLevelInner[1] = t;
47 gl_TessLevelOuter[0] = t;
48 gl_TessLevelOuter[1] = t;
49 gl_TessLevelOuter[2] = t;
50 gl_TessLevelOuter[3] = t;
52 float x = float(gl_InvocationID % 3) / 2;
53 float y = float(gl_InvocationID / 3) / 2;
55 vec4 x1 = mix(gl_in[0].gl_Position, gl_in[1].gl_Position, x);
56 vec4 x2 = mix(gl_in[2].gl_Position, gl_in[3].gl_Position, x);
58 pos[gl_InvocationID] = mix(x1, x2, y);
59 color[gl_InvocationID] = gl_PatchVerticesIn == 4 ? vec4(x, y, 0, 1) : vec4(0);
62 [tessellation evaluation shader]
64 #extension GL_ARB_tessellation_shader : require
66 layout(quads, equal_spacing) in;
74 float x = gl_TessCoord.x;
75 float y = gl_TessCoord.y;
76 vec4 vx[3], cx[3], v, c;
78 for (int i = 0; i < 3; i++) {
80 vx[i] = mix(pos[i*3], pos[i*3+1], x*2);
83 vx[i] = mix(pos[i*3+1], pos[i*3+2], (x-0.5)*2);
89 v = mix(vx[0], vx[1], y*2);
92 v = mix(vx[1], vx[2], (y-0.5)*2);
97 fs_color = gl_PatchVerticesIn == 9 ? c : vec4(0);
107 gl_FragColor = fs_color;
118 clear color 0.1 0.1 0.1 0.1
120 patch parameter vertices 4
121 draw arrays GL_PATCHES 0 4
122 relative probe rect rgb (0.0 , 0.0 , 0.476, 0.476) (0.0, 0.0, 0.0)
123 relative probe rect rgb (0.524, 0.0 , 0.476, 0.476) (0.5, 0.0, 0.0)
124 relative probe rect rgb (0.0 , 0.524, 0.476, 0.476) (0.0, 0.5, 0.0)
125 relative probe rect rgb (0.524, 0.524, 0.476, 0.476) (0.5, 0.5, 0.0)