Search Unity

Detail maps in the HDRP Lit Shader

Discussion in 'General Graphics' started by Koach, Jul 14, 2018.

  1. Koach

    Koach

    Joined:
    Feb 14, 2018
    Posts:
    3
    My team and I have recently upgraded our project to the 2018 beta build, and I've been catching up on the differences between the old Standard Shader, and the new Lit Shader. One aspect that has been tough to figure out is the new way detail maps work. Specifically, in the old one, if I wanted just a separate detail bump map, I could plug it in as a regular bump map, which was extremely handy when I wanted to add little texture touches that could be scaled separately from the original albedo (For instance, a wall with a stripe on it. I can scale the stripe however I like it, and then use a generic rough surface bump map on the detail inputs, and scale it finely, to create a high quality granular texture to the wall). But now as I understand it, there is only one slot for detail maps, and they make use of RGB channels for separate maps. According to the lit shader documentation, the red channel is an overlaid albedo, while the green channel is a bump map, but I've tried reducing all the red out of an image (in gimp 2) only to still have an albedo cluttering up my textures. So my concern is mostly related to how to manipulate the RGB channels, with regards of how to enter them into the detail map. For example, if I want only a detail bump map (green channel), with no albedo (red channel) or specular map (blue channel)
     
  2. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    585
    Great question! Fighting with that as well.
     
    florianalexandru05 likes this.
  3. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    704
  4. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    704
    I you want a detail map that affects bump only, you will need to set this in it's channels:
    • Red Channel: mid grey (128)
    • Green Channel: Y value (green) of normal map
    • Blue Channel: mid grey (128)
    • Alpha Channel: X value (red) of normal map

    Note that the alpha channel is mandatory, because leaving it blank will result in wrong normal values.
     
    arturmandas, OfficialHermie and Koach like this.
  5. Koach

    Koach

    Joined:
    Feb 14, 2018
    Posts:
    3
    Thanks for the information everyone! Just to update, one of the big issues I had with the new shaders was how to change the individual channels properly, since I was using Gimp 2 and not photoshop. So through these threads I figured out what needed to be done, but not how to do it per se. After a bit of experimentation and chatting on various sites, I finally figured out a suitable method for doing this with gimp, and I'll write it out here for anyone else frustrated. It's a little long winded, but it's worked great. Coincidentally, one of the resources I used was http://docs.cryengine.com/display/SDKDOC2/Detail+Maps as it turns out that cryengine uses practically the same method.

    Now as for doing this in Gimp, the easiest method I found was to decompose an image, copy the images I wanted into the appropriate named layers, and then recompose it. This would ensure that exactly the greyscale information I want goes into each channel. So the steps are as follows

    First I pick the image that I want to be my main detail map, just like you would for a tileable texture in the old system. It doesn't matter at this point if it's greyscale or not, but it does need to be RGBA. If it doesn't already have an alpha channel, you can right click on the layer and select Add Alpha Channel. The alpha channel will be empty, but that's fine, all of these layers will be tweaked.

    Next I decompose the image by going to Colors - Components - Decompose. This takes all the greyscale information from the RGB channels and the alpha channel and turns them into layers. It's important that you don't change the names of the layers, as that will be how they recompose later.

    Next, separately, I open the image I'm going to use as my normal map, and do the same thing: Colors - Components - Decompose. With those layers, I take the layer labelled as the green channel and copy just that selection (you can hide the other layers to make sure they don't get copied), and then go back into the main image and paste it into the layer labelled alpha. Next, you take the red channel of your decomposed normal map, and paste it into your green channel.

    Now that the normal map is out of the way, you can put whatever you think is appropriate in the other channels, remembering what each one does. Most of the time, I keep things simple and just use a gray scale image of the source image I was using, but for more complicated detail maps you'll need to decide for yourself.

    Once you have the layers the way you want, you'll need to remove the individual alpha channels on each layer: right click each layer and click Remove Alpha Channel one by one. Then go back to Colors - components - Recompose. Make sure your result is in RGBA mode. If recompose is greyed out and you can't click it, make sure you've removed all the alpha channels from each layer.

    Once I figured out how it works, I've actually come to appreciate it a lot more than the old Standard Shader detail maps. For one thing, while I was hoping to create a detail map that has only a bump map, it's kind of unnecessary, as once the map is properly made, you can just throttle down the other sliders so that only your bump map information is visible, without the overlay albedo or gloss maps
     
  6. VCDESIGN

    VCDESIGN

    Joined:
    Jul 18, 2017
    Posts:
    43
    Hello guys, I've made a tool that converts your texture maps automatically into the Detail Map from Lit Shader.
    No more manual work in Photoshop.

    Check it out: https://gum.co/Nbdfn

    upload_2019-4-18_20-29-44.png
     
  7. dandeentremont

    dandeentremont

    Joined:
    Jan 11, 2013
    Posts:
    24
    I'm really curious why they decided to go with that channel placement for the normals. Why not 2 channels that were beside eachother? Like Albedo, Normal, Normal, Smooth? There must be a reason.
     
  8. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Because that's been the industry standard for storing normals for a long time, at least when BC5 isn't being used.

    The alpha channel of a DXT5 (aka BC3) is much higher quality than the individual RGB channels. The RGB color uses 4 bits per pixel, like a DXT1 (aka BC1), and the A uses 4 bits by itself. The RGB channels are also correlated, meaning what's in one channel affects the others, where as the A is uncorrelated; it's compressed by itself. Compression artifacts are generally more noticeable for normals as well.

    So why not BA for the normals? Because the green channel is also slightly higher quality than red or blue. No where near as nice as the alpha, but still better. The RGB colors are compressed with 16 bit color palettes, which uses 5 bits for red, 6 bits for green, and 5 bits for blue. So the two best quality channels are the green and alpha, so that's what the normals use.

    I mentioned BC5 above. That's a compression format that is basically two BC3 alpha channels as the red and green channels. I believe this is the default format for regular normal maps for the HDRP, and it's also an option for the URP and built in rendering paths.
     
  9. dandeentremont

    dandeentremont

    Joined:
    Jan 11, 2013
    Posts:
    24
    Thank you, very interesting!