基本的OpenGL光照问题

发布于 2024-10-02 01:21:50 字数 164 浏览 0 评论 0原文

我认为这是一个非常愚蠢和新手的问题,但我是图形和 openGL 方面的新手。绘制了一个球体并在附近放置了一个光源,还指定了环境光,我开始尝试光和材质值,并得出了一个令人惊讶的结论:我们用 glColor* 指定的颜色并不重要当照明启用时。相反,等效的是材质的环境成分。这个结论正确吗?谢谢

I think this is an extremely stupid and newbie question, but then I am a newbie in graphics and openGL. Having drawn a sphere and put a light source nearby, also having specified ambient light, I started experimenting with light and material values and came to a surprising conclusion: the colors which we specify with glColor* do not matter at all when lighting is enabled. Instead, the equivalent is the material's ambient component. Is this conclusion correct? Thanks

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

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

发布评论

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

评论(2

十年不长 2024-10-09 01:21:50

如果启用了照明,则使用材质颜色(嗯,颜色 - 有几种颜色用于不同类型的光响应)来代替顶点颜色 。材质颜色由 glMaterial* 函数指定。

如果您想重用代码,可以使用 glEnable(GL_COLOR_MATERIAL)glColorMaterial(GL_AMBIENT_AND_DIFFUSE) 将旧的 glColor* 调用映射到自动材料颜色。

(请尽快切换到着色器 - 着色器方法既简单又更强大)

If the lighting is enabled, then instead of the vertex color, the material color (well, colors - there are several of them for different types of response to light) is used. Material colors are specified by glMaterial* functions.

If you want to reuse your code, you can use glEnable(GL_COLOR_MATERIAL) and glColorMaterial(GL_AMBIENT_AND_DIFFUSE) to have your old glColor* calls mapped to material color automatically.

(And please switch to shaders as fast as possible - the shader approach is both easier and more powerful)

沙与沫 2024-10-09 01:21:50

我想你还没有使用片段着色器。来自 glprogramming.com

顶点颜色 =
    该顶点的材料发射 + 
    由材质环境缩放的全局环境光
    该顶点的属性 + 
    来自所有的环境、漫反射和镜面反射的贡献
    光源,适当衰减

所以是的,不使用顶点颜色。

编辑:您还可以在 GL 规范中查找 GL 闪电方程(您附近有一个,是吗?^^)

I suppose you don't use fragment shader yet. From glprogramming.com:

vertex color =
    the material emission at that vertex + 
    the global ambient light scaled by the materials ambient
    property at that vertex + 
    the ambient, diffuse, and specular contributions from all the
    light sources, properly attenuated

So yes, vertex color is not used.

Edit: You can also look for GL lightning equation in GL specification (you have one nearby, do you? ^^)

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