OpenGL Java color material is darkened when depth checking is disabled

I worked with the depth buffer in OpenGL (JOGL) to make sure that some elements appear before others by disabling the depth buffer (described in detail in a previous Java OpenGL question saving the depth buffer ).

This works, except when I set the color of the element that is drawn when the depth test is disabled, none of the material shines appear. The element appears as a darker version of the original color (it seems that it is not affected by the lighting effect). Is there a reason why this is happening? and how can i prevent this?

thanks jeff

+4
source share
1 answer

Since you have no answers yet, I will try to do it, although I really have a little idea.

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

  • Unlike the ambient and diffuse component of the lighting model, the mirror component must take into account the position of the eyes relative to the object and light source. This way, it is likely to be faster when OpenGL uses a depth buffer. I assume that in this way - for every pixel that needs to be drawn, it can use the depth value to complete the eye coordinates using the z-component.

  • Perhaps this is also due to the weakening of light? When light attenuation is used, OpenGL calculates the distance the light must travel before reaching your eye (or simplifies it by only calculating the distance between the light and the object? I'm not sure.)

Thus, I assume that it is correct to use lighting without a depth buffer. I think you mentioned in your other post that you cannot just clear the depth buffer, because it will interfere with the rest of the application? I think there should be a stencil solution, something similar to "Example 10-1: Using the stencil test" at http://www.glprogramming.com/red/chapter10.html (it is written in C, but I hope what it looks like jogl). A stencil will simply close the remaining application from drawing your precious pixels.

+2
source

Source: https://habr.com/ru/post/1305177/


All Articles