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. Dismiss Notice

Tip for lightmapping a terrain

Discussion in 'Editor & General Support' started by Charz, Dec 2, 2010.

  1. Charz

    Charz

    Joined:
    Apr 15, 2010
    Posts:
    20
    Hi,

    I wrote this tip, hoping someone might benefit from it. I didn't thoroughly search the forums so excuse me if this was repeated in any way.

    Now, Imagine you have created a complicated terrain with trees, grass, etc.. and you have added a building where the player would explore as part of his endless journey. Now you wish to lightmap the whole scene (Terrain, building and any objects within) using high settings, then you would encounter a problem... lightmaping process takes forever!!

    Generally for buildings with ceilings, sheds or any object that occludes the light from the sky, you will need 3-4 bounces, high final gather amount: 500+ and of coarse a high resolutionn lightmap. Fortunately, Beast is quite fast with these kinds of objects.

    On the other hand, Beast appears to be very slow at baking terrains mainly by the impact of indirect bounce and final gather ray amounts. The good new is that terrains are almost lit by direct lighting (from sun+sky) and thereby, you could render them with much lower settings and surprisingly enough realism.

    So here are the steps of combining two different baking settings one to your terrain and one for the rest of your objects:
    Note: you have to set deferred lighting as your rendering path in the player settings.

    1- Create a terrain. Add textures, trees, grass, etc...mark it static.

    2- Add you imported objects ( buildings, objects, etc...) mark static those you wish to lightmap.

    3- Apply a special tag to all your static objects excluding the terrain. This will make it easier to select them all later on.

    4- Open the lightmapping panel and set your terrain bake map resolution to your final production amount- it should be at least twice the size of your terrain's height map resolution.

    5- Now set indirect bounces to 1, contrast threshold to 0.1 and Final gather rays to 20 only - (v. low settings)

    6- Bake everything. Notice that the baking speed is relatively fast because you have set very low FG amount.

    7- Once the baking is finished, check lock atlas in the lightmapping panel - this will ensure the maps will not change in your second baking process.

    8- Now select all your static objects except the terrain ( select by tag as mentioned in item 3)

    9- Return to the lightmapping panels and set the baking settings to high ( 4 bounces, 0.05 contrast, 700+ FG rays and optionally ambient occlusion if you wish)

    10- Hit "Bake selected" to bake all your selected objects without the terrain. Notice that the baking speed is still very acceptable and the resulting lighting quality will be up to your expectations.

    The main reason behind this is that realtime terrains have generally far less details than modeled objects. they are also exposed to direct uniform lighting which is cast from the sky leading to minimal indirect lighting variations which may become almost impossible to witness when mixed with the various irregular textures and other distracting items such as grass, rocks and trees.

    Thanks for your patience in reading the above and your comments or alternative suggestions are mostly welcomed.
     
  2. dashmasterful

    dashmasterful

    Joined:
    Feb 3, 2010
    Posts:
    166
    this is excellent, than you very much
     
  3. Charz

    Charz

    Joined:
    Apr 15, 2010
    Posts:
    20
    Of coarse dont forget to turn the "Ambient color" in the render settings to pure black before you bake any lightmaps and only rely on the sky color and sky light intensity in the lightmapping panel. This is very IMPORTANT so that you dont end up having double intensity from both colors.

    Once the lightmap baking process in complete, you can safely turn the "Ambient color" back to what every you like. This way you can add some ambient lighting to your moving or non-static objects.

    Also it is worth mentioning that in Unity 3. all Nature tree shaders ( Old ones and the tree creator ones) do recieve any lightmaps. Instead they relay on two things: 1- on the "Ambient color" in the render settings. 2- on a built-in ambient occlusion effect which adds nice fake GI to the areas in shadow. I think this is a smart move from the developers as it reduces the lightmap calculation time which would be so slow if the trees were included in the calculation.
     
  4. sjm-tech

    sjm-tech

    Joined:
    Sep 23, 2010
    Posts:
    729
    Thanks for your tips!
     
  5. subhomukh1407

    subhomukh1407

    Joined:
    Aug 2, 2018
    Posts:
    7
    I have a issue with the terrain light mapping can you help me. I am using Unity 2020.2. this is desk patches appear at the end of light mapping probably due to UV chart, I am not sure.
     

    Attached Files: