OpenGL Tessellation

时间:2013-05-28 18:01:59

标签: opengl tessellation

我正在尝试编写Tessellation着色器。但是,我首先要确保管道正在我的计算机上工作,所以我写了一些非常基本的细分代码。

但是,当我尝试运行它时,我不断收到链接器错误,说我的曲面细分评估着色器未编译。有谁知道这意味着什么,或者下面的代码是否错误?

tessellation.vert

#version 400

layout (location = 0 ) in vec2 in_position;
layout (location = 1 ) in vec4 in_color;

void main()
{
    gl_Position = vec4(in_position, 0.0, 1.0);
}

tessellation.tcs

#version 400

layout( vertices = 2 ) out;


void main()
{
    gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;

    gl_TessLevelOuter[0] = float(2.0);
    gl_TessLevelOuter[1] = float(2.0);
}

tessellation.tes

#version 400

layout( isolines ) in;

void main()
{
    float u = gl_TessCoord.x;

    vec3 p0 = gl_in[0].gl_Position.xyz;
    vec3 p1 = vec3(0.5, gl_in[0].gl_Position.y, 0.0);
    vec3 p2 = vec3(0.5, gl_in[1].gl_Position.y, 0.0);
    vec3 p3 = gl_in[1].gl_Position.xyz;

    float u1 = (1.0 - u);
    float u2 = u * u;

    // Bernstein polynomials
    float b3 = u2 * u;
    float b2 = 3.0 * u2 * u1;
    float b1 = 3.0 * u * u1 * u1;
    float b0 = u1 * u1 * u1;

    // Cubic Bezier interpolation
    vec3 p = p0 * b0 + p1 * b1 + p2 * b2 + p3 * b3;

    gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * vec4(p, 1.0);
}

tessellation.frag

#version 400

layout ( location = 0 ) out vec4 FragColor;

void main()
{
  FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}

0 个答案:

没有答案