Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize texture upload of morph targets #5037

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions src/scene/morph.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,12 @@ class Morph extends RefCountedObject {
}

// build texture for each delta array, all textures are the same size
const arraySize = this.morphTextureWidth * this.morphTextureHeight * numComponents;
const packedDeltas = halfFloat ? new Uint16Array(arraySize) : new Float32Array(arraySize);
for (let i = 0; i < deltaArrays.length; i++) {
const data = deltaArrays[i];

const texture = this._createTexture('MorphTarget', this._textureFormat);
const packedDeltas = texture.lock();

// copy full arrays into sparse arrays and convert format (skip 0th pixel - used by non-morphed vertices)
for (let v = 0; v < usedDataIndices.length; v++) {
const index = usedDataIndices[v];
Expand All @@ -197,9 +198,9 @@ class Morph extends RefCountedObject {
}

// create texture and assign it to target
texture.unlock();
const target = deltaInfos[i].target;
const format = this._textureFormat;
target._setTexture(deltaInfos[i].name, this._createTexture('MorphTarget', format, packedDeltas));
target._setTexture(deltaInfos[i].name, texture);
}

// create vertex stream with vertex_id used to map vertex to texture
Expand Down Expand Up @@ -266,9 +267,8 @@ class Morph extends RefCountedObject {
}

// creates texture. Used to create both source morph target data, as well as render target used to morph these into, positions and normals
_createTexture(name, format, pixelData) {

const texture = new Texture(this.device, {
_createTexture(name, format) {
return new Texture(this.device, {
width: this.morphTextureWidth,
height: this.morphTextureHeight,
format: format,
Expand All @@ -280,13 +280,6 @@ class Morph extends RefCountedObject {
addressV: ADDRESS_CLAMP_TO_EDGE,
name: name
});

if (pixelData) {
texture.lock().set(pixelData);
texture.unlock();
}

return texture;
}
}

Expand Down