禁用深度测试时 Java OpenGL 颜色材质变暗

发布于 2024-08-26 14:10:52 字数 312 浏览 4 评论 0原文

我一直在 OpenGL (JOGL) 中使用深度缓冲区,以通过禁用深度缓冲区来确保某些项目在其他项目之前渲染(详细信息请参阅我之前的问题 Java OpenGL 保存深度缓冲区)。

这是有效的,除非当我设置禁用深度测试时正在绘制的项目的颜色时,不会显示任何材质光泽。该项目被渲染为原始颜色的较暗版本(似乎没有真正应用照明效果)。发生这种情况有什么原因吗?我该如何防止这种情况发生?

谢谢, 杰夫

I've been working with the depth buffer in OpenGL (JOGL) to ensure certain items are rendered in front of others by disabling the depth buffer (detailed in my previous question Java OpenGL saving depth buffer).

This works, except when I set the color of an item that is being drawn when the depth test is disabled, none of the material shininess shows up. The item is rendered as a darker version of the original color (it seems like there is no lighting effect really applied to it). Is there a reason why this would be happening? and how might I prevent this?

thanks,
Jeff

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

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

发布评论

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

评论(1

短叹 2024-09-02 14:10:52

既然到目前为止你还没有得到答案,我会尝试一下,尽管我在这里真的有点猜测。

我可以想象为什么会发生您所看到的效果的几个原因:

  • 与照明模型的环境和漫反射组件相比,镜面反射组件需要考虑相对于对象和光源的眼睛位置。因此,当 OpenGL 使用深度缓冲区时,这可能会更快。我假设,这样 - 对于要绘制的每个像素 - 它可以使用深度值来完成眼睛坐标与 z 分量。

  • 或许也与光衰减有关?当使用光衰减时,OpenGL会计算光线在到达您的眼睛之前必须经过的距离(或者是否通过仅计算光线和物体之间的距离来简化?我不确定。)

所以我假设,如果没有深度缓冲区,就不可能正确使用光照。我想您在另一篇文章中提到,您不能只清除深度缓冲区,因为它会干扰应用程序的其余部分?我认为应该有一个带有模板的解决方案,类似于 http://www.glprogramming.com/red/chapter10.html (它是用 C 编写的,但我希望它在 JOGL 中类似)。模板只会阻止剩余的应用程序在您宝贵的像素上进行绘制。

Since you got no answers so far, I'll try to give it my shot, although I'm really a bit guessing here.

A few reasons I can imagine, why the effect you see would happen:

  • In contrast to the ambient and diffuse component of the lighting model, the specular component needs to take into account the eye location relative to the object and light source. So this will probably be faster, when OpenGL uses the depth buffer. I assume, that this way - for every pixel to be drawn - it could use the depth value to complete the eye coordinates with the z component.

  • Maybe it's also related to light attenuation? When light attenuation is used, OpenGL calculates the distance, which the light has to travel before reaching your eye (or does it simplify by only calculating the distance between the light and the object? I'm not sure.)

So I assume, that it's not possible to use lighting correctly without a depth buffer. I think you mentioned in your other post, that you can't just clear the depth buffer, because it would interfere with the rest of the application? I think there should be a solution with stencils, something similar to "Example 10-1 : Using the Stencil Test" in http://www.glprogramming.com/red/chapter10.html (it's written in C, but I hope it's similar in JOGL). The stencil would simply bar the remaining application from drawing over your precious pixels.

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