This Post contains several things I made to udnerstand and work with surfaces:
Tool 1: GMS Blend mode test
A Tool to test different extended blend-modes and thus hopefully start to understand how they work.
Tool 2: Masking in GMS
A tool that explains how premultiplying alpha into a sprite and shape color works and how that can be used to draw on a surface and to make masks for surfaces similar to masks in drawing programs.
Gimp Script: Premultiply Alpha
A Gimp Script-Fu script to premultiply alpha into an image.
TOOL 1: GMS blend mode test
Windows install version: https://www.dropbox....(v1-0).zip?dl=0
Windows no install version: https://www.dropbox....nstall.zip?dl=0
Tested the no-install-version on two systems and both anti-virus-scanners rang alarm. One even automatically removed it and I had to manually get it out of quarantine.
Android Version: https://play.google....ames.gms_bm_gen
The Program has a fixed resolution width of 1024px. So on most mobiles everything will be a bit small. On a 5" display it's just so useable with a pen. On Tablets it's much easier to use.
This tool will help understand how blend modes in Game Maker: Studio and maybe also other programs work. I made this for a
project of mine. Main purpose was to find different ways to blend light halos into a scene. Either by directly blending the halo
sprites with the background or by blending the halo sprites with a surface creating a light map and then blending that surface
with the background.
For that purpose you can choose a sprite to be blended, set it‘s attributes like size, color and alpha and set the blend mode.
This sprite will then be drawn multiple times to the upper left quadrant with a solid black background, to the upper right quadrant
with a solid white background and to the lower left quadrant with a solid concrete photo-background.
Then the sprite will also be drawn on a map-surface and that map will then be drawn to the lower right quadrant with a solid
concrete photo-background as well. You can choose the clearing type of that surface and how it is blended with the background.
Finally you can also set the brightness of the concrete photo-background. This is important when the blendmodes add or multiply
There are some minor bugs left like sprites being drawn in other quadrants when scaled up. At the moment I do not plan to fix
those bugs or add another feature. I learned from this what I needed to learn and that‘s that. I hope no one minds.
TOOL 2: Masking in GMS
Nov 30th 2014: Added another little tool I made to learnmore about premultiplying alpha into a sprite or color and like this drawing on a surface and then masking the surface.
The whole idea is comparing different methods of drawing on a surface by setting up a reference and then different examples on other methods.
- drawing to the application surface in bm_normal
- drawing to a surface and then to the application surface both in bm_normal
- drawing to a surface in bm (src_alpha_sat | zero) and then to the application surface in bm (one | inv_src_alpha)
- premultiplying and then drawing to the application surface
- premultiplying, drawing to a surface and then to the application surfacein both in bm (one | inv_src_alpha)
- and the same as the last but drawing a mask on the surface in bm (one | src_alpha) or (one | inv_src_alpha)
There's an explanation to each example when hitting the i-buttons at the bottom of each example and I'll also include the .gmz in case you want to read the code. I tried to clean it up a bit after I was finished, but it's not really optimized. Though I guess it's still easy enough to read with the comments I added.
Here's the .gmz:
and a screenshot:
Edit Dec 17. 2014:
Added Fonts to the test to show different way to premultiply their alpha.
GIMP Script: Premultiply Alpha
This script copies the active layer and premultiplies the alpha values into the colors of the copied layer. The original layer is kept but will be set invisible.
This can be used to easily premultiply the alpha values into the colors of an image.
You can do the same to any sprite ressource within GMS as well (not sure from what version on though). Open the sprite properties and then the editor. Just beneath the menu there's a tool bar and the the right most icon is 'Pre-Multiply Alpha'. There's one important thing to know though: Usually you'll create your sprites in an external program like GIMP. Depending on how you create and save the file premultiplying in GMS could lead to very bright borders. I don't yet know when that happens, but guess it's something about how the fully transparent pixels were saved.
The script actually just does the steps descriped in this post:
It's probably not well coded since lhalf a day ago I didn't know anything about scripting in GIMP yet, but it does work and that's what counts I guess
Save the script in your GIMP-scripts folder wich on windows usually is located at C:\user\<username>\.gimp-2.x\scripts
If GIMP is already running, go to Filters -> Script-Fu -> Refresh scripts
- Select the layer you want to have premultiplied
- Apply the mask if the layer still has any (the script will fail if a mask exists)
- Select: Colors -> Premultiply Alpha
- Export to PNG
Edited by The Reverend, 31 May 2015 - 06:03 PM.