Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Three.js: When and how often are attributes passed to GPU

Tags:

three.js

I'm working on a WebGL scene in Three.js that uses custom shaders and am trying to optimize the rendering. To do so, I'm wanting to understand: When and how often is data passed into the GPU?

Does every vertex, uv, etc. that are passed as attributes or uniforms into the shaders need to be passed in each frame, or do these values get passed once and cached until the user sends new data for a given attribute or uniform key?

I'd be grateful for any help others can offer in describing the times when data is passed into the GPU in WebGL.

like image 565
duhaime Avatar asked Oct 12 '25 04:10

duhaime


1 Answers

BufferGeometry is very efficient because it sends attributes (such as UVs, normals, vertices, and indices) only once to the GPU when you declare the Mesh.

If you want to make changes to one of these attributes after it's been initiated, at a later frame, you must set its .needsUpdate property to true, and then it will be re-sent to the GPU. Otherwise, the initial values will remain in GPU cache undisturbed.

See: https://threejs.org/docs/#api/core/BufferAttribute.needsUpdate

like image 114
Marquizzo Avatar answered Oct 16 '25 06:10

Marquizzo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!