-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Fix simultaneous usage of clearcoat and tangent data #17831
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
Conversation
Clearcoat normals need to use temporary variable names that are different from regular normals so that there's no name conflict. This also moves sampling of the normal map outside of the normal perturbation helper function so that there isn't as much duplicate code.
In case a material has both regular and clearcoat normal maps and is using vertex tangents, we can compute the tangent space matrix made out of the three basis vectors once and use it for both regular and clearcoat normals.
|
Not sure what's up with the CI, looks like it maybe timed out due to some unrelated condition? |
|
Current (https://threejs.org/examples/webgl_materials_physical_clearcoat): PR: It seems the actual |
Prior to this PR clearcoat used "normalMap" in case per-vertex tangents were enabled, and "clearcoatNormalMap" in case per-vertex tangents were disabled. Now we're correctly always using "clearcoatNormalMap".
|
Looks like the previous code also had another bug - in case per-vertex tangents were being used, clearcoat would use the regular normal map. I used that as a reference so I accidentally broke the case that was previously working correctly. Added a commit to always use the right normal map now. |
@Mugen87 No, that is a bug in the PR. |
|
@Oletus said
Can you please point to the bug you were referring to -- and presumably fixed? // I spent about an hour studying your PR and I agree your refactoring is an improvement. Thanks! |
|
I didn't file a separate bug report for the bugs. Bug 1: there's a shader name conflict when Bug 2: clearcoat shader code under the
|
|
@Oletus This looks good to me. Thank you. It is not your fault, but IMO, the shader code with the chunks is very fragile. Logical errors and edge cases are easy to overlook. I found the bug you introduced prior to you mentioning it (bug 2), but I did not notice the redeclaration bug you fixed (bug 1) until I asked. I think it would be beneficial if @arobertson0 would review these changes, too. |
On it =) |
|
The examples are running correctly, and the code is clear and seemingly correct =) I'm noticing that the contents of |
The examples worked before... The related examples don't use tangents. Testing requires a lot of effort, and numerous use cases. |
|
Should we add something to examples to have at least a basic test for this? It would be easy enough to add variations of geometry that use computed per-vertex tangents to the webgl_materials_physical_clearcoat example. |
That is up to @mrdoob. For the record, there are 8 cases:
|
|
I don't think the mentioned examples should block this PR from being merged. They can also be added at a later point, too. |
|
Looks good to me. We can improve things as we go. |
|
Thanks! |
|
/ping @sunag FYI. :-) |


Clearcoat normals need to use temporary variable names that are different from regular normals so that there's no name conflict. This also moves sampling of the normal map outside of the normal perturbation helper function so that there isn't as much duplicate code.