Skip to content

[Fix] Fix to morphing using incorrect shader when multiple morph meshes are used #7848

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

Merged
merged 1 commit into from
Jul 22, 2025
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/scene/morph-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class MorphInstance {
const outputType = this.morph.intRenderFormat ? 'uvec4' : 'vec4';

return ShaderUtils.createShader(this.device, {
uniqueName: 'TextureMorphShader',
uniqueName: `TextureMorphShader_${maxCount}-${this.morph.intRenderFormat ? 'int' : 'float'}`,
attributes: { vertex_position: SEMANTIC_POSITION },
vertexChunk: 'morphVS',
fragmentChunk: 'morphPS',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ export default /* glsl */`
void main (void) {
highp vec3 color = vec3(0, 0, 0);

ivec2 pixelCoords = ivec2(uv0 * vec2(textureSize(morphTexture, 0).xy));

for (int i = 0; i < count; i++) {
uint textureIndex = morphIndex[i];
vec3 delta = texture(morphTexture, vec3(uv0, textureIndex)).xyz;
vec3 delta = texelFetch(morphTexture, ivec3(pixelCoords, int(textureIndex)), 0).xyz;
color += morphFactor[i] * delta;
}

Expand Down
6 changes: 4 additions & 2 deletions src/scene/shader-lib/wgsl/chunks/internal/morph/frag/morph.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ export default /* wgsl */`
varying uv0: vec2f;

var morphTexture: texture_2d_array<f32>;
var morphTextureSampler : sampler;
uniform morphFactor: array<f32, {MORPH_TEXTURE_MAX_COUNT}>;
uniform morphIndex: array<u32, {MORPH_TEXTURE_MAX_COUNT}>;
uniform count: u32;

@fragment
fn fragmentMain(input : FragmentInput) -> FragmentOutput {
var color = vec3f(0, 0, 0);
let textureDims = textureDimensions(morphTexture);
let pixelCoords = vec2i(input.uv0 * vec2f(textureDims));

for (var i: u32 = 0; i < uniform.count; i = i + 1) {
var textureIndex: u32 = uniform.morphIndex[i].element;
var delta = textureSample(morphTexture, morphTextureSampler, input.uv0, textureIndex).xyz;
var delta = textureLoad(morphTexture, pixelCoords, textureIndex, 0).xyz;
color += uniform.morphFactor[i].element * delta;
}

Expand Down