Skip to content
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

Changing transparent property doesn't have any effect on materials, if true is not provided in the constructor #23866

Closed
soadzoor opened this issue Apr 7, 2022 · 4 comments

Comments

@soadzoor
Copy link
Contributor

soadzoor commented Apr 7, 2022

Describe the bug

It seems the since r137, the default value for transparent prop for materials need to be true (provided in the constructor) if you ever want to make the material transparent in its lifetime. If the default value is false (or is not provided), then changing it to true won't have any effect.

To Reproduce

Steps to reproduce the behavior:

  1. Create a mesh
  2. Some time later (with setTimeout, or by a click event, or anything), attempt to make the material transparent, like this: mesh.material.transparent = true; mesh.material.opacity = 0.5;
  3. Note how the material remains unchanged

Live example

https://jsfiddle.net/9cjg5ofs/2/

Expected behavior

Prior r137, it worked as expected, users could change the transparent property from true to false, and vica versa, and it took effect immediately.

Proof of this (same code, different three.js version (r136)): https://jsfiddle.net/a7hotpb2/

Platform:

  • Three.js version: [dev, r137+]
@soadzoor
Copy link
Contributor Author

soadzoor commented Apr 7, 2022

It seems the following workaround works: material.needsUpdate = true. But it's not very nice, since it was not required before r137. Also, I can't see any information about this in the migration guides, so I guess it's not the intended behavior.

@soadzoor soadzoor changed the title Changing "transparent" property doesn't have effect on materials, if true is not provided in the constructor Changing transparent property doesn't have effect on materials, if true is not provided in the constructor Apr 7, 2022
@soadzoor soadzoor changed the title Changing transparent property doesn't have effect on materials, if true is not provided in the constructor Changing transparent property doesn't have any effect on materials, if true is not provided in the constructor Apr 7, 2022
@Mugen87
Copy link
Collaborator

Mugen87 commented Apr 7, 2022

see #23576 (comment)

We updated the docs with the new behavior. The change is actually noted in the migration guide for 136 → 137 (see last note).

https://github.com/mrdoob/three.js/wiki/Migration-Guide#136--137

@Mugen87 Mugen87 closed this as completed Apr 7, 2022
@soadzoor
Copy link
Contributor Author

soadzoor commented Apr 7, 2022

@Mugen87 Oh, right, I must've overlooked, sorry.
But it does work the other way around, though: changing it from true to false, without settings needsUpdate = true. Is that okay?

@Mugen87
Copy link
Collaborator

Mugen87 commented Apr 7, 2022

It works because blending is disabled. However, the define OPAQUE would still be set in your shader which can produce issues. Probably not in your particular case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants