Has anyone figured out a way to do this? - I’d like to bake AO for environment sections that are later assembled procedurally and lit with mostly-real-time lighting but baked AO.
I was hoping I could just have a white ambient colour, no direct lights, and bake. But in reality, there’s no way to add a flat ambient light to the bake - only an ‘environment light’, which is occluded and bounces - leading to inconsistency between baked sections.
It’s annoying, as I’m sure the bake process is generating the AO separately at some point, there just seems to be no way to access it on it’s own
Has anyone solved this problem?
(Baking in external tools isn’t really an option, as I want to be able to assemble the level sections in Unity)
What have you tried? it should be possible to quickly bake AO only in Unity using GPU PLM. Something like a white or near-white sky with ambient pushed up worked fine when I tried it.
Alternatively you could do something like have 6 directional lights oriented in 6 different directions of a cube with no shadows to fill in light from all directions and then have AO on top.
Looks good for a single scene, but if I bake 2 scenes individually, then load them both in together, there’s a significant difference in intensity of the should-be-unoccluded areas. This is mostly because the sky light gets occluded by the large cuboids, so the ground is darker, even when well outside of AO range
Test scenes currently look like this (bright white ‘environment lighting’ color, strong AO, no other lights, Progressive CPU lightmapper)
I could probably bodge it a bit in the shader with some scaling/clamping. Or maybe by preprocessing the lightmap texture and changing the import settings to make it not-a-lightmap (as ideally I want a regular LDR texture, not dLDR or RGBM)
(When baking the AO, I’m actually creating 2 extra copies of the level section, and placing them to the left+right of the section being baked, intended to minimize seams at the edge)
Unity has a bunch of materials on its learning and manuals. It states (from memory) that you should use a specific mode of baking via script to mass bake a bunch of scenes that will be streamed in or out. This is a known and addressed workflow you should look up.
Finally, there is Bakery for nvidia gpu owners, and this I own. It’s pretty good. Does vert baking too for AO and such.
Unity’s GPU PLM (just tested again just now) is pretty absurd really. It’s fast, then it stops for ages, then it’s fast. It doesn’t seem to care if I’m running it on a tron mainframe or a spectrum either, some serious bottlenecks in there.
That’s not the issue at all. The issue here is that ‘environment light’ (indirect light with occlusion and bounce) behaves very differently to ‘flat ambient light’ (which is what I’d like), so I’m baking indirect shadowing that I don’t want - if I just had pure AO, the sections would join cleanly (unless there’s a strong AO shadow right near a section edge).
The ‘many directional lights’ solution might actually the answer here… could take a lot more than 6 to get even lighting though…
If using PLM, make sure Direct contribution for AO is also 1 or more, else it’ll be physically accurate and remove AO wherever lighting touches it.
Since physically accurate AO actually only exists in shadow.
The many lights thing is not a solution except for showing off 1-2 models. It just won’t work for varied env. I’ve done this AO thing perfectly fine my end - what stops you baking with flat white as sky? - Under Environment section in lighting you should be able to change from Skybox to flat colour.
Even the ‘flat colour’, when baked, is treated by the lightmapper as a 360-degree indirect/sky light which can be occluded and bounced. In the previous image, the large ‘building’ on the right secetion is casting a subtle indirect shadow (in all directions, it’s blocking a small amount of ‘sky light’ from reaching the ground), and causing the significant seam.
This test is using 6 white directional lights, no indirect light, and strong AO - which seems to be going in the right direction - the remaining bit of seam is expected. (In practice it’d be combined with at least a directional light, and the AO wouldn’t be quite that strong)
You could try providing a custom meta pass that assigns a black albedo to all surfaces, so whenever a ray strikes any surfaces that path is essentially terminated. Only rays hitting the environment directly from a lightmap texel would provide a value > 0 which sounds like what you want.