• Advertisement
Sign in to follow this  

Alpha Testing: I manage to "scorch" my edges

This topic is 1807 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

 - Both editors and loaders can play funny tricks to save space, like storing RGB-layer of pixels with alpha 0 as black (0).

 

Again, this is a sign of pre-multiplied alpha... meaning that something with color: (R, G, B, A) = (1.0, 1.0, 1.0, 0.5) will be stored in a way that the color is multiplied by the alpha channel: (0.5, 0.5, 0.5, 0.5).

 

This doesn't require the alpha to be 0.0.

 

The reason why this is done is not to save memory, but instead to save processing in the pixel shader during the blend operation.

 

The "typical" alpha blend operation is: Source * (Source_Alpha) + Destination * (1 - Source_Alpha), which is done once per pixel per frame that the texture is drawn.

 

If you pre-multiply your texture, the equivalent blend operation becomes:  Source + Destination * (1-Source_Alpha), meaning that you get to save the computation by skipping the multiplication by Source_Alpha (because it's already multiplied in!)

 

Hope this explains things a bit more.

Share this post


Link to post
Share on other sites
Advertisement

The reason why this is done is not to save memory, but instead to save processing in the pixel shader during the blend operation.
 
The "typical" alpha blend operation is: Source * (Source_Alpha) + Destination * (1 - Source_Alpha), which is done once per pixel per frame that the texture is drawn.
 
If you pre-multiply your texture, the equivalent blend operation becomes:  Source + Destination * (1-Source_Alpha), meaning that you get to save the computation by skipping the multiplication by Source_Alpha (because it's already multiplied in!)

Well, several image editors have issues when saving files, in that they zero out RGB values for pixels whose alpha is zero. It's not that they're converting to pre-multiplied (as RGB values for pixels with alpha > 0 will be preserved, not pre-multiplied). It may be to save space in the image files, or it may just be that they weren't designed with our usage scenarios in mind (e.g. filtering the images on the GPU).

Pre-multiplied alpha can be faster if you're composing images on the CPU, but I doubt it makes a difference on the GPU, which have dedicated raster-op units for this .

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement