Mixing OpenGL GL_SRC_COLOR / GL_DST_COLOR

Is there a way to specify either {GL_SRC_COLOR, xxx} , and {xxx, GL_DST_COLOR} so that the colors of the source and destination are multiplied, and also make sure that if GL_SRC_ALPHA = 0, then the result is {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA} ?

I create an overlay rectangle over my game world that starts transparent, but over time at night the overlay becomes a combination of blue and primary colors.

I tried {GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA} among others, as shown below. In both photographs, the left side is daytime without overlapping, and on the right side is labeled.

Night time right, overlay (SRC) at full alpha

1

The daytime overlay on the right is at 0 alpha.

2

The problem is that with an SRC alpha of zero, the target color doubles. I would like it to remain the same as without overlay, so that I can only adjust the opacity during the game and go into the night. Is there a way to do this or another way to achieve the same effect?

+4
source share
1 answer

I decided. This is easier than using alpha in fact. I used this for overlay:

 {GL_DST_COLOR, GL_ZERO} 

Initially, when you have daytime, you don’t want any color changes, so you set the color of your overlay to {255,255,255} (white). Alpha is not used and does not matter. Then this color is multiplied by the destination color (background of the world). As you approach night time, you can tint the world to any color by adjusting only the color of your overlay. If you need blue, then you must adjust the other channels (red and green) down, leaving a relatively larger blue channel at your destination (world background). Here is the effect of setting the color to {120, 150, 200} .

1

+3
source

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


All Articles