NodeMaterial: Add support for compute() integrated into the material#30768
NodeMaterial: Add support for compute() integrated into the material#30768sunag merged 6 commits intomrdoob:devfrom
compute() integrated into the material#30768Conversation
📦 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 |
|
Definitely much better than the |
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 withinFnwill be done just before the object is rendered bycompute().The example below guides the position of Sprites based on
PointsNodeMaterialandSkinnedMesh.