Material optimization

Hi Maximum-Dev!

A) Previously I have asked this on the forums and the reply I got was that 1 Texture map + Alpha channel = 2 Texture maps in terms of memory usage. Is this true in all cases? do we get no benefit from packing into alpha channel then?
Yes this is true in all cases because DXT5 compression is used when you have an alpha channel, which doubles the texture memory since the alpha channel does NOT get compressed. One way to keep the texture memory down when using an alpha channel is to force DXT1 compression with 1-bit alpha (no gradients in alpha anymore), but as of right now, UE 4.11 does not allow you to do that (if anyone knows a way then please correct me). The benefit you get from packing a texture in the alpha channel is 1 less texture sampler call.

B) If if we put Roughness into the B channel of normal map. How is the normal map supposed to work without it’s B channel? do we have to append the RG with a flat blue color or something? wouldn’t this result in wrong light receiving?
The blue channel of a normal map does not contain that much information, so you can re-construct the normals using DDX and DDY. See https://forums.unrealengine.com/showthread.php?15179-Storing-a-heightmap-in-Normal-Map-B-Channel&highlight=reconstruct+normals+from+red+green+channels for doing that.

C) If the answer to question A is that 1 Texture map + Alpha channel = 2 Texture maps then why they put grey scale Albedo into the Alpha channel?
They are doing it this way to save texture sampler calls. You’re limited to 16 texture samplers per material (unless you use “Shared: Wrap” in your Sampler Source), and 2 (or 3?) are already reserved for lightmaps and something else (can’t remember what), so that leaves you with about 13-14 texture samplers. By packing 3 different textures into the normal map, they save 2 texture samplers per material type, which adds up quickly.

So for example, let’s say you’re making a material that contains 3 different texture types (dirt, concrete and grass). If you only need a normal map, a reflectance map and a grayscale albedo (more like a gradient ramp) map, then packing all 3 into the normal map texture like the example above would make sense, and would give you 3 texture samplers total instead of 9. But if you a few more textures, for example a roughness map and a AO map, then you might as well NOT use the alpha channel of the normal map for the grayscale albedo and instead use a second texture where you would pack the roughness map in the red channel, grayscale albedo in the green channel and the AO in the blue channel. Doing it this way, you still use the same amount of texture memory, but you get 2 more textures for free basically (as long as none of your texture maps use an alpha channel).

I hope this helped make a little more sense. I am sure you’ll get more info from other people as well, good luck :slight_smile: