Reflection probe for refractions behaving like reflections when scene useRightHandedSystem

Hi,

I am trying to implement refractions with PBRMaterials to refract an image of a GLB and sphere through a glass mesh.

I am able to refract perfectly fine except for when i set scene.useRightHandedSystem = true. My app requires scene.useRightHandedSystem = true. Peeking into the BJS code for reflection probes, it looks like reflection probes should be able to handle right handed system and so i suspect this may be a bug.

You can run the below PG to see that the refraction in the glass material is behaving like a reflection. Commenting out the line that toggles on right handed system will show a correct refraction.

ohhh looks like a bug to me @Evgeni_Popov can you have a look into it ? if not I will check later tonight.

You need to set the invertZ property of the refraction texture to true to make it work in rhs:

2 Likes

I am wondering whether it should be manual or not ?

Yup! That did it. Thank you.

Iā€™d be in favour of a more automatic approach as well. Canā€™t really see a use case for keeping it as it is now.

I agree, hereā€™s the PR:

1 Like

I may have found another ā€œbugā€ regarding refraction. Based on GLTF specs and mentioned elsewhere on the web, glass usually has a ior of 1.5. Iā€™ve updated the PG for a box (our glass window) to have an ior of 1.5. You can see that the refracted image is heavily magnified even though the sides of the box is flat like a glass window.

When I recreate the scene in Blender, the glass window does not magnify at all regardless of ior value. This to me appears to be reasonable and correct output.

Is it a bug that BJS is rendering heavily magnified refraction?

This magnification is not because of the IOR but because you are using a probe, which by default is supposed to represent the geometry at infinite distance. You should use a local probe (cube map) instead, if you want a more localized render.

To convert a cube map to a local cube map, you must set the boundingBoxPosition and boundingBoxSize properties. For example:

2 Likes

Thanks. This is helpful. Learning lots.