Moving normalMap on InstancedMesh with onBeforeCompile

Hey !
Hope you are doing well.

I’ve currently a 3D Model, with an atlas texture (3 textures side by side), that I offset in my onBeforeCompile accordingly to what I want.

The problem is : I see the normalMap still in the texture when my light moves.

My question is : how can I offset also the normalMap (and I assume, all the roughness/bump and other maps, but I’m not sure about what I’m saying right now)

Thanks for your ideas !
Alex

If you go here: three-shaderlib-skim

and click “unfold all” .. you can see the unrolled source code for the standardmaterial.
You’ll see:

These are the UV coords that you will also have to override with your injection.

So here in the vertex shader:

after the <uv_vertex> chunk.. you’ll have to adjust all the channels you care about:

#ifdef USE_ALPHAMAP

YOUR_UV_ADJUSTMENT_FUNCTION(vAlphaMapUv)

#endif USE_ALPHAMAP 

...
vLightMapUv 
vAoMapUv 
3 Likes

Also in case you aren’t aware, the shader “chunks” are also accessible and globally modifiable…

via the THREE.ShaderChunks map…

so you could modify the

THREE.ShaderChunks.uv_pars_vertex += "your uvmodifying code...

globally at init time if you want to have some common behavior globally.

I don’t really suggest that for this case but just wanted to show how it all works. I think onBeforeCompile is the way to go until you need something more complex.