The_Lightmapper icon indicating copy to clipboard operation
The_Lightmapper copied to clipboard

Proposal: export glTF files with lightmaps

Open dirkk0 opened this issue 1 year ago • 9 comments

I think the lightmapper can be changed so that lightmaps can be exported to glTF files.

The challenge is to make use of a feature of the blender exporter which can export a Baked Ambient Occlusion texture. To do that one needs to add a gltf settings node to the material and connect the baked lightmap to it.

I made this video to showcase the process. https://youtu.be/Kd_IFycRqEg

So, two steps are needed:

  1. change the order at the mix node (easy, change lines 341 to 344 with mixNode.inputs[2/1])
  2. add a gltf settings group node

Does this make sense?

dirkk0 avatar May 18 '23 12:05 dirkk0

Hi,

I think there's already sort of something like that available - If you go to Utilities and select "GLTF Utilities", there's a button called "Add GLTF Node":

image

I never really got far with it because I don't have any specific test settings, but if A-Frame isn't too hard to setup, I might give it a go during the weekend, since adding a utility to go through all the materials and rearranging the links shouldn't be too hard.

Did I understand it correctly, that the correct setup would be like this? - Does A-Frame just assume that the UV map for the "main" texture is channel 1 when it's not specified?:

image

Naxela avatar May 18 '23 17:05 Naxela

Oh, I didn't see that!

And yes, that's what I meant! A-Frame relies on ThreeJS, and thankfully Diego just updated it: https://github.com/aframevr/aframe/issues/5288

You don't have to set up A-Frame (you can, of course, and I would be very glad to assist!) but you can use Don McCurdy's gltf viewer: https://gltf-viewer.donmccurdy.com/

If it works there, it works anywhere.

Thank you so much!

PS: BabylonJS viewer: https://sandbox.babylonjs.com/

PlayCanvas Viewer: https://playcanvas.com/viewer

dirkk0 avatar May 18 '23 18:05 dirkk0

Thank you very much for these, would save me a lot of time trying to set up viewers for these frameworks! - With a bit of luck, I might be able to have a utility feature added sometime this weekend

Naxela avatar May 19 '23 09:05 Naxela

Awesome, thank you! Let me know if I can assist.

dirkk0 avatar May 19 '23 09:05 dirkk0

I've tried a bit on doing this, and I've gotten it working to some extent - The problem is that the .hdr lightmaps are "downgraded" from 32-bit to 8-bit jpg/png files, thus you loose quite a bit of lighting data. While 8-bit works fine to some extent (but it becomes washed out and not fully HDR), I'm looking into if I can make something work with the encoded 8-bit files - The problem with this is that it needs a decoder on the other end too, and I don't know if A-Frame have some way to decode RGBD files?

Naxela avatar May 26 '23 10:05 Naxela

Not entirely sure, tbh. Since A-Frame is a wrapper around THREE, there seems to be a way but not very straightforward: https://discourse.threejs.org/t/threejs-loader-add-hdr/25758 So, the gltfLoader might support this but I wouldn't know how to test this.

How about a switch? I could imagine a use case where people would like to directly look into the textures and can't see/edit .hdr files directly.

dirkk0 avatar May 26 '23 10:05 dirkk0