Nodes: Some refactoring and clean up #27512
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Refactoring including removing some no longer needed NodeBuilder methods, some nodes and node builders clean up (e.g. using node chaining more, simplifying some code paths, fixing some methods signatures to be more consistent, cleaning up the flows algorithm), and fixes of a few potential and current bugs (including cases when a TempNode, which was used more than once was generated more than once, or when it was possible to generate something like
mix( abc, def, ghi ).xyz = somethingElse
-- both these issues could happen in a quite a number of cases -- it's still not perfect now, but hopefully should become so with another PR unifying Node and TempNode). Also this cleans up the resulting shader code in quite a lot of cases (mostly by addingNodeBuilder.formatOperation()
method; the refactoring of TextureNode also helps).This PR mostly only cleans the nodes/ directory, not touching renderers or node examples (they can be cleaned up in a separate PR).
Unfortunately there seems to be a VERY strange bug with normal maps, of which I have no idea what it is caused by. You can see it as a "blockiness" on the fibers ball in the webgpu_clearcoat example.
If you replace the code for the fibers ball with the following it becomes easier to see:
You can see that the first ball has a blocky-like map (instead of the correct "meridians"-like) and the last ball has just a flat map, whilst it should be visible as having large cavities.
The most interesting part is that (at least on my machine) if you try to move the camera (by move+rotate or zooming in) so that only one of these two balls is visible, then somewhere along that path both balls magically autofixes (this happens in 100% of time). Even more interestingly, if two other new balls are removed -- this no longer happens, the bug still occurs and no longer fixes.
I have no idea why this happens -- but I'm very sure this is not a bug in this PR but rather maybe some WebGPU bug -- I checked the original and the new vertex and fragment shaders and they are 100% the same in terms of functionality.
The PR is tested on all WGSL examples that were at the moment of its creation and all GLSL examples that worked at the moment of its creation.
(I've spent about 2.5 months working on this PR... Sorry that it has so much changes combined together, I will try to split it into smaller PRs if requested -- or will just rebase it on the latest dev if it's OK to merge as this is)