使用顶点着色器时如何获得平坦的、非插值的颜色
有没有办法实现这一点(OpenGL 2.1)?如果我像这样画线,
glShadeModel(GL_FLAT);
glBegin(GL_LINES);
glColor3f(1.0, 1.0, 0.0);
glVertex3fv(bottomLeft);
glVertex3fv(topRight);
glColor3f(1.0, 0.0, 0.0);
glVertex3fv(topRight);
glVertex3fv(topLeft);
.
.
(draw a square)
.
.
glEnd();
我会得到所需的结果(每个边缘有不同的颜色),但我希望能够计算着色器中的片段值。如果我在设置着色器程序后执行相同的操作,我总是会在顶点之间获得插值颜色。有办法解决这个问题吗? (如果我能使用四边形得到相同的结果,那就更好了)
谢谢
Is there a way to achieve this (OpenGL 2.1)? If I draw lines like this
glShadeModel(GL_FLAT);
glBegin(GL_LINES);
glColor3f(1.0, 1.0, 0.0);
glVertex3fv(bottomLeft);
glVertex3fv(topRight);
glColor3f(1.0, 0.0, 0.0);
glVertex3fv(topRight);
glVertex3fv(topLeft);
.
.
(draw a square)
.
.
glEnd();
I get the desired result (a different colour for each edge) but I want to be able to calculate the fragment values in a shader. If I do the same after setting up my shader program I always get interpolated colors between vertices. Is there a way around this? (would be even better if I could get the same results using quads)
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您不希望基元内的顶点属性之间进行插值(例如,您的情况下线段中的颜色),您将需要传递相同的颜色两次,因此最终会复制您的几何图形:
(v0 由结构体 p0 组成以及 p1 和 c1 的 c0、v1 等..)
对于使用颜色插值绘制线条:
对于不使用插值绘制:
请注意,这意味着您不能再使用
GL_x_STRIP
拓扑,因为您不想共享基元内的属性。If you don't want the interpolation between vertice attributes inside a primitive (e.g. color in a line segment in your case) you'll need to pass the same color twice, so end up duplicating your geometry:
(v0 is made of structs p0 and c0, v1 of p1 and c1 etc..)
For drawing the line with color interpolation:
For drawing without interpolation:
Note this mean you can no longer use
GL_x_STRIP
topology, since you don't want to share attributes inside a primitive.