Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
着色器翻转面 我试图用OpenGL和C++来构造渲染引擎。但似乎无法克服这个问题。使用不同的着色器对同一模型进行5次不同的渲染,在5个着色器中的4个着色器中,背面消隐工作正常。但是,在细分着色器中,它不是。任何向外的面都是不可见的,因此您可以直接看到后面的面。有人知道为什么这个着色器会翻转面吗_Opengl_Glsl_Shader_Culling_Tessellation - Fatal编程技术网

着色器翻转面 我试图用OpenGL和C++来构造渲染引擎。但似乎无法克服这个问题。使用不同的着色器对同一模型进行5次不同的渲染,在5个着色器中的4个着色器中,背面消隐工作正常。但是,在细分着色器中,它不是。任何向外的面都是不可见的,因此您可以直接看到后面的面。有人知道为什么这个着色器会翻转面吗

着色器翻转面 我试图用OpenGL和C++来构造渲染引擎。但似乎无法克服这个问题。使用不同的着色器对同一模型进行5次不同的渲染,在5个着色器中的4个着色器中,背面消隐工作正常。但是,在细分着色器中,它不是。任何向外的面都是不可见的,因此您可以直接看到后面的面。有人知道为什么这个着色器会翻转面吗,opengl,glsl,shader,culling,tessellation,Opengl,Glsl,Shader,Culling,Tessellation,顶点着色器 void main() { worldVertexPosition_cs = (transformationMatrix * vec4(position_vs, 1.0)).xyz; worldTextureCoords_cs = textureCoords_vs; worldNormal_cs = mat3(transpose(inverse(transformationMatrix))) * normal_vs; } 控制着色器 float getTes

顶点着色器

void main()
{
    worldVertexPosition_cs = (transformationMatrix * vec4(position_vs, 1.0)).xyz;
    worldTextureCoords_cs = textureCoords_vs;
    worldNormal_cs = mat3(transpose(inverse(transformationMatrix))) * normal_vs;
}
控制着色器

float getTessLevel(float distance0, float distance1)
{
    float avgDistance = (distance0 + distance1) / 2.0;
    avgDistance = (100 - avgDistance) / 20;
    if (avgDistance < 1) {
        avgDistance = 1;
    }
    return avgDistance;
}

void main()
{
    worldTextureCoords_es[gl_InvocationID] = worldTextureCoords_cs[gl_InvocationID];
    worldNormal_es[gl_InvocationID] = worldNormal_cs[gl_InvocationID];
    worldVertexPosition_es[gl_InvocationID] = worldVertexPosition_cs[gl_InvocationID];

    float eyeToVertexDistance0 = distance(eyePos, worldVertexPosition_es[0]);
    float eyeToVertexDistance1 = distance(eyePos, worldVertexPosition_es[1]);
    float eyeToVertexDistance2 = distance(eyePos, worldVertexPosition_es[2]);

    gl_TessLevelOuter[0] = getTessLevel(eyeToVertexDistance1, eyeToVertexDistance2);
    gl_TessLevelOuter[1] = getTessLevel(eyeToVertexDistance2, eyeToVertexDistance0);
    gl_TessLevelOuter[2] = getTessLevel(eyeToVertexDistance0, eyeToVertexDistance1);
    gl_TessLevelInner[0] = gl_TessLevelOuter[2];
}
片段着色器

void main()
{
    vec3 unitNormal = normalize(worldNormal_fs);
    vec3 unitLightVector = normalize(lightPosition - worldVertexPosition_fs);

    float dotResult = dot(unitNormal, unitLightVector);
    float brightness = max(dotResult, blackPoint);
    vec3 diffuse = brightness * lightColor;

    FragColor = vec4(diffuse, 1.0) * texture(texture_diffuse0, worldTextureCoords_fs);
    FragColor.rgb = pow(FragColor.rgb, vec3(1.0/gamma));
}
在中,您必须定义生成的三角形的缠绕顺序。
这是通过
cw
ccw
参数完成的。默认值为
ccw

生成顺时针基本体:

中的布局(三角形,cw);
或生成逆时针基本体:

中的布局(三角形,ccw);
void main()
{
    vec3 unitNormal = normalize(worldNormal_fs);
    vec3 unitLightVector = normalize(lightPosition - worldVertexPosition_fs);

    float dotResult = dot(unitNormal, unitLightVector);
    float brightness = max(dotResult, blackPoint);
    vec3 diffuse = brightness * lightColor;

    FragColor = vec4(diffuse, 1.0) * texture(texture_diffuse0, worldTextureCoords_fs);
    FragColor.rgb = pow(FragColor.rgb, vec3(1.0/gamma));
}