Description
Is your feature request related to a problem? Please describe.
Stride's blend transparency expects premultiplied colour:
MaterialTransparencyBlendFeatureusesBlendStates.AlphaBlend(premultiplied);- its shader,
MaterialSurfaceDiffuseSpecularAlphaBlendColor, only scales the alpha, not the RGB.
So a texture used as the base colour of a blended material has to be imported premultiplied (ColorTextureType.PremultiplyAlpha). The same image used by an opaque or cutout material has to be imported straight, otherwise its RGB is darkened where the alpha is low. One image therefore needs two texture assets when it is shared. #3810 does that for glTF models, with a <name>_premultiplied copy.
Most engines, and glTF itself, keep textures in straight alpha, with one asset per image. The material decides how to blend.
Describe the solution you'd like
A way for a blended material to use a straight-alpha texture. For example:
- a material option, or a compute node, that multiplies the diffuse RGB by its alpha before blending (
ComputeTextureColor.Swizzle = "aaaa"does not work, because it also squares the alpha); - or a non-premultiplied blend mode for
MaterialTransparencyBlendFeature(BlendStates.NonPremultiplied).
Then the model importer can import every image once, straight, and drop the premultiplied copy.
Describe alternatives you've considered
Keep premultiplied textures for blended materials, and duplicate shared images, as #3810 does. It works, but it doubles the texture memory for those images, and users doing the same by hand have to know about it.
Additional context
Premultiplying in the shader happens after texture filtering, so transparent edges can show a slight halo. Engines usually handle that when the texture is processed, by bleeding colour into fully transparent texels.
Activity