Naxela / The_Lightmapper

Fast and easy baked GI Lightmaps for Blender and Cycles
GNU General Public License v3.0
690 stars 52 forks source link

Is possible to Generate Lightmaps without modifying the Blender Scene Materials? #154

Open nicoraf opened 1 year ago

nicoraf commented 1 year ago

Hello, for a particular pipeline, we are interested to generate the lightmaps of the Meshes, we are interested in baked texture and the UV mapping , but we want to keep the material of the Mesh preserved. Is there a way to achieve that? I guess that if not it will be a nice to have.

Naxela commented 1 year ago

Hi and thanks for using the addon! - If I understand you correctly you just want to bake the lightmaps without actually applying them to the materials in your scene? In that case, it's possible using the headless toggle:

image

That should work in case you want to export your scenes to external game engines, using gltf or similar

I hope this helps! - If not let me know

nicoraf commented 1 year ago

Hi @Naxela , thanks for your message. I tested it before raising the issue, with the latest version of Blender 3.2.2 . If I Select Don't apply materials, and then I click "Build lightmaps" , I don't see at blender any Image with with a name "MeshName_bake" . Ideally I would expect to see the image and also the light UV map . Thanks

Naxela commented 1 year ago

Hi @nicoraf - All your baked images should be present in a folder located where your blend file is:

image

If you bake with headless mode turned on, do you mean that no lightmaps are saved in the lightmap folder - If you click Explore Lightmaps?:

image

Or do you just want to have the images loaded but not applied inside the blender file itself (Visible in the image editor for example)?

nicoraf commented 1 year ago

Yes we want to have the images embedded inside the blender file itself, but not attached to a material.

Naxela commented 1 year ago

Oh now I understand - I don't think there's currently a way to do that while in headless mode. I can try to add the feature sometime during the weekend, but until then can you test if the following script work?:

import bpy, os

for file in os.listdir(os.path.join(os.path.dirname(bpy.data.filepath), bpy.context.scene.TLM_EngineProperties.tlm_lightmap_savedir)):
    if file.endswith(".hdr"):
        bpy.ops.image.open(filepath=os.path.join(os.path.join(os.path.dirname(bpy.data.filepath), bpy.context.scene.TLM_EngineProperties.tlm_lightmap_savedir), file))

Just copy paste the code into the scripting panel:

image

And your lightmaps should now be loaded:

image

I hope this helps

nicoraf commented 1 year ago

Thanks, we will wait you add this feature. We appreciate it.

So I guess the natural way will be to add a combination of check options so that "Build lightmaps", include the bake images embedded with the same name convention, but it does not modify the materials. However the UV mapping is also inside the Mesh objects.

Naxela commented 1 year ago

Hi, I added this as an option in the latest commit (https://github.com/Naxela/The_Lightmapper/commit/4bc61625edae4726660b28feb88146b62021a3fc):

After you've baked, just go into utilities, and select load lightmaps at runtime:

image

nicoraf commented 1 year ago

Hi @Naxela , thank you very much , we will be testing it and I will comment here again.

nicoraf commented 1 year ago

Hi @Naxela , we tested your changes and we have the following feedback.

When we select load lightmaps, it loads the lightmap image textures, but it only loads image textures with HDR format. We are interested to load PNG images and ideally to be able to choose between PNG and JPEG. One reason is because we prefer that format, but there is another reason is that to our understanding the GLTF exporter add on does not support HDR.

Another comment that is independent of 1). Although the approach of doing that in two steps work for us. Ideally we would prefer that the add on, directly have the images packed after backing, without modifying the materials.

Also maybe if possible , and makes sense to even never have the images in a subfolder, has to be able to have all the images inside blender, so later someone can export it to GLB format.

Maybe it could be added an option "Pack Backed Images", and another combo that we can choose the image format PNG, JPEG, etc ?

Thanks