Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Lighting Strategy

Discussion in 'Universal Render Pipeline' started by jsebast, May 20, 2022.

  1. jsebast

    jsebast

    Joined:
    Oct 6, 2017
    Posts:
    6
    Sorry if this isn't the correct subform, but as I'm doing 3d lighting in URP it seemed like the closest match.

    I am currently attempting to light a scene with a number of various lights (mostly spotlights). I have a single floor object that runs the length of my level.

    I am aware that unity has a maximum limit of 8 lights lighting a single object. When I have more than this number, moving the camera around causes various lights to "flicker" on and off on the ground, even if I set them to important. After doing some research this seems to be expected for the above reason of too many lights hitting one object. After some experimentation, removing lights causes the flickering to stop as would be expected.

    My question is this, the flicker is pretty awful aesthetically. Even if I subdivide my floor into several tiled objects, how can I ensure that no more than X number of lights is hitting it at one point? Does anyone have a strategy for this? Do you mix more baked lighting in to give the illusion of lighting? Do you subdivide the object down significantly? Is there a "butter" zone for that?

    Thanks ahead of time.
     
  2. Matt-Cranktrain

    Matt-Cranktrain

    Joined:
    Sep 10, 2013
    Posts:
    129
    If the scene is static, with the lights not moving at all, then you can bake the light map and escape these limitations of the realtime lights in URP. CatlikeCoding has an incredibly in-depth reference to baking lights that goes into lots of detail (it's in a series about implementing a totally custom SRP which is almost certainly more complicated than you're looking for, so the first part is the helpful bit.)

    However if your scene isn't static - perhaps your lights move around - then you'll probably want to carve up your floor into a set of multiple meshes. I do this for the terrain in my game, since my scene isn't static and lights can be anywhere that the player builds them.

    It's also worth mentioning that multiple real-time lights in URP is expensive and you'll probably want to somehow implement an upper bound on them because you really feel the performance impact at 10+ lights on lower hardware. I fade my real lights to fake decal "lights" in the distance and this is good enough for my stylised game.
     
  3. burningmime

    burningmime

    Joined:
    Jan 25, 2014
    Posts:
    845
    This is going depend a lot on your lights and scene.

    I have a school scene where there's tons of lights (up to like 25 affecting things on screen at once since it's zoomed out 3rd person). I solved this by using fully baked light using Bakery + light volume (instead of probes) + SH lightmaps. With these things together, you can get some specular highlights from light maps. It's not perfect, but it performs really quite well and supports an unlimited number of lights with global illumination, as long as those lights aren't moving.

    upload_2022-5-22_23-46-4.png

    You also get static objects (eg chairs) casting shadows onto dynamic objects (eg people):

    upload_2022-5-22_23-44-54.png

    What you don't get from this technique is shadows from dynamic objects onto static objects. I'm considering using subtractive for fake "shadows" from a nonexistant directional light -- they won't look physically correct, but they'll at least kinda be there. However, I can't get Unity to actually render it without maintaining a separate URP branch which is a massive PITA unless you have a team big enough make it a PI someone else's A.

    The other problem is that you need special shaders for just about everything. However, once you get the hang of it, it's not that bad; basically I just stick an extra subgraph node at the end of shader graph and plug those outputs into the final product, and you can keep it compatible with the standard lit shaders for most materials.

    (And yes I know the hair looks bad and the back of the sink is missing and the glass is opaque and the sweatshirt is tucked in and the skirt looks like a fashion crime in progress; this is all very WIP)
     
    Last edited: May 23, 2022
    Noisecrime likes this.
  4. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,887
  5. jsebast

    jsebast

    Joined:
    Oct 6, 2017
    Posts:
    6
    Sorry for the late reply.

    @burningmime and @Matt-Cranktrain - Baked lighting will work just fine for most lighting situations, but how are you ensuring your main character is lit? I'm working on a 3rd person perspective 3d game (see here if you're curious: https://www.instagram.com/moongeyserstudios/). Am I missing a really important feature and I can do baked lighting for static objects but real-time for dynamic objects via layer?

    Do you just use one directional real time light?

    @Stardog - I'll look into this but i'm on 2020 LTS. I'll update URP and see if this feature was added. I'll have to also do an analysis on what impact this will have on my game.

    Thanks for all your help
     
  6. burningmime

    burningmime

    Joined:
    Jan 25, 2014
    Posts:
    845
    For my game, the lighting is baked into a light volume, which is a feature of Bakery. There's a 3D texture that specifies the light intensity/color/direction at every point in the volume, and based on that, it can calculate at runtime the diffuse + specular. Since it's just a couple texture samples per fragment, it's constant time no matter how many lights there are and the shadows are "free" (no shadow maps being rendered), so performance is pretty fantastic. Think light probes on steroids.

    However, it only works for scenes where you can know that all dynamic objects will be inside the volume. It also won't work for really massive scenes or moving lights (but neither will light maps). Deferred rendering is a more flexible approach, and is built into Unity so you don't have to buy Bakery or implement it yourself.