Looking to add movement to my meshes using a vertex shader, I've run into an issue where translating my meshes in the scene also affects the position of a sinus wave. The goal is to keep the sinus wave consistent across both meshes even when translation occurs.
While exploring a potential solution in this post: Keep movement of vertexShader despite of its mesh rotation, I attempted to implement the suggested approach but have encountered difficulties. Below is the shader code I've been working with:
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;
}
It seems that applying modelPosition.x on the translate[3].y line may not be the correct approach, but I'm unsure of what to use instead. The differing appearances of the planes can be seen on this codepen: https://codepen.io/michaelgrc/pen/GRMxYBm
If anyone can identify where I may be going wrong, your insights would be greatly appreciated. Thank you.