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

Ambient Occlusion not baked

Discussion in 'Global Illumination' started by EarthHobbit, Sep 9, 2019.

  1. EarthHobbit

    EarthHobbit

    Joined:
    May 10, 2016
    Posts:
    41
    I am having a scene with Baked Global Illumination. When I bake it, I can't see any effect of Ambient Occlusion next to objects. The walls have some AO after baking, but as you can see on the picture below, smaller objects (the bowl is 0.3 units wide) do not show any AO. Bowl and wooden table below have been set to static, light is a Baked directional light.
    Is there anything wrong with my settings below ?

    Thanks

    Screenshot 2019-09-09 at 16.43.26.png

    Screenshot 2019-09-09 at 16.45.17.png
     
    Justice0Juic3 likes this.
  2. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,366
    Lars-Steenhoff likes this.
  3. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,449
    Is there baking of AO planned for GPU?
     
  4. Lars-Steenhoff

    Lars-Steenhoff

    Joined:
    Aug 7, 2007
    Posts:
    3,449
    Ok I just noticed this: so there is my answer
    Features added in 2020.1 (will not be backported)
    • GPU backend can now export AOVs to train ML code for de-noising lightmaps. Only available in developer mode (2020.1.0a1).
    • Compressed transparency textures; 75% memory reduction by using rgba32 instead of floats (2020.1.0a2).
    • GPU lightmapper can now write out the filtered AO texture to disk, alongside the Lighting Data Asset. Only available in On Demand mode. Only available through experimental API(2020.1.0a3).
     
    KEngelstoft likes this.
  5. ethanicus

    ethanicus

    Joined:
    Aug 24, 2015
    Posts:
    39
    Hi, sorry for this necro, but I thought I'd share my findings since this issue remains relevant to those using Unity 2019.x for purposes such as VRChat map creation (as VRChat, as of current, only uses 2019 for creating and uploading maps). Please feel free to correct me if anything I say is incorrect.

    These are the steps I followed to manually add the AO to the lightmaps.

    First you will need to create a script to tell Unity to export the AO maps separately from the lightmaps. Here is the script I created for this:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEditor.Experimental;
    5.  
    6. [ExecuteInEditMode]
    7. public class EnableLightmappingExtract : MonoBehaviour
    8. {
    9.     public bool extractAmbientOcclusion;
    10.     bool lastEAO;
    11.  
    12.     void Awake()
    13.         {
    14.         UpdateEAO();
    15.         }
    16.  
    17.     void Update()
    18.         {
    19.         if (extractAmbientOcclusion != lastEAO)
    20.             {
    21.             UpdateEAO();
    22.             }
    23.         }
    24.  
    25.     private void UpdateEAO()
    26.         {
    27.         lastEAO = extractAmbientOcclusion;
    28.         Lightmapping.extractAmbientOcclusion = extractAmbientOcclusion;
    29.         print("Lightmapping.extractAmbientOcclusion = " + Lightmapping.extractAmbientOcclusion);
    30.         }
    31.     }
    32.  
    Put this on a gameobject in your scene, and check the box. You should see "Lightmapping.extractAmbientOcclusion = True" in the console if this is successful.

    In the Lighting tab, ensure Ambient Occlusion is enabled, and bake the lighting. To my knowledge, the extract feature only works for Progressive CPU, not GPU. I haven't yet tested to see if this is the case.

    Once the bake is complete, look inside the folder named after your scene, created next to your scene file. You'll have 3 files for each lightmap, suffixed as "_ao", "_comp_dir", and "_comp_light". Navigate to this folder in Explorer, and open each _comp_light file in an image editor (the .exr, not the .meta). I use Photoshop, so I cannot give any information on how to do this in other image software, or even if you can.

    You'll see something like this.

    upload_2022-7-11_4-24-42.png

    Now drag in the corresponding _ao file, select "As Transparency", and click OK.

    upload_2022-7-11_4-26-5.png

    Place the _ao layer under the _comp_light layer, and then create a clipping mask with the top layer (ctrl + alt + G). You should now see something like this.

    upload_2022-7-11_4-28-9.png

    Now save the file, make sure the type is .exr, and overwrite the original _comp_light file.

    So far for me, this seems to work. It's my assumption that the alpha channel of the _comp_light file is used as AO. All of this is based on less than an hour of screwing around with this, so I could be very wrong about anything here.

    Keep in mind that if you bake your lighting again, you will have to do this all over again. I recommend creating a Photoshop batch editing sequence to handle this for you.

    Hope this helps anybody that happens to wander by!
     

    Attached Files: