Jump to content


Photo

All About Extended Blend Modes


  • Please log in to reply
168 replies to this topic

#1 Sinaz

Sinaz

    MCP Killer

  • Retired Staff
  • 2751 posts
  • Version:GM8

Posted 09 November 2006 - 12:58 AM

//in progress

Normal
Result = source color + destination color * (1 - source alpha)
draw_set_blend_mode(bm_normal)
draw_set_blend_mode_ext(bm_src_alpha, bm_inv_src_alpha)


Dissolve
if ( random(1) < src alpha ) {Result = source color} else {Result = destination color}
Is not supported by D3D blend modes; requires pre-processing of source image.


Darken
Result = min(source color, destination color)

Multiply
Result = source color * destination color / maximum value for bitdepth
draw_set_blend_mode_ext(bm_dest_color, bm_zero)
draw_set_blend_mode_ext(bm_zero, bm_src_color)


Color Burn
Linear Burn
Darker Color
Lighten
Screen
Color Dodge

Linear Dodge (add)
draw_set_blend_mode(bm_add)
draw_set_blend_mode_ext(bm_one, bm_one)


Lighter Color
Overlay
Soft Light
Hard Light
Vivid Light
Linear Light
Pin Light
Hard Mix
Difference
Exclusion
Hue
Saturation
Color
Luminosity



So, we have access to all these extended blend modes, but what the heck do they do?!?

I'm a professional game artist, and I can't even begin to visualize the extended blend modes from their description.

So I made a little app to help me visualize them. It didn't help much, so I thought I'd put this up on the forum and try to get some more of the Expert users to write about their experiments with blend modes.

Blend Mode Viewer gm6
CONTROLS:
Up / Down: cycle Source blend mode
Left / Right: cycle Destination blend mode
Digit 1: toggle Layer 0 background
Digit 2: toggle Layer 1 background

Space: Toggle slide show mode
NOTE: slide show mode simulates pressing Up and Right in a sequential order. If you stop the slide show and need to go back, try hitting Left or Down.

Feel free to edit this gm6 and post your own file with worthwhile results.

I imagine there is a whole slew of effects we can accomplish by using the extended blend modes, if only we had a notion of exactly what the results would look like.

Edited by Sinaz, 27 August 2008 - 08:37 PM.
** Old Experts Topic **

  • 0

#2 FredFredrickson

FredFredrickson

    Artist

  • Global Moderators
  • 9196 posts
  • Version:GM8

Posted 09 November 2006 - 03:19 AM

I believe there was a blend more viewer created a while ago in the WIP section, but I never got to checking it out. It would be handy for someone to explain this in plain old English though, because I find myself in the same boat as you - a professional artist who has no idea what the extended blend modes actually do.
  • 0

#3 Yourself

Yourself

    The Ultimate Pronoun

  • Retired Staff
  • 7341 posts
  • Version:Unknown

Posted 09 November 2006 - 03:33 AM

When GM (or rather, Direct3D) goes to draw a pixel there's a source color (the color of the pixel we're going to draw) and a destination (the color that's already in the pixel we're drawing to). When determining the new color of the pixel, Direct3D will combine the source and destination colors according to the blend mode. Each component of the colors is stored as a floating point value between 0 and 1. The new color is calculated by multiply each component of the source color by some factor and by multiplying each component of destination color by some other factor and then we add the results together component by component. The factors you can multiply by are described in the manual.
  • 1

#4 FredFredrickson

FredFredrickson

    Artist

  • Global Moderators
  • 9196 posts
  • Version:GM8

Posted 09 November 2006 - 03:40 AM

Hehe, well that was quick and easy. Thanks Yourself!
  • 0

#5 Sinaz

Sinaz

    MCP Killer

  • Retired Staff
  • 2751 posts
  • Version:GM8

Posted 09 November 2006 - 05:09 AM

