Home Technical Talk

Specular AO in PBR (specifically metalness workflow)

polycounter lvl 8
Offline / Send Message
Olli. polycounter lvl 8
I like overlaying some AO on to my specular map so the model doesnt look so flat when its reflecting light (i guess it sort of simulates self reflection in a way). How exactly would I do this in a metalness workflow (for example in UDK or Marmoset) where you dont really have a specular map. I guess for metals you can just put the AO in the albedo map which is used as specular, but for non metals, The only place i can think of putting it would be the gloss map, but that wouldnt have the intended effect at all.

Replies

  • Farfarer
    I think generally you'd bake out something like a cavity map or a specular occlusion map and it would get plugged in somewhere as a unique slot, which would then mask the specular reflection.

    Although you might get away with a high contrast + brightness tweak of AO map or something, if you don't have the extra texture space for a unique map.
  • Olli.
    Offline / Send Message
    Olli. polycounter lvl 8
    So basically i just have to hope theres a seperate AO slot which affects specular too?

    I guess in UDK its a bit more flexible with the whole shader editor
  • EarthQuake
    Large scale ao baked into the specular input just doesn't make much sense with modern shaders. Think about what AO is, and then think about what the specular input defines.

    If you have large scale AO on your spec, what you're really saying is, anywhere that ambient bounced light would be blocked, the surface is less reflective too. In reality, the surface reflectivity does not change in any way unless the surface itself changes. So, if you stuck a light right next to that occluded area, it wouldn't reflect the light source, which doesn't compute from a physical accuracy standpoint.

    In the past, the ambient image based lighting wasn't very sophisticated, so maybe it made sense to multiply your AO on your spec map as a crude sort of reflection occlusion. These days, however, we have local IBL probes for ambient diffuse and specular reflections, and where that fails, we have screen space reflections to fill in the gaps. So more often than not the object is simply reflecting the correct information.

    That said, it can make sense to have micro-occlusion for small cracks and crevices that the shaders and geometry are not sophisticated enough to deal with, and thats what the cavity map is generally for.
  • Olli.
    Offline / Send Message
    Olli. polycounter lvl 8
    In the past ive used it for concave areas quite liberally, even if the detail isnt sharp enough to show up on a cavity map.

    here's a visualisation of what i mean.
    Zfv65bG.png

    light coming in the direction of the arrow i wouldnt want to have a specular highlight on the part ive colored in, since it would look like the light is shining through the model.

    Would i just have to paint that part black in the cavity map?.
  • EarthQuake
    Yeah this is the perfect example of when you would NOT want to occlude that area in the spec map, that area is no less reflective, you just want it to reflect the correct data instead. Again SSR should help. If your engine doesn't have SSR, maybe a specular occlusion map (only if it applies to the ambient IBL and nothing else), but when you occlude that area in the spec map, you're telling the shader that even if you have a dynamic light source shining directly on that area, that the area shouldn't reflect. This doesn't make sense.
  • EarthQuake
    Here is an example:
    specocc01.jpg
    1. basic mesh, no ao, IBL only
    2. basic mesh, baked ao, IBL only - occluded areas are darker, actually, they are *less reflective*, this may look like what you want, but in terms of physics, this is inaccurate.
    2b. baked ao content
    3. basic mesh, no ao, IBL only, SSR on - this is much closer to the desired results, instead of making the material less reflective, the surface is actually reflecting other nearby surfaces
    4. IBL + dynamic light, specular reflection is shadowed correctly from dynamic light
    5. IBL + dynamic light + specular AO, again as the AO map lowers the reflectivity of the surface, even dynamic lights shining at the model are less reflective than they should be, again this is simply physically implausible
    6. IBL + dynamic light + SSR, again this is closer to the desired result.

    Disclaimers:
    SSR is not a perfect technique, its expensive, it requires screen space content so it can't reflect an object it can't see, so there are certainly some drawbacks. However, going forward with rendering tech, this is closer to what you can expect to see. Eventually we will have some sort of realtime radiosity, which includes more realistic reflection occlusion which should fill in the weak spots of techniques like SSR.

    Another example of why baking ao into your reflectivity content is bad (this applies to diffuse as well, large scale ao should really only be multiplied on ambient diffuse lighting):

    Look under your fridge. Its really dark under there, right? Now, shine a flash light. What happens? Does it stay dark, or does the flashlight light up the area? When you bake large scale AO down to diffuse/spec maps, you're preventing those surfaces from ever being lit 100% by the light that hits the surface. It would be akin to shining the flashlight below the fridge and nothing happening, again this is simply physically implausible.
  • Olli.
    Offline / Send Message
    Olli. polycounter lvl 8
    hmmm.. I really wish i had marmoset on my laptop so i could test stuff out while discussing it. Ive just always been kind of disappointed with SSR, since sometimes it sort of bugs out, and especially in marmoset its very low quality in the viewport (maybe thats just my settings) and the cavity is too small (less than 1cm wide) that self shadowing wont work in there.

    The only scenarios i can think of where i would want a reflection on that part is if i had a light source inside the cavity (no reason for that) or if i put the camera inside the cavity (no reason for that either)

    SSR probably works most of the time, but i find that the few angles where it doesnt work and you get a sliver of shining specular in the cavity it just makes me cringe and id rather just paint the whole thing black on the inside so that never happens :P

    edit: whoa an example appeared while i was typing this..

    2 and 5 definitely look better to me.. Maybe i need to start looking at texturing from a new angle, and let go of some of the old conventions im so used to (oh the good old days when you had to add specular highlights to the diffuse texture :) )

    I think example 3 shows what im most frustrated by, when the cavity actually becomes brighter than the outside surface (how does that even make sense.. the outside is reflecting the bright surroundings directly, while in the cavity the light has to bounce 2 or 3 times which should dim it)

    also the grain visible in example 6 is a huge bummer
  • EarthQuake
    Olli. wrote: »
    hmmm.. I really wish i had marmoset on my laptop so i could test stuff out while discussing it. Ive just always been kind of disappointed with SSR, since sometimes it sort of bugs out, and especially in marmoset its very low quality in the viewport (maybe thats just my settings) and the cavity is too small (less than 1cm wide) that self shadowing wont work in there.

    Yeah, this is sort of by design. You can make it look a bit better in the viewport by setting the resolution to 2:1 (double) in the render tab. The basic reason it looks crappy in the viewport is for performance, we multi-sample it when you export an image to significantly improve the image quality. You can up your export resolution to say 3840x2160 as well for even better quality.
    The only scenarios i can think of where i would want a reflection on that part is if i had a light source inside the cavity (no reason for that) or if i put the camera inside the cavity (no reason for that either)
    Naa, there are plenty of scenarios other than those, really any time a dynamic light his the surface in a way that would reflect is case where you wouldn't want to occlude the specular with AO. So, unless your game only uses ambient IBL for lighting, this happens quite frequently.
    SSR probably works most of the time, but i find that the few angles where it doesnt work and you get a sliver of shining specular in the cavity it just makes me cringe and id rather just paint the whole thing black on the inside so that never happens :P
    Sure, SSR is far from perfect, and the question is basically, can you live with it being wrong in some very specific situations (SSR), or being wrong always (AO in spec). If you understand how ao in spec is wrong, but want to do it anyway, I mean feel free. In this case you can put the ao in the spec map if you have one, in the cavity (thought it will probably apply to both ambient and direct diff and spec in most engines), or some engines that use the metalness workflow have a secondary specular input (like UE4) where you can add an AO map (and add the ao to the albedo for metals in this case. Check UE4 docs for more: https://docs.unrealengine.com/latest/INT/Engine/Rendering/Materials/PhysicallyBased/index.html
  • Olli.
    Offline / Send Message
    Olli. polycounter lvl 8
    Its just dawned on me that i should PROBABLY be using dynamic lights when setting up marmoset renders. Usually I just throw my model in to the toolbox and let the IBL do all the lighting, and that might have contributed to my mostly negative experiences with marmoset lighting :D
  • EarthQuake
    Olli. wrote: »
    Its just dawned on me that i should PROBABLY be using dynamic lights when setting up marmoset renders. Usually I just throw my model in to the toolbox and let the IBL do all the lighting, and that might have contributed to my mostly negative experiences with marmoset lighting :D

    Oh yeah for sure, personally I think of the IBL as just the ambient lighting pass. I do most of my lighting work with dynamic lights, and our area lights are really cool. The biggest issue with IBL is that its too expensive to cast shadows from IBL in real time (if it did that, your need to multiply AO on spec would go away too). Eventually we want to add some sort of radiosity solution which should handle that, but that's a long term thing.

    But yeah, dynamic lights are great, I usually turn the IBL intensity down a bit and just use it as a fill light essentially.
  • Yogensya
    Offline / Send Message
    Yogensya polycounter lvl 9
    EarthQuake wrote: »
    Yeah, this is sort of by design. You can make [SSR] look a bit better in the viewport by setting the resolution to 2:1 (double) in the render tab. The basic reason it looks crappy in the viewport is for performance, we multi-sample it when you export an image to significantly improve the image quality. You can up your export resolution to say 3840x2160 as well for even better quality.

    Have you guys considered a resolution scale option in the Capture Settings window? Having to "manually" render at 4k or similar only to resize in PSD to get more samples in SSR or Alpha dithering is not ideal. Something that works like the resolution setting in the Render tab, but affects the outputted image only would be handy.

    As for AO in Specular, i have been avoiding it lately. It's basically baking lighting info on a texture that should only define material reflectivity. That extra darkness can look better in a specific render, but it contradicts one of the purposes of PBR, to make sure the materials are lit as accurately as possible in different lighting conditions.

    However, i think it remains the artist final decision, so for example authoring a specular map only for a specific render shouldn't be out of the question, as long as it's done knowing all that has been discussed here. :)
Sign In or Register to comment.