1

How do I pass an array of vec3 data to a vertex shader using ThreeJS?

air_parcel_pos: {
   type: "???",
   value: the array of data
}
3
  • 1
    .type is not used. three.js r.103. Commented Apr 22, 2019 at 18:06
  • I was wondering why this page in the documentation ( threejs.org/docs/#api/en/core/Uniform ) didn't make sense to me. Thanks. Commented Apr 22, 2019 at 19:09
  • dupe' stackoverflow.com/questions/25249190/… Commented May 11, 2019 at 21:50

1 Answer 1

4

The initialization value has to be an array of values which correspond to the GLSL data type.

e.g.

If the uniform variable is an array of vec3

uniform vec3 u_array[3];

then the initialization value can be an array of THREE.Vector3

var uniforms = {
    u_array: {value: [
        new THREE.Vector3(1, 0, 0),
        new THREE.Vector3(0, 1, 0),
        new THREE.Vector3(0, 0, 1)
    ] }
};

var material = new THREE.ShaderMaterial({  
    uniforms: uniforms,
    vertexShader: // ...
    fragmentShader: // ...
});

Further data types are Vector2, Vector4 or Color. An array of float or int can be set by an array of values.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, your answer expanded my understanding this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.