google / model-viewer

Easily display interactive 3D models on the web and in AR!
https://modelviewer.dev
Apache License 2.0
6.76k stars 801 forks source link

normalTextures acting oddly with KHR_materials_variants #4443

Closed echadwick-artist closed 10 months ago

echadwick-artist commented 11 months ago

Description

normalTextures are lighting oddly when materials are swapped using KHR_materials_variants. 2023-09-03 17_14_34-EricChadwick com

This occurs with the attached model, both when embedded with 3.2.0 and when loading the model into the Editor.

StainedGlassLamp.zip

Error does not occur when loading the model in BabylonJS Sandbox: 2023-09-03 17_17_06-Babylon js - StainedGlassLamp glb

Threejs Editor may have a clue. If the second number next to the normalTexture is changed to +1, the bump is inverted. Perhaps this value is being ignored (or forced to 1) with variants. image

Live Demo

https://ericchadwick.com/gltf/index.html#StainedGlassLamp

  1. Scroll to the StainedGlassLamp example (anchor should take you there).
  2. Switch the variant to "Lamp Off"
  3. Notice how the lighting appears to invert on the dark bumpy metal around the stained glass, on the bumpy details in the base, etc.
  4. Switch the variant back to "Lamp On", and notice the change in lighting on the bump maps.

Version

Browser Affected

OS

AR

echadwick-artist commented 10 months ago

I have simplified the problem and made another example asset. This only has a single mesh, a baseColorFactor and a normalTexture.

bump-variants-simple

glTF file: bump-variants-simple.zip

elalish commented 10 months ago

Thank you for the simplified example and the clue - I think you're right. I'll look into it.