Skip to content

improve morphAttributes perfomance #26692

@CITIZENDOT

Description

@CITIZENDOT

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.

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.

image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions