Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
NodeMaterial: WebGPU #20421
NodeMaterial: WebGPU #20421
Conversation
|
@Mugen87 folow ( #20421 (comment) ) ( f738e6a ) |
|
I don't think it is necessary to make a new example for nodes anymore. Do you mind modifying the existing |
|
@Mugen87 You have any idea for that error message I am getting: |
This message did not pop up in my tests so far but I assume that /cc @Kangz @takahirox |
|
@mrdoob This PR looks really great! In context of design, I would highlight one important aspect since it will accompany node material from the very beginning. With the current implementation, nodes have the responsibility to control their build/generation. This process is mainly done with a node builder with is injected as a parameter. One could consider a different architecture such that nodes do not have any build/generate methods but just describe themselves. You then have a centralized entity that traverses through the node composition and performs the build. I personally favor the current approach since it's similar to having |
Mmmmh it should work with the std140 layout, but WebGPU seems to think it is 28 bytes probably because of a bad array stride? Could you share permalink of the GLSL->SPIRV compilation in http://shader-playground.timjones.io/ ? |
|
I don't know how to share a permalink. Here is some sample code:
It seems that even if a single float only takes 4 bytes, it's necessary to put 12 bytes as padding when starting with |
|
I guess we need the logic from the UBO PR that determines the total buffer size according to the STD140 layout. https://github.com/mrdoob/three.js/pull/15562/files#diff-cba50499b84f8d3f3690b625a907ba74R209 |
|
Ah yes, I misread. It is expect that the buffer would use 28 bytes in std140 layout because things are mostly padded to 16 bytes all the time. Like you said, the logic in the UBO PR should help. |
|
I think in changing the properties to |
|
I add Nodes support for PointsMaterial ( 99cced5) in some minutes, very simple... This can be used for any material of threejs too. |
|
|
||
| } | ||
|
|
||
| let uniformGroup; |
Mugen87
Sep 29, 2020
•
Collaborator
This variable should be called just uniform. Instances of WebGPUUniform are not related to group.
This variable should be called just uniform. Instances of WebGPUUniform are not related to group.
| @@ -19,6 +21,8 @@ class WebGPURenderPipelines { | ||
| this.glslang = glslang; | ||
| this.sampleCount = sampleCount; | ||
|
|
||
| this.nodeBindings = new WeakMap(); |
Mugen87
Sep 29, 2020
Collaborator
This can be renamed to just bindings.
This can be renamed to just bindings.
| @@ -200,6 +212,12 @@ class WebGPURenderPipelines { | ||
|
|
||
| } | ||
|
|
||
| getNodeBindings( object ) { |
Mugen87
Sep 29, 2020
•
Collaborator
And this to getBindings().
And this to getBindings().
| import NodeSlot from '../nodes/core/NodeSlot.js'; | ||
| import NodeBuilder from '../nodes/core/NodeBuilder.js'; | ||
|
|
||
| class WebGPUNodeUniformsGroup extends WebGPUUniformsGroup { |
Mugen87
Sep 29, 2020
Collaborator
Can you also use just WebGPUUniformsGroup? Eventually, bindings should only be managed over the node material system.
Can you also use just WebGPUUniformsGroup? Eventually, bindings should only be managed over the node material system.
|
Nice! I think we should manage now all existing uniforms over the node material system so the following code block can be eliminated: three.js/examples/jsm/renderers/webgpu/WebGPUBindings.js Lines 40 to 56 in b1390eb Instead of this code, we just have this: const bindings = this.pipelines.getBindings( object ); |
|
When you look at the shader code in When managing all bindings over the node material system, I suggest to finally review and then merge this PR since it is a proper first step. |
| createUniformFromNode( node, shaderStage, type ) { | ||
|
|
||
| const uniformNode = super.createUniformFromNode( node, shaderStage, type ) | ||
| const nodeData = this.createDataFromNode( node, shaderStage ); |
Mugen87
Sep 29, 2020
•
Collaborator
This call irritated me a bit. You call createDataFromNode() here although this method was already called inside of createUniformFromNode(). I understand that you only call it to get the (already existing) node data.
This code will be more clear when it is align to WebGPUProperties or WebGLProperties. Meaning to transform it to a getter. The implementation of createDataFromNode() and createDataFromNode () is already similar to:
three.js/src/renderers/webgl/WebGLProperties.js
Lines 5 to 18
in
b1390eb
The method creates a cached object if necessary. But this creation is not something the caller has not know about. Ideally, the code would be:
const uniformNode = super.getUniformNode( node, shaderStage, type )
const nodeData = this.getUniformNodeData( node, shaderStage );
In my mind create*() methods are factory methods that always return a new instance when called. This is currently not true for both uniform methods.
This call irritated me a bit. You call createDataFromNode() here although this method was already called inside of createUniformFromNode(). I understand that you only call it to get the (already existing) node data.
This code will be more clear when it is align to WebGPUProperties or WebGLProperties. Meaning to transform it to a getter. The implementation of createDataFromNode() and createDataFromNode () is already similar to:
three.js/src/renderers/webgl/WebGLProperties.js
Lines 5 to 18 in b1390eb
The method creates a cached object if necessary. But this creation is not something the caller has not know about. Ideally, the code would be:
const uniformNode = super.getUniformNode( node, shaderStage, type )
const nodeData = this.getUniformNodeData( node, shaderStage );In my mind create*() methods are factory methods that always return a new instance when called. This is currently not true for both uniform methods.
sunag
Sep 29, 2020
Author
Collaborator
This was get before getNodeData I will keep and I have that change the logic of createUniformFromNode... This code block changed a lot from yesterday to today because of the implementation of texture2d uniform...
This was get before getNodeData I will keep and I have that change the logic of createUniformFromNode... This code block changed a lot from yesterday to today because of the implementation of texture2d uniform...
I am already thinking about cleaning and |
if ( material.isMeshBasicMaterial ) {
bindings = this._getMeshBasicBindings();
} else if ( material.isPointsMaterial ) {
bindings = this._getPointsBasicBindings();
...It is not clear to me where you want to move these functions, it is for |
I thought we could remove them and add the common bindings ( |
This would change a lot, a very simple implementation would mix the logic of the procedural with natives... I don't think it's appropriate for the moment. |
|
No problem. We can experiment later with this. But the goal should be that all bindings are defined by the node material system at some point (and not be hard-wired in the renderer). In general, the renderer should not perform any checks for materials anymore (e.g. test for |
|
If so, I see no reason not to leave the properties hybrid right now because code block like this don't make much sense... thinking ahead. layout(set = 0, binding = 2) uniform OpacityUniforms {
float opacity;
} opacityUniforms;
layout(set = 0, binding = 3) uniform sampler mySampler;
layout(set = 0, binding = 4) uniform texture2D myTexture; |
|
Yeah, the current shader code was more or less developed for testing. If we can consolidate this in order to avoid unnecessary bindings, we should do so. We just have to be aware that UBOs might be shared across multiple shader programs. So e.g. |
Yes, this feature already exists in the current node material system we should only bring it to the new node system: ( https://github.com/mrdoob/three.js/blob/dev/examples/jsm/nodes/accessors/CameraNode.js#L100 ) |
|
@sunag Do you think you can finish the PR in the next time by adding support for It would be good to have a basic version of the node material in place so we can move on with developing the renderer at other places. |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.


@Mugen87 @mrdoob Very, very draft to facilitate the understanding... this is a step implement to WebGL too, is my new approach, merger node slots directly in ShaderLiib... The next step in this PR is implement uniforms.
I fork the example
webgpu_sandbox.htmland added just some lines code: