GLSL:顶点着色器到片段着色器,无变化

发布于 2024-11-05 04:16:53 字数 68 浏览 1 评论 0原文

如何将数据从顶点着色器传输到片段着色器而无需更改? 我需要对顶点像素说它们具有这种颜色。这种颜色我只能在顶点着色器中获得。

How to transfer data from vertex shader to fragment shader without changes?
I need to say to the vertex pixels that they have this color. This color I can obtain only in the vertex shader.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

楠木可依 2024-11-12 04:16:55

您必须使用变化,因为每个片段都受到多个顶点的“影响”(除非您正在渲染GL_POINTS),因此您必须跨线/多边形对它们进行插值。 GLSL 的最新版本允许指定平面着色插值,它不会在整个图元中插值,而忽略其他顶点的值。

我怀疑您想要做的就是仅以不同的颜色渲染与顶点相对应的像素,这是正确的吗?在这种情况下,事情就不那么容易了,您可能需要先渲染填充的多边形,然后重新渲染为 GL_POINTS 。此时,不会对变化的变量进行插值,因为每个片段都受到单个顶点的影响。

You have to use a varying, because each fragment is "influenced" by more than one vertex (unless you are rendering GL_POINTS), so you have to interpolate them across the line/polygon. Recent versions of GLSL allow to specify flat shading interpolation, which doesn't interpolate the value throughout the primitive, ignoring the values from the other vertices.

I suspect thought that what you want to do is to render only the pixels corresponding to the vertices in a different color, is that correct? In that case it's not so easy, you would probably want to render the filled polygons first, and then re-render as GL_POINTS. At that point, varying variables are not interpolated because each fragment is influenced by a single vertex.

强辩 2024-11-12 04:16:55

这里有一个关于 GLSL 的很好的教程: NeHe GLSL 教程

如果您想要在顶点着色器和片段着色器之间共享数据,请使用内置类型之一,例如 gl_Color

如果您想将顶点着色器计算的颜色传递到您将创建的片段着色器具有以下行的片段着色器: gl_FragColor = gl_Color

gl_Color 将根据顶点着色器写入的颜色自动为您设置。您可以通过设置内置变量之一(例如 gl_FrontColor)或其同类之一:gl_BackColor 等来从顶点着色器写入颜色。

Here's a good tutorial on GLSL: NeHe GLSL tutorial

If you want to share data between vertex and fragment shaders use one of the built in types, for example gl_Color

If you want to pass through the color computed by the vertex shader to through the fragment shader you would create a fragment shader with the following line: gl_FragColor = gl_Color

gl_Color will be automatically set for you from the colors written by the vertex shader. You write a color from the vertex shader by setting one of the built-in variables, like gl_FrontColor, or one of it's peers: gl_BackColor etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文