2013-12-18 7 views
1

링크 http://prideout.net/blog/?p=48#shaders에서 삼각형 테셀레이션을 테스트하고 있습니다. 모든 쉐이더는 제대로 컴파일되지만, 나는 명령을 사용하여 프로그램을 링크 할 때 :GLSL의 테셀레이션 쉐이더에서 링크 오류

glLinkProgram(programID); 

나는 다음과 같은 오류있어 : 그것은 내가 명령을 사용하여 TC 셰이더의 출력을 이상한

Tessellation control info 
(0): error C6029: No input primitive type 
---------------------------------------- 
Tessellation evaluation info 
(0): error c7005: No tessellation primitive mode specified 
----------------------------------------------------------- 
Geometry info 
(0): error C6022: No input primitive type 
(0): error C6029: No ouput primitive type 
---------------------------------------- 
Not valid 

를 선언 할 것을 :

layout(triangles, equal_spacing, cw) in; 
01 : TE 셰이더

layout(vertices = 3) out; 

입력 레이아웃 명령을 사용하여

왜 아직도이 오류가 발생합니까? 답변을 드리겠습니다.

버텍스 쉐이더 :

나는 다음에 내 쉐이더를 넣어

#version 410 core 

in vec4 Position; 
out vec3 vPosition; 

void main() 
{ 
    vPosition = Position.xyz; 
} 

TC 쉐이더 :

#version 410 core 

layout(vertices = 3) out; 
in vec3 vPosition[]; 
out vec3 tcPosition[]; 

#define ID gl_InvocationID 

void main() 
{ 
    float TessLevelInner = 3; 
    float TessLevelOuter = 2; 
    tcPosition[ID] = vPosition[ID]; 
    if (ID == 0) { 
     gl_TessLevelInner[0] = TessLevelInner; 
     gl_TessLevelOuter[0] = TessLevelOuter; 
     gl_TessLevelOuter[1] = TessLevelOuter; 
     gl_TessLevelOuter[2] = TessLevelOuter; 
    } 
} 

TE 쉐이더 :

#version 410 core 
//TessEval 

layout(triangles, equal_spacing, cw) in; 
in vec3 tcPosition[]; 
out vec3 tePosition; 
out vec3 tePatchDistance; 
uniform mat4 Projection; 
uniform mat4 Modelview; 

void main() 
{ 
    vec3 p0 = gl_TessCoord.x * tcPosition[0]; 
    vec3 p1 = gl_TessCoord.y * tcPosition[1]; 
    vec3 p2 = gl_TessCoord.z * tcPosition[2]; 
    tePatchDistance = gl_TessCoord; 
    tePosition = normalize(p0 + p1 + p2); 
    gl_Position = Projection * Modelview * vec4(tePosition, 1); 
} 

지오메트리 쉐이더 :

#version 410 core 
//fragment shader 
out vec4 FragColor; 
in vec3 gFacetNormal; 
in vec3 gTriDistance; 
in vec3 gPatchDistance; 
in float gPrimitive; 
uniform vec3 LightPosition; 

float amplify(float d, float scale, float offset) 
{ 
    d = scale * d + offset; 
    d = clamp(d, 0, 1); 
    d = 1 - exp2(-2*d*d); 
    return d; 
} 

void main() 
{ 
    vec3 AmbientMaterial = vec3(0.04f, 0.04f, 0.04f); 
    vec3 DiffuseMaterial = vec3(0, 0.75, 0.75); 
vec3 LightPosition = vec3(0.25, 0.25, 1); 
    vec3 N = normalize(gFacetNormal); 
    vec3 L = LightPosition; 
    float df = abs(dot(N, L)); 
    vec3 color = AmbientMaterial + df * DiffuseMaterial; 

    float d1 = min(min(gTriDistance.x, gTriDistance.y), gTriDistance.z); 
    float d2 = min(min(gPatchDistance.x, gPatchDistance.y), gPatchDistance.z); 
    color = amplify(d1, 40, -0.5) * amplify(d2, 60, -0.5) * color; 

    FragColor = vec4(color, 1.0); 
} 

