Skip to content

Commit 60f307f

Browse files
sunagLeviPesin
andauthored
Universal Renderer and WebGPUBackend (#26079)
* Universal Renderer and WebGPUBackend ( WIP ) * cleanup * Rename constants.js to Constants.js * revisions * cleanup * cleanup * Rename /universal to /common * Update examples/jsm/renderers/common/Renderer.js Co-authored-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com> * Update examples/jsm/renderers/common/Renderer.js Co-authored-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com> * Update examples/jsm/renderers/common/Textures.js Co-authored-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com> * Update examples/jsm/renderers/webgpu/backends/webgpu/utils/WebGPUTextureUtils.js Co-authored-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com> * Update examples/jsm/renderers/webgpu/backends/webgpu/utils/WebGPUTextureUtils.js Co-authored-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com> * Update examples/jsm/renderers/webgpu/backends/webgpu/utils/WebGPUPipelineUtils.js Co-authored-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com> * Update examples/jsm/renderers/webgpu/backends/webgpu/utils/WebGPUPipelineUtils.js Co-authored-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com> * Update examples/jsm/renderers/common/nodes/Nodes.js Co-authored-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com> * Update examples/jsm/renderers/webgpu/backends/webgpu/utils/WebGPUPipelineUtils.js Co-authored-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com> * Update examples/jsm/renderers/webgpu/backends/webgpu/utils/WebGPUAttributeUtils.js Co-authored-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com> * Update examples/jsm/renderers/webgpu/backends/webgpu/utils/WebGPUAttributeUtils.js Co-authored-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com> * Simplifies paths. * cleanup * cleanup * fix resize * update tip * update tip * Rename: webgpu/builder to webgpu/nodes * cleanup --------- Co-authored-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com>
1 parent 7d32e6a commit 60f307f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+4655
-3676
lines changed

examples/jsm/nodes/Nodes.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,7 @@ export { default as NodeObjectLoader } from './loaders/NodeObjectLoader.js';
141141
export { default as NodeMaterialLoader } from './loaders/NodeMaterialLoader.js';
142142

143143
// parsers
144-
export { default as WGSLNodeParser } from './parsers/WGSLNodeParser.js';
145-
export { default as GLSLNodeParser } from './parsers/GLSLNodeParser.js';
144+
export { default as GLSLNodeParser } from './parsers/GLSLNodeParser.js'; // @TODO: Move to jsm/renderers/webgl.
146145

147146
// materials
148147
export * from './materials/Materials.js';

examples/jsm/nodes/core/NodeBuilder.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ class NodeBuilder {
6868
this.flowCode = { vertex: '', fragment: '', compute: [] };
6969
this.uniforms = { vertex: [], fragment: [], compute: [], index: 0 };
7070
this.codes = { vertex: [], fragment: [], compute: [] };
71+
this.bindings = { vertex: [], fragment: [], compute: [] };
72+
this.bindingsOffset = { vertex: 0, fragment: 0, compute: 0 };
73+
this.bindingsArray = null;
7174
this.attributes = [];
7275
this.bufferAttributes = [];
7376
this.varyings = [];
@@ -93,6 +96,22 @@ class NodeBuilder {
9396

9497
}
9598

99+
getBindings() {
100+
101+
let bindingsArray = this.bindingsArray;
102+
103+
if ( bindingsArray === null ) {
104+
105+
const bindings = this.bindings;
106+
107+
this.bindingsArray = bindingsArray = ( this.material !== null ) ? [ ...bindings.vertex, ...bindings.fragment ] : bindings.compute;
108+
109+
}
110+
111+
return bindingsArray;
112+
113+
}
114+
96115
setHashNode( node, hash ) {
97116

98117
this.hashNodes[ hash ] = node;

examples/jsm/nodes/display/ViewportSharedTextureNode.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { addNodeClass } from '../core/Node.js';
33
import { addNodeElement, nodeProxy } from '../shadernode/ShaderNode.js';
44
import { viewportTopLeft } from './ViewportNode.js';
55

6-
let rtt = null;
6+
let sharedFramebuffer = null;
77

88
class ViewportSharedTextureNode extends ViewportTextureNode {
99

@@ -13,9 +13,9 @@ class ViewportSharedTextureNode extends ViewportTextureNode {
1313

1414
}
1515

16-
constructRTT( builder ) {
16+
constructFramebuffer( builder ) {
1717

18-
return rtt || ( rtt = builder.getRenderTarget() );
18+
return sharedFramebuffer || ( sharedFramebuffer = super.constructFramebuffer( builder ) );
1919

2020
}
2121

examples/jsm/nodes/display/ViewportTextureNode.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,56 @@ import { NodeUpdateType } from '../core/constants.js';
33
import { addNodeClass } from '../core/Node.js';
44
import { addNodeElement, nodeProxy } from '../shadernode/ShaderNode.js';
55
import { viewportTopLeft } from './ViewportNode.js';
6-
import { Vector2 } from 'three';
6+
import { Vector2, FramebufferTexture } from 'three';
77

8-
let size = new Vector2();
8+
const _size = new Vector2();
99

1010
class ViewportTextureNode extends TextureNode {
1111

1212
constructor( uv = viewportTopLeft, level = null ) {
1313

1414
super( null, uv, level );
1515

16-
this.rtt = null;
17-
1816
this.isOutputTextureNode = true;
1917

2018
this.updateBeforeType = NodeUpdateType.FRAME;
2119

2220
}
2321

24-
constructRTT( builder ) {
22+
constructFramebuffer( /*builder*/ ) {
2523

26-
return builder.getRenderTarget();
24+
return new FramebufferTexture();
2725

2826
}
2927

3028
construct( builder ) {
3129

32-
if ( this.rtt === null ) this.rtt = this.constructRTT( builder );
33-
34-
this.value = this.rtt.texture;
30+
if ( this.value === null ) this.value = this.constructFramebuffer( builder );
3531

3632
return super.construct( builder );
3733

3834
}
3935

4036
updateBefore( frame ) {
4137

42-
const rtt = this.rtt;
43-
4438
const renderer = frame.renderer;
45-
renderer.getDrawingBufferSize( size );
39+
renderer.getDrawingBufferSize( _size );
40+
41+
//
42+
43+
const framebufferTexture = this.value;
44+
45+
if ( framebufferTexture.image.width !== _size.width || framebufferTexture.image.height !== _size.height ) {
46+
47+
framebufferTexture.image.width = _size.width;
48+
framebufferTexture.image.height = _size.height;
49+
framebufferTexture.needsUpdate = true;
50+
51+
}
4652

47-
rtt.setSize( size.width, size.height );
53+
//
4854

49-
renderer.copyFramebufferToRenderTarget( rtt );
55+
renderer.copyFramebufferToTexture( framebufferTexture );
5056

5157
}
5258

examples/jsm/nodes/lighting/AnalyticLightNode.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { vec3 } from '../shadernode/ShaderNode.js';
66
import { reference } from '../accessors/ReferenceNode.js';
77
import { texture } from '../accessors/TextureNode.js';
88
import { positionWorld } from '../accessors/PositionNode.js';
9+
//import { step } from '../math/MathNode.js';
910
import { cond } from '../math/CondNode.js';
1011
import MeshBasicNodeMaterial from '../materials/MeshBasicNodeMaterial.js';
1112

@@ -51,6 +52,9 @@ class AnalyticLightNode extends LightingNode {
5152
const depthTexture = new DepthTexture();
5253
depthTexture.minFilter = NearestFilter;
5354
depthTexture.magFilter = NearestFilter;
55+
depthTexture.image.width = shadow.mapSize.width;
56+
depthTexture.image.height = shadow.mapSize.height;
57+
//depthTexture.compareFunction = THREE.LessCompare;
5458

5559
rtt.depthTexture = depthTexture;
5660

@@ -128,7 +132,7 @@ class AnalyticLightNode extends LightingNode {
128132

129133
}
130134

131-
update( frame ) {
135+
update( /*frame*/ ) {
132136

133137
const { light } = this;
134138

examples/jsm/nodes/lighting/HemisphereLightNode.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class HemisphereLightNode extends AnalyticLightNode {
1414

1515
super( light );
1616

17-
this.lightPositionNode = objectPosition;
18-
this.lightDirectionNode = objectPosition.normalize();
17+
this.lightPositionNode = objectPosition( light );
18+
this.lightDirectionNode = this.lightPositionNode.normalize();
1919

2020
this.groundColorNode = uniform( new Color() );
2121

examples/jsm/nodes/utils/EquirectUVNode.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import TempNode from '../core/TempNode.js';
2-
import { negate } from '../math/MathNode.js';
32
import { positionWorldDirection } from '../accessors/PositionNode.js';
43
import { nodeProxy, vec2 } from '../shadernode/ShaderNode.js';
54
import { addNodeClass } from '../core/Node.js';
@@ -16,10 +15,10 @@ class EquirectUVNode extends TempNode {
1615

1716
construct() {
1817

19-
const dir = negate( this.dirNode );
18+
const dir = this.dirNode;
2019

2120
const u = dir.z.atan2( dir.x ).mul( 1 / ( Math.PI * 2 ) ).add( 0.5 );
22-
const v = dir.y.clamp( - 1.0, 1.0 ).asin().mul( 1 / Math.PI ).add( 0.5 );
21+
const v = dir.y.negate().clamp( - 1.0, 1.0 ).asin().mul( 1 / Math.PI ).add( 0.5 ); // @TODO: The use of negate() here could be an NDC issue.
2322

2423
return vec2( u, v );
2524

examples/jsm/renderers/webgpu/WebGPUAnimation.js renamed to examples/jsm/renderers/common/Animation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class WebGPUAnimation {
1+
class Animation {
22

33
constructor() {
44

@@ -55,4 +55,4 @@ class WebGPUAnimation {
5555

5656
}
5757

58-
export default WebGPUAnimation;
58+
export default Animation;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import DataMap from './DataMap.js';
2+
import { AttributeType } from './Constants.js';
3+
import { DynamicDrawUsage } from 'three';
4+
5+
class Attributes extends DataMap {
6+
7+
constructor( backend ) {
8+
9+
super();
10+
11+
this.backend = backend;
12+
13+
}
14+
15+
delete( attribute ) {
16+
17+
const attributeData = super.delete( attribute );
18+
19+
if ( attributeData !== undefined ) {
20+
21+
this.backend.destroyAttribute( attribute );
22+
23+
}
24+
25+
}
26+
27+
update( attribute, type ) {
28+
29+
const data = this.get( attribute );
30+
31+
if ( data.version === undefined ) {
32+
33+
if ( type === AttributeType.VERTEX ) {
34+
35+
this.backend.createAttribute( attribute );
36+
37+
} else if ( type === AttributeType.INDEX ) {
38+
39+
this.backend.createIndexAttribute( attribute );
40+
41+
} else if ( type === AttributeType.STORAGE ) {
42+
43+
this.backend.createStorageAttribute( attribute );
44+
45+
}
46+
47+
data.version = this._getBufferAttribute( attribute ).version;
48+
49+
} else {
50+
51+
const bufferAttribute = this._getBufferAttribute( attribute );
52+
53+
if ( data.version < bufferAttribute.version || bufferAttribute.usage === DynamicDrawUsage ) {
54+
55+
this.backend.updateAttribute( attribute );
56+
57+
data.version = bufferAttribute.version;
58+
59+
}
60+
61+
}
62+
63+
}
64+
65+
_getBufferAttribute( attribute ) {
66+
67+
if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
68+
69+
return attribute;
70+
71+
}
72+
73+
}
74+
75+
export default Attributes;

0 commit comments

Comments
 (0)