quadPatPad

[GameMaker]  Shader for pushing vertices to add padding around sprite.

This asset pushes vertices to add padding around drawn sprites, so there is empty space around sprite for effects such as outlines. 

If your sprite is edge-to-edge, or you have automatic sprite trimming on, then some parts of the sprite will touch the edges of quad; which many have found can't then have outline there. This asset showcases how to add arbitrary amount of padding with shaders, therefore allowing outlines (or other effects) around sprite.

 The examples in asset  only uses it for outlines, but you can modify it for your needs, replace the effect in shader with something else for example.

On GitHub : [GitHub] quadPatPad

Using

Following uses default settings, adds 1px padding and 1px outline:

quadPatPadSet();
// Draw stuff in-between, like `draw_self()`
quadPatPadEnd();

You do not need to call End in same event. Note that the asset requires and will use "shader_enable_corner_id(true)", it will break if you set it otherwise.

You may pass optional parameters with struct.

quadPatPadSet({
    // Padding related.
    debug : [ 1, 0, 0, 0.5 ], // Visualized debug color.
    padding : 4, // How far vertices are pushed.
    
    // Outline related.
    offsets : [ ], // Positions for outline neighbour checks.
    threshold : 0.5, // What is considered empty pixel for outline.
    outline : [ 0, 0, 0, 1 ] // Color of outline.
}); 
// Draw stuff in-between, like `draw_self()` 
quadPatPadEnd();

The asset can't deal with rotations, are GameMaker bakes those into underlying vertex buffers, so there is no usable rotational information within vertex shader.


Considerations

Alternative approach is to just disable automatic sprite cropping, and manually add padding around the sprite. This is manual work, but is more performant and robust than this asset.

If you look at the shader, it does use a quite few calculations to achieve padding around the sprite without affecting visual size. That's why manual padding is more performant. This asset also has downside of requiring use of corner ID, and inability of supporting rotations.

But it has dynamic padding size, which can also be used for cropping, so that's something.

Download

Download NowName your own price

Click download now to get access to the following files:

quadPatPad_package_with_examples.yymps 120 kB
quadPatPat_package.yymps 7 kB
quadPatPat_project.yyz 123 kB
quadPatPat_Windows.zip 3.1 MB
quadPatPat_HTML5.zip 716 kB

Leave a comment

Log in with itch.io to leave a comment.