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

Feedback Supporting Player Placed Lights/Ray Tracing Limitations

Discussion in 'Global Illumination' started by LaireonGames, Sep 27, 2021.

  1. LaireonGames

    LaireonGames

    Joined:
    Nov 16, 2013
    Posts:
    705
    Hey everyone, welcome to my madness!

    So I've been working on a game like Minecraft for a long time with one of its key characteristics being that it has more modern graphics.

    Aiyana: https://twitter.com/laireon

    What I've struggled with from early on is how the hell am I going to support player placed lights? Well the lighting part is easy, use deferred rendering and job done. But. The shadows.... oh that keeps me up at night.

    Take this scene for example.

    Screenshot_2.png

    Looking at it from a performance point of view its 10 point lights with shadows, meaning 60 scene renders. However, the real problem is that to a Minecraft player this is totally normal and a low number of lights for how they usually build things.

    I've changed the core mechanics to not rely on lighting to deter enemies, allow you to carry torches etc but players will still want to build structures exactly like this. I've also tried to do things like make the lights pretty bright so they will spread them out more.

    The problem I see is that if I do the usual trick of things like only having say 10 (already a high number) as a max of point light shadows and turn them on/off depending on distance etc then its going to look really bad for things like looking at your castle at a distance and realising the light appears to be seeping through the walls.

    I keep trying to come up with a 'real' solution but I feel stumped. I've considered things like:

    1) Waiting for HDRP to mature but I'm guessing it will be 2 years before I feel happy to even try to shift to it (cause screw rewriting some of my 2k+ line long shaders in a node based system!). However I'm losing so much confidence in Unity if this will even improve the situation since too often the talk about new features is everything is amazing, but seeing comments and posts the reality is another story.

    2) Using ray tracing to handle shadows for those with the hardware and hacks like above for everyone else which is going to be the majority of players. However I'm not even confident this will scale feasibly. Sure the premise of 'screen based shadows' sounds good but I imagine each light leans more towards an exponential rather than a flat cost (this is a guess from a surface level understanding of the subject).

    3) I've considered some sort of baked solution where I sort of generate shadow maps on the fly but it makes my mind boggle just trying to account for new chunks constantly being added to the world whilst also accounting for a day/night cycle.

    4) It also feels like I might be able to solve this with an entirely custom lighting system that runs from the voxel data I already have. But I don't have any experience building something like that from scratch to know if it will even solve these problems and I imagine it will take a crazy amount of effort to find out. I did speak to someone at Unity who gave me some pointers around making one but it was from the perspective of fixing a bug around light leaking rather than a whole system and I was loathe to try to implement it without a picture of a full system in mind.

    I already have a pseudo lighting system in there that mimics how Minecraft handles lighting by running a flood fill algorithm on empty space. It works nicely to mimic looking down a dark cave but its extremely primitive and I'm trying to offer something more modern, thus realtime shadows on top of this.

    Am I missing something that could help?

    Global Illumination is also something I mean to look into more, but from what I've read so far it just sounds like another layer on top of my problems to make lighting look nicer and wont do anything to ease my shadow performance woes.
     
    Last edited: Sep 28, 2021
    PutridEx likes this.
  2. YondernautsGames

    YondernautsGames

    Joined:
    Nov 24, 2014
    Posts:
    352
    Not my forte, but since nobody else has answered and I had the link, you could look at segi to get a better picture of a full voxel solution:
    https://github.com/sonicether/SEGI

    I don't know how easy it is to get working these days, but the demos looked really good
     
  3. Deleted User

    Deleted User

    Guest

  4. LaireonGames

    LaireonGames

    Joined:
    Nov 16, 2013
    Posts:
    705
    Thanks for the responses but I don't think/know if these will solve my issues :(

    From what I've read about SSGI I'm guessing it doesn't affect the shadow generation. E.G when reading on the HDRP docs:

    "SSGI and RTGI completely replace all lightmap and Light Probe data." but nothing about if it still generates real time shadow maps. In fact shadows are not mentioned at all on their page which just opens up more questions for me.

    Does SSGI not need to generate realtime shadow maps?

    Oh yeah I forgot I did look at SEGI in the past, but a quick glance of the mega forum post about it doesn't leave me with confidence though since people said it struggles badly with moving cameras
     
  5. Deleted User

    Deleted User

    Guest

    u have to optimize the shadow performance and want some GI, right?....or am i wrong??
     
  6. LaireonGames

    LaireonGames

    Joined:
    Nov 16, 2013
    Posts:
    705
    GI is just a nice to have that I'm not worried about, yet.

    Overal yes I want to optimise shadow performance but ideally I'm trying to find out if there are systems where I can support as many shadows as possible without nasty hacks, since players can place as many lights as they like in the world.

    Screen Spaced Shadows are the sort of thing that would fit this category, but full ray tracing is the only thing that I can think of that might achieve that (but of course comes with too much hardware constraints currently).

    If SSGI within HDRP also handles shadows then great, but reading the documentation doesn't leave me with confidence that it does that since they are lacking as usual. My guess is it will still generate a shadow map as a separate process and then apply SSGI on top of/in combination with it.
     
  7. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
    If you're on 2021.1 and up, you can use shadow caching. And render shadows onDemand, maybe a good value would be twice every second, instead of how it is now, 60(assuming your FPS is 60) times per second.

    Unfortunately as it is, point light shadows have huge performance costs, more than usual i'd say. I heard they might work on this in the 2022 cycle, optimizing the CPU side of it with burst.
    PrepareLightsForGPU (the CPU side of it) in particular, when using point shadows. It's already optimized using burst and jobs in 2022, but just lights, not shadow perf.

    Caching might help you here, but I doubt you're on 2021.
    Although, I might be wrong but at some point even caching won't save you from the performance hit if you have a _ton_ of point light shadows. I doubt you'll get to that number though, and you can just limit the amount of shadows on screen using shadow settings.

    Other then that, only thing I can think off is to play with shadow settings, distance, etc. Maybe not every point light has to have shadows, or you could try to shadow the light with a spot light since it'll be cheaper for shadows, and the pointlight has it's shadows disabled. As for the how, i'll leave that to you :D -- just throwing ideas.
     
    Last edited: Oct 3, 2021
    LaireonGames likes this.
  8. LaireonGames

    LaireonGames

    Joined:
    Nov 16, 2013
    Posts:
    705
    Isn't this all HDRP only? I don't think I can hack the conversion to HDRP yet, its a complete rethink of so many important aspects of the project and I highly doubt I can recreate our current visual style of volumetric lighting.

    Agreed, its obscene how much CPU time it takes to gather them up! The hit on the GPU I can understand, but the CPU hit is really rough
     
  9. PutridEx

    PutridEx

    Joined:
    Feb 3, 2021
    Posts:
    1,136
    Oh my bad, my mind instantly thought you were using HDRP when you mentioned modern graphics. :D
    Cool project by the way!

    --
    Maybe try to use Next-gen shadows, the asset? I think they have caching there, although i'm not sure. You can ask in discord if it might help you in this case.
     
  10. LaireonGames

    LaireonGames

    Joined:
    Nov 16, 2013
    Posts:
    705
    This is the sad state of Unity right now, HDRP really should be the perfect fit for this project but I just have zero confidence that what Unity says matches the reality of the situation. The risk feels too real that I will spend weeks converting to HDRP only to find the performance hit in other situations is far too heavy.

    Glad you like the look of the project :)

    Already got it, and is a great tool :) Pretty sure its not got shadow caching though because I see the same performance hits whether is on or off.