Skip to content

Release 2.0

Compare
Choose a tag to compare
@Grisgram Grisgram released this 03 Apr 15:37
· 46 commits to main since this release

Pre-Baking of outlined Sprites

Release 2.0 brings in a completely new and amazing feature, together with a new OutlineObjectBaked.

What is pre-baking?

The assigned sprite will be copied to a surface (with all its frames) and the outline shader will run on that surface once. It takes all the parameters into account (texture page borders, outline strength, etc) and renders the outline on all frames.

With the sprites I used for testing this pre-baking took between 0 and 5 milliseconds, so if you pre-bake lots of sprites, you should do it at level initialization.

This version uses the Canvas 2.0 Library (The``dev` branch) by @tabularelf to create the surface.

But if it takes 5ms, what is the benefit?

The benefit is runtime performance! Lots of!
While the shader, when it runs "live" costs you some draw batches and texture swaps (roughly 4 or 5 swaps/batches due to shader activation, copying the frame to a surface, rendering it, copying it back to app surface...), the prebaked sprite only costs ONE swap/batch!
This is a 80% performance win compares to "live shading"!

Look at this demonstration video - the numbers in braces on top tell you the swaps/batches.
The left sprite is shaded live and you see the numbers go up from (8)(7) to (13)(11), while the right sprite is pre-baked and you see them increase only by 1, to (9)(8).

outline-prebaking.mp4

Ok looks great, how do I use it?

Simple!
Just use the OutlineObjectBaked instead of OutlineObject. They both behave identical, while the Baked version uses pre-baking.

That's it!

Have fun,

Yours, Gris