When GM (or rather, Direct3D) goes to draw a pixel there's a source color (the color of the pixel we're going to draw) and a destination (the color that's already in the pixel we're drawing to).  When determining the new color of the pixel, Direct3D will combine the source and destination colors according to the blend mode.  Each component of the colors is stored as a floating point value between 0 and 1.  The new color is calculated by multiply each component of the source color by some factor and by multiplying each component of destination color by some other factor and then we add the results together component by component.  The factors you can multiply by are described in the manual.

<{POST_SNAPBACK}>


Yeah, that's pretty much what the manual says... but I can't take that information and use it to imagine what two images will do to each other using any given combination of blend modes.

bm_add, bm_subtract, and bm_max (or whatever) are pretty simple... but trying to custom design blend modes is a bit weird.

Hopefully we'll get some good experimentation going on here.
  • 0

#6 Calle

Calle

    GMC Member

  • GMC Member
  • 689 posts

Posted 09 November 2006 - 05:41 PM

The function is not very useful, actually. Not very often you do these kind of things, and there are alternative ways. However, I also wondered what the different effect would be and made a fast test just to see different effects. It is not the best sprite for the test I suppose, but you can change it yourself.

Increase/Decrease by using left and right mouse button on the white squares.

http://ekdahlproduct.../calle/test.gm6
  • 0

#7 OpticalLiam

OpticalLiam

    GMC Member

  • New Member
  • 782 posts

Posted 09 November 2006 - 05:57 PM

"The function is not very useful, actually."

I'm lolling.

Anyway, my contribution:

Multiply:
draw_set_blend_mode_ext(bm_dest_color,bm_zero)

Negative:
draw_set_blend_mode_ext(10,1) or (10,10)

Modulate2x:
draw_set_blend_mode_ext(bm_dest_color,bm_src_color
);

I would really like to know how many of Photoshop's blend modes are achieved, but I'm sure using this little tool I could work out similar techniques, so thanks for that!
  • 0

#8 Jeggi

Jeggi

    GMC Member

  • New Member
  • 258 posts

Posted 09 November 2006 - 11:40 PM

Just a small note to Calli's gm6 file. Try using the sky background that comes with GM. Then you will see the effect better.

Anyways. I've been programmin with GM since 4.3. Although I've tryed multible times, i've never been able to get a good hang of how to use the blend functions, so I really hope you guys will have a good dissucion (spelling?) so that members (and me) reading this will be better at using the blend modes.
  • 0

#9 Daniel-Dane

Daniel-Dane

    GMC Member

  • New Member
  • 3581 posts

Posted 11 November 2006 - 12:21 AM

You can all agree with me that the basic blend modes are easy when you first catch it. The ext(ra) blend modes are really a pain. Either it will result in a black screen, a white screen or inverted (in a dark/light color)!

GearGOD have made the metalball (no, not meatball) example, and (she?) is using blend mode ext with white sprites in different alphas to make a lot of bueatiful colors.

Now, I still don't get them ... That's why I wrote my "Learn Blend Mode Ext(ra)" (Just released version 2 ... advertise *ha ha* !).
But truth is, I still don't quite get it. But seeing something Visual really helps a lot :(.
  • 0

#10 Molecule

Molecule

    GMC Member

  • New Member
  • 51 posts

Posted 14 November 2006 - 09:35 PM

