I’m trying to implement a CustomShader with a vertex shader that would let me “wobble” the individual vertices on an imported GLB object.
As an example of what I mean, if you go to Three.js’ editor and click Examples > Shaders, it’ll call up a crazy rainbow geometric thing. Click “Play” in the menu and it’ll start wobbling. Look at it wobble!
The relevant OpenGL shader can be viewed/edited by clicking on the Isosahedron 1 object in the Scene, then clicking the GEOMETRY tab, then clicking SCRIPT > EDIT. There is this function that sets a uniform called time:
function update( event ) {
this.material.uniforms.time.value = event.time / 500.0;
}
And then if you click MATERIAL > VERT it has the function that changes the position of the vertexes as a function of time:
uniform float time;
varying vec3 vPosition;
void main() {
vPosition = position;
vPosition.x += sin( time + vPosition.z * 4.0 ) / 4.0;
vPosition.y += cos( time + vPosition.z * 4.0 ) / 4.0;
gl_Position = projectionMatrix * modelViewMatrix * vec4( vPosition, 1.0 );
}
Which is pretty neat in its simplicity – it grabs each vertex, alters its x and y positions as a function of the z position and time, and then sends that back to the output.
I’ve done a lot of Googling relating to CustomShader and vertexShaderText but found almost no documentation as to what objects exist to be called by it. The relevant doc page gives some tantalizing hints, but I’ve found nothing explaining much of this. What can one access in vsInput? What is vsOutput.positionMC looking for? (What’s the MC stand for?) Etc. etc.
If someone could give me a little hint, or point me in the right direction, I’d be super thrilled.
The use case for this: I am creating a cloud from a GLB model in a Cesium environment, and I’d like its vertices to sort of wobble convincingly. This seems like something that is a perfect fit for a vertex shader. I’ve been able to do this very nicely with the Three.js editor, but I can’t seem to figure out how to implement a similar function in Cesium.
Thanks so much. I am aware that CustomShader is marked as “experimental” and my hopes for documentation should be accordingly low!