Can Lightmaps be created by only using BJS?

Hello Babylon Forum :slight_smile:

Is there a way to create a Lightmap for a Scene only using BabylonJS? I am working on a Project where I want the best lighting possible with a nice performance as priority. I was trying out a way to bake AO to my Scene in blender and export it back to Babylon, but this obviously requires the export and import after the effects are bakedā€¦ So is there a way to create a Lightmap and apply it to the Scene, just using Babylon? Some sort of ā€œon load functionā€ that works its way before the scene is fully loaded. Maybe with a Custom loading Screen to hide the long waiting time :smiley: I know that I am asking for a lot here :face_with_diagonal_mouth:

Thank you very much for all the Help!

Iā€™m afraid this does not exist (or I would have used it for my project :grin:). I believe @PatrickRyan is the best expert to expose the possibilities you have for your case as of just now.

@Sarrus4x4, currently, there is no way to do create an environment map from the scene. It is on our wish list but didnā€™t make it into our priorities for the 6.0 release. I can pitch it to the team again for 7.0, but it will have to compete against all of the other features and enhancements that are on the horizon.

The process would likely need to be an offline process, where you are able to do a set-up step to bake from a scene and save out an env file to be used like any other. This would be most performant as it is no different than what we have for IBL now. If we need it to be done at runtime, it would likely need to be done during a loading screen as we would need to write out six HDR textures at a size that retains the quality you need, which could get expensive.

Otherwise, in terms of performance if needed while a scene was running, it would likely be similar to real-time filtering or reflection probes and would need to be able to be throttled so as to not eat up too much frame time. The problem is the trade-off for calculations done for real-time environment map creation versus everything else you are doing in your scene on any given frame.

But I will tag it again for discussion in our planning session for the next release.

Thank you very much for your answer!

So what you are explaining here is purely hypothetical? Could it be done automatically if the use of some external program is acceptable? What is mean is: Is it possible to export a Scene from Babylon, apply some visual effects and reimport it back to Babylon all during the load time? And if so, how could this be done? I have this awesome Blender Plugin for shadows and AO, and Iā€™d love to use it on my Scene before it is loaded in Babylon. But this would have to be done automatically ā€˜on Loadā€™ because the Scene might change on every new Load (it is a 2D room editor with an option to turn your Scene into 3D by pressing a button).

Thank you :slight_smile:

May I ask how you solved this ā€˜problemā€™?

  • Did you just take the hit in performance and use real time shadows?
  • Did you manually generate and apply a shadow map externally, because your project does not need to be fully automated?
  • Did you find a way to automate the process of applying a shadow map by using external programs?

Sorry for asking, but I am in dire need of a solution :smiley:

I wasnā€™t really in need of shadowmap. My scene is all around alpha blended materials, refraction and reflection and shadows are of little importance. My need was to be able to have a blend of exterior and interior environment on the parts that are visible both from the exterior and the inside. Typically glass-like.
So, I donā€™t think my little trick will work for you. For the record, what I did is that I loaded once a default env for the interior and made tiled (skybox mode) screenshot from an orthographic camera. Did the same with my exterior, custom skybox. Next blended both in photoshop, did some mask painting and generated a new env for my interior from there.

Oh, that sounds cool, but you are right when saying that I does not work for my application :slight_smile:

Iā€™m sorry. I know itā€™s a burdain and a downside to building the scene with fx in BJS (rather than just simply all from blender). Hopefully, weā€™ll have access to a solution in a near future. Meanwhile, I suppose you will need to find some sort of ā€˜compromiseā€™. May be bake some of your shadows in blender, those less affected by fx and who donā€™t need to be dynamic. May be still add a shadowgenerator for the others (with of course an impact on performance).

Donā€™t worry, Iā€™ll find a way.

As I mentioned in my reply to @PatrickRyan I will try to use Blender as a tool to bake some shadows to my Scene. Now Iā€™ll need to find a way to create an automated workflow to export a scene from Babylon, import it to blender, bake some shadows + AO and finally reimport it to Babylon :smiley:


I already found out how to use this cool Blender Light Baking Plugin to make my scene look a bit more realistic and export it back to Babylonā€¦ (baked AO+shadows on the left :smiley: )

