Alpha in Normal map ?

Hi,

I’m currently merging 2 texture and i need a normal map to use a mask (alpha).

Multiplying the alpha with the texture work with texture but with normal it’s not working… it’s creating weird behavior.

I know it must be easy and i’m really close to achieving it.

fixed3 baseNormal = UnpackNormal(normalMapOutput);
fixed3 bloodNormal = UnpackNormal(bloodNormalTexture);
fixed3 combinedNormal = combineNormalMaps(baseNormal, bloodNormal);
o.Normal = combinedNormal;

so all Work excepts my bloodNormal need to be masked with a mask. I already got the mask but i don’t know how to mask a normal.

Any Helps ?

Regards,

Paul-André

i managed to work it out with :

fixed3 newBlood = lerp(bloodNormal, fixed3(0, 0, 1), (1 - bloodAlpha.a));

Would there be a better way ? more performant ?

It should be as simple as:

o.Normal = combinedNormal * bloodAlpha.a;

That would be bad, as the resulting normal when the alpha is zero would be (0,0,0) which will result in the lighting going black!

@Pabi - What you’re doing is fine. A very minor optimization would be to remove the “1-” and just use:
lerp(fixed3(0,0,1),bloodNormal,bloodAlpha.a);

A lerp is fairly inexpensive overall, so I wouldn’t worry about it. Using a custom UnpackNormal function on desktop & console could be slightly faster by taking advantage of how normal maps are unpacked to apply your mask, but in the grand scheme of shader performance it’s not going to save a ton compared to the overall complexity of your average lit shader.

1 Like

Thank bgolus !!! :smile: