☑ How does the lightmapper work?

Hi,

I think I am misunderstanding something crucial about the Playcanvas built-in lightmapper. By default all scene lights are set to dynamic and all models to non-baked, so I went through all models and set them to “Lightmapped”, then I went through all lights and set them to “Bake”.
Finally after I activated “Auto rebake” the lights went on again and everything looked like it did before with dynamic lighting, at least in the editor. But when I launch the preview my scene is dark again. Is there some scene setting I am missing for doing the pre-render lightmap generation?

Thanks,
Florian

Without sharing link to your project, is hard to understand what could be wrong.
Runtime lightmapping bakes lights into textures to reduce real-time cost of calculating lights every frame. It will look almost the same.

Sorry, I forgot. The project is here https://playcanvas.com/project/432521
The scene I am struggling with is called “Restaurant”.

That’s pretty cool project you’ve got :slight_smile:

  1. You’ve got assets non-preloading. So they stream in async. Runtime baking by default bakes on start which is straight after preload. But your static assets not yet available by that time.
    So either you set them to preload, or better: tag all assets that expected to be lightmapped, then make counter of loading using assets events, and once all loaded, call app.lightmapper.bake().

  2. You’ve used Specular texture on Ambient slot on materials (floor).

  3. JPEG for Normal Maps - is no good. JPEG is lossy, and will change pixels, so vectors wont get normalized, leading to bad noise problems when calculating reflection vector.

  4. Draw Calls - if you open your app with Profiler (launch option), then take a look in Draw Calls section - that is what being rendered. In you case there is 400dc - that is loads :frowning: think about reducing it if you want to keep performance reasonable :slight_smile:

  5. For light sources with shadows, if you do make them to affect non-baked geometry, it will be costly to calculate shadows. Perhaps consider using two lights there - one that will render lightmap with shadows, and one that affects non-baked with no shadows.

  6. Dynamic objects, shall not cast shadows on lightmaps.

  7. Lightmap resolution can be changed on individual objects using multiplier value, or globally in project settings, consider increasing it to have move clear shadows :slight_smile:

Let me know if it helps.

1 Like

Ahhh this is because of my custom LOD handling, damn it, I knew that one was going to bite me one day :smiley:
I am at home now, and the project is on our company account, but I will immediately check these issues on monday.

Thank you very much for your help :slight_smile: much appreciated!

1 Like

You know that all your projects are accessible from any computer you use that has browser? :slight_smile: I sometimes jump on stuff at home, because everything is in a cloud.

Thanks, yes I know :slight_smile:

Ok I checked everything today:

That was the problem, thank you, I added this call to my LOD streaming script and now it works :slight_smile: just one question: is there a way to listen to an event for when the baking is done? I tried ‘lightmapper:end’ but it did not work

Fixed

Very good point, thank you![quote=“max, post:4, topic:2842”]
Draw Calls - if you open your app with Profiler (launch option), then take a look in Draw Calls section - that is what being rendered. In you case there is 400dc - that is loads :frowning: think about reducing it if you want to keep performance reasonable :slight_smile:
[/quote]

Interesting, I will keep an eye on that one, maybe we have to introduce mesh LOD as well as texture LOD.

We are currently experimenting with this, to find a trade-off between performance and good looks :slight_smile:

Fixed

Yes we will experiment with that one as well, to get best looks for good performance :slight_smile:

1 Like

is there a way to listen to an event for when the baking is done?

Baking is actually sync, means that calling bake will block for the time it takes to bake, so there is no event needed, if you want to notify other scripts, you can fire you own event:
this.app.fire('lightmapper:baked);
And subscribe to it:
this.app.on('lightmapper:baked');

1 Like

Thanks, it works :slight_smile:

The support here at Playcanvas is really great, thank you for your help!

1 Like

We try our very best! :slight_smile:
If you have a feedback on things (honest please), it will be very useful too. Things that feel awkward or even frustrating, or some thing that could be easier to do (and you have good idea how) - that would be really useful!

1 Like

Thank you, yes we will!