Bugs on MirrorTexture caused by useRightHandedSystem = true flag

Hey guys,
I’m working on a project for a 3D Viewer on which I create a ground with a PBRMaterial with a Mirror Texture to reflect a 3D model on it.

I was working on Babylon 4.2 and the MirrorTexture was working fine, but I just upgrade to the 5.02 version and after that, I had a bug on the reflextion, like if now is reflecting on the wrong axis.


After some research, I get into the line of code that I needed to solve the problem and it was the useRightHandedSystem = true flag, if I change it to false, the reflection work perfectly. However, all the textures get mirrored. The licence plate should show 3DC.


I also found that almost all the test are made in Babylon left handed system, so it is usual to have some bugs on the right one.

This is my code for creating the MirrorTexture for the ground:

public createGroundDark(model: any) {
this.groundDark = MeshBuilder.CreateBox("mirror", { height: 100, width: 100, depth: 0.01 }, this.scene)
this.groundDark.rotation.x = Math.PI / 2;
this.groundDark.position.y = -3.5;
this.groundDark.isPickable = false;
const renderList = model.meshes;
this.groundDark.material = new PBRMaterial("mirrorMat", this.scene);
this.groundDark.material.diffuseColor  = new Color3(0.25,0.25,0.25);
this.groundDark.material.emissiveColor = new Color3(0.1,0.1,0.1);
this.groundDark.material.reflectionTexture = new MirrorTexture("mirrorTex", 2048, this.scene, true);
this.groundDark.material.reflectionTexture.mirrorPlane = new Plane(0,-1,0,-3.5);
this.groundDark.material.reflectionTexture.renderList = renderList;
this.groundDark.material.reflectionFresnel = true;
this.groundDark.material.reflectionStandardFresnelWeight = 0.5;
this.groundDark.material.reflectionTexture.level = 0.5;
this.groundDark.material.reflectionTexture.adaptiveBlurKernel = 8;

}

Where model.meshes are all the bike parts. The 3D model get imported with ImportMeshAsync function that loads a .glb file.

Could you please check?

@sebavan , have we changed something in the Mirror Texture for 5.0?

Nothing that we do intentionally :slight_smile:
We will need a repro in the Playground to go further

Definitely nothing intentional and I can not seem to be able to repro so it would be great if you could share your use case ?

Hi guys,

Sorry for the long reply. Now I have a repro that illustrates my error.

Mirror Texture Right Handed Bug | Babylon.js Playground (babylonjs.com)

If the flag useRightHandedSystem is false, the reflections of the 3D model are exactly were I want (on the floor), but the licence place and the letters on the floor are mirrored (they are not legible)

But if the flag is on true, the reflection is rendered in a plane positioned somewhere else (don’t understad why the the position of the mirrorPlane changes, I undestand that the flag changes the sign of the z axis, which is 0), but the licence plate and the words are legible.

Thank you for your help :slightly_smiling_face:

cc @cedric or @bghgary

@Cedric is on vacation for a couple of weeks. I’ll see if I can investigate.

Let me know if I can help @bghgary

1 Like

@sebavan Feel free to investigate. I don’t really know anything about mirror textures.

2 Likes

This would be fixed by Fix Mirror Reflection in right handed system by sebavan · Pull Request #12521 · BabylonJS/Babylon.js · GitHub

2 Likes