• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker alpha not working with blend modes?

B

bdonohue

Guest
Hi,

Is an image's alpha not adjustable when you use blend modes? For example:

Code:
gpu_set_blendmode_ext(bm_subtract,bm_src_color);
draw_sprite_ext(spr_water1, 0, x, y, image_xscale, image_yscale, image_angle, image_blend, 0.2);
gpu_set_blendmode(bm_normal);
No matter what value I change the 0.2 to, nothing looks any different.

Thanks!
 

samspade

Member
Hi,

Is an image's alpha not adjustable when you use blend modes? For example:

Code:
gpu_set_blendmode_ext(bm_subtract,bm_src_color);
draw_sprite_ext(spr_water1, 0, x, y, image_xscale, image_yscale, image_angle, image_blend, 0.2);
gpu_set_blendmode(bm_normal);
No matter what value I change the 0.2 to, nothing looks any different.

Thanks!
You may also want to review this reference for a good explanation of how blendmodes work in general.

Blendmodes GML Reference
 
B

bdonohue

Guest
Thank you for the replies :)

Read the Manual entry on gpu_set_blendmode_ext() about what values it accepts. bm_subtract is not one of them.
Hmm... ok so bm_subtract is not valid there? I'm confused because the table on that page does not list bm_subtract, but the corresponding graphic below it does list bm_subtract. In fact I see two inconsistencies between the table and graphic... typos maybe?

Anyway, I tried different values in the gpu_set_blendmode_ext(src,dest) and none of them seem to let me then adjust the alpha of the image.
Code:
gpu_set_blendmode_ext(bm_zero,bm_src_color);
draw_sprite_ext(spr_water1, 0, x, y, image_xscale, image_yscale, image_angle, image_blend, 0.2);
gpu_set_blendmode(bm_normal);
Is there any way I can do this?
 

samspade

Member
You'll probably have to read up to understand why what you're doing won't work.

Blendmodes are not super complicated, but they aren't intuitive. Essentially they're a series of basic math equations (addition and multiplication) done in a specified order. What you're doing is working, it just isn't what you expected.

The first paragraph of the link I posted is this:

"Saying that some modes "do not take the alpha value fully into account" seems a bit misleading. The ways in which alpha is taken into account simply may not be what the user desires or expects."
 

Binsk

Member
You don't fully understand how blend modes work.

When you render something, math happens and you are left with the colors that you want to draw as a result. However, on the screen already are some colors from the last render. How should we mix the colors? That is what the blend mode defines.

Now, realize that the alpha channel IS CONSIDERED AS PART OF THE COLOR DATA. This means that when you change the blend mode you are changing HOW the alpha is used. It is simply another channel just like red is a channel, green is one, and blue is one. The computer doesn't care what they're for and simply uses them as the blend mode says it should (which, as you are finding out, is not what you'd expect).

Take a look at the blend mode definitions. Notice how neither of the ones you are using tell the alpha to affect the color channels?

In case you don't know the math that blend modes do, this is what happens:

Final color on screen = rendered_color * arg0_blend_command + old_color * arg1_blend_command

As an example, you are using bm_zero and bm_src_color. Let's assume you are drawing a white square on top of a black background. The math is a follows:

[1, 1, 1, 0.2] * [0, 0, 0, 0] + [0, 0, 0, 1] * [1, 1, 1, 0.2] = [0, 0, 0, 0.2]

That would be a black square with 0.2 transparency.
 
Last edited:
B

bdonohue

Guest
Ok, thank you all very much for the assistance with this! I think I do understand better now. I guess the alpha is technically working, just not as I would expect it to. My background is graphics/Photoshop, so I guess I was expecting blend modes to work the same way they do in Photoshop.

Thanks!
 

Karlstens

Member
You'll probably have to read up to understand why what you're doing won't work.

Blendmodes are not super complicated, but they aren't intuitive. Essentially they're a series of basic math equations (addition and multiplication) done in a specified order. What you're doing is working, it just isn't what you expected.

The first paragraph of the link I posted is this:

"Saying that some modes "do not take the alpha value fully into account" seems a bit misleading. The ways in which alpha is taken into account simply may not be what the user desires or expects."
Heya @samspade - big fan of your youtube channel. I would love to see you cover GPU blend modes in an upcoming vid - as there's a real visual aspect to blending, I think it would be great to see some examples :D
 
Last edited:
Top