model-viewer
model-viewer copied to clipboard
Transparent materials invisible when shadow-intensity enabled in 1.12.0
Description
The problem is that in new version (1.12.0) material with transparency becomes completly invisible if shadow-intensity is set to value greater than 0. If you open URL below and set value to 0 the "glass" would become visible. Otherwise it's invisible. This bug is only in the newest version 1.12.0. There was no such problem in 1.11.0.
Live Demo
https://quirky-nonchalant-mare.glitch.me
Version
- model-viewer: v1.12.0
Browser Affected
- [x] Chrome, version: 103.0.5060.66
- [x] Edge
- [x] Firefox
- [ ] IE
- [ ] Safari
OS
- [ ] Android
- [ ] iOS
- [ ] Linux
- [ ] MacOS
- [ ] Windows
AR
- [x] WebXR
- [ ] SceneViewer
- [x] QuickLook
After my own research of the code I can say that the "glass" has property visible (mesh.visible) set to false, because somehow this glass is marked as "bakedShadow". This issue is similar to #3398
@elalish I believe you are aware of this issue.
The issue here is probably the change between versions 1.11.1 and 1.12.0 in ModelScene.ts
in findBakedShadows
function:
1.11.1
const material = mesh.material as Material;
if (!(material as any).isMeshBasicMaterial || !material.transparent) {
return;
}
1.12.0
if (!material.transparent) {
return;
}
In this case material of glass mesh is MeshPhysicalMaterial that's why it's marked as bakedShadow in the newest version.
It's true, but we did this for a reason (see your PR). At the same time we added bounds checks; I believe if you simply make your glass material smaller (rather than including the frame), then we will see that it is smaller than the bounding box and thus not mark it as a shadow.
That's true that if I make the glass thicker it will work correctly. But I think it's bug anyway. How can I achieve correct result everytime even if object has various dimensions?
It's also about extents: shadow planes have to go all the way to the boundaries of the scene. If you don't overlap your frame object, that should also take care of it. Detecting baked shadows is a heuristic, unfortunately, so it will never be correct always.
Can you provide some examples where baked shadow were created without using an unlit shadow material? This case is quite interesting because in most of usecases, glass is made with plane (where one of dimension is 0). Will model-viewer mark it as baked shadow too? We need to come up with an idea how to fix this issue, because in version 1.12.0 some of our models stopped working correctly.
No, but we found a bunch. Anyway, all you have to do is ensure your glass doesn't extend past everything else in your model, because we check not just that one dimension is 0, but also that the other dimensions match the bounding box dimensions of the scene. In your model it appears the glass should be smaller than the frame, but I'd guess it actually overlaps it and hence trips the logic.
Someone else just ran into this and found that it started working properly when bounds="tight"
is specified. This is going to become the default in v2.0 anyway, but can you check if that helps?
Yea, it helps. I didn't notice that this property somehow affects baked shadows. Anyway, thank you for your help!
Yeah, it shouldn't; it's a bug. But that option will be removed for v2.0 so that no one has to remember anymore.
Fixed by #3683