Problems encountered when creating Interior Mapping materials on surfaces

As the title suggests, when I was making this material, I found that the mapping did not achieve the desired effect,
I have previously achieved a similar effect in Unity, but when porting the Unity code to Babylonjs, it may have been due to insufficient understanding of the engine that this feature was not implemented.
When conducting the investigation, I personally believe that the problem occurred in the area where the TBN matrix was created. However, due to personal reasons, I do not know how to modify this area. When conducting the investigation, the result I obtained was not what I wanted. I don’t know if any expert can give me some guidance

Here is the relevant code reproduced in the amusement park

If I understood correctly, I think you’re trying to achieve this effect:

3 Likes

Yes, that’s exactly the effect. Thank you

1 Like


这是完成的效果

This looks great!

Hello boss, regarding this material, I have encountered a problem now. It is with the current material. My model only displays the normal effect when the angle is vector3 (0,0,0). Once the model rotates the angle, the material written in this code will not present the correct effect. Afterwards, I looked at the case provided by the previous classmate and found that the material also encountered the same problem after the model was rotated. May I ask what the reason is?
Please find attached the scene where I encountered the problem after modifying it, as well as the scene where I encountered the problem after modifying it
Case 1

Case 2

I made some changes to this case, and the same error I encountered occurred

It seems like it is enough to counter the camera rotation. https://playground.babylonjs.com/#D34XLG#7

Can we rotate vEyePosition somehow? Otherwise I would feed in the new camera.

1 Like

Thank you, I will attempt to implement this modification.

Based on the case you provided, I conducted my own testing and found that I modified the x-axis and z-axis directions of the plane according to the corresponding code. However, I found that the results did not perfectly display the corresponding effects. What is the reason for this.
I see from the information that the upper and lower limits of beta are between PI/2 and - PI/2, and the upper and lower limits of gamma are between PI and - PI. Is this related to these factors?

This is the problem I encountered after making the modifications

Boss, if the camera type is not ArcRotateCamera but FreeCamera or Targeted Camera, how should the angle of the model be corrected?
This is the code I tested myself in a scenario, but the results were not satisfactory. How can I solve this situation

Boss, please take a look at the subsequent modification process. I tried various modifications later, but the results were not good. When using babylonjs, I used dot to calculate the angle and converted it, but I did not see it in the opinions given by everyone. May I ask if it is possible to normalize (vPosition - vEyePosition) in vec3 rayDir; What about processing the vertices in this step?

I don’t understand the code well enough. So I would have to dig deeper for I which I do not have the time, sorry.

I would have thought though, given my experiment from above, you can rotate the camera by the inverse of the plane.

Afaik (someone please correct me if I am wrong :flushed:) the worldViewProjection matrix does factor in the scene camera (is it “view”?). So get the camera matrix, apply the inverse rotation, rebuild the worldViewProjection matrix and feed that as uniform to the shader.

If the code works for a mesh with identity matrix (0,0,0 rotation), then transform the vectors with the mesh inverse matrix.

For performance reason (and ease of impl), it should be possible to just use the transpose of the mesh matrix. matrices - Transpose of inverse vs inverse of transpose - Mathematics Stack Exchange