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

WebGLNodeBuilder: Move sizeNode under positionNode #23043

Merged
merged 1 commit into from
Dec 19, 2021

Conversation

wmcmurray
Copy link
Contributor

I faced a "race condition" bug while using PointsNodeMaterial with positionNode + sizeNode.

How:
I was changing the position of each points with a couple nodes, then I re-used one of those nodes inside the node hierarchy of my sizeNode.

Result:
The position of each points was 0,0,0 because, in the resulting shader code, every variables generated by my nodes where appended where the size is defined (after gl_PointSize = size;), therefore the position definition above was referencing a variable that is not yet set (something like this: transformed = nodeVar7;), therefore the position was not set.

I wonder if there could be other race conditions like this ? Would it be a good idea to always put all variables at the top instead ?

cc @sunag

to mimic their order inside the actual shader code of Points material
@sunag
Copy link
Collaborator

sunag commented Dec 18, 2021

Would you have a small example just to confirm what am I thinking?

@wmcmurray
Copy link
Contributor Author

Sure ! 😄
Here is the bug in action: https://codepen.io/wmcmurray/pen/dyVRMog?editors=0010
The problem arise on line 65, if you comment it, everything will work as intended !

@sunag
Copy link
Collaborator

sunag commented Dec 19, 2021

@wmcmurray Thanks and great example.
Before merging your PR I would like to make sure this cannot be fixed in the flow process.

@wmcmurray
Copy link
Contributor Author

@sunag Yes feel free to come up with a better solution ! 🙂 I realized (while making the example) that the problem is a bit more complex than I initially thought !

Copy link
Collaborator

@sunag sunag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The WebGLNodeBuilder slot sequence must follow the same defined in ShaderLib/ShaderChunk of Three.js core. For this reason this change was necessary. The same thing would don't happen in WebGPU because WebGPUNodeBuilder is fully based in flow process. Thanks!

@sunag sunag changed the title Move sizeNode under positionNode WebGLNodeBuilder: Move sizeNode under positionNode Dec 19, 2021
@Mugen87 Mugen87 added this to the r136 milestone Dec 19, 2021
@Mugen87 Mugen87 merged commit cc8142d into mrdoob:dev Dec 19, 2021
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

Successfully merging this pull request may close these issues.

3 participants