Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Using Blue channel in normal map for storing additional information

Discussion in 'Shaders' started by MorganSandb, Nov 7, 2017.

  1. MorganSandb

    MorganSandb

    Joined:
    Jun 4, 2015
    Posts:
    19
    Hi Good people of the unity forums!
    I was wondering if someone here have been using the blue channel in the normal maps for storing additional information? Any downsides to this? and or tips/tricks?

    I tried searching around, and found close to nothing related to this for unity.
     
  2. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    823
    As from my understanding the blur color is needed in order to normalize the vector information in the normal map. You could calculate it back in the shader from the red and green channel, but that would be a calculation overhead that might be relevant. I guess, that's why nobody is doing it.
     
  3. nat42

    nat42

    Joined:
    Jun 10, 2017
    Posts:
    353
    I think it's likely on par with (or cheaper even) than normalising the value (not saying you necessarily would, depends on your target I guess) but limiting the bandwidth may make it worth it (and 2 channel normal maps may play nicer with compression)

    Not what Bgolus says here: https://forum.unity.com/threads/does-unity-standard-shader-pack-textures.502974/#post-3276446
     
  4. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    823
    Hm very interesting! Is unity really already doing that? Well, I guess than it only makes sense to use the blue channel for something else, right? Do you already do that (Or have you tried it)?
     
  5. nat42

    nat42

    Joined:
    Jun 10, 2017
    Posts:
    353
    Sorry, for now that's all I've got
     
  6. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    We almost always pack our normals into two channels and do something else with whatever is left.
     
  7. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    If you use Unity's built in Normal Map texture import setting, anything in the blue channel will be thrown away on desktop/console. For mobile normal maps are stored as since a lot of mobile texture formats don't support alpha or offer little to no benefit to using it over a color value.

    Since DXT5 compress the alpha separately and at much higher quality you get much nicer normal maps using the alpha for the "red channel". Additionally the green color has more precision than the red or blue in DXT1 or DXT5 (which is really a DXT1 for the RGB), which is why traditionally the green channel is left where it is and the red channel is moved to the alpha. I've also worked with custom engines that move the red to the green channel and the green to the alpha instead, but it's unusual, though since lighting is usually coming from above it does result in slightly better looking normals.

    For the last ~10 years the BC5 texture format has been used as well, which is a texture format that is basically two DXT5 alpha channels for it's red and green channels. Unity didn't support it until recently as it wasn't supported on the PS3 and Unity only just dropped support for the PS3 in the last year, though the texture format first appeared on the Xbox 360. Since it is just a two channel format there's no option to pack additional data in the blue channel.

    There's also the newly supported BC7 format which is higher quality than DXT1 or DXT5 with support for RGBA so you can pack all sorts of data into that and still have a higher quality than DXT5 with additional data packed in the red and blue. Whether it'll be better than a DXT5 with only the normal will depend on the content. BC5 will likely look better than BC7.

    Whether the quality difference is a concern for you or not is up to you.


    Also, as mentioned in the other thread, if you choose to use any of these it means you cannot use Unity's built in shaders or usual normal unpacking functions directly. Well, that's not true. As of 2017.1 or .2 (?) you can use BC5 normals with built in shaders.
     
  8. MorganSandb

    MorganSandb

    Joined:
    Jun 4, 2015
    Posts:
    19
    Thanks for quick answers! looks like we are skipping using the normal map blue channel then!