OpenGL Alpha mixes with the wrong color

I am trying to create a simple ray tracer. I have a perspective view that shows rays visible for debugging purposes.

In my screenshot below, I have one white sphere to be emitted, and a green sphere representing the eye.

Rays are drawn as lines with

glLineWidth (10.0f)

If a ray passes a sphere, it is assigned a color

glColor4ub (100,100,100,100);

in my initialization code, I have the following:

    glEnable (GL_ALPHA_TEST);
    glAlphaFunc (GL_GREATER, 0.0f);
    glEnable (GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_SRC_ALPHA);

In the screenshot you can see that for some reason, the rays passing between the point of view and the sphere are mixed with the axis of the line behind the sphere, and not with the sphere itself.

Here is a screenshot:

screenshot

- , ?

!!

+3
3

, , ?

, Z-, , . - ( ), , .

, , Z- . Z- . , OpenGL API . ( , , , -)

+7
  • glAlphaFunc, .
  • : glBlendFunc(GL_ONE, GL_ONE) ( , .
  • ( ) : glDepthMask(GL_FALSE)
  • .
+2

AlphaTest is intended only for discarding fragments, not for mixing them. Check the specification Using this, you tell OpenGL that you want it to throw out pixels instead of drawing them, so you won’t be able to mix transparently. The most common blending function is glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); You can also check the OpenGL Transparency FAQ .

0
source

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


All Articles