I am extremely new to Babylon and this field of work, by the way, so donā€™t hesitate to tell me if what I am suggesting is bonkers.

Thank you for all your time

@Sarrus4x4, I think I mentioned this in another thread, but you could try exporting your Babylon scene as a glTF file and bringing it to Blender to bake your lighting or IBL. You should then be able to just use the product of that bake in your scene without needing to send the scene back to Babylon.

If you are baking an hdr file for IBL, you can then import that and apply it to your scene. If you are baking shadow maps onto a pre-existing UV set in your mesh - for shadow maps you need a separate atlased UV set for all meshes so that the lightmap can be baked into a single texture - then you can simply take the baked texture back to Babylon and apply it in your scene.

As you mention, the connective tissue here is the missing piece. I havenā€™t worked on a pipeline like this, but I have heard of others doing a scene export to render a ray traced image in headless Blender for things like room configurators. The user sets up their scene, then they can generate a high-quality render of the space, obviously not in real time.

Thank you for your time.

What do you mean by ā€œwithout needing to send it backā€? When I bake something to my Scene in Blender I still need to get the results back to my Babylon applicationā€¦ But this would also require some of that ā€œconnective tissueā€ in some form of pipeline, right?

That sounds like something I could use. A view minutes of waiting for a Scene to get exported, baked and displayed in Babylon with new visual features would be a great solution. Iā€™ll investigate further and try to find information on such a pipeline.

I guess the key word is ā€˜the sceneā€™. Of course you still need to import the result in BJS but it will be through the meshes materials and the new atlased UV. I hope your scene, meshes and UVs arenā€™t all too many and complex though. Else, this is likely to take quite a bit of effort the way I understand it.

Oh, I see. I was thinking about only baking shadows and AO to the floor and walls for simplicity, but Iā€™ll have to see about that.

So now Iā€™ll be on the lookout for a method to automatically send Files from BJS to Blender and backā€¦ :slight_smile:

What do you mean by ā€˜automaticallyā€™. Are you making an editor or something? If so, that might become a long journey. I shall send you strength :mechanical_arm: and resilience :smiley: Meanwhile, have a great day :sunglasses:

1 Like

I mean fully automatic :smiley:
Yes, I am working on a 2D room editor where users have the option to press a button and (possibly after some time) see the 3D version of the scene. The Basic Functionality is already there (2D view is fully functional and on the press of a button you can see the 3D rendered scene). Now I want to make it look pretty by adding AO, Shadows, etc. without my performance going to waste (because it also runs on mobile). So all/most effects should be baked before the scene is loaded.

I take it from your message, that this is a quite complicated process, and I am in for some nerve wracking hours of Work :smiley:

Edit: Just thinking of it right now. Now that I understand better where youā€™re heading.
Ever thought of using Houdini for the bake and the backend? May be check this out and cc @br-matt might be able to give you some hints on the process they used for this awesome project, will you? thx a lot :pray:

Thank you so much!
Iā€™ll go check it out :slight_smile:

1 Like

Yep Houdini indeed can be used for that. The other good part about it, can be containerized and run in the cloud. I canā€™t go too much into specifics as I just know the topic at a high level. Someday @Valentine will get to present the whole crazy process beyond just baked textures.

One thing to watch out for is cost of sending off to a render farm. The larger scenes cost hundreds to thousands to get a really good render.

1 Like

@Sarrus4x4, my apologies for not being clear. I was specifically speaking about sending the glb back to Babylon after baking. If the UVs on your meshes are set up to accept baked lighting before export, then you only need to send the texture(s) back to the scene with a simple texture load and apply to material. There would be no need to send the entire scene glb back into Babylon since the only addition would be the textures. This would save on some download time on the userā€™s end.

1 Like

Hi all. You can build lightmaps baking with blender and python on server side and save new lightmaps and ambient occlusion as images and use as lightmap and AO textures

const lightmap = new BABYLON.Texture("lightmap.png", scene);
const material = new BABYLON.StandardMaterial("material", scene);
material.lightmapTexture = lightmap;
1 Like