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?
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…
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).
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.
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:
void Start() {
ReflectionProbe reflectionProbe = GetComponent<ReflectionProbe> ();
string path = AssetDatabase.GetAssetPath(reflectionProbe.customBakedTexture);
string targetExtension = reflectionProbe.hdr ? "exr" : "png";
if (string.IsNullOrEmpty(path) || Path.GetExtension(path) != "." + targetExtension)
{
// We use the path of the active scene as the target path
string targetPath = System.IO.Path.GetDirectoryName(SceneManager.GetActiveScene().path);
if (string.IsNullOrEmpty(targetPath))
targetPath = "Assets";
else if (Directory.Exists(targetPath) == false)
Directory.CreateDirectory(targetPath);
string fileName = reflectionProbe.name + (reflectionProbe.hdr ? "-reflectionHDR" : "-reflection") + "." + targetExtension;
path = AssetDatabase.GenerateUniqueAssetPath(Path.Combine(targetPath, fileName));
}
if (!string.IsNullOrEmpty(path))
Lightmapping.BakeReflectionProbe(reflectionProbe, path);
}
You can also iterate through all the GameObjects in the scene if you want and bake every custom reflection probe:
object[] obj = GameObject.FindObjectsOfType (typeof(GameObject));
foreach(object o in obj)
{
GameObject go =(GameObject) o;
ReflectionProbe probe = go.GetComponent<ReflectionProbe>();
if (probe && probe.mode == UnityEngine.Rendering.ReflectionProbeMode.Custom)
{
//Bake it using the code in Start
}
}