Babylonjs equivalent of Threejs's modelViewMatrix?

In this shader Glow Effect - ShaderFrog.com (you can use the tabs on the top left to view source, or click “edit source” to play with the source code). You can see the outline effect is properly “sticking” to the object when the object is rotated. The calculation of the fresnel rim is based on the model, view, and position, and the normal of the surface.

I’m trying to define a mapping between threejs matricies and babylon matricies. You can see in any of the babylon linked playground examples above, the effect does not properly stick to the rim of the object in babylon.

Ah - i just found the problem! The original shader linked above multiplies the normal by the normalMatrix, which I thought was a no-op, but the normalMatrix in three.js is the “inverse transpose of the modelviewmatrix” three.js docs

as a hack, if I do this

            mat4 x = inverse(transpose(view * world));
            fNormal = (x * vec4(normal, 1.0)).xyz;

Then the fresnel rim works properly.

3 Likes