-
-
Notifications
You must be signed in to change notification settings - Fork 35.6k
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
NodeMaterial: Add support for compute()
integrated into the material
#30768
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
Does this mean that the type of an assigned positionNode will be inferred based on whether compute() is called? For instance, if material.positionNode is assigned the value of Fn(() => { return positionLocal })(), will that be evaluated as code that should run in the vertex shader, whereas Fn(() => { return positionLocal })().compute() will try be evaluated as a compute shader? |
@cmhhelgeson Compute functions do not return values by default, but now the returned value will be bound to the chosen material input. In this sense, the computation will be done whenever the material is rendered, the value returned from the compute function will be the value that will be generated in the vertex-stage or fragment-stage as the user created the code. You can return |
I'm not sure I understand, so the values that gets assigned to position in positionNode will equal the values that are returned per each vertex/instance in the compute shader. Additionally, the compute shader generated by assigning a ComputeNode to positionNode is automatically executed once per material render, meaning the code flow per frame would be something along the lines of A. Run compute node/compute shader to assign position values -> B. Run position/vertex shader which will use the values computed by the compute shader as its position values. |
Yes, that's basically it. The main difference here is that you don't need to use |
Related issue: Fixes #30612 (comment)
Description
Compute can now be used directly on materials. They will only be computed before the object is rendered, if the object is not in the camera view or is invisible for another reason the computation will also be ignored.
The Node returned within
compute()
is computed directly in the Material, while all other calculations withinFn
will be done just before the object is rendered bycompute()
.The example below guides the position of Sprites based on
PointsNodeMaterial
andSkinnedMesh
.