NME PBRMetallicRoughnessBlock reflections are incorrect with right handed coordinate system

See example scene here: https://playground.babylonjs.com/#LMXNIX

Reflection renders with different direction than the skybox (the bright window is in another direction) and is shaded incorrectly (has black fresnel region in the middle even though material should be fully reflective).

You can compare to left handed coordinate system by changing the “scene.useRightHandedSystem” to false on line 4.

Amazing. I didn’t even know of changing to a right handed system. As far as I knew BJS was left handed. It’s great to have this feature of changing it to right handed, although, obviously it doesn’t yet work just a 100% :wink:

Yeah, and unfortunately right handed coordinate sytem is sometimes needed when dealing with GLTF files.

When you load a gltf file with the default left handed system, GLTFLoader applies coordinate transfer to the gltf root node because gltf files themselves operate in right handed space. This is fine in most cases.

However, if you were to use gltf as a scene hierarchy format and wanted to “parent” other meshes (gltf or not) to gltf model nodes. Now you all of a sudden have a problem:

  • If you parent another gltf model to those gltf nodes, and now the coordinate transfer is applied twice. First inherited from the base gltf model root node, then again from the child model. Which results in incorrect transform and possibly also inverse shading.
  • Or if you parent non-gltf model. Then you have a model that doesn’t expect to have coordinate transform applied, but has it inherited from the parent gltf root node. Same issues apply here.

So in that case the only practical solution is to enable right handed mode where no such root node transform is applied. But then you have Babylon.js bugs all around because most developers use it in the default left handed mode. :grimacing:

That really sounds like an issue, since BJS seems willing to push integration with Blender.

So this is an interesting one :slight_smile:

Basically, when we save a node material, we store its side orientation (CW, CCW) which sounds normal and when we parse it, we assign back the value. In your case the material has been created on a left handed scene default editor scene and you are trying to use it in a right handed scene.

Basically, you need to specify the handedness of the material after load to a right handed context: https://playground.babylonjs.com/#LMXNIX#5

Thanks for actually asking the question, as it highlighted another issue which will be fixed by Fix double opposite in PBR NME Right Handed by sebavan · Pull Request #12266 · BabylonJS/Babylon.js · GitHub

3 Likes

Hmm. That fixed the dark spot in the middle, but reflection direction still doesn’t match the skybox.

Try for example when the “TV” reflection is in the middle of the sphere you can actually still see corner of it in the background, but it should be directly behind the camera when that happens.

Compare that to the left handed version where reflection direction matches perfectly. Although hard to say if the bug is in the skybox or NME material rendering.

Or is that what your “double opposite” fix was about, but that just isn’t live on the sandbox yet?

Yup yhis is exactly what yhe PR is supposed to fix :slight_smile: