我设法对每个补丁有4个顶点的四边形进行细分(尽管有一些小问题,我会尽快修复),但是接下来我想为每个补丁(四边形)着色不同的颜色,或者如果我可以得到一个补丁并将其阴影也很好,这可能吗?
有人对我将如何做有任何想法吗?
Tess控制着色器
#version 410 core
layout(vertices = 4) out;
void main(void)
{
gl_TessLevelOuter[0] = 2.0;
gl_TessLevelOuter[1] = 4.0;
gl_TessLevelOuter[2] = 6.0;
gl_TessLevelOuter[3] = 8.0;
gl_TessLevelInner[0] = 8.0;
gl_TessLevelInner[1] = 8.0;
gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
}
苔丝评估着色器
#version 410 core
layout(quads, equal_spacing, ccw) in;
// quad interpolate
vec4 interpolate(in vec4 v0, in vec4 v1, in vec4 v2, in vec4 v3)
{
vec4 a = mix(v0, v1, gl_TessCoord.x);
vec4 b = mix(v3, v2, gl_TessCoord.x);
return mix(a, b, gl_TessCoord.y);
}
void main()
{
gl_Position = interpolate(
gl_in[0].gl_Position,
gl_in[1].gl_Position,
gl_in[2].gl_Position,
gl_in[3].gl_Position);
}
Geo Shader
#version 410 core
layout(triangles, invocations = 1) in;
layout(triangle_strip, max_vertices = 4) out;
void main(void)
{
gl_Position = gl_in[0].gl_Position;
EmitVertex();
gl_Position = gl_in[1].gl_Position;
EmitVertex();
gl_Position = gl_in[2].gl_Position;
EmitVertex();
EndPrimitive();
}