# Trying to convert a DXT5NM Normal Map for use in my scene

I have a handful of these strange normal maps I need to use in my scene that store X in the Alpha channel, Y in the green channel, and require you to calculate Z with the following formula:

Z = sqrt(1 - (X * X + Y * Y))

Red is always 100% and Blue is 0%, but these channels are not used.

Despite figuring this much out, I haven't been able to produce a node setup that can correctly convert this into the desired purpley tangent space normal map.

Any ideas?

• Do you want to keep them in this format? Commented Mar 27, 2018 at 8:11

Ok, first thing is to split out the channels with the separate RGB node. We'll put down a few re-routes too so we don't go nuts and mix channels up:

Next, put in a Combine XYZ node to recompile the channels together. (note that you can use a Combine RGB node here instead of you like, they are identical aside from labels and the color of the output socket. Color and Vector and both a generic vector3 format inside Cycles, they are only differentiated for UI clarity reasons).

Now, currently we have Z=0. That's not going to work. As you noted in the OP, we need to derive Z from X and Y. The reason for this is that X and Y have already been normalized so the full XYZ vector is in a 0-1 range. Thus we can't just shove a 1.0 in there, we need to actually compute Z using the forumla you have above. (note that this setup is exactly what the Unreal 4 engine DeriveNormalZ does under the hood).

First the multiplications within the parentheses, X * X and Y * Y:

Then sum the result:

Subtract that from 1:

Now we need the square root of that result. That's the same as raising to the power of 0.5, so one more math node:

Finally, the particular normal map you provided appears to be DirectX formatted, so we need to flip the G(Y) channel too:

And it works!

• Thank you! I was doing something somewhat similar, but I ended up swizzling the channels from 0 to 1 to -1 to 1 and doing a couple of other things differently Commented Mar 27, 2018 at 13:19

I managed to generate the Z channel in the normal map according to this scheme (taken from UE4). In the "normal" texture, everything is as usual, only the Blue channel, replaced by roughness.