I'd like to apply some movements on my meshes using a vertex-shader. I noticed that when I translate my meshes in my scene it also moves the position of my simple sinus wave. I'd like to have the same sinus wave on both my meshes even if I translate my meshes in my scene.
I had a first lead with this post : Keep movement of vertexShader despite of its mesh rotation
I tried to reproduce this solution but I'm missing something. Here's my shader :
uniform float uTime;
void main()
{
mat4 translate = mat4(1.0);
vec4 modelPosition = modelMatrix * vec4(position, 1.0);
translate[3].y = sin(uTime * 2. + modelPosition.x *1.);
vec4 modelPosition2 = modelMatrix * translate * vec4(position, 1.0);
gl_Position = projectionMatrix * viewMatrix * modelPosition2;
}
I think I shoudn't apply my modelPosition.x on the translate[3].y line but I don't know what to call instead. As you can see on this codepen, my planes look different : https://codepen.io/michaelgrc/pen/GRMxYBm
Does anyone see what I'm missing ? Thanks a lot
I needed to use position.x instead of modelPosition.x to solve my issue :
translate[3].y = sin(uTime * 2. + position.x);