Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Possible to have normal map "below" object normals?

Discussion in 'Shaders' started by Warrior1424, Dec 17, 2015.

  1. Warrior1424

    Warrior1424

    Joined:
    Sep 30, 2010
    Posts:
    984
    (Note: Surface Shader)
    Is it possible to have lighting from a normal map appear below lighting from the object's normal?

    Imagine some bumpy rock directly underneath the surface of some glass, where the rock uses a normal map, and the glass uses the object's normal. Lighting would fall according to the rock's normal map, but there would still be the glare from the glass directly above it (the "glass" would effectively be just the glare, giving the illusion of glass). Note that this would be in single shader on a single object.

    What might be easier (although not necesarrily possible) would be to make the object render normally (with diffuse and bump maps), then calculate the lighting if it were to fall on the object's normals (ignoring the bump map from before), and add/screen that to everything before.

    I don't want anyone to write a whole shader for me, I just need to know if this is possible, and if so, how to access both methods of light falling on an object (with normal map and with object's normals).

    Also it is very late at the time of writing, so I hope this all makes sense.
     
  2. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Yes, this is possible. You could do it in a single pass without much effort.

    Have a look for "clear coat" shaders and stuff, too, that sounds like something that might suit your needs.
     
  3. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    It depends on whether you want to do it forward or deferred. Forward is simple as Farfarer mentions.

    Deferred it's a different thing, because there is no room in the g-buffer to store two normals. In that case I would do the bottom layer deferred and later add the glass as transparent shader. (If the objects are exactly the same, you can do this without any z-fighting.)
     
  4. Warrior1424

    Warrior1424

    Joined:
    Sep 30, 2010
    Posts:
    984
    I googled every possible variation of "clear coat" and found tons of assets I could purchase, but nothing I could look at to figure out how to implement it myself. I found one free asset on the asset store that had a physically based coat shader, but it isn't a surface shader, making studying it useless.

    It seems like I would use "float3 worldNormal; INTERNAL_DATA" , but I still don't know how to use it to receive light in addition to the normal map.
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,236
    To do it as a surface shader would require implementing a custom lighting model (which is relatively easy) and a custom SurfaceOutput struct (which I haven't tried to do so I don't know if it's even possible) or using the world normal light you're attempting.

    Either way I think it's more work than you're expecting it to be.