Threejs ac group 511163089
Vertex shader
This is what determines where on the screen you end up drawing that dot, and xyz ends up in the range of [-1,1] z to deal with occlusion
How do you pass in the position of the dot there’s VAO, VBO and all that stuff but we’ve encapsulated it for you based on threejs, EMM, threejs called attribute
[0.0, 0.1, 0.2, 0.3, 0.4, 0.5……] [0.0, 0.1, 0.2, 0.3, 0.4, 0.5……]
So 0.0, 0.1, and 0.2 correspond to x, y, and z at the first point and then xyz at the second and third points
You can also add other attributes if you want to use them
I mentioned earlier that the model is triangular
Here some vertices will be duplicated, so we have index field, specify the number of vertices, write index [0,1,2,2,3,0] to the index 0,1,2 and draw the first triangle
In the threejs
As long as you create BufferGeometry of type Buffer, the attribute is assigned to you
If you want to customize geometry shapes that he doesn’t have, you need to configure them yourself
You can look at the bufferGeometry attribute and index of this ball to understand F12
var geometry = new THREE.SphereBufferGeometry(10); Var material=new three. ShaderMaterial({vertexShader: ‘// this vertexShader
// attribute vec3 position; You don’t have to write “three” in this sentence
Void main() {gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); } ', fragmentShader: 'void main() {gl_FragColor=vec4(1.0); } `,})Copy the code
var mesh=new THREE.Mesh(geometry,material);