gpt4 book ai didi

opengl - 为什么 gl_Color 不是片段着色器的内置变量?

转载 作者:行者123 更新时间:2023-12-04 02:39:06 24 4
gpt4 key购买 nike

顶点着色器应该输出裁剪空间中的顶点位置:

Vertex shaders, as the name implies, operate on vertices. Specifically, each invocation of a vertex shader operates on a single vertex. These shaders must output, among any other user-defined outputs, a clip-space position for that vertex. (source: Learning Modern 3D Graphics Programming, by Jason L. McKesson)

为此,它有一个名为 gl_Position 的内置变量。

同样,片元着色器需要输出颜色:

A fragment shader is used to compute the output color(s) of a fragment. [...] After the fragment shader executes, the fragment output color is written to the output image. (source: Learning Modern 3D Graphics Programming, by Jason L. McKesson)

但是没有为此定义的 gl_Color 内置变量:opengl44-quick-reference-card.pdf

为什么 OpenGL API 中会出现(明显的)不一致?

最佳答案

那是因为 OpenGL 管道使用 gl_Position 来完成多项任务。 The manual says : "写入 gl_Position 的值将被基元组装、裁剪、剔除和其他固定功能操作使用,如果存在,它们会在顶点处理发生后对基元进行操作。"

相比之下,管道逻辑不依赖于最终像素颜色。

关于opengl - 为什么 gl_Color 不是片段着色器的内置变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20286156/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com