Hi, I have some normal maps which contain only the X and Y components of the vector to save space, thus cutting the normal map down to two channels. I believe the way to recreate Z in the shader is : +sqrt(1 – x*x – y*y) Can anyone post a line of shader script which achieves this ? -Gary
Unity is already doing this, when you choise "Texture Type - Normal Map" and "Format - Compressed" in texture inspector
Here's what Unity uses to unpack two-channel normals: Code (csharp): inline half4 UnpackNormal(half4 packednormal) { half4 normal; normal.xy = packednormal.wy * 2 - 1; normal.z = sqrt(1 - normal.x*normal.x - normal.y * normal.y); return normal; } Note that the input is a four-channel DXT5-compressed colour, with X and Y stored in the W and Y components, respectively.
Daniel Brauer I prefer to use Code (csharp): normal.xy = packednormal.wy * (255.0 / 128.0) - 1.0; instead Code (csharp): normal.xy = packednormal.wy * 2 - 1;
Presumably you'd only want to use that fraction for unpacking if you'd used the reciprocal for packing. But why would you want to limit your range like that in the first place?
it's because i want to unpack color(128, *, *) to vector(0, *, *), with standart UnpackNormal it will be (0.00392..., *, *)