Alpha multiplication in Node Material using NME

Currently working with NodeMaterial. There is a need to apply texture with transparency on top of some background. The problem is that texture gets a grey outline around itself.

I assume the core issue is in alpha multiplication.

The first example, I attempt to premultiply alpha right in the nodes but seems like it makes no difference. The final result has grey outlines.

In the second example, I premultiply alpha outside of NME and simplify the graph a bit - and it works! You can see the text has no grey outlines.

Could you please advise what I am doing wrong in the first example and how I can achieve the second result without premultiplying the colors of the image outside of the NME.
Maybe there is completely different way to achieve what I want, a less brut-force one :slightly_smiling_face:

(There is another “solution” by changing sampling mode to nearest, but that kills the quality, I specifically want to achieve a second result with trilinear filtering)

You are not doing anything wrong, see this page for some explanations about why one should always use pre-multiplied textures if the texture has an alpha channel:

If you don’t, you will end up with the artifacts you noticed with your first node material.

1 Like

Great, that makes sense :+1: . Although I still don’t understand why multiplying channels on the NME level doesn’t work, is it not the same as multiplying them before using them as a texture? Probably it’s something related to how the pipeline works and the buffer is uploaded to GPU.

The problem is within the texture read performed by the GPU and the fact it is doing bilinear filtering (as you noticed, using nearest filtering does work). If the texture has no pre-multiplied alpha then this bilinear filtering will have some artifacts, as shown in the article, and you can’t fix it (there’s no way you could tell the GPU to multiply the rgb channels with the a channel after it has read the texture but before it applies the bilinear calculation).

Note that one way to fix the problem on your side would be to use nearest filtering and apply bilinear calculation yourself… But that means doing 4 texture reads in the node material and doing the bilinear calculation in the node material too.

2 Likes

I see, that makes sense. Thank you a lot!

1 Like