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. Let us know your feedback about the Global Illumination changes in the 2023.2 beta.
    Dismiss Notice
  3. Dismiss Notice

How to baking light probes only?

Discussion in 'Global Illumination' started by Skolstvo, Jun 2, 2016.

  1. Skolstvo

    Skolstvo

    Joined:
    Dec 21, 2015
    Posts:
    107
    We all know that Enlighten is garbage at making realistic static lightmaps. So obviously to get good results I use a good renderer like Blender Cycles to bake my lightmaps. It works flawlessly.

    The problem is that I can't bake lightprobes. The solution would be to bake only light probes in Unity. The problem is that I have no idea how to do that. Essentially Unity should have an option to bake only light probes by spending no actual resolution on meshes and only use them as a base for clustering. This way it would be possible to make lightmapping that looks good in Unity.

    We all know that sometimes Enlighten just hangs until the heat death of the Universe if your mesh is a bit too dense or the UV's aren't just right. So why is enlighten even bothering when it could bypass the things it's no good at, and concentrate on light probes.

    Also I don't understand why reflection probe baking isn't exposed in the api. Essentially I use reflection cubemaps that are located at a safe space in my project. I then use Custom cubemaps in the reflection probes so that Unity's "intelligent" Global illumination system doesn't throw away my reflection probes at any chance it gets.

    The problem is that baking custom reflection probes is only possible if you click on every reflection probe individually and press bake. Why is there no option to rebake your custom baked reflection probe through code. I used ReflectionProbe.RenderProbe(null); but that is pointless. Why isn't the "bake" function exposed? I can click it, why can't I write it?
     
    Last edited: Jun 2, 2016
  2. KEngelstoft

    KEngelstoft

    Unity Technologies

    Joined:
    Aug 13, 2013
    Posts:
    1,366
    With Enlighten we couldn't make a flow that allows for just baking the light probes as the precompute is still what takes a big chunk of time and is needed regardless. To simulate just baking probes you can set the resolution to a very low value (0 should work :)).
    With the progressive lightmapper we are building, just baking light probes is super quick...
     
  3. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    157
    Custom Reflection Probes cannot be updated via scripting currently because we don't have that API yet, but I will put it on my list. From the Editor you can bake all the Reflection Probes including the custom ones from the Lighting window using the option Bake Reflection Probes(Bake button combo list).
     
  4. Skolstvo

    Skolstvo

    Joined:
    Dec 21, 2015
    Posts:
    107
    @KEngelstoft

    I appreciate you taking the time to answer, but there are some models, especially complicated CAD models which enlighten simply can't handle at all. An external baker has no problems with complicated geometry. If a face is too small in the UV scale it will simply not render correctly. Cycles doesn't die when it can't properly lightmap geometry.
     
    Last edited: Jun 3, 2016
  5. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    157
    We actually do have an API for baking custom reflection probes in Lightmapping class. But remember if you have never baked your custom reflection probe before and don't have any texture set on it, when you exit Play Mode you will loose the change on your reflection probe because in Play Mode a temporal copy of the scene is used.
    You can use the code from below to bake the custom reflection probe from a cs script:

    Code (CSharp):
    1.  
    2. void Start() {
    3.  
    4.         ReflectionProbe reflectionProbe = GetComponent<ReflectionProbe> ();
    5.  
    6.         string path = AssetDatabase.GetAssetPath(reflectionProbe.customBakedTexture);
    7.  
    8.         string targetExtension = reflectionProbe.hdr ? "exr" : "png";
    9.         if (string.IsNullOrEmpty(path) || Path.GetExtension(path) != "." + targetExtension)
    10.         {
    11.             // We use the path of the active scene as the target path
    12.             string targetPath = System.IO.Path.GetDirectoryName(SceneManager.GetActiveScene().path);
    13.             if (string.IsNullOrEmpty(targetPath))
    14.                 targetPath = "Assets";
    15.             else if (Directory.Exists(targetPath) == false)
    16.                 Directory.CreateDirectory(targetPath);
    17.            
    18.             string fileName = reflectionProbe.name + (reflectionProbe.hdr ? "-reflectionHDR" : "-reflection") + "." + targetExtension;
    19.             path = AssetDatabase.GenerateUniqueAssetPath(Path.Combine(targetPath, fileName));
    20.         }
    21.        
    22.         if (!string.IsNullOrEmpty(path))
    23.             Lightmapping.BakeReflectionProbe(reflectionProbe, path);
    24.     }
    25.  
    You can also iterate through all the GameObjects in the scene if you want and bake every custom reflection probe:

    Code (CSharp):
    1.  
    2. object[] obj = GameObject.FindObjectsOfType (typeof(GameObject));
    3.         foreach(object o in obj)
    4.         {
    5.             GameObject go =(GameObject) o;
    6.             ReflectionProbe probe = go.GetComponent<ReflectionProbe>();
    7.             if (probe && probe.mode == UnityEngine.Rendering.ReflectionProbeMode.Custom)
    8.             {
    9.                 //Bake it using the code in Start
    10.             }
    11.         }
    12.  
     
  6. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,782
    So basically we have to use reflection probes (low res medium density and custom shader of course) to replace lightprobe?
     
  7. berniegp

    berniegp

    Unity Technologies

    Joined:
    Sep 9, 2020
    Posts:
    40
    Noisecrime, koirat and hippocoder like this.