开发者

Java OpenGL color material darkens when depth test is disabled

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 开发者_C百科lighting effect really applied to it). Is there a reason why this would be happening? and how might I prevent this?

thanks, Jeff


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