Saturday, November 11, 2023
HomeiOS Developmentios - Steel is premultiplying texture alpha between fragment attachment & fragment...

ios – Steel is premultiplying texture alpha between fragment attachment & fragment shader arg— why?


I am satisfied that Steel is alpha-premultiplying my texture in some unspecified time in the future between the attachment commandEncoder.setFragmentTexture(…, index: 0) and the fragment shader’s arguments (texture2d<float> texture [[texture(0)]],). The Xcode Steel Body Seize appears to substantiate this:

Inspecting the draw… command’s fragment texture binding:

Fragment binding in Xcode's frame debugger

reveals that is clearly a non-alpha-premultiplied picture (which I do know to be true of the CGImage it comes from— it is pulled from the community and is loaded manually with texture.exchange(…, withBytes: …), not MTKTextureLoader):

Inspecting with Pre-Multiplied Alpha enabled; too mild on the semi-transparent edges to be right:
Inspecting with Pre-Multiplied Alpha enabled; too light on the semi-transparent edges to be correct
Inspecting with Pre-Multiplied Alpha enabled; right imagery:
Inspecting with Pre-Multiplied Alpha enabled; correct imagery

Nevertheless, when debugging the identical texel as returned by the dataTexture.pattern(dataTextureSampler, in.dataTextureCoordinate) name within the fragment shader (utilizing the 0 texture fragment binding), the pixels are actually clearly alpha-premultiplied:

Inspecting with Pre-Multiplied Alpha enabled; right imagery:
Inspecting with Pre-Multiplied Alpha enabled; correct imagery
Inspecting with Pre-Multiplied Alpha disabled; too darkish on the semi-transparent edges to be right:
Inspecting with Pre-Multiplied Alpha disabled; too dark on the semi-transparent edges to be correct


So why is Steel doing this? Is that this documented wherever? (I’ve scoured the Steel Shading Language Specification Model 3.1 to no avail.) Is that this configurable by some means? (There is a trace to the aim of this by the argument identify of dataTexture— I actually want to hold the literal values within the texture except I say in any other case.)

Mixing is being carried out with RGB: add, one, oneMinusSourceAlpha; A: add, one, oneMinusSourceAlpha; as is customary for pre-multiplied alpha mixing (although I am fairly positive that is not related right here since we’re fragment inputs, not blended outputs).

Utilizing Xcode 15.0.1 with an iPad Professional 11″ 2021 iPad13,6 working iPadOS 17.1; and in addition Xcode 15.1 beta 2 with an iPhone 14 Professional iPhone15,2 working iOS 17.2 beta 2.



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments