现代 OpenGL 颜色

发布于 2024-09-17 23:33:20 字数 154 浏览 1 评论 0原文

我注意到旧代码有 GL_AMBIENT、GL_DIFFUSE、GL_SPECULAR 等带有 glMaterialfv 的输入。这些在现代 GLSL 代码中是如何替换的?

例如,假设导入模型的库(Assimp)为此类颜色类别提供直接值,它们仍然可以直接使用(在核心上下文上)吗?

I noticed old code has GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR etc. inputs with glMaterialfv. How are those replaced in modern GLSL code?

e.g. Assuming a library importing models (Assimp) gives direct values to such color categories , can they be still used directly (on core Context)?

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

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

发布评论

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

评论(1

度的依靠╰つ 2024-09-24 23:33:20

是的,至少是这样(当然,在现代代码中,您在着色器中处理大部分计算)。

一种典型的可能性是对环境颜色、灯光位置、眼睛位置等使用uniform。然后设置几个variable将用于将漫反射颜色和镜面反射颜色从顶点着色器传递到片段着色器。您的顶点着色器根据uniform 输入计算这些变化的值。

然后,片段着色器接收(例如)纹理和上面提到的变化,并将它们组合在一起(以及您可能需要的任何其他输入)以生成片段的最终颜色(它是分配给gl_FragColor)。

Yes, at least sort of (though, of course, in modern code, you handle most of that computation in shaders).

One typical possibility is to use uniforms for your ambient color(s), light position(s), eye position, etc. Then set up a couple of varyings that will be used to pass a diffuse color and specular color from your vertex shader to your fragment shader. Your vertex shader computes values for those varyings based on the uniform inputs.

The fragment shader then receives (for example) a texture and the varyings mentioned above, and combines them together (along with any other inputs you might want) to produce a final color for the fragment (which it assigns to gl_FragColor).

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