Search Unity

Dynamically lighting a huge city with a day/night cycle

Discussion in 'General Graphics' started by Ducahl, Mar 25, 2015.

  1. Ducahl

    Ducahl

    Joined:
    Dec 9, 2014
    Posts:
    20
    Hi, I am trying to figure out an efficient way of turning on accent lighting in a procedurally built huge city scene at runtime that has a day/night cycle. (procedurally being a player can place building tiles, so I can't predetermine where these building assets may be, they are all dynamically placed at runtime.)

    For example, turning on lights that would shine on the sides of buildings, "uplighting", flood lights, street lights, etc.

    From what I have found, it seems dynamic lights are too expensive. I have tried light probes but they don't have enough detail.

    Lightmapping seems like it could work, but I don't have a good way of accessing lightmaps and swapping the data off and on for those lights. Also lightmapping takes a lot of time to compute and I will only be using AO and lighting info for the dynamic lights in the scene.

    Another way I thought about accomplishing this would be possibly creating geo that is using a self-illuminated shader and place them around, simulating the shape of a projected spotlight. Then hiding/revealing it when I want the lights to turn on and off.

    Anyone have any ideas?
     
  2. raja-bala

    raja-bala

    Joined:
    Jul 11, 2012
    Posts:
    29
    I hope I'm not misunderstanding you, but why are dynamic point/spot lights too expensive? If you're using the deferred shading pipeline, it shouldn't be a big cost (shadows cast by them might be, but the lighting is dependent on pixels lit, so it's fairly cheap).
     
  3. Ducahl

    Ducahl

    Joined:
    Dec 9, 2014
    Posts:
    20
    If you run the frame debugger you will find that each light is about 2 draw calls each. This isn't much by itself, but if you have 100's of buildings with 2-4 lights each, this will add up quickly. That is without any sort of shadows turned on.

    Currently the size of my grid for the city game is 16x16 = 256 assets x 2 lights lets say = 512 x 2 draw calls each = 1024 draw calls total estimated average. Could potentially be higher if a user places a building with a higher light count.

    I am already having performance issues , I'd hate to add another 1024 drawcalls at nighttime.
     
  4. raja-bala

    raja-bala

    Joined:
    Jul 11, 2012
    Posts:
    29
    100 buildings aren't going to be visible on the screen at the same time, right?
     
  5. Ducahl

    Ducahl

    Joined:
    Dec 9, 2014
    Posts:
    20
    There is an overhead view where you see a good portion of them. Its like a builder view so you can see where you are placing buildings. Picture sim city .
     
  6. dualcarbon

    dualcarbon

    Joined:
    Jan 7, 2014
    Posts:
    30
    I think Daytime lighting wouldn't be an issue since you use one light for the whole scene. The issue would be with lighting night a scene. You could use a mixture of lightmaps and realtime lighting and probably get what you want.
     
  7. Ducahl

    Ducahl

    Joined:
    Dec 9, 2014
    Posts:
    20
    I was kind of thinking of this as being a possibility. But I can't make this decision lightly because that will be 100's of hours of lightbaking because I'd have to do it for every building asset.

    My most prevalent solution at the moment is to use LODs to control the lighting. At LOD1 I will have dynamic lights, but at LOD2 or LOD3 I will create fake lighting geo , atlas and combine it. Because far away you don't need the detail, you just need the basic shape of a light being illuminated.