Skip to content

Commit 3f5605c

Browse files
authored
Merge pull request #20421 from sunag/nodematerial-webgpu
NodeMaterial: WebGPU
2 parents 214135b + b0a7b5d commit 3f5605c

33 files changed

+1589
-196
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import AttributeNode from '../core/AttributeNode.js';
2+
3+
class UVNode extends AttributeNode {
4+
5+
constructor( index = 0 ) {
6+
7+
super( 'vec2' );
8+
9+
this.index = index;
10+
11+
}
12+
13+
getIndexProperty( prefix ) {
14+
15+
return prefix + ( this.index > 0 ? this.index + 1 : '' );
16+
17+
}
18+
19+
getAttributeName( /*builder*/ ) {
20+
21+
return this.getIndexProperty( 'uv' );
22+
23+
}
24+
25+
getAttributeProperty( builder ) {
26+
27+
// customize 'uv' property
28+
const property = this.getIndexProperty( 'vUv' );
29+
30+
this.setAttributeProperty( property );
31+
32+
return super.getAttributeProperty( builder );
33+
34+
}
35+
36+
}
37+
38+
export default UVNode;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import Node from './Node.js';
2+
3+
class AttributeNode extends Node {
4+
5+
constructor( type, name = null, property = null ) {
6+
7+
super( type );
8+
9+
this.name = name;
10+
this.property = property;
11+
12+
}
13+
14+
setAttributeName( name ) {
15+
16+
this.name = name;
17+
18+
return this;
19+
20+
}
21+
22+
getAttributeName( /*builder*/ ) {
23+
24+
return this.name;
25+
26+
}
27+
28+
setAttributeProperty( name ) {
29+
30+
this.property = name;
31+
32+
return this;
33+
34+
}
35+
36+
getAttributeProperty( builder ) {
37+
38+
const attribute = builder.getAttribute( this.getType( builder ), this.getAttributeName( builder ), this.property );
39+
40+
return attribute.property;
41+
42+
}
43+
44+
generate( builder, output ) {
45+
46+
const attributeProperty = this.getAttributeProperty( builder );
47+
48+
return builder.format( attributeProperty, this.getType( builder ), output );
49+
50+
}
51+
52+
}
53+
54+
export default AttributeNode;
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import Node from './Node.js';
2+
3+
class InputNode extends Node {
4+
5+
constructor( type ) {
6+
7+
super( type );
8+
9+
this.constant = false;
10+
11+
Object.defineProperty( this, 'isInputNode', { value: true } );
12+
13+
}
14+
15+
setConst( value ) {
16+
17+
this.constant = value;
18+
19+
return this;
20+
21+
}
22+
23+
getConst() {
24+
25+
return this.constant;
26+
27+
}
28+
29+
generateConst( builder ) {
30+
31+
return builder.getConst( this.getType( builder ), this.value );
32+
33+
}
34+
35+
generate( builder, output ) {
36+
37+
const type = this.getType( builder );
38+
39+
if ( this.constant === true ) {
40+
41+
return builder.format( this.generateConst( builder ), type, output );
42+
43+
} else {
44+
45+
const nodeUniform = builder.getUniformFromNode( this, builder.shaderStage, this.getType( builder ) );
46+
const propertyName = builder.getPropertyName( nodeUniform );
47+
48+
return builder.format( propertyName, type, output );
49+
50+
}
51+
52+
}
53+
54+
}
55+
56+
export default InputNode;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
class Node {
2+
3+
constructor( type = null ) {
4+
5+
this.type = type;
6+
7+
this.needsUpdate = false;
8+
9+
Object.defineProperty( this, 'isNode', { value: true } );
10+
11+
}
12+
13+
getType( /*builder*/ ) {
14+
15+
return this.type;
16+
17+
}
18+
19+
update( /*frame*/ ) {
20+
21+
console.warn( "Abstract function." );
22+
23+
}
24+
25+
generate( /*builder, output*/ ) {
26+
27+
console.warn( "Abstract function." );
28+
29+
}
30+
31+
build( builder, output ) {
32+
33+
builder.addNode( this );
34+
35+
return this.generate( builder, output );
36+
37+
}
38+
39+
}
40+
41+
export default Node;

0 commit comments

Comments
 (0)