-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
Cloned ShaderMaterial won't upload its uniform textures #22718
Comments
I've left a long comment for this I've also made an issue on three.js repo: mrdoob/three.js#22718
The current behavior is actually intended. I agree the implementation can be confusing but the problem is that the A class like |
100% agreed. Referencing implementation of other builtin materials such as
What is the reason Edit: Also thanks for the quick response as usual. |
Um, that is actually a good point. I'm not sure why not just an assign happens like with built-in materials. It seems more consistent to me if built-in and custom materials are treated in the same way. However, it could be difficult to change this now since there might be users who rely on the current behavior. E.g. they use different texture repeat/offset settings with the same image source (in context of spritesheets). |
@Mugen87 can't you just add some flags to clone() to adjust the behaviour? |
That is also 100% understandable, yes... Having a logic that detects textures with |
Instead of setting In this way textures wouldn't be marked too early for a texture upload. However, if a texture's image is already "ready", the renderer should detect it since the version of the cloned texture would be @0b5vr Do you mind testing this approach in your project by adding |
Um, it's probably a bad idea. Existing texture objects can break when a higher version number gets replaced with a smaller one. |
Hmm, how so? |
Sorry, I have described the issue not correctly. It's about this line: three.js/src/renderers/webgl/WebGLTextures.js Line 367 in e1ead8c
Let's say you have two textures A and B. A has version |
Closed via #23637. I don't think there will be a solution for the sync pattern mentioned in #23637 (comment). However, cloning textures in the callback function or by using async/await should now work. |
Describe the bug
ShaderMaterial.clone()
fails? to clone texture uniforms to cloned one.The intention of "?" above is I don't know I should treat this as a bug or an intended behavior.
The behavior is counter-intuitive anyway imo.
Inside the code
Here is what
ShaderMaterial.clone()
will do:three.js/src/materials/ShaderMaterial.js
Line 86 in d9af995
and here is how the
cloneUniorms
clone textures:three.js/src/renderers/shaders/UniformsUtils.js
Lines 17 to 22 in d9af995
This will leave
.version
of cloned textures to be0
.Constructor of texture sets version to 0, and clone does not change the value.
And this leads to not upload assigned textures to GPU.
Reproducing the issue
I've made a working example that triggers the issue.
https://glitch.com/edit/#!/grand-plume-windflower
Workaround
There is a workaround code commented out in the Glitch example above.
Manually copying uniform textures to the cloned one will resolve the issue.
Setting
.needsUpdate
of cloned textures will also resolve this.Expected behavior
I have to ask first whether the current behavior is intended or not. If this is not intended, I would like to make it ( reference copy || bump
.version
) these uniform textures whenShaderMaterial.clone()
is called.Detailed context which probably doesn't matter for you
I'm doing the development of three-vrm.
I was trying to bump three.js version from r126 to r133.
three-vrm 1.0 uses extended
ShaderMaterial
(MToonMaterial
namely) and a GLTFLoader plugin which loads the material.(my current working branch is
#1.0
if you're interested)In GLTFLoader, there is a code which clones materials for corresponding material variants:
three.js/examples/jsm/loaders/GLTFLoader.js
Line 2980 in d9af995
Recently, one of variant conditions are changed from
useVertexTangents
touseDerivativeTangents
and this triggers the issue for the first time for us.
PR: #22584
Since this issue has a workaround it can be resolved by our side but it takes a whole business day to resolve this 😭
Understandable difficulty since we're using ShaderMaterial in an unusual way and there is no other users who combines ShaderMaterial with GLTFLoader plugins...
Platform
The text was updated successfully, but these errors were encountered: