[SOLVED] Lightmapping not working (because of batching)

I feel kinda stupid asking this, because the issue doesn’t seem that big… like I just need to flip a bool somewhere. But for the life of me I can’t find what’s going wrong.

Here is my scene lightbaked in the editor:

And here it is at runtime:

Note that the weird yakuza sign appears to be the layout of the scene viewed from above.

I should note that all my “prototype assets” (basically everything) use the same material and are in the same batch group.

Dev Scene:
https://playcanvas.com/project/774964/overview/projectq

is the weird yakuza sign on layer ‘world’ or on layer ‘ui’?

Hi @CaseyDeCoder,

Would it be possible to provide a link to the project?

1 Like

see if the workaround mentioned here could solve it for you

It’s at the bottom of my post.

I’m on my phone now but I will try this later.

also, you mention batch group … I don’t think batching is compatible with lightmapping at the moment … I have a plan to work on it (and create an atlas for lightmaps), but at the moment each mesh has separate lightmap and so batching wipes those most likely (or uses just one at random on all meshes)

I briefly forked the project and added a script to bake the lightmaps 5 seconds after loading, and it works. There was some artifacting in the lightmap result, but I think that is more related to the UVs of the model.

I just applied a script to Root with this in the initalize:

setTimeout(function() {
        this.app.lightmapper.bake();
    }.bind(this), 5000);

this is the result I get:

I’ve had to do something similar with other projects where it seems like Playcanvas bakes the lightmaps before everything is ready, and I need to tell it to bake later. Usually I just have a built in preloader with each scene and bake after everything is loaded and enabled.

Hope that’s helpful.

1 Like

I suspect the batching is the issue … and you force rebake lightmaps after batching … and the result is incorrect as uv coordinates now overlap for batched mesh.

2 Likes

Turning batching off has completely fixed the issue. It raised the draw calls from 7 to (worst case) 79 though… but framerate didn’t seem to suffer from it. If it does become a problem in the future, then I suppose we can always ‘batch’ them in blender… by which I mean merge everything into 1 model.

Unfortunately my UVs are correct Eproasim, since I had PlayCanvas generate them and they work in the editor.

I thank both of you for your help, but I’d urge the PlayCanvas Team to document their incompatibility inside the user manual. I’ve read the lightmap and batching pages twice over and if there was a mention of it I should have seen it.

2 Likes

Adding: https://github.com/playcanvas/developer.playcanvas.com/pull/249

2 Likes

@mvaligursky, out of curiosity, would lightmaps work with hardware instancing?

Instanced meshes are not in the scene as such … they’re something a script generates and renders directly in a way … so those are not lightmapped. That would need each instance to have separate lightmap as well?

1 Like

@mvaligursky, How to do lightmapping for instanced meshes in that case? Can you share a code snippet for the same?
Thanks.

Are you talking about lightmapping one mesh, and then rendering it 100 times with exactly the same lightmap?

I guess one of the options here would be to lightmap it manually, see how it’s done here:
http://playcanvas.github.io/#/graphics/lights-baked

it calls app.lightmapper.bake. By default it bakes the whole scene, but you can specify list of entities I think which are baked. And after this is baked, you’d set up instancing using the mesh, similarly to how it’s done here:

http://playcanvas.github.io/#/graphics/hardware-instancing

or maybe even here:

http://playcanvas.github.io/#/graphics/batching-dynamic

1 Like

Can you please share a simple project where we use both lightmapping with lights at different places and hardware instancing together?

It is working with a single directional light, but in our use case we use different spot lights at different places, where instanced models reside. Can you tell me which approach to use in this scenario?
Thanks

Lightmapping bakes the lighting into a model. So when you move this model to different places, the lighting will stay the same and will not be changed based on your spot lights.

You can perhaps only bake directional light, and keep spot lights realtime? Of course this can get pretty expensive pretty quickly if you need more lights / especially if they use shadows.

Perhaps you can not use instancing … and simply place your objects to location as needed, and bake all of them?

I’m sorry but I don’t have a project like this to share.

@mvaligursky, Thanks for the reply. Will try baking with directional light.

Any update on batching being compatible with light mapping? I know this is a decently large feature but I just thought I’d check.

1 Like

No update on this unfortunately, and no plans in the short term.