Skip to content

Bundled Scene 73 is sensitive to unsafe inline WGSL mangling #95

Description

@Popov72

Problem

http://localhost:5174/bundle-scene73.html can render incorrectly when production bundle WGSL identifier mangling rewrites too aggressively inside inline shader strings.

Scene 73 renders CarbonFiberWheel.glb twice in split viewports: native glTF PBR on one side and the checked-in NME material on the other. The non-bundled scene is fine, but the bundled page is sensitive to mangleInlineWgsl() replacements in scripts/bundle-scenes-core.ts.

What we found

The full historical inline WGSL mangling list is not safe for Scene 73. Delta-debugging the generated bundled output showed that these replacements must currently be skipped to keep Scene 73 visually correct:

worldNormal
environmentIrradiance
translucencyIntensity
baseLayerAbsorption
ccNormalW
ccVRefract
ssRefractionIrradiance
NdotVUnclamped
diffuseTransmissionAcc
ccIorInv
finalSpecularScaledDirect
colorSpecEnvReflectance
ccRoughnessIn

With those identifiers excluded from replacement, the Scene 73 bundle stays under its size ceiling and the bundled screenshot matches the known-good output. With the unsafe replacements enabled, the bundled scene produces a visible rendering mismatch even though the source scene and shader code are otherwise unchanged.

Suspected root cause

mangleInlineWgsl() is a raw string replacement pass over bundled JavaScript. Scene 73 mixes native PBR shader assembly and NME-generated shader code, and not all shader fragments are equivalent semantic scopes. A global textual replacement can rename a variable in one inline WGSL snippet without guaranteeing that every generated/connected reference in the final composed NME/PBR shader is renamed consistently and safely.

This means the current approach is fragile: an identifier that looks safe in one shader path can collide with or disconnect generated code in another path once Vite/Terser chunking and NME shader generation are involved.

Desired fix

Replace or constrain the ad-hoc global text mangling so inline WGSL identifiers are only shortened with shader-aware scope information, or maintain an explicit allowlist/denylist with coverage for bundled NME/PBR scenes. Scene 73 should remain part of the validation set because it exercises the problematic combination: PBR clearcoat + NME material + split viewports + production bundle minification.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Fields

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions