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 78 79 80 81 82
|
# Number of input CP = 1
# Number of output CP = 1
# Draw 256 patches.
#
# Each patch is tessellated like a quad with a 4x4 vertex pattern.
# (which is 3x3 sub-quads = 18 triangles)
[require]
GLSL >= 1.50
GL_ARB_tessellation_shader
[vertex shader]
#version 150
out vec3 inpos[16];
void main()
{
const int num = 16; // number of patches in one direction, num*num patches in total
for (int i = 0; i < 16; i++) {
inpos[i].xy = vec2(gl_VertexID % num, gl_VertexID / num) / num + vec2(i % 4, i / 4) / (3 * num);
inpos[i].z = float(gl_VertexID / 64);
}
}
[tessellation control shader]
#version 150
#extension GL_ARB_tessellation_shader : require
#extension GL_ARB_arrays_of_arrays : require
layout(vertices = 1) out;
in vec3 inpos[][16];
out vec3 outpos[][16];
void main()
{
gl_TessLevelInner[0] =
gl_TessLevelInner[1] =
gl_TessLevelOuter[0] =
gl_TessLevelOuter[1] =
gl_TessLevelOuter[2] =
gl_TessLevelOuter[3] = 3.0;
outpos[gl_InvocationID] = inpos[gl_InvocationID];
}
[tessellation evaluation shader]
#version 150
#extension GL_ARB_tessellation_shader : require
#extension GL_ARB_arrays_of_arrays : require
layout(quads, equal_spacing) in;
in vec3 outpos[][16];
out vec3 color;
void main()
{
ivec2 coord = ivec2(round(gl_TessCoord.xy * 3));
vec3 v = outpos[0][coord.y * 4 + coord.x];
gl_Position = vec4(v.xy * 2 - 1, 0, 1);
color = v.zzz - vec3(0, 1, 2);
}
[fragment shader]
#version 150
in vec3 color;
void main()
{
gl_FragColor = vec4(color, 1);
}
[test]
clear color 0.1 0.1 0.1 0.1
clear
patch parameter vertices 1
draw arrays GL_PATCHES 0 256
relative probe rect rgba (0, 0, 1, 0.24) (0, 0, 0, 1)
relative probe rect rgba (0, 0.26, 1, 0.24) (1, 0, 0, 1)
relative probe rect rgba (0, 0.5, 1, 0.24) (1, 1, 0, 1)
relative probe rect rgba (0, 0.76, 1, 0.24) (1, 1, 1, 1)
|