I am a threejs developer and I am not familiar with the babylon API. When I use shaderMaterial and try to unpack the normal map in the fragment shader, I use the threejs approach. I also checked the source code of babylon. The reference is the same article, but babylon has some special processing that puzzles me. By the way, I tried to load a gltf model and replace its material, and finally output the color of the normal map, but it is different from what I expected.
I can get the tbn matrix by this function,but when I looked up the source code to find out why the unexpected results occurred, I found that when invertNormalMapX is true, the x component of tangentSpaceParams is -1. Why is this necessary? And why does Babylon load a gltf model and replace its material and the output normal map looks wrong?
I read the link you gave. The reason for this difference is that the normalmap required by Babylon is from DX while the normalmap required by Threejs is from OpenGL. So the output to the screen will look inconsistent, right?
Thank you. I understand the reason for the difference and I am also reading the source code. However, I only found that the tangentSpaceParams parameter of the cotangent_frame function has changed. I tried to fill in the same parameters, but the actual display effect is still unexpected.
I’ll try to read what you did in perturbNormal. Can you give me some source code links?