마지막으로,이 내가 쉐이더 소스를 설정하는 코드입니다 :

#version 410 core 
//geometry shader 
layout(triangles) in; 
layout(triangle_strip, max_vertices = 3) out; 
in vec3 tePosition[3]; 
in vec3 tePatchDistance[3]; 
out vec3 gFacetNormal; 
out vec3 gPatchDistance; 
out vec3 gTriDistance; 
uniform mat4 Modelview; 
uniform mat3 NormalMatrix; 

void main() 
{ 
    vec3 A = tePosition[2] - tePosition[0]; 
    vec3 B = tePosition[1] - tePosition[0]; 
    gFacetNormal = NormalMatrix * normalize(cross(A, B)); 

    gPatchDistance = tePatchDistance[0]; 
    gTriDistance = vec3(1, 0, 0); 
    gl_Position = gl_in[0].gl_Position; EmitVertex(); 

    gPatchDistance = tePatchDistance[1]; 
    gTriDistance = vec3(0, 1, 0); 
    gl_Position = gl_in[1].gl_Position; EmitVertex(); 

    gPatchDistance = tePatchDistance[2]; 
    gTriDistance = vec3(0, 0, 1); 
    gl_Position = gl_in[2].gl_Position; EmitVertex(); 

    EndPrimitive(); 
} 

조각 셰이더

std::string filename = "shaders//terrain//terrain_TCShader.glsl" 
FILE* fp = fopen(fileName.c_str(), "rt"); 
if (!fp) 
    return; 
// Get all lines from a file 
vector<string> sLines; 
char sLine[255]; 
while (fgets(sLine, 255, fp)) 
    sLines.push_back(sLine); 
fclose(fp); 

const char** sProgram = new const char*[sLines.size()]; 
for (int i = 0; i < sLines.size(); i++){ 
    sProgram[i] = sLines[i].c_str(); 
} 

    //Also for GL_TESS_EVALUATION_SHADER, ..VERTEX, ...FRAGMENT 
pShader[st] = glCreateShader(GL_TESS_CONTROL_SHADER); 
glShaderSource(pShader[st], 1, (const GLchar**)sProgram, NULL); 
glAttachShader(pProgram, pShader[st]); 
glCompileShader(pShader[st]); 
//==> I tried to check error here but it's ok, the compiler do not notify anything 

모든 쉐이더를 컴파일, 나는이 프로그램을 링크

glLinkProgram(pProgram); 

// 다시 오류를 확인하십시오.

glGetProgramiv(pProgram, GL_INFO_LOG_LENGTH,&infologLength); 

    if (infologLength > 0) 
    { 
     infoLog = (char *)malloc(infologLength); 
     glGetProgramInfoLog(pProgram, infologLength, &charsWritten, infoLog); 
      } 

// 여기에서 설명한대로 오류가 발생했습니다.

+1

의 크기를 변경 한, I는 오류를보고하지 않는다. 셰이더 설정 코드를 게시 할 수 있습니까? 이 업체는 무엇입니까? 어떤 플랫폼? – thokra

+0

안녕하세요 thokra, 설치 쉐이더 코드를 추가했습니다. 지원해 주셔서 감사합니다. 그것에 대한 의견을 보내주십시오. – khanhhh89

+0

오류 설명에 "기본 출력 없음"이라고 표시되어 "레이아웃 (정점 = 3) 없음"으로 인해 나타납니다. TC shader의 맨 위에 있지만 여기에 넣습니다. – khanhhh89

답변

0

나는이 문제를 해결했다. 오류는 셰이더를로드하는 코드에 있습니다.

glShaderSource(pShader[st], 1, (const GLchar**)sProgram, NULL); 

난 숯 GLSL 사양으로 당 * 어레이 sProgram