Skip to content

Instantly share code, notes, and snippets.

@pushmatrix
Created October 26, 2024 01:25
BFCM Globe 2023: Trig airplane movement
this.currentTime = { value: 0 };
airplaneMaterial.onBeforeCompile = (shader) =>; {
shader.uniforms.uTime = this.currentTime;
// Inject the uTime uniform into the shader
shader.vertexShader = 'uniform float uTime;\n' + shader.vertexShader;
// Modify the position calculations of the vertex shader to include our animation math
shader.vertexShader = shader.vertexShader.replace(
`#include <begin_vertex>;`,
`
vec3 transformed;
float speed = 0.2;
float radius = 1.0;
float theta = uTime * speed;
// Rotate each vertex around the origin
transformed.x = position.x * cos(theta) - position.y * sin(theta);
transformed.y = position.x * sin(theta) + position.y * cos(theta);
transformed.z = position.z;
// Offset each vertex by the radius
transformed.x += cos(theta) * radius;
transformed.y += sin(theta) * radius;
`
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment