麻烦将变量传递给片段着色器

时间:2013-11-06 03:05:27

标签: c++ opengl

我尝试了一些不同的代码变体,而且我唯一能让它工作的是我是否禁用了曲面细分着色器。

当我运行此代码时,没有任何渲染....

static const GLchar* vertShaderSource[] =
{
    "#version 430 core \n"
    "layout (location = 0) in vec4 offset; \n"
    "layout (location = 1) in vec4 color; \n"
    "out vec4 vs_color; \n"
    "void main(void) \n"        
    "{ \n"
    "const vec4 vertices[3] = vec4[3](vec4(0.25,-0.25,0.5,1.0),vec4(-0.25,-0.25,0.5,1.0),vec4(0.25,0.25,0.5,1.0)); \n"
    "gl_Position = vertices[gl_VertexID] + offset; \n"
    "vs_color[gl_VertexID]=color; \n"
    "} \n"
};

//SOURCE FOR TESSALATION CONTROL SHADER
static const GLchar* TCSsource[] = 
{
    "#version 430 core \n"
    "layout (vertices = 3) out; \n"
    "in vec4 vs_color[]; \n"
    "out Tess{ \n"
    "vec4 tcs_color; \n"
    "} Out[]; \n"
    "void main(void) \n"
    "{ \n"
    "if(gl_InvocationID == 0) \n"
    "{ \n"
    "gl_TessLevelInner[0] = 5.0; \n"
    "gl_TessLevelOuter[0] = 5.0; \n"
    "gl_TessLevelOuter[1] = 5.0; \n"
    "gl_TessLevelOuter[2] = 5.0; \n"
    "} \n"
    "gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position; \n"
    "Out[gl_InvocationID].tcs_color = vs_color[gl_InvocationID]; \n"
    "} \n"
};


//SOURCE FOR THE TEESALATION CONTROL SHADER
static const GLchar* TEShaderSource[] =
{
    "#version 430 core \n"
    "layout (triangles,equal_spacing,cw) in; \n"
    "in Tess{ \n"
    "vec4 tcs_color; \n"
    "} In[];"
    "out vec4 tes_color; \n"
    "void main(void) \n"
    "{ \n"
    "gl_Position = (gl_TessCoord.x * gl_in[0].gl_Position + gl_TessCoord.y * gl_in[1].gl_Position + gl_TessCoord.z * gl_in[2].gl_Position); \n"
    "tes_color = In[0].tcs_color; \n"
    "} \n"
};


//SOURCE CODE FOR FRAGMENT SHADER
static const GLchar* fragShaderSource[] =
{
    "#version 430 core \n"
    " \n"
    "in vec4 tes_color; \n"
    "out vec4 color; \n"
    " \n"
    "void main(void) \n"
    "{ \n"
    "color = tes_color; \n"
    "} \n"
};

0 个答案:

没有答案