Hi,
So I am trying to move assets over from Blender via GLTF/GLB to BabylonJS. In doing so, however, because the Materials are PBRMaterials from Blender, I need to add an environment Image/Texture to the scene to emit the light, as required by PBRMaterial, correct? This affects how the materials look in the given lighting.
So, the issue is, I have a lot of materials, and I don’t want to have to change the attributes/settings of each material manually when I load them in, because I want to be able to load in multiple different models as selected by the user, and having 11,000 lines of code to manually adjust each attribute by material name wouldn’t be efficient.
Thus, I would like to use a JSON companion file (that contains all of the settings of the material) associated with each material, and just assign the attributes in order in a looping function. This way, I don’t need to know the name of the material, and I can just access the matching JSON key via the material’s name value.
I think this would probably be the best way to do it, no?
That being said, I want to be able to load in the preset settings from the glb file into the engine with the inspector open, so that I may adjust the needed attributes/settings based on the environment image, and directional light/other lights in the scene, and then save all of those attributes associated with that material into JSON format and export the JSON file to my server.
I’ve been looking at the inspector code, and I couldn’t find a way to do this: how can I access the properties of a particular node/material/texture/light/etc. in the Inspector code/package? Thanks.
Not always. An environment texture is only actually required when either:
- There no lights. An environment texture is in essence lighting. With no lights or env texture, everything will be black.
- There are materials which are smooth enough to be reflective of the environment texture.
If this environment texture requirement assumption is what is driving this whole thing, you could just use lights. Conversely, ditching lights, and just having environment lighting might make for a lot less adjustments.
Assuming that you still need some changes, are your blender materials done using the Principled BSDF
node? You might improve the situation by changing the .blend as much as possible, and changing materials to principled as much as possible, so you can specify what you want there. Getting the as many things right in the export to begin with has its advantages.
Having another file to fix the export file, has a lot of moving parts. Another way of getting everything into a single file is to do your changes with the inspector then export the final file right from the scene. I have never done it, but think there are 2 formats GLTF/GLB, and BABYLON.
Thank you very much for your reply. That helped a lot. However, I am use the Principled BSDF node, and it seems that what is shown in Babylon is not as good as is shown Blender right before the export. So I figured that was due to the environment Texture. I’m also not sure what glTF might not carry over from what is in Blender to the load in in Babylon. It seems some of the material nodes/sockets in Blender are not supported via glTF/Babylon. So I’m trying to figure out what to add/edit in the material in Babylon in order to get up to a good enough/similar fidelity to what is in Blender. That’s why I figured I probably have to edit each material in the Babylon Inspector and then export it to be used in the “product” scene.
I also have a followup question though: if I want to create reflections on shiny or metallic surfaces, wouldn’t I need an environment Texture, since I don’t think Babylon can use raytracing to reflect objects in the scene?
You can use probes if you want dynamic reflection on objects, which will indeed use the environment texture to work.
First, the “not as good” work flow / mindset is not that optimal. Best to just try and get the best values which work in your deployment environment in as early as possible in your work flow. Forget what combination of settings looks great in Blender, or just save that version with those settings in a separate .blend.
Also, a warning about the variation between browsers. I have the EXACT same scene from these browsers:
-
Firefox
-
Chrome
-
Edge
Everything looks more greenish on Chrome, and greenish & either washed out or something on Edge. I suppose, in converse, one could also say Firefox looks more red. @Deltakosh, you know about the Edge blurriness, right?
This is not something new. Different graphics display inconsistently across different programs on the very same system. You need to keep this in mind. The difference between the shaders in BJS and Blender are far greater.
BTW, you can actually change a materials albedo, when it is a texture. They are not generally known, and one way is not really represent-able in Blender.
If you find metallic === 0.42 looks about as good it gets for a material from the inspector, then go back to the .blend & plug that in. That way it just gets generated that way, no code / files / file loading & fix up.
There are 2 caveats to this though. Sometimes an exporter has to bake something due to it not being in the output format. When that happens, things can be a lot more different or possibly ignored. An example where baking is required is if you set something to a procedural texture like the material below:
Also, is the UI in Blender effective for changing something? With the double translation going on from Blender to GLTF & GLTF to BJS, this is no sure thing. You should check your exporter documentation for the first half. I work on the .babylon exporter for Blender. There it is only a single translation there. For PBR out of principled the mapping is: