#GMTWeekly: Extended Blend Modes Pt. 1

Hello everyone!

I have been wanting to get back into some #gamedev tutorials for quite some time now. For the time being, I’m going to start doing weekly Game Maker: Studio tutorials to get things rolling. I have a fairly long list of requests, but feel free to send your other ideas my way!

Blend Modes

What are blend modes? Blend modes tell GM what formula(s) to use when blending pixels (your source) with pixels that have previously been drawn to the screen (your destination). By default, GM uses a mode called bm_normal. This mode draws everything how you’d typically expect things to be drawn. If you have a red pixel, and you draw blue over the top of it, it becomes a blue pixel (this is somewhat dependent on the alpha channel of each pixel, as well).

Extended Blend Modes

Ok, so what are extended blend modes? Extended blend modes are a bit more difficult to grasp for most beginner to intermediate users. When setting an extended blend mode, you choose a mode for both your source and destination, separately.

draw_set_blend_mode_ext(source, destination);

The formula for drawing a pixel to the screen is as follows:

((Rs, Gs, Bs, As) * BLEND_MODE_INFO_SOURCE) + ((Rd, Gd, Bd, Ad) * BLEND_MODE_DEST)

Practical Example

Today I will talk about an applicable example that I use in both my previous project, INK, and my current project, FaraWay. This extended blend mode combines both bm_dest_alpha (Ad, Ad, Ad, Ad) and bm_inv_src_alpha (1-As, 1-As, 1-As, 1-As). If you can’t tell by looking at it, this blend mode draws pixels ONLY to positions that are currently drawn to already.

This is how I get ink to splatter correctly on non-rectangular objects (like spikes) in INK. Simply put, it prevents anything from “drawing outside of the lines”.

I also use this effect to draw silhouettes in our new Spaceboy Games project, FaraWay. When an object is behind another object, you draw the *behind* object blended with black (after applying the blend mode) to draw all or partial silhouettes on top of the *front* object.

Project

I have attached a sample project that allows you to mess with this blend mode by drawing colorful shapes when the left mouse button is down. The extended blend mode allows you to scribble around freely without any of the ink effecting anything other than the blank white sprite space (the black background is left unaltered).

GMTWeekly0.gmx.rar

GMTWeeklyGif0

I hope this inspires you to come up with cool new effects for your games!

Thanks,
Z

#GMTWeekly: Extended Blend Modes Pt. 1

2 thoughts on “#GMTWeekly: Extended Blend Modes Pt. 1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s