From 97cc7d9137b3c808ce3f56f675d1b95413245e3f Mon Sep 17 00:00:00 2001 From: bjorn Date: Tue, 20 Jun 2023 21:42:44 -0700 Subject: [PATCH] Fix issue with blend shape compute shader; It was only copying the raw vertex data for the first blend shape, not the first blend shape in each group. --- etc/shaders/blender.comp | 3 ++- src/modules/graphics/graphics.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/etc/shaders/blender.comp b/etc/shaders/blender.comp index b50f5aad..5b7b6569 100644 --- a/etc/shaders/blender.comp +++ b/etc/shaders/blender.comp @@ -10,6 +10,7 @@ layout(push_constant) uniform PushConstants { uint vertexCount; uint blendShapeCount; uint baseBlendVertex; + bool first; }; struct ModelVertex { @@ -36,7 +37,7 @@ void lovrmain() { uint vertexIndex = baseVertex + GlobalThreadID.x; uint blendVertexIndex = baseBlendVertex + GlobalThreadID.x; - ModelVertex vertex = baseBlendVertex == 0 ? rawVertices[vertexIndex] : vertices[vertexIndex]; + ModelVertex vertex = first ? rawVertices[vertexIndex] : vertices[vertexIndex]; for (uint i = 0; i < blendShapeCount; i++, blendVertexIndex += vertexCount) { float weight = weights[i / 4][i % 4]; diff --git a/src/modules/graphics/graphics.c b/src/modules/graphics/graphics.c index 6ae6e1ad..81b57295 100644 --- a/src/modules/graphics/graphics.c +++ b/src/modules/graphics/graphics.c @@ -4206,6 +4206,7 @@ static void lovrModelAnimateVertices(Model* model) { for (uint32_t j = 0; j < group->count; j += chunkSize) { uint32_t count = MIN(group->count - j, chunkSize); + bool first = j == 0; MappedBuffer mapped = mapBuffer(&state.streamBuffers, chunkSize * sizeof(float), state.limits.uniformBufferAlign); memcpy(mapped.pointer, model->blendShapeWeights + group->index + j, count * sizeof(float)); @@ -4215,7 +4216,7 @@ static void lovrModelAnimateVertices(Model* model) { gpu_bundle_info bundleInfo = { layout, bindings, COUNTOF(bindings) }; gpu_bundle_write(&bundle, &bundleInfo, 1); - uint32_t constants[] = { group->vertexIndex, group->vertexCount, count, blendBufferCursor }; + uint32_t constants[] = { group->vertexIndex, group->vertexCount, count, blendBufferCursor, first }; uint32_t subgroupSize = state.device.subgroupSize; gpu_push_constants(state.stream, shader->gpu, constants, sizeof(constants));