使用曲面细分时遇到问题。
请参阅以下链接
渲染后您可能会看到一些灰色区域。如果我旋转相机,它们也会改变(就像一个闪亮的效果。)
任何人都可以帮我弄清楚是什么原因吗?提前谢谢。
这是我的代码:
顶点着色器:
in vec3 vertex_position;
in vec2 vertex_texcoord;
void main()
{
v_pos = vec3(vertex_position);
v_texcoord = vertex_texcoord;
}
TC着色器:
layout(vertices = 3) out;
in vec3 v_pos[];
in vec2 v_texcoord[];
out vec3 tc_pos[];
out vec2 tc_texcoord[];
#define ID gl_InvocationID
#define TESS_LEVEL_INNER 3.0
#define TESS_LEVEL_OUTER 2.0
void main()
{
tc_pos[ID] = v_pos[ID];
tc_texcoord[ID] = v_texcoord[ID];
if (ID == 0)
{
gl_TessLevelInner[0] = TESS_LEVEL_INNER;
gl_TessLevelOuter[0] = TESS_LEVEL_OUTER;
gl_TessLevelOuter[1] = TESS_LEVEL_OUTER;
gl_TessLevelOuter[2] = TESS_LEVEL_OUTER;
}
}
着色器:
layout(triangles, equal_spacing, cw) in;
in vec3 tc_pos[];
in vec2 tc_texcoord[];
out vec3 te_pos;
out vec2 te_texcoord;
void main()
{
vec3 p0 = gl_TessCoord.x * tc_pos[0];
vec3 p1 = gl_TessCoord.y * tc_pos[1];
vec3 p2 = gl_TessCoord.z * tc_pos[2];
vec2 t0 = gl_TessCoord.x * tc_texcoord[0];
vec2 t1 = gl_TessCoord.y * tc_texcoord[1];
vec2 t2 = gl_TessCoord.z * tc_texcoord[2];
te_pos = p0 + p1 + p2;
te_texcoord = t0 + t1 + t2;
vec4 p_t = vec4(te_pos-cam_pos.xyz,1.0) * cam_ori;
gl_Position = perspective_mat * p_t;
}
几何着色器:
layout (triangles) in;
layout (triangle_strip, max_vertices=3) out;
in vec3 te_pos[3];
in vec2 te_texcoord[3];
out vec2 g_texcoord;
void main()
{
gl_Position = gl_in[0].gl_Position;
g_texcoord = te_texcoord[0];
EmitVertex();
gl_Position = gl_in[1].gl_Position;
g_texcoord = te_texcoord[1];
EmitVertex();
gl_Position = gl_in[2].gl_Position;
g_texcoord = te_texcoord[2];
EmitVertex();
EndPrimitive();
}
片段:
in vec2 g_texcoord;
out vec4 frag_color;
void main()
{
frag_color = texture(tex_unit, g_texcoord);
}