# Does unpackNormals return normals in world space?

Hey.

Im having some problems with normal mapping a terrain mesh.

The normals map was created in world machine and the normals dont much up with what you would expect from the lighting direction in unity. The mesh normals work fine.

I think its just something simple like flipping a axis on the normal map but cant get it to work no matter what I flip.

To help me figure it out I decided to render the normals as the color to see what the issue is. The mesh normals in world space look as you expect the to. They are mostly green on flat areas and fade between blue/red/black on curves.

The unpacked normals form the normal map look mostly blue just like the normal map texture. This would suggest the normals are still in tangent space. I was expecting them to be in world space after being unpacked?

Can someone confirm they are meant to be in world or tangent space so I can rule out that as the problem.

If they are in tangent space can some please tell of a why to convert they to world space in the fragment program so I can render them as the color and compare to mesh normals to help debug.

Thanks

It basically just calculates the z value from x and y and rescales it from [0,1] to [-1,1]. Here’s the UnpackNormal function from unity 4.3.3.

inline fixed3 UnpackNormalDXT5nm (fixed4 packednormal)
{
fixed3 normal;
normal.xy = packednormal.wy * 2 - 1;
// Flash does not have efficient saturate(), and dot() seems to require an extra register.
normal.z = sqrt(1 - normal.x*normal.x - normal.y*normal.y);
#else
normal.z = sqrt(1 - saturate(dot(normal.xy, normal.xy)));
#endif
return normal;
}

inline fixed3 UnpackNormal(fixed4 packednormal)
{