点的直通几何着色器
我在为点编写简单的直通几何着色器时遇到一些问题。我认为它应该是这样的:
#version 330
precision highp float;
layout (points) in;
layout (points) out;
void main(void)
{
gl_Position = gl_in[0].gl_Position;
EmitVertex();
EndPrimitive();
}
当我没有指定几何着色器时,屏幕上会显示一堆点,但是当我尝试将此着色器链接到我的着色器程序时,不会显示任何点,也不会报告任何错误。
我正在使用 C# 和 OpenTK,但我不认为这是问题所在。
编辑:人们要求其他着色器,尽管我确实在没有使用几何着色器的情况下测试了这些着色器,并且它们在没有几何着色器的情况下工作得很好。
顶点着色器:
void main()
{
gl_FrontColor = gl_Color;
gl_Position = ftransform();
}
片段着色器:
void main()
{
gl_FragColor = gl_Color;
}
I'm having some problems writing a simple pass-through geometry shader for points. I figured it should be something like this:
#version 330
precision highp float;
layout (points) in;
layout (points) out;
void main(void)
{
gl_Position = gl_in[0].gl_Position;
EmitVertex();
EndPrimitive();
}
I have a bunch of points displayed on screen when I don't specify a geometry shader, but when I try to link this shader to my shader program, no points show up and no error is reported.
I'm using C# and OpenTK, but I don't think that is the problem.
Edit: People requested the other shaders, though I did test these shaders without using the geometry shader and they worked fine without the geometry shader.
Vertex shader:
void main()
{
gl_FrontColor = gl_Color;
gl_Position = ftransform();
}
Fragment shader:
void main()
{
gl_FragColor = gl_Color;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不太确定(没有几何着色器的实际经验),但是您不必指定输出顶点的最大数量。在你的情况下,它只是一个,所以尝试
也许着色器编译成功,因为你仍然可以通过 API 指定顶点数(我认为至少在兼容性方面)。
编辑:您使用内置的变化
gl_FrontColor
(并在片段着色器中读取gl_Color
),但随后在几何着色器中您不会传播它到片段着色器(它不会自动传播)。这给我们带来了另一个问题。您将新语法(例如
gl_in
)与旧的已弃用语法(例如ftransform
和内置颜色变化)混合在一起。也许这不是一个好主意,在这种情况下你遇到了一个问题,因为如果我没记错的话,gl_in
没有gl_Color
或gl_FrontColor
成员。因此,最好的办法是使用您自己的颜色变量作为顶点和几何着色器的out
变量以及几何和片段着色器的in
变量(但请记住,in
必须是几何着色器中的数组)。I'm not that sure sure (have no real experience with geometry shaders), but don't you have to specify the maximum number of output vertices. In your case it's just one, so try
Perhaps the shader compiles succesfully because you could still specify the number of vertices by the API (at least in compatibility, I think).
EDIT: You use the builtin varying
gl_FrontColor
(and readgl_Color
in the fragment shader), but then in the geometry shader you don't propagate it to the fragment shader (it doesn't get propagated automatically).This brings us to another problem. You mix new syntax (like
gl_in
) with old deprecated syntax (likeftransform
and the builtin color varyings). Perhaps that's not a good idea and in this case you got a problem, asgl_in
has nogl_Color
orgl_FrontColor
member if I remember correctly. So the best thing would be to use your own color variable asout
variable of the vertex and geometry shaders and asin
variable of the geometry and fragment shaders (but remember that thein
has to be an array in the geometry shader).