Ok, if you for example want to draw a pixel on another pixel that is on the background, the color of the pixel on the background is the destination color and the color of the pixel you are drawing is the source color.
The colors have four channels: Red, green, blue and alpha.
For the source they are called: Rs, Gs, Bs, As and for the destination: Rd, Gd, Bd, Ad. I dont know why the destination color has an alpha channel... :(

What the draw_set_blend_mode_ext(src,dest)-function does is to multiply the source color channels with the src-factors and the destination color channels with the dest-factors and then add the results together! It works like this:

You want to use multiply blend mode and have dark-red for the source color and yellow for the destination color.
You use draw_set_blend_mode_ext(bm_dest_color,bm_zero);
The channel values for the source color(dark-red) are Rs:0.5, Gs:0, Bs:0, As:1.
For the destination color(yellow) they are Rs:1, Gs:1, Bs:0, As:1.
The factors that the source should be multiplied with(bm_dest_color) are Rs:Rd, Gs:Gd, Bs:Bd, As:Ad and for the destination(bm_zero) they are all set to 0.

Step 1: Multiply the source color with the src-factors.
The value of the red channel in the source color is 0.5 and should be multiplied with the red channel in the destination color(1): 0.5x1 = 0.5.
Do the same thing with the other channels:
Green: 0x1 = 0. Blue: 0x0 = 0. Alpha: 1x1 = 1.

Step 2: Multiply the destination color with the dest-factors.
Red: 1x0 = 0. Green: 1x0 = 0. Blue: 0x0 = 0. Alpha: 1x0 = 0.

Step 3: Add the channels together and you get the result.
Red: 0.5+0 = 0.5. Green: 0+0 = 0. Blue: 0+0 = 0. Alpha: 1+0 = 1.

Result: Dark-Red! :(
If the channel values are more than 1 they will be set to 1.

If you read the whole post you have to understand how it works! :D
  • 0

#11 clam_is_good_29

clam_is_good_29

    GMC Member

  • New Member
  • 44 posts

Posted 15 November 2006 - 05:18 AM

I dont know why the destination color has an alpha channel... :(

If you're drawing on a surface, the alpha can be something other than 1(ie by using draw_clear_alpha(col,alpha) or drawing on it with bm_subtract). I think that technically the main game surface has alpha, but it doesn't do a lot to change it, as it's not being drawn on top of anything (I guess it does matter if you're drawing on top of it using the ext blend modes though).
  • 0

#12 Yourself

Yourself

    The Ultimate Pronoun

  • Retired Staff
  • 7341 posts
  • Version:Unknown

Posted 15 November 2006 - 05:54 AM

Alpha is a component of color. Wondering why the destination has it is like wondering why the destination has a blue component. The only difference is that alpha doesn't show up as a visible color, but it does determine how a pixel will appear when you draw on it.
  • 0

#13 tsa05

tsa05

    GMC Member

  • New Member
  • 713 posts
  • Version:GM:Studio

Posted 15 November 2006 - 06:03 PM

Rock On, Molecule!

If you read the whole post you have to understand how it works

I couldn't agree more.
All that's really left to do in this topic now is to make a comparison table showing all of Photoshop's blend modes and their GM equivalents. Maybe if I have time later...
  • 0

#14 OpticalLiam

OpticalLiam

    GMC Member

  • New Member
  • 782 posts

Posted 15 November 2006 - 08:19 PM

All that's really left to do in this topic now is to make a comparison table showing all of Photoshop's blend modes and their GM equivalents.  Maybe if I have time later...


If you would do that, I'd be eternally greatful. I would do it myself but I'm lazy.
  • 0

#15 tsa05

tsa05

    GMC Member

  • New Member
  • 713 posts
  • Version:GM:Studio

Posted 17 November 2006 - 03:33 PM

Ok, it's almost the weekend, perhaps I will--anyone else out there, feel free to chime in too.

Without having to go fishing through Photoshop at the moment, I'll do the easy one that I know off the top of my head (aside from multiply, which we've seen):
Screen:
draw_set_blend_mode_ext(bm_one,bm_inv_src_color);
Screen takes the inverse of the foreground and multiplies it by the background. Then it adds the result to the background.

Also, it should be noted that I'll be limited to far fewer blend modes, unless someone knows something about GM that I don't regarding these modes...
For example, Darken is accomplished by comparing the luminance of the source and destination pixels. The darker value determines which color is used (applied normally). Lighten is, naturally the reverse. I don't know of a way to get GM to perform that comparison.

The same is true for the lighting modes.
Hard light is nothing more than a combined multiply and screen. Colors brighter than middle gray (127 127 127) are screened and colors darker are multiplied. And Overlay does the same, but reverses the actions. We now have the GM equivalents for both, but I have no idea how to make GM compare on a per-pixel basis.

Soft Light performs lighten on all colors above 50% grey and darken on all colors below.

Pin Light does the same as above, only based on the destination pixel's luminance rather than 50% grey.

Vivid Light changes the source's contrast by the brightness above or below 50% grey.

Hard Mix--forget it.  Does a combo vivid light + posterize!

And there are even a few others. But I'll look back over them and see what else can be done.

Linear Dodge:
draw_set_blend_mode_ext(bm_one,bm_one);
As far as I can tell, Adobe seems a bit vague in describing this one...
I thought it might be draw_set_blend_mode_ext(bm_src_color,bm_one), but it's too much.
Edit:Right. Linear Dodge is the Photoshop equivalent of Add. Still learning new things every day!

Edited by tsa05, 17 November 2006 - 06:31 PM.

  • 0

#16 OpticalLiam

OpticalLiam

    GMC Member

  • New Member
  • 782 posts

Posted 17 November 2006 - 06:57 PM

tsa05, you may find this link useful:

http://www.lightcraf...Blend_Modes.php
  • 0

#17 tsa05

tsa05

    GMC Member

  • New Member
  • 713 posts
  • Version:GM:Studio

Posted 17 November 2006 - 07:56 PM

Oh, thanks, but I already know what the blend modes do (I can't tell if you're hinting that I don't know what I'm talking about)... It's really just a matter of remembering the algorithms. I explained a number of them above--did you see any that struck you as inaccurate?

I've already outlined the main difficulty with replicating most of Photoshop's blend modes--the fact that they often hinge upon per-pixel comparisons and subsequent multiple cases. But Multiply, Screen, and Linear Dodge are all quite possible (Linear Burn seems like it should be too, but alas, no subtract!).

It surprised me that GM doesn't have a few more bm options--even just brightness would add some extra functionality.

All that being said, there's actually a number of things that can be done with Alpha. The trick here would be to include something like bump displacement maps for your sprites, but mapped to whatever blend calculation you wanted. Using source_alpha, and particularly source_alpha_sat in conjunction with drawing a sprite map over an already drawn sprite (thus now part of the destination), you can get things like linear burn. And as for the "true" blending modes, where you actually combine source and destination, well, ick. I can imagine finagling together something using the sprite from screen and from surface functions to put together a sprite map, but I don't really have the heart to try!

I wonder if Mark has considered making some of the mapping-type blend modes easier... Anyways, use multiply basically to drop in sprites with white removed, screen to drop in sprites with black removed, and linear dodge if you get bored, but that seems to be about all. If I think of another I'll post--if any of y'all think of another, please tell me!!!

Edited by tsa05, 17 November 2006 - 07:58 PM.

  • 0

#18 OpticalLiam

OpticalLiam

    GMC Member

  • New Member
  • 782 posts

Posted 18 November 2006 - 01:06 PM

Oh, thanks, but I already know what the blend modes do (I can't tell if you're hinting that I don't know what I'm talking about)...  It's really just a matter of remembering the algorithms.  I explained a number of them above--did you see any that struck you as inaccurate?


Not at all, you strike me as one of the most informed people on the GMC. The link was honestly just incase you may find it helpful in your quest of finding blend mode combinations, sorry if I may have caused any offence.
  • 0

#19 Daniel-Dane

Daniel-Dane

    GMC Member

  • New Member
  • 3581 posts

Posted 18 November 2006 - 10:04 PM

It surprised me that GM doesn't have a few more bm options--even just brightness would add some extra functionality.

<{POST_SNAPBACK}>

you strike me as one of the most informed people on the GMC.

<{POST_SNAPBACK}>

Something doesn't fit there, even I know that blend mode ext does have brightness :/.
  • 0

#20 Yourself

Yourself

    The Ultimate Pronoun

  • Retired Staff
  • 7341 posts
  • Version:Unknown

Posted 18 November 2006 - 10:16 PM

Something doesn't fit there, even I know that blend mode ext does have brightness :/.


No it doesn't. It works with the RGBA form of color, not an HSBA form of color. The reason there are so few blend modes available is because this is what is available in Direct3D (or so sayeth Mark). Photoshop can do fancy things because it has the filters written in software and doesn't have to draw things in real time.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users