Search Unity

lots of small point lights?

Discussion in 'General Graphics' started by Innovine, Sep 18, 2020.

  1. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    Hi
    Is it terribly expensive to have a lot of small point lights, that overlap a little?

    I am building a cockpit, and I would like to have a tiny light shining on each instrument gauge. Although the light and gauge are static, the pilot can adjust the brightness up and down, so I cannot bake the lighting. Here is how it looks using point lights:

    https://i.imgur.com/8qssoCJ.png

    I have adjusted the range quite low so the lights are not intersecting with very many scene objects, yet they overlap with each other a little. They are also casting shadows. One thing I love with the real light source is the specular highlight on the gauge surface shows where the light source is in 3d, with looks absolutely awesome in vr..

    My question is if this approach is going to cripple my performance (in VR), and are there any potential optimizations I can do? I would like to have maybe 20 or more of these lights. I tried baking the diffuse into a texture in blender and using it as the emissive in my material, and it kind of works but I dont know if that is faster or not... if possible i'd like to go with the real light... any advice would be appreciated.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Yes. Especially since the point lights in that example don't overlap "a little", they overlap a lot. Since they're shadow casting it's even more significantly bad. Not really the overlapping, just point light shadows are really expensive.

    There are ways to fix this, but not a ton that Unity supports out of the box.

    If you're using forward rendering, the simplest solution is to use a lot of layers and limit each light to one dial at a time. You can reuse the layer for multiple lights / dials, but you have to make sure the light's sphere does not overlap the bounds of another dial in the same layer, or both will still be affected by it.

    The next option would be to use Unity's mixed baked lighting with shadow masks. That makes all shadows cast by static geometry get baked into their lightmaps, and only dynamic objects get rendered into the shadow map. But you get to keep the nice specular since that's still rendered by the light itself. Except this is a cockpit which is presumably moving which complicates things. There used to be a way to set something to be lightmap static and not batching static to do something like this, but that doesn't seem to exist anymore.

    Now for what I'd do is do the above method, but 100% manually in the shader. Bake out the diffuse lighting as a mask texture, then have a virtual point light calculated in the shader itself to do the specular, and output as part of the shader's emissive.
     
  3. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    Thanks for the response. I don't know enough shader stuff to do that, so I'll try shrinking the lights and using multiple layers.

    I did bake some emissive maps using blender but the results were not very nice. It just looked lower quality, even with the texture resolutions turned up quite high. I don't know why, 8bit color channel maybe? Some kind of aliasing somewhere, I don't know.

    Performance is currently acceptable with 10 of them, and I don't have too much more fancy effects to add to my scene overall, so perhaps I'll be ok with simple things like separating the lights. If I need to squeeze a few more frames out of it I'll come back to the baked and shader approach..

    I'll try look into the mixed baking some more. The position of the light relative to the gauge never changes, so there's a chance to bake something, but the strength of the light can be turned up and down, and of course there is light coming from the windows and cabin lights too which needs to be mixed in.