【问题标题】:Why doesnt my passthrough geometry shader work?为什么我的通过几何着色器不起作用?
【发布时间】:2021-11-02 01:03:57
【问题描述】:

我正在制作立方体地球的项目。我为纹理实现了顶点和片段着色器,它工作得很好(使用相机移动)。 我想添加一个直通几何着色器,但我无法让它工作。

顶点着色器

#version 450 core

layout (location = 0) in vec3 position;
layout (location = 1) in vec2 textureCoords;

out vec2 textCoords;

uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;

void main()
{
    gl_Position = projection * view * model * vec4(position, 1.0);
    textCoords = textureCoords;
}

几何着色器

#version 450 core
layout (triangles) in;
layout (triangles, max_vertices = 3) out;

in vec2 textCoords[];

out vec2 TextCoords;


void main()
{
int i;
    for(i = 0; i < gl_in.length(); i++)
    {
        gl_Position = gl_in[i].gl_Position;
        TextCoords = textCoords[i];

        EmitVertex();
    }
    EndPrimitive(); 
}  

片段着色器

#version 450 core

in vec2 TextCoords;

out vec4 fragmentColor;

uniform sampler2D earth;

void main()
{
    fragmentColor = texture(earth, TextCoords);
}

我使用了来自learnopengl 的着色器类,我在 Main 中唯一更改的是着色器构造函数中的几何着色器路径。

几何着色器之前

]

几何着色器之后

【问题讨论】:

    标签: c++ opengl glsl shader geometry-shader


    【解决方案1】:

    问题是

    layout (triangles, max_vertices = 3) out;

    应该是

    layout (triangle_strip, max_vertices = 3) out;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多