Search Unity

Shading and Lighting in Shadowgun

Discussion in 'Made With Unity' started by robert, Jun 8, 2011.

  1. robert

    robert

    Moderator

    Joined:
    Dec 21, 2008
    Posts:
    265
    Hi guys,

    I hope you like what you see on all the screenshots and videos of Shadowgun - the new game by MADFINGER games.

    We try to shed some light on the tech behind the pretty pixels in this blog post. Enjoy :D
     
  2. Thomas-Pasieka

    Thomas-Pasieka

    Joined:
    Sep 19, 2005
    Posts:
    2,174
    Excellent post and great looking visuals Robert. Those guys deserve the spot on the front page ;)
     
  3. 2dfxman

    2dfxman

    Joined:
    Oct 1, 2010
    Posts:
    178
    Ooh advanced, me like
     
  4. cupsster

    cupsster

    Joined:
    Apr 14, 2009
    Posts:
    363
    looks nice.. I suppose this will be new feature in unity.. are probes baked with beast?
     
  5. h.istvan

    h.istvan

    Joined:
    Aug 4, 2009
    Posts:
    77
    Screens are nice! Unity really laid on these fps demos!:)
    Maybe the next "COD" will be a Unity game!:D:D
     
  6. 2dfxman

    2dfxman

    Joined:
    Oct 1, 2010
    Posts:
    178
    Ahaha good one
     
  7. robert

    robert

    Moderator

    Joined:
    Dec 21, 2008
    Posts:
    265
    @cupsster: Yeap :) So they get the awesome Beast's GI, can be baked together with lightmaps or separately. After the main GI calculations are done, baking the probes is pretty fast, so you can iterate on re-baking the probes quickly. And when baking lightmaps at the same time you won't notice the added time much.
     
  8. Diogo-Teixeira

    Diogo-Teixeira

    Joined:
    Apr 9, 2010
    Posts:
    494
    Awesome work guys. I'd very much love to see this feature integrated in Unity, along with directional/RNM lightmaps.

    My question would be why split into tetrahedra instead of using a simple octree?
     
  9. robert

    robert

    Moderator

    Joined:
    Dec 21, 2008
    Posts:
    265
    That's a good question. And there's a couple of reasons, actually.

    If you're thinking about a solution where probes would be nodes of the octree, then it's actually not much better solution than a regular grid. It still needs to store visibility in every probe to avoid probes within or past walls to leak through those walls. There's not much artist control on where to place the probes (which is a problem in itself), so the local resolution will usually be many times higher than actually needed, which will make an expensive technique (bigger memory footprint due to the need of storing visibility and more complex interpolation) even more expensive. The interpolation is also more expensive and complex, as not only the 8 probes forming the current cell need to be taken into account, but also potentially some extra probes from the adjacent cells if the adjacent cells have different size than the current one.

    I discussed a bunch of related techniques in this blog post, but that was a while ago and my concept changed a bit. Still any suggestions are very welcome :)
     
  10. roka

    roka

    Joined:
    Sep 12, 2010
    Posts:
    598
    really nice render , fantastic
     
  11. Diogo-Teixeira

    Diogo-Teixeira

    Joined:
    Apr 9, 2010
    Posts:
    494
    Sounds like a robust lightweight alternative. Thanks for clearing that up.
     
  12. yomo710

    yomo710

    Joined:
    May 25, 2011
    Posts:
    77
    Like it
     
  13. NomadKing

    NomadKing

    Joined:
    Feb 11, 2010
    Posts:
    1,461
    I thought the screenshots of this looked great when they where posted a few weeks back, but compared to the video they didn't do it justice! It's amazing how much of a difference the light probes make to the charcater lighting. Looking forward to having a play with those :)
     
  14. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,123
    will this stuff in some way do RNMs? or somehow make the baked lightmap effect the normal maps?
     
  15. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,794
    It's mostly for dynamic object to get some GI like lighting. It's not really for added speculars etc to things that have proper lightmaps. At least from what they've shown so far, it doesn't look like the implementation will have anything to do with RNM.
     
  16. kurylo3d

    kurylo3d

    Joined:
    Nov 7, 2009
    Posts:
    1,123
    Damn... thats the one thing that really bugs me about unity.. this whole dual lightmap system is just lame. Kinda wish we had a choice to use rnms in beast or something.
     
  17. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Very impressive, yet inspiring, not intimidating. Encourages me to raise my game.
     
  18. designxtek

    designxtek

    Joined:
    Mar 13, 2009
    Posts:
    147
    I'm using the Unity 3.5 beta. I love the beast lightmapping system and light probes! I was wondering how ShadowGun was able to accomplish muzzle flashes lighting up their characters.

    Since the characters are constantly moving around throughout the scene how does that work?

    Thanks!
     
  19. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I'm hoping that this shader will be made available to us from unity, and optimised for mobile, where it matters the most of all :)
     
  20. robert

    robert

    Moderator

    Joined:
    Dec 21, 2008
    Posts:
    265
    That was actually a very simple thing to do. Shadowgun sets the max number of pixel lights to 0 and the max number of vertex lights to 0. That causes the normal fallback mechanism in forward rendering to force ANY realtime lights directly to SH.

    So the way lighting is calculated for the character, is that Unity first gets the interpolated SH probe calculated based on the baked probes. Then Unity searches for any realtime lights that might affect the character, casts them to SH at the character's position and adds the resulting SH probe to the interpolated probe. That gets set as the shader uniforms.

    The shader samples SH per vertex as usual (and then calculates the directional light per pixel).

    You can set the max number of pixel lights to 0, but setting the max vertex lights to 0 isn't possible yet - we want to solve it nicer for the next version, so that you can have more control over which lights exactly will get casted to SH.

    In the meantime you can still achieve the exact same effect, but requires some effort. You will need to call GetInterpolatedLightProbe() yourself first. Then find the lights you want to affect the object and cast them to SH same way as the code examples in LightProbes.coefficients do. Finally pack the coefficients into shader uniforms as described here in A10 and sample them in the shader (as described there, which is what Unity's ShadeSH9() does).

    It's very simple, but may sound intimidating, so we'll figure out a nice way to configure lights that way for the next release.
     
  21. winterkewl

    winterkewl

    Joined:
    Oct 28, 2011
    Posts:
    53
    Is there any chance now that 3.5 RC1 is available that there will be a tutorial on how you were able to achieve such amazing lighting and shading in shadowgun?

    It would greatly appreciated!
     
  22. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I think REJ might have a shader that we can apply that just works. But you will have to sacrifice your 7th child for it and run backwards naked around unity hq 3 times.

    I really like the information about lighting up (muzzle flashes/explosions) for free, Robert. Thanks!
     
  23. winterkewl

    winterkewl

    Joined:
    Oct 28, 2011
    Posts:
    53
    7th child sacrificed, the headquarters is a bit far from LA but I'll start running backwards now. :)
     
  24. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    No sign of said shader yet :(
     
  25. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
  26. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    Ancient thread being ressurrected - but did this ever become possible to do? - in 4.5 there's still no obvious way to limit the number of vertex lights.

    I'm currently implementing my own vertex lighting solution, as Unity's vertex lights still don't work with lightmapped objects - and wondering how to also apply these lights to lightprobe-lit objects.
     
  27. robert

    robert

    Moderator

    Joined:
    Dec 21, 2008
    Posts:
    265
    I thought about an option on a light to force it to SH, but never did it. I might revisit it post-5.0.

    In the meantime you can use these examples I wrote to add contribution from your lights to the baked light probes.

    In 5.0 the functions from the above examples are built-in.