Skip to content

Instantly share code, notes, and snippets.

@Eideren
Last active July 20, 2020 16:52
Show Gist options
  • Save Eideren/bed2cf79e2b59ca88a31052a82890c5d to your computer and use it in GitHub Desktop.
Save Eideren/bed2cf79e2b59ca88a31052a82890c5d to your computer and use it in GitHub Desktop.
Ramblings on stride, alpha, transparency and premultiply

Multiple file formats embeds their alpha in the standard, non-premultiplied, format leading to ugly edges around transparent areas when the engine interprets those as premultiplied. There's a couple of reasons to use premultiplied alpha, you can google about this subject if you want to read if/why you should do so.

PSD outputs standard alpha out of the box, to have decent premultiplied results with that format you'll have to create an explicit alpha channel and use it as a global mask for the whole picture, if you have multiple layers with different alphas it becomes really tedious to manage that channel for every changes that you make.

TIFF on the other hand outputs premultiplied alpha and, for photoshop, converting PSDs to TIFF is mostly non-destructive as the format itself can be lossless and embeds all of the photoshop layers, groups, masks and such in the file.


Stride's texture transparency block has an Alpha property which describes how the alpha is interpreted and compressed when stored in GPU and CPU memory (and perhaps on disk when you build your game), the source for those is in AlphaFormat.cs.

  • None: Ignores alpha, the alpha channel won't be stored in memory at all.
  • Mask: BC1, each pixel will either be fully opaque or fully transparent, alpha is one bit per pixel.
  • Explicit: BC2, alpha takes 4 bits per pixel, this format has a fairly limited precision so it is best to use it with textures containing large blocks of semi-transparent pixels or for sharp transparency transitions, like edge anti-aliasing
  • Interpolated: BC3, 8 bits per pixel for alphas, the largest format, it is best suited to textures containing lots of differing alpha values, like glowing particles.
  • Auto: Will guess the right format based on the content of the texture. Right now the logic is return None when the source texture format doesn't have alpha, Mask if any pixel's alpha is either fully opaque or fully transparent (0 || 255) and Interpolated if that's not the case. Right now it doesn't have logic to guess for Explicit.

The Block Compression Texture Format

Those are for Direct3D though, depending on the graphics api those format might not be supported and so will be replaced by other, potentially larger, formats.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment