Bakery - GPU Lightmapper (v1.96) + RTPreview [RELEASED]

I believe so, as I think that was the default?

It wasn’t so if you didn’t go to experimental settings and enabled it on purpose, it shouldn’t happen…
Otherwise, not sure why it’s taking so long. If you can send me the mesh + its .meta file + your ftGlobalStorage.asset, I can try to reproduce it and see what’s going on.

Shadows are needed for dynamic objects (effects, projectiles, character and mobs).
To improve performance, I have several lighting quality settings:

  • low settings (only lightmaps)
  • medium settings (lightmaps + dynamic light sources without shadows)
  • high settings (lightmaps + dynamic light sources with shadows)

As I said, everything works, but every time after baking the lighting, recreating prefabs is not very convenient.

Fully baked lightmaps assume you’re using light probes (or volumes) for dynamic objects, not real-time lights.
If you want objects to receive real-time lighting (without casting shadows), you can create 2 versions of each light with a differnt culling mask - i.e. one is fully baked, and another only affects dynamic objects (and doesn’t have a Bakery component).
If you need dynamic objects to cast shadows, properly mixing with baked shadows, your only option is to bake using Shadowmask mode (and set lights’ Baked Contribution to “Shadowmask and Indirect”).

Baking in Unity 6 seems to work fine for the most part until I select to bake adaptive probe volumes (from the Bakery window) at which point it just gets stuck like this forever.

Hmm, is it with the latest (very latest) patch?

I updated from GIT (using the internal updater) an hour or so before this happened and it happened just before I posted, so I would assume so.

hey , i have a question yesterday i was using bakery to bake lightsmap for a huge scene , all baked good , then unity crash idk why , when i reopen my game all lightsmap are gone from the object but still in storage of unity , and also when i want to rebake something it give me black lightsmap and it use only 10mb of vram , any help please ?

Sorry, we haven’t been able to reproduce it in a separate demo scene. However we did find what it seemed to be a conflict with another plugin: AutoLOD. The error seems to have stopped since deleting it. Thanks for the help anyway!

1 Like

I’ve noticed that after baking my scenes, I can no longer access _MainLightPosition variable in shaders (its always (0,0,1)). I did some debugging in SRP code and noticed that the mainLightIndex value is always -1 after bake, due to which main light data is not set. Duplicating the main light fixes this, but breaks lighting as then everything becomes too bright. I’m not sure if this is a Unity 6 thing or is this somehow related to Bakery - I’ve just upgraded to U6 from 2022 and started noticing this :thinking:

Hello, I have an error when trying to bake APV right after finishing a full render. The error says “Add at least one LightProbeGroup (L1)”

My setup has 1 main scene plus 6 additive scenes. The lightmaps are separated to four groups, which makes some scenes share a lightmap group.

To fix the error, I’ve tried the following:

  • making sure that there is a lighting data and that Adaptive Probe Volumes appear when using Render Debugger. I do this by hitting “Generate Lighting” under Lighting → Adaptive Probe Volume settings
  • In Bakery, I also unchecked “Unload scenes before render”

(The two methods above used to fix the problem, but hours later, I kept getting the error again.)

I also tried:

  • Clearing:

    • the bake data via Unity lightmapper
    • Bakery bake data and settings
    • Bakery cache
    • Unity GI cacke
  • Then hitting Bakery’s Render button

After this, the lighting data disappears but the new Bakery lightmap shows. I would uncheck “Export geometry and maps” and “Unload scenes before render”, and then hit the “Render Adaptive Volumes”. This would also throw out the “Add at least one LightProbeGroup (L1)” error.

If you could kindly point out how I could fix this, it would be much appreciated!

---------- Edit ----------

I unchecked “Split by baked tag” and the APV started baking xD but then -! I got a new error :sob:
Error = “Thread group count is above the maximum allowed limit. Maximum allowed thread group count is 65535.” I saw your post in the APV thread before this so I’ve already:

  • bumped the minimum probe spacing from 0.25 to 2
  • disabled
    • sky occlusion
    • dilation
    • virtual offset
    • reduced the size of the volumes

But I’d still get the “Thread group count is above the maximum allowed limit. Maximum allowed thread group count is 65535.” error

---------- Edit 2 ----------

I tested on a small scene, no additive scenes. After a Bakery bake, I unchecked:

  • “Export geometry and maps”
  • “Unload scenes before render”
  • “Split by baked tag”

Then I got the “Add at least one LightProbeGroup (L1)” error again. It happens with both Legacy and L1 probes.

---------- Edit 3 ----------

I managed to get the Bakery APV baking after rendering the lightmaps. The issue was that some additive scenes didn’t have an adaptive probe volume in the scene.

But then the next error that popped up was “Can’t read lightmap for GI”.

I only have 4 lightmap groups and the lighting data asset also shows 4 lightmaps, but the .ftracelog seems to be trying to load a 5th lightmap.

The name of the 5th lightmap “Environment Terrain1” is same name as the first additive scene. This 5th lightmap was saved in the temp folder

TBH I dislike the way APVs are integrated into Unity. The whole system feels like it needs major refactoring. Needless complexity everywhere.

I’m not entirely sure it’s worth supporting APV in its current state. I’d rather work on something like cascaded/atlased/clipmap Bakery volumes that would live in a tiny isolated script instead of spreading over all systems. If I make it use global shader variables without having to assign data per-object, I can theoretically patch Unity includes to switch to this code instead of the default APV path.
And to be fair, it’s more interesting to design a working system than to debug someone else’s code that’s also constantly changing :sweat_smile:
At least this way I will fully understand what’s going on.

Anyway, the errors you’re having are probably trivial to fix. Can you send me some test project where I can reproduce it? My test scenes are pretty limited, I guess.

“Add at least one LightProbeGroup (L1)” is probably a consequence of another error. Anything else in the console?

This one is from Unity code. Can you bake your APV in this scene using the standard baker?

Unity doesn’t allow overriding probe placement and final data post-processing, and they have some bugs there.

Do you mean you baked both scenes together, and then tried to bake APV just for one of them? Probably won’t work, as it currently needs complete geometry match between lightmap bake and APV bake.

If you didn’t save the scene after the bake and before the crash, the lightmap/renderer connections are not there, and a rebake is needed.

Do you mean you successfully rebaked the same huge scene, but the lightmaps are black?
Did you bake it previously without it being black?
Are you using Bakery components on your lights?
Do you have your models UV1-unwrapped (“Generate lightmap UVs” enabled on your models)?
Are you on HDRP? Possibly the lights are just too dim?
Or did you use very high values for Intensity or Indirect Intensity on any lights (>100000)? Using enormous values for both can cause a numeric overflow.

Ah, interesting. I wonder how it was affecting it…

It happens if you bake your directional light completely (i.e. Full Lighting render mode or Direct and Indirect baked contribution). This way there is no light, no shadowmap, etc (and no associated cost). If you want it to exist in the shaders, you need to use some mixed mode (Shadowmask, Subtractive) or bake Indirect-only.
If you don’t actually want any cost of the light and use these variables for custom stuff, you can send a custom variable with e.g. Shader.SetGlobalVector.

2 Likes

Figured this :sweat_smile: It is a bit annoying tho as some assets that I use, utilize the main light direction and modifying them is a bit painful. Also note, 2022 didn’t have this issue prior to migrating to U6.

In-case anyone needs, here is the script I use:

[ExecuteAlways]
[RequireComponent(typeof(Light))]
internal sealed class MainLight : MonoBehaviour
{
    private static readonly int PropMainLightPosition = Shader.PropertyToID("_MainLightPositionCustom");
    private static readonly int PropMainLightColor = Shader.PropertyToID("_MainLightColorCustom");

    private Light mainLight;

    private void Awake()
    {
        mainLight = GetComponent<Light>();

        if (mainLight.type == LightType.Directional)
        {
            return;
        }

        Debug.LogError($"{mainLight} must be a directional light!", this);
        enabled = false;
    }

    private void Update()
    {
        Shader.SetGlobalVector(PropMainLightPosition, -mainLight.transform.forward);
        Shader.SetGlobalVector(PropMainLightColor, mainLight.color);
    }
}

Then, I add the following custom node and use it in my graphs (Amplify, something similar should work in regular graphs also):

Get Direction (note, I use *Position suffix as Unity uses this naming for light direction vars):

float3 direction = _MainLightPosition;
if (all(direction == float3(0, 0, 1))) {
  direction = CustomPosition;
}

return direction;

Get Color:

float4 color = _MainLightColor;
if (all(color == float4(0, 0, 0, 0))) {
  color = CustomColor;
}

return color;
1 Like

This magically went away after several restarts so likely just a Unity bug.

With regards to “why use AVPs?” - It’s purely for the Sky Occlusion feature which is really nice when working with realtime day/night cycles. It added a little bit of what really felt like realtime GI. Is there anything else you would recommend as an alternative for similar functionality?

2 Likes

My suspicion is that it was always like this, but before U6 it was still sending the last known/rendered value to the shaders.

The issue is not Bakery-only - same thing will happen with built-in bakers if you make the light fully baked. Both will enabled the isBaked flag and set LightmapBakeType.Baked type, which means the engine will stop updating the real-time light completely.

Thanks for posting your solution though - I hope others will find it handy!

No existing replacement, but I can easily force Bakery to render Skylight to a shadowmask channel and then… then I’d need to hack all render pipeline includes to have a “directional light” ignoring the normal but using that mask. I should try that.

2 Likes

Hey @guycalledfrank, there isn’t really any “problem”, but I figured I’d say something about this.

In URP, when opening the Custom Functions for any of your shader graphs, I am met with an error message: "undeclared identifier 'GlossyEnvironmentReflection' at line 757". I don’t know what the error means because the functions all still work without issue from what I can tell, but the error still shows up.

When I take a look at BakeryDecodeLightmap.hlsl, my IDE (Rider) does indeed show a cannot resolve symbol error. The hlsl file is missing some includes. Adding them does fix the error, but again, even without doing that, the function still works the same either way, so I have no idea why it’s complaining.

Is this something that’s happening on your end too, or is it just me? I’m not sure if it’s something that even needs to be resolved or not, but figured I bring it up.
I’m using the latest URP Bakery graphs and Unity 2022.3

1 Like

Hi! I have a question Mr. F,

Is it possible to mix both “Full Lighting” and “Shadowmask” in one scene?

Basically what I did is bae the full lighting in one scene then bake the shadowmask in another.

Good afternoon.

I am reaching out as recently Bakery has been failing to run over the past week due to a Cuda Error:

And the log is presenting this:

Init...
fixpos12
Loading geometry...
Loading alphas...
Tile size: 4096
Device 0: NVIDIA GeForce RTX 3090 (ON)
Used host memory: 28mb, available GPU memory: 23300mb
MODE: fixpos12
USING FLOAT
Load shaders...
Loading shader fixPos12.ptx::oxMain...
Loading shader lambert_backface_check.ptx::oxMain...
Loading shader clip_rtx.ptx::oxMain...
Loading shader shadow_rtx.ptx::oxMain...
Loading shader attrib_trimeshLOD.ptx::interpolate...
Used host memory: 41mb, available GPU memory: 23300mb
Used host memory: 41mb, available GPU memory: 23300mb
Create buffer...
Num passes: 2
Num tex: 2
Pass uvpos_[redacted]_LMA1.lz4_HDR...
Skipping pass Mask
Used host memory: 41mb, available GPU memory: 23300mb
Launch 1x1 tiles...
Tile 0x0...
Streaming...0
nFNLFPFSd
Launching...
Error (-1): Unknown error (Details: Function "_rtContextLaunch2D" caught exception: Encountered a CUDA error: cudaDriver().CuEventSynchronize( m_event ) returned (700): Illegal address, file: <internal>, line: 0)

Doing some research online, it appears that from an nVidia moderator, “It means your kernel is making an illegal, out-of-bounds access. That is a defect in the code and needs to be debugged. It is not a problem with your GPU, driver, or CUDA setup.”

Post in question.

I was hoping for some insight, or if this will assist in some way to fix this bug.

As I am a new user and can only put one embedded image in a post, I am adding a 2nd post with my main bakery settings, in case it helps.

I’m using per-vertex APV with sky occlusion combined with AO-only bakery lightmaps (with bicubic filtering) for fine detail. This is working very well in Meta Quest 3, the lightmaps make up for the lack of SSAO. Per-pixel APV is super costly though and has too many artifacts.

But I’m having problems baking APV with the bakery window, so I’m having to use the default unity ones trying to match the look.

With Bakery:

With Unity 6:

Seems like there is some sort of error in the SH encoding?

A separate issue is that the BakingSet is created outside the scene-named folder.