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

Image based lighting

Discussion in 'Shaders' started by temps, Dec 9, 2011.

  1. temps

    temps

    Joined:
    Dec 7, 2011
    Posts:
    10
    Hi,

    At the moment we are in preproduction and our upcomming game will feature mostly outdoor scenes. I thought it would be a good idea to light it with a cubemap. Especially interesting now when HDR will be available in 3.5. We will be using deferred and Ive realized the lighting is fixed blinnphong and it would be hard if not imposssible to find a way around it.

    I guess I could use the cube in the surface shader and pass it into emissive. But the best way would probably to do this in the lighting stage. Is there a way to code the lighting yourself or is it a lost cause?
     
  2. duke

    duke

    Joined:
    Jan 10, 2007
    Posts:
    763
  3. temps

    temps

    Joined:
    Dec 7, 2011
    Posts:
    10
    Unfortunately the only thing I can change in deferred is how to blend the already calculated light buffer in the final pass. The lighting pass is fixed blinn-phong. All I want to do really is to replace the static ambient light with a cubemap lookup. I still want to keep blinn-phong lighting for all the lights in the scene and thats why I hope it might be doable with some hacking.

    Cool link, thanks.
     
    Last edited: Dec 14, 2011
  4. Cameron_SM

    Cameron_SM

    Joined:
    Jun 1, 2009
    Posts:
    915
    Using you own lighting model in surface shaders will force those objects to be rendered in forward mode, as deferred lighting is calculated in pre-pass and is uniformly applied in screen space. So, using a surface shader with a custom lighting model for everything kinda defeats the purpose of using deferred rendering to begin with. \

    :(

    Would be nice if we could override the pre-pass lighting model to do exactly those kind of things, SH ambient ect. Also, if that model was then used as a global override for any existing forward-rendered surface shaders (everything in unity free, alpha shaders in pro+deferred) that did not try to implement their own custom lighting model (less fragmentation in rendering pipeline ftw). Not sure why we can't, probably not enough requests for unity devs to spend time implementing and exposing such a feature.

    Also, probably not useful but Unity apparently has built in Spherical Harmonics of a sort, they're vertex based and designed as a fallback for low-end hardware (which really doesn't make much sense to me), the details are rather vague and spattered through different sections of the manual. The most I've ever found about them in one place is here:

    http://unity3d.com/support/documentation/Components/RenderTech-ForwardRendering.html

    Still, I'd like to know exactly what it's doing and how it calculates those SH terms for dynamic/moving objects. I'm probably getting my terms and use-cases confused, I always thought SH was really only useful for IBL type stuff. If anyone know more details about this and how they're used in Unity I'd love to hear it.

    Duke: Those links to Codeflow are great, he posts heaps of great stuff and has a very down-to-earth method of explaining/illustrating relatively complex concepts. I used some of his ideas on physics resting constraints for a game prototype not too long ago.
     
    Last edited: Dec 14, 2011
  5. Cameron_SM

    Cameron_SM

    Joined:
    Jun 1, 2009
    Posts:
    915
    Actually, has anyone tried modifying/overriding the "Hidden/Internal-PrePassLighting" shader in the same way you can override the terrain shaders?

    If you can then adding in a SH ambient term would be rather trivial.
     
  6. temps

    temps

    Joined:
    Dec 7, 2011
    Posts:
    10
    Wohoo! Thanks for the "Hidden/Internal-PrePassLighting" tip. What I've done is to replace the directional light calculation with a cubemap lookup and it seems to work pretty good.
     
  7. Cameron_SM

    Cameron_SM

    Joined:
    Jun 1, 2009
    Posts:
    915
    Nice to know that works, I'll have to keep it in mind. :)
     
  8. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Note that you have to restart Unity to get it to work the first time. After that you'll see changes reflected immediately on reimport.
     
  9. Cameron_SM

    Cameron_SM

    Joined:
    Jun 1, 2009
    Posts:
    915
    We really ought to make an advanced shader development section on the Community wiki so we can document all of these more advanced tricks (as opposed to the wiki just being a free shader bank), it seems unlikely this kind of thing will ever be covered by the default unity documentation (would generate too many support problems for them, people messing with stuff they perhaps shouldn't).