/trig_airplanes.js Secret
Created
October 26, 2024 01:25
BFCM Globe 2023: Trig airplane movement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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