twostraws / Inferno

Metal shaders for SwiftUI.
Other
2.47k stars 119 forks source link

Premultiply alpha more consistently #7

Closed daprice closed 1 year ago

daprice commented 1 year ago

I noticed some of the shaders produced a fringe on antialiased edges because they were, I think unintentionally, multiplying the alpha value by itself. I believe I fixed this by starting with an alpha of 1.0h in all the places where a color is multiplied by the alpha value. The affected shaders were AnimatedGradientFill, GradientFill, Infrared, InvertAlpha, and Sinebow.

For example, the animated gradient fill without my fix (there’s a whitish fringe around the edges, especially visible on the left and right sides of the circle and the figure’s right arm):

Screenshot 2023-11-17 at 4 47 09 PM

With my fix, the edges are smooth because the alpha of the returned color matches that of the original pixel:

Screenshot 2023-11-17 at 4 46 43 PM
twostraws commented 1 year ago

Perfect – thank you!