Search Unity

Lighting techniques for procedural caves

Discussion in 'General Discussion' started by Chrisad, Oct 2, 2019.

  1. Chrisad

    Chrisad

    Joined:
    Mar 12, 2013
    Posts:
    55
    Hello everyone,

    I am working on a game with procedural contents create at runtime to create caves.
    I am using Dungen to generate my level at runtime. For people who don't know how Dungen works,
    the cave is composed of rooms and corridors which are prefabs. In my case, I have a second procedural
    step that create different props for each room at runtime.

    Starting from this, I cannot use lightmapping techniques, or any bake solution. I can't bake the lighting of a room and merge it at runtime either since each room is different. I need to rely on realtime setup only. I usually put a lot of lights in each rooms, but the result isn't great (cannot use light bounds etc).

    How do you light your cave scene in your project ? Do you know any method to light an environment like this ?

    If you have any technical papers on the subject don't hesitate to send it to me.
    I was thinking of using a dynamic SDF representation of the scene and use it to light my scene but I don't know how efficient this can be.
     
  2. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    Unwrap manually the cave to a light map, do lighting in that light map texture.
     
  3. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,025
    I don't have much experience with this, but one thing for sure is that SSAO is great to create occlusion that really gives a sense of the space in procedural levels.
     
    Martin_H and Chrisad like this.
  4. iamthwee

    iamthwee

    Joined:
    Nov 27, 2015
    Posts:
    2,149
    What you need is DXR raytracing!
     
    Ryiah likes this.
  5. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,983
    I think this is probably your best bet
     
  6. dwit_mass_creation

    dwit_mass_creation

    Joined:
    Jun 18, 2015
    Posts:
    74
    How to do it in Unity:


    They (The Elder Scrolls Blades) had exactly same problems (connected rooms from prefabs) and solved them.
    They are using lightmaps with prefabs and blending lightmaps on rooms connections.
    And they are using custom light probes generated from Unity light probes.
    There are some more optimizations (visibility culling etc). Worth watching.
     
  7. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    328
    Just use dynamic lighting? :p
     
  8. Chrisad

    Chrisad

    Joined:
    Mar 12, 2013
    Posts:
    55
    I watched this video too :D
    But my problem is since the content inside a prefab is not static, I have nothing to pre-bake. The props of a rooms are only know at runtime. In TES, the content of a prefab seems to be static.
     
    Martin_H likes this.
  9. Chrisad

    Chrisad

    Joined:
    Mar 12, 2013
    Posts:
    55
    That what I used. But the result is not great. I want to know if any of you use special techniques to deal with lighting in procedural context. I was thinking of using unlit shaders and fake everything too. But I would like to move my project to the HDRP pipeline, and rely on the realtime lighting system if possible.
     
  10. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    I maybe have overestimate you, so let me detail. Use render texture and custom render texture.

    If you store world normal, world position and albedo in a texture, you can pass the light parameter (color, position direction) and resolve it yourself in that texture as if it's a Gbuffer. Not only you would have light, but that light can be "baked" or "cached" such as you can accumulate lighting on it at each pass. That allow you to use more expensive diffuse light as you don't need to update it each frame for static element. And you can use all the lightmap trick, like: store non overlapping different light intensity on a single channel, modulate them after with color and intensity only with a global tint, perfect for dungeon with a lot of candle and torch)

    That texture solution can (mostly) be a RUNTIME lightmap (if you have module, you can pre unwrap, if the mesh has been compose dynamically, you can unwrap it manually at generation time).

    Another solution is simply a 3D texture (native or slice atlas). You pass the light parameter and let each cell resolve itself (store direction and attenuated color by distance and shadow) then use that data sampled back by objects where each fragment just query a single cell. You will have problem with light bleeding if you don't do a custom shadow pass (store depth from light point of view, compare to each fragment while resolving).

    But mostly you really just need a custom shadow only. And accumulating with a runtime lightmap would help a lot to have complexity.
     
    Chrisad likes this.
  11. Chrisad

    Chrisad

    Joined:
    Mar 12, 2013
    Posts:
    55

    I understood a different thing in your first comment. But your explanation helps me a lot to understand what you mean, thank you. I will try to implement your ideas.
     
    neoshaman likes this.
  12. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    That was my guess :p
     
    Chrisad likes this.
  13. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    328
    You mrntioned the rooms are prefabs while the props are placed procedurally. How about baking the light on the rooms and lit the props via light probes, treating them as dynamic objects?
     
  14. LiamBlack

    LiamBlack

    Joined:
    Oct 4, 2019
    Posts:
    3
    Good decision.
     
  15. Chrisad

    Chrisad

    Joined:
    Mar 12, 2013
    Posts:
    55
    By default, light probes are scene objects (data saved in the scene) and cannot be moved. I would have to create a custom probes system (like Bethesda did)
    And if I baked the rooms without the props on it, the lighting will be wrong (shadows for example.
     
  16. Chrisad

    Chrisad

    Joined:
    Mar 12, 2013
    Posts:
    55
    By searching more info about the ideas of @neoshaman I found info about voxel global illumination and screen space global illumination. The last one is used in Path of Exile. This could do the job without having to bake anything.
     
  17. one_one

    one_one

    Joined:
    May 20, 2013
    Posts:
    621
    If you come up with a production-ready global illumination solution that is real-time or can be baked during runtime, let us know...
     
    Last edited: Oct 4, 2019
    Trigve, Rich_A and Martin_H like this.
  18. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
  19. Chrisad

    Chrisad

    Joined:
    Mar 12, 2013
    Posts:
    55
    I don't expect to have something ultra realistic. I will try to implement the most naive solution. If I got good results even with some limitations it would be enough. The only thing I want it something good enough for my game.
    But I keep in mind the potential complexity.

    I will post any results in this thread.
     
  20. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    I don't mean in the realism, I mean in the complexity to result. I did propose a voxel solution in part of my expansion on the lightmap lighting. Going GI might be overkill.

    Anyway these improvement are cumulative, a flood fill voxel light (compute light at every point of the grid then sample by all objects per fragment) is the first step to GI anyway, once that's done you will have to raymarch. Screen space GI is ultra expensive though.

    But if you want a starting point look at SEGI.
    https://github.com/sonicether/SEGI

    There is a thread on unity, and I posted a detailed breakdown of the shader code
    https://forum.unity.com/threads/segi-fully-dynamic-global-illumination.410310/page-44#post-3827629
    There is many post after this one that continue the break down.
     
    Chrisad likes this.
  21. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    328
    What about image based lighting? You render a cubemap and use its mip maps for diffuse lighting.
     
    neoshaman likes this.
  22. Chrisad

    Chrisad

    Joined:
    Mar 12, 2013
    Posts:
    55
    Do you mean create a cubemap of every rooms and use it ?
     
  23. OCASM

    OCASM

    Joined:
    Jan 12, 2011
    Posts:
    328
    Yep, it's a cheap enough process that you can even do it at runtime.
     
    neoshaman likes this.
  24. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    That can be good too, it's kinda teh same principle than the lightmap, ie bake light into a texture projected back to teh geometry.
     
  25. Chrisad

    Chrisad

    Joined:
    Mar 12, 2013
    Posts:
    55
    My only problem would be that I will have to generate those cubemaps at runtime since the content of a rooms is generated at runtime too. I don't know how many time this can take.
     
  26. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    Just try
     
    OCASM and Chrisad like this.