-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Description
Description
Currently, morphAttributes are handled inefficiently because, before uploading the DataTextures to GPU, renderer iterates over every element in the morphAttribute's ArrayBuffer and assigns it to buffer (which is used to create DataTexture). This does not happen with BufferGeometry.attributes.
three.js/src/renderers/webgl/WebGLMorphtargets.js
Lines 85 to 105 in d930553
| for ( let i = 0; i < morphTargetsCount; i ++ ) { | |
| const morphTarget = morphTargets[ i ]; | |
| const morphNormal = morphNormals[ i ]; | |
| const morphColor = morphColors[ i ]; | |
| const offset = width * height * 4 * i; | |
| for ( let j = 0; j < morphTarget.count; j ++ ) { | |
| const stride = j * vertexDataStride; | |
| if ( hasMorphPosition === true ) { | |
| morph.fromBufferAttribute( morphTarget, j ); | |
| buffer[ offset + stride + 0 ] = morph.x; | |
| buffer[ offset + stride + 1 ] = morph.y; | |
| buffer[ offset + stride + 2 ] = morph.z; | |
| buffer[ offset + stride + 3 ] = 0; | |
This is a perfomance profile for a geometry with only 2 morphAttributes. uploadTexture takes about 0.66ms whereas the update is taking 16ms. Because it is iterating over every single element in the ArrayBuffer before uploading to GPU.
Solution
I'm not sure if this is the only way, but If the morphAttributes are parsed such that, it can be directly consumed by GPU/WebGL, this overhead can be avoided.
Alternatives
NA
Additional context
No response
