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

Graphics HXGI Realtime Dynamic GI

Discussion in 'Tools In Progress' started by Lexie, May 24, 2017.

  1. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Ill be adding HxVolumetric support once I've finished the major things I want to support. This will allow it to capture the GI data calculated by HXGI from emissive surfaces and bounce lighting from any dynamic unity light flagged to interface with HXGI. To be clear HxVolumetric lighting does not interface with SEGI or unity's baked/pre-computed GI, the GI data for both of these methods are not stored in a way that allows volumetric rendering.

    One of the reasons I chose this method was that it would be able to handle volumetric rendering.

    I'm working on some translucent material support now, this will allow the bounce lighting to travel through transparent objects and have their color effect the outcome.
    The cool thing about this is if you have an object that is opaque, you can still set the alpha. So something like a blue tarp will send some blue light through it, Another example would be alpha cutout leaves that lets some green light through the canopy with out the downsides/overhead of using a real transparent shader. It will also support transparent shaders as well so you could have a red window that would change all incoming GI lighting.

    To be clear this is just for lighting generated by my system, so emissive surfaces and the bounce lighting from dynamic lights. It wont actually change the direct lighting from unity's dynamic lights (transparent shadows and caustics). That is a bit beyond the scope of what I'm trying to achieve.

    Once the main system is done ill be adding forward rendering support. that will enable transparent shaders to be able to be lit by the GI data as well.
     
    one_one, wetcircuit, punk and 2 others like this.
  2. HTusa

    HTusa

    Joined:
    Aug 2, 2017
    Posts:
    9
    So in theory, this would allow arbitrary shaped volumetric lights? Like a bright neon sign (an emissive surface) in a fog would accurately (or at least reasonably well faked) cast volumetric light around it.

    That would be amazing because right now all the volumetric light solutions I've seen rely solely on Unity lights. That means only cone-shaped, spherical and other Unity-light-shaped volumetrics. Which is a pain to work with in some situations.
     
    Shinyclef and buttmatrix like this.
  3. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Yes. one thing to note is that emissive materials do not cast really sharp shadows. they still cast shadows and the light is blocked by objects, but the lighting detail is not as high as dynamic shadow map lights.

    So it will be more like the air around emissive surfaces will be lit rather then the sharp rays of detail you get from using shadow maps. Will still look sweet though.
     
    buttmatrix and hopeful like this.
  4. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    502
    You sir are a man of vision.
    If you do I fact achieve all of this, you are going to see a sales boost in your vulumetric lighting solution as well...
     
  5. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,676
    I already have the HxVolumetric Lighting, but it would be heaven to have it integrated with a performant realtime GI system.
     
    one_one and wetcircuit like this.
  6. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    I've added support for dynamic non-shadow casting point and spot lights. Still needs some work to better simulate the attenuation for unity's lighting, but its a start. It supports a max of 50 spot and 50 point lights. ill increase the max once I've finished. preliminary tests was 1ms to calculate the injection of 50 point lights on my laptop (970m, around the speed of a 660GTX) so that's not to bad.

    I'll have to render out my own low res shadow maps to enable support for shadow casting point and spot lights. i'll get started on that soon. At some point it would be faster to just replace unity's lighting system all together hmmm.



    Ill get shadow casting point and spot light support done tomorrow then move onto specular support.
     
    Last edited: Aug 3, 2017
    ftejada, Billy4184, DasBiot and 9 others like this.
  7. tweedie

    tweedie

    Joined:
    Apr 24, 2013
    Posts:
    311
    This is advancing at a terrific pace :) Awesome updates.
     
  8. BruceBarratt

    BruceBarratt

    Joined:
    Jun 20, 2015
    Posts:
    57
    That is insanely
    That is insanely awesome. I've long been wanting translucency in forests and for the GI to be able to let some of the light come through and pick up the leaf colour would be amazing. Light hitting the leaf directly from the directional light wouldn't be able to 'bounce' light directly through it would it? That would make the full translucency affect. In your clarification you are saying the light has to bounce off a solid surface first and from that point it can go through a transparent material and pick up colour? If that's the case do you think having direct light pick up colours going through transparent materials is something that could be done by someone else and work with your system?

    Sorry if my question is confusing. I don't really know anything about how this works.
     
    one_one likes this.
  9. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    502
    Wow I agree with everyone on your pace. It is impressive. Try not to burn out!

    Is my understanding correct in that this means with a bit of scripting I could potentially have the closest x point and spot lights contributing to GI, and the the remaining be regular unity point and spot lights in deferred mode?
     
  10. chiapet1021

    chiapet1021

    Joined:
    Jun 5, 2013
    Posts:
    605
    Pretty sure a bunch of us would throw down gobs of cash for a custom render loop of yours. :D
     
  11. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    ideally my system would support all lights with-in the volume so you wouldn't have to bother. I should really do some partitioning of the light data. so each thread group only bothers about the lights that are with in the bounds it's calculating for. Right now its pretty much a brute force method.

    when the direct lighting hits the translucent surface, some of the light would bounce away from the surface and some light would go through the surface. it will act like a light diffuser.
     
    Ogdy, Arganth and SteveB like this.
  12. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    408
    @Lexie looking amazing bro
     
  13. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    I got Shadow casting point light support added. you can set the resolution of the custom shadow map used for all the point lights. It stores them in a cubemap array. Ill be doing the same for spot lights as well.

    Downside is I need to save all the shadow maps so I can do the injection in one pass. This means you have to specify how many cubemaps need to be set aside for this system (increasing VRAM usage). but it also makes it possible to update all the shadow maps over x frames instead of all at once. making the cost of rendering the shadows each frame a lot smaller.

    It gave me an idea of how i could get my old custom shadow casting lighting system working with forward rendering and do all the lighting in a single pass (great for VR). But ill save that for another time.

    Moving onto shadow casting spot light support now. should be really simple now that I understand texture arrays.

    I'm marking cascades, point/spot light support as done so I don't forget.

     
    Last edited: Aug 4, 2017
    ftejada, Elzean, DasBiot and 16 others like this.
  14. Howard-Day

    Howard-Day

    Joined:
    Oct 25, 2013
    Posts:
    137
    So freaking good! I love it.
     
  15. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    I wasn't able to completely finish Shadow casting spotlight support, still need to do multiple samples of the shadow maps to clean up issues near multiple surfaces. the light attenuation is also incorrectly calculating, Ill need to look through unity's shaders to figure out what functions they use. Ill finish it up next week and move onto specular support, But over all I'm pretty happy with this progress.


     
    Last edited: Aug 5, 2017
    ftejada, Elzean, chingwa and 13 others like this.
  16. Yuki-Taiyo

    Yuki-Taiyo

    Joined:
    Jun 7, 2016
    Posts:
    72
    Could HxGI be supported by current-gen consoles ? (Xbox One, PS4, Switch)
     
  17. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Xbox and ps4 yes, not sure about switch
     
  18. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
  19. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    502
    +10 Likes. Very like!
     
  20. sledgeman

    sledgeman

    Joined:
    Jun 23, 2014
    Posts:
    389
    Hm...i have to say it is a very nice result / accomplishment in comparison to some of my Vray Gi Tests ;)
     
  21. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    I posted example code for this a year and a half ago. Shipped two PSVR titles (Wayward Sky and Dino Frontier) using very similar code. It only fails on very complex geometry intersections... And by fail I mean look no worse than not doing it at all.
    https://forum.unity3d.com/threads/fixing-screen-space-directional-shadows-and-anti-aliasing.379902/
     
    hopeful likes this.
  22. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    If you sample all 9 neighbors of the fragment it looks a lot better. I found only doing a 4 tap didn't really work on any diagonal geo. Also you can do a gather sample instead of sampling each pixel.
     
    bgolus likes this.
  23. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    Yep, the real code I used is using PSSL (PS4 Shaders) and those gather functions. I also do some minor biasing to favor the original sample to deal with depth precision issues sometimes getting false positives.

    I thought about doing an update to they post with the code I use now, but it's for Unity 5.4 and I haven't tested with the reversed depth (to see if the biasing is even needed still) and I keep hoping Unity will officially release their HD renderer & scriptable render loop stuff which hopefully won't suffer from these problems.
     
    Last edited: Aug 5, 2017
    Lexie likes this.
  24. macdude2

    macdude2

    Joined:
    Sep 22, 2010
    Posts:
    686
    I think it would be greatly appreciated as who knows when Unity is going to fix things! Also, just wondering, is there a way to put this aa code in the standard shader? I couldn't quite find where it would go after poking around for a few hours.
     
  25. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    I did it by replacing the Autolight.cginc.

    The easiest way to do it is replacing the file in the Unity folder and deleting your project's shader cache to force rebuilding of the built in shaders. For Wayward I made copies of the Standard Shader and all the related cginc files as I made several other changes and we were constantly changing Unity versions which overwrites the Unity directory.

    For Dino all the shaders are all custom with a clustered lighting system, but I still use Unity's directional lighting since I didn't have time to write my own cascaded shadow system.
     
    Last edited: Aug 6, 2017
  26. macdude2

    macdude2

    Joined:
    Sep 22, 2010
    Posts:
    686
    Ok, thanks, I'll definitely look into that!
     
  27. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Spot light support is pretty much done. Going to move over to voxel traced specular support soon, just need to clean up some code.

     
    pcg, Elzean, DasBiot and 10 others like this.
  28. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    Dear god, that image on the left looks clean. Nicely done
     
  29. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    The inspector UI for SEGI exposes about a dozen parameters which can be tweaked to achieve the desired result. Generally speaking, lighting is always a balancing act with about a dozen parameters, but it can be unwieldy trying to balance them all without some sort of procedural options. Fortunately, SEGI does include an option to save render settings as a data file which can be loaded to toggle different render configurations.

    Perhaps it's too early to tell, but what can we expect from HxGI by way of UI tools?
    Can we expect this type of functionality, as described above?
     
  30. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    There really isn't that many things to change. its more on the material and light settings rather then the GI settings. You only really set a couple of values for quality. I could have a profile that you can save out, but its only going to be like 4 values.
     
    hopeful and tweedie like this.
  31. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    That's amazing +1
     
  32. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    I'm going to say it again here, You just achieve what enlighten and Unity cannot. Shame on you Unity :/
     
  33. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    I've gotten specular approximation added. This method of specular contribution from the GI is really cheap to calculate. it should look a lot better then my old implementation from the start of this thread. This setting is for lower end machines that cant handle the ray traced reflections.

    Moving onto voxel traced specular tomorrow.




    Haha, yeah. Everything can move as well. So it can handle something complex like opening and closing a door.
     
    one_one, DasBiot, SteveB and 5 others like this.
  34. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    well that is just getting better, alright this might be totally unrelated. But that bunny shadow make me wondering. Have you tried to add some kind of sphere/capsule soft shadow?
     
  35. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Not sure what you mean by that, the shadows in that scene are all from indirect lighting only. The indirect light shadows are pretty soft. Here is an area light with/with out a bunny blocking the lights. I cant make the indirect shadows any sharper then that unfortunately. If you need sharper indirect lighting then cone traced GI is your best bet, but that tends to be pretty slow and comes with a lot of light leaking.

     
    Shinyclef likes this.
  36. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Oh i think i know what your talking about, the last of us used stretched spheres to do soft shadows for all their characters. Not sure if ill add something like that.
     
    Shinyclef likes this.
  37. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    off-topic: capsule shadows on the menu for NGSS
     
  38. chiapet1021

    chiapet1021

    Joined:
    Jun 5, 2013
    Posts:
    605
    So this + NGSS 2.0 = magically delicious lighting and shadows, if we can get access to both and they work together. :)
     
    one_one, macdude2 and Arganth like this.
  39. MelvinEng

    MelvinEng

    Joined:
    Jan 11, 2016
    Posts:
    14
    Hello Lexie,

    Wow, that's really awesome news!
    Thus far, I haven't heard of anybody taking into account translucency in real-time GI at all.
    So you're the first!
    Just wondering...while you're at it, would it be possible to also take into account the effects of refraction as the light travels between 2 different mediums? (as in caustics)
     
  40. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Out of scope of this system. It doesn't have the resolution to calculate something like that.
     
    Shinyclef likes this.
  41. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,788
    Yep that one :D. No Worries though, just purely curiousity
     
  42. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    502
    Whoa dude... That's the cheap version? All I wanted was a decent lighting atmosphere for my voxels. This is looking to deliver everything I hoped for... even with this low setting... With all of these light types, multiple light support, translucency plans, voxel reflections (even low quality), are you 'still' expecting this to be performant, or are you seeing a pretty steady non-trivial decline in performance per supported feature.

    Also, will we be able to turn some of these features off for the less powerful gpus out there?

    It's really looking amazing and thank you for your updates! Really great to see this work.
     
    DMeville and Misciagno like this.
  43. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,676
    It certainly sounds like it, doesn't it? If so, it would really help games tailor their FX to the hardware and manage a stable frame rate.
     
  44. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,492
    What's the estimated minimal spec for running this a 30 fps?
    I feel this will help more people feel grounded in expectation
     
  45. Shinyclef

    Shinyclef

    Joined:
    Nov 20, 2013
    Posts:
    502
    I imagine an answer to this question will be vary greatly depending on certain variables like scene complexity, voxel resolution, distance/cascades, other graphical burdens the game has to deal with...

    It would be better measured as cost in ms given a certain stable test scene with x triangles, y cascades, z features turned off, etc.
     
  46. Lexie

    Lexie

    Joined:
    Dec 7, 2012
    Posts:
    646
    Yes. there are a few settings to make this run on lower end machines.
     
    neoshaman, Shinyclef and hopeful like this.
  47. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,492
    That's expected of course, it's about making a rough estimate to get the order of magnitude, not everyone understand the ms lingo either. Think fermi estimation, I wouldn't expect this to run on a mali 400mp1 :eek:

    For example my omputer run segi at 10 fps on the procedural demo. It's a 2GB 920M
     
  48. Mauri

    Mauri

    Joined:
    Dec 9, 2010
    Posts:
    2,663
    SEGI uses Cone Tracing (which is overall slow), whereas HXGI uses Light Propagation Volumes (?) for lighting.
     
  49. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,492
    Yes but that's just a point of reference, that's the point. When people ask for low end machine, where is the cutting point? Where is the reasonable expectation? With segi some people where disappointed because they had no reference, but those who followed since the beginning and had the early demo, knew what to expect. Managing expectation in cutting edge stuff like this is important IMHO.
     
    one_one likes this.
  50. macdude2

    macdude2

    Joined:
    Sep 22, 2010
    Posts:
    686
    This looks great, but I'm curious why the AO seems so strong in this scene? I assume its not something you can change, but it just doesn't quite look right to me...