Wrap texture around object without stretching with MeshStandardMaterial

Hello,

I try to wrap a texture around an object without stretching while scaling.

I have the following ShaderMaterial and it works as I need it.

But I want to make use of it with a MeshStandardMaterial instead of ShaderMaterial.

How am I able to solve this?

Best

You can use yourStandardMaterial.onBeforeCompile=(shader)=>{

}
To intercept the shader before compilation, then modify it to include your custom code.
You can use this site to figure out which parts of the shader you need to replace…
https://ycw.github.io/three-shaderlib-skim/dist/#/latest/standard/vertex

3 Likes

Thanks for your reply.

I already tried to create the material by using onBeforeCompile but I failed. I have no clue about glsl so I will be very grateful if you could help me here.

1 Like

Here ya go:

https://flint-separated-stretch.glitch.me

code (look in triplanar-mapping.js):

3 Likes

Hi,

I was able to implement your code into my project. It works as intended. Very nice - thank you!

Is it possible to make normalMap and roughnessMap behave the same way as map?

It should be yeah.