如何可视化 OpenGL ES 2.0 片段着色器
我正在尝试围绕 OpenGL ES 着色器进行思考:
顶点: 因此,顶点着色器正在处理 glDrawXXX 中所有对象/网格的顶点。就像你有 2 个三角形网格形成一个正方形/盒子一样。这使得可以围绕每个顶点移动、设置颜色等等?
分段: 是顶点之间的所有内容吗?
如何在心里想象这一点?
I am trying to wrap my brain around OpenGL ES shaders:
Vertex:
So Vertex shaders are handling the vertices for all objects/mesh in a glDrawXXX. Like if you have 2 triangle meshes forming a square/box. This makes it possible to move around each vertex, set colors, and more?
Fragment:
Is it everything in between the vertices?
How to get a mental visualization of this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在最直接、最简单的情况下;
为图元的每个顶点调用顶点着色器。 100 个顶点 = 100 次调用活动顶点着色器。然后,后一阶段从顶点生成三角形。
现在,对于顶点着色器生成的每个三角形,它都会被光栅化以生成片段(即潜在的像素)。光栅化器在三角形的每个顶点之间进行线性插值以生成三角形的片段位置。您感到困惑的地方可能是认为片段着色器与顶点着色器是一对一调用的。不,可能会生成零到数百万个片段 - 这取决于生成的三角形(视觉上)有多大。在生成的每个片段上调用片段着色器。它取决于顶点着色器输出的顶点。
如果一个三角形距离视点很远,它可能是一些碎片。如果它靠近屏幕,它可以占据整个视口。
In the most straightforward, simple case;
The vertex shader is called for every vertex of a primitive. 100 Vertices = 100 invocations of the active vertex shader. A latter stage then generates triangles from the vertices.
Now, for each triangle generated by the vertex shader, it gets rasterized to generate fragments (i.e. potential pixels). The rasterizer linearly interpolates between each vertex of a triangle to generate the fragment locations of the triangle. Where you are getting confused is probably thinking that the fragment shader is called 1-to-1 along with the vertex shader. Nope, there can be zero to millions of fragments generated - it depends upon how big (visually) the resulting triangle is going to be. The fragment shader is called on each fragment generated. it depends on the vertices output by the vertex shader.
If a triangle is far away from the viewpoint, it may be a few fragments. If it's close to the screen it can take up the whole viewport.