Skip to content
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

Universal Renderer and WebGPUBackend #26079

Merged
merged 26 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a16e9fe
Universal Renderer and WebGPUBackend ( WIP )
sunag May 18, 2023
5b58ba9
cleanup
sunag May 18, 2023
fa15e4d
Rename constants.js to Constants.js
sunag May 18, 2023
29ba8ac
revisions
sunag May 23, 2023
988d2bd
cleanup
sunag May 23, 2023
bcd8d8f
cleanup
sunag May 23, 2023
10611dc
Rename /universal to /common
sunag May 23, 2023
5f15a5f
Update examples/jsm/renderers/common/Renderer.js
sunag May 23, 2023
121240a
Update examples/jsm/renderers/common/Renderer.js
sunag May 23, 2023
9cf8437
Update examples/jsm/renderers/common/Textures.js
sunag May 23, 2023
727f917
Update examples/jsm/renderers/webgpu/backends/webgpu/utils/WebGPUText…
sunag May 23, 2023
2d4b8ed
Update examples/jsm/renderers/webgpu/backends/webgpu/utils/WebGPUText…
sunag May 23, 2023
317dbd1
Update examples/jsm/renderers/webgpu/backends/webgpu/utils/WebGPUPipe…
sunag May 23, 2023
243a0d2
Update examples/jsm/renderers/webgpu/backends/webgpu/utils/WebGPUPipe…
sunag May 23, 2023
007d995
Update examples/jsm/renderers/common/nodes/Nodes.js
sunag May 23, 2023
3f2c9e4
Update examples/jsm/renderers/webgpu/backends/webgpu/utils/WebGPUPipe…
sunag May 23, 2023
964dc50
Update examples/jsm/renderers/webgpu/backends/webgpu/utils/WebGPUAttr…
sunag May 23, 2023
1136afc
Update examples/jsm/renderers/webgpu/backends/webgpu/utils/WebGPUAttr…
sunag May 23, 2023
f073954
Simplifies paths.
sunag May 23, 2023
e94455b
cleanup
sunag May 23, 2023
4235b2a
cleanup
sunag May 23, 2023
47f1e59
fix resize
sunag May 23, 2023
3ec909b
update tip
sunag May 23, 2023
9dd3099
update tip
sunag May 23, 2023
a93dc62
Rename: webgpu/builder to webgpu/nodes
sunag May 23, 2023
378e09d
cleanup
sunag May 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions examples/jsm/nodes/Nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ export { default as NodeObjectLoader } from './loaders/NodeObjectLoader.js';
export { default as NodeMaterialLoader } from './loaders/NodeMaterialLoader.js';

// parsers
export { default as WGSLNodeParser } from './parsers/WGSLNodeParser.js';
export { default as GLSLNodeParser } from './parsers/GLSLNodeParser.js';
export { default as GLSLNodeParser } from './parsers/GLSLNodeParser.js'; // @TODO: Move to jsm/renderers/webgl.

// materials
export * from './materials/Materials.js';
Expand Down
19 changes: 19 additions & 0 deletions examples/jsm/nodes/core/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class NodeBuilder {
this.flowCode = { vertex: '', fragment: '', compute: [] };
this.uniforms = { vertex: [], fragment: [], compute: [], index: 0 };
this.codes = { vertex: [], fragment: [], compute: [] };
this.bindings = { vertex: [], fragment: [], compute: [] };
this.bindingsOffset = { vertex: 0, fragment: 0, compute: 0 };
this.bindingsArray = null;
this.attributes = [];
this.bufferAttributes = [];
this.varyings = [];
Expand All @@ -93,6 +96,22 @@ class NodeBuilder {

}

getBindings() {

let bindingsArray = this.bindingsArray;

if ( bindingsArray === null ) {

const bindings = this.bindings;

this.bindingsArray = bindingsArray = ( this.material !== null ) ? [ ...bindings.vertex, ...bindings.fragment ] : bindings.compute;

}

return bindingsArray;

}

setHashNode( node, hash ) {

this.hashNodes[ hash ] = node;
Expand Down
6 changes: 3 additions & 3 deletions examples/jsm/nodes/display/ViewportSharedTextureNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { addNodeClass } from '../core/Node.js';
import { addNodeElement, nodeProxy } from '../shadernode/ShaderNode.js';
import { viewportTopLeft } from './ViewportNode.js';

let rtt = null;
let sharedFramebuffer = null;

class ViewportSharedTextureNode extends ViewportTextureNode {

Expand All @@ -13,9 +13,9 @@ class ViewportSharedTextureNode extends ViewportTextureNode {

}

constructRTT( builder ) {
constructFramebuffer( builder ) {

return rtt || ( rtt = builder.getRenderTarget() );
return sharedFramebuffer || ( sharedFramebuffer = super.constructFramebuffer( builder ) );

}

Expand Down
34 changes: 20 additions & 14 deletions examples/jsm/nodes/display/ViewportTextureNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,56 @@ import { NodeUpdateType } from '../core/constants.js';
import { addNodeClass } from '../core/Node.js';
import { addNodeElement, nodeProxy } from '../shadernode/ShaderNode.js';
import { viewportTopLeft } from './ViewportNode.js';
import { Vector2 } from 'three';
import { Vector2, FramebufferTexture } from 'three';

let size = new Vector2();
const _size = new Vector2();

class ViewportTextureNode extends TextureNode {

constructor( uv = viewportTopLeft, level = null ) {

super( null, uv, level );

this.rtt = null;

this.isOutputTextureNode = true;

this.updateBeforeType = NodeUpdateType.FRAME;

}

constructRTT( builder ) {
constructFramebuffer( /*builder*/ ) {

return builder.getRenderTarget();
return new FramebufferTexture();

}

construct( builder ) {

if ( this.rtt === null ) this.rtt = this.constructRTT( builder );

this.value = this.rtt.texture;
if ( this.value === null ) this.value = this.constructFramebuffer( builder );

return super.construct( builder );

}

updateBefore( frame ) {

const rtt = this.rtt;

const renderer = frame.renderer;
renderer.getDrawingBufferSize( size );
renderer.getDrawingBufferSize( _size );

//

const framebufferTexture = this.value;

if ( framebufferTexture.image.width !== _size.width || framebufferTexture.image.height !== _size.height ) {

framebufferTexture.image.width = _size.width;
framebufferTexture.image.height = _size.height;
framebufferTexture.needsUpdate = true;

}

rtt.setSize( size.width, size.height );
//

renderer.copyFramebufferToRenderTarget( rtt );
renderer.copyFramebufferToTexture( framebufferTexture );

}

Expand Down
6 changes: 5 additions & 1 deletion examples/jsm/nodes/lighting/AnalyticLightNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { vec3 } from '../shadernode/ShaderNode.js';
import { reference } from '../accessors/ReferenceNode.js';
import { texture } from '../accessors/TextureNode.js';
import { positionWorld } from '../accessors/PositionNode.js';
//import { step } from '../math/MathNode.js';
import { cond } from '../math/CondNode.js';
import MeshBasicNodeMaterial from '../materials/MeshBasicNodeMaterial.js';

Expand Down Expand Up @@ -51,6 +52,9 @@ class AnalyticLightNode extends LightingNode {
const depthTexture = new DepthTexture();
depthTexture.minFilter = NearestFilter;
depthTexture.magFilter = NearestFilter;
depthTexture.image.width = shadow.mapSize.width;
depthTexture.image.height = shadow.mapSize.height;
//depthTexture.compareFunction = THREE.LessCompare;

rtt.depthTexture = depthTexture;

Expand Down Expand Up @@ -128,7 +132,7 @@ class AnalyticLightNode extends LightingNode {

}

update( frame ) {
update( /*frame*/ ) {

const { light } = this;

Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/nodes/lighting/HemisphereLightNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class HemisphereLightNode extends AnalyticLightNode {

super( light );

this.lightPositionNode = objectPosition;
this.lightDirectionNode = objectPosition.normalize();
this.lightPositionNode = objectPosition( light );
this.lightDirectionNode = this.lightPositionNode.normalize();

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

Expand Down
5 changes: 2 additions & 3 deletions examples/jsm/nodes/utils/EquirectUVNode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import TempNode from '../core/TempNode.js';
import { negate } from '../math/MathNode.js';
import { positionWorldDirection } from '../accessors/PositionNode.js';
import { nodeProxy, vec2 } from '../shadernode/ShaderNode.js';
import { addNodeClass } from '../core/Node.js';
Expand All @@ -16,10 +15,10 @@ class EquirectUVNode extends TempNode {

construct() {

const dir = negate( this.dirNode );
const dir = this.dirNode;

const u = dir.z.atan2( dir.x ).mul( 1 / ( Math.PI * 2 ) ).add( 0.5 );
const v = dir.y.clamp( - 1.0, 1.0 ).asin().mul( 1 / Math.PI ).add( 0.5 );
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.

return vec2( u, v );

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class WebGPUAnimation {
class Animation {

constructor() {

Expand Down Expand Up @@ -55,4 +55,4 @@ class WebGPUAnimation {

}

export default WebGPUAnimation;
export default Animation;
75 changes: 75 additions & 0 deletions examples/jsm/renderers/common/Attributes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import DataMap from './DataMap.js';
import { AttributeType } from './Constants.js';
import { DynamicDrawUsage } from 'three';

class Attributes extends DataMap {

constructor( backend ) {

super();

this.backend = backend;

}

delete( attribute ) {

const attributeData = super.delete( attribute );

if ( attributeData !== undefined ) {

this.backend.destroyAttribute( attribute );

}

}

update( attribute, type ) {

const data = this.get( attribute );

if ( data.version === undefined ) {

if ( type === AttributeType.VERTEX ) {

this.backend.createAttribute( attribute );

} else if ( type === AttributeType.INDEX ) {

this.backend.createIndexAttribute( attribute );

} else if ( type === AttributeType.STORAGE ) {

this.backend.createStorageAttribute( attribute );

}

data.version = this._getBufferAttribute( attribute ).version;

} else {

const bufferAttribute = this._getBufferAttribute( attribute );

if ( data.version < bufferAttribute.version || bufferAttribute.usage === DynamicDrawUsage ) {

this.backend.updateAttribute( attribute );

data.version = bufferAttribute.version;

}

}

}

_getBufferAttribute( attribute ) {

if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;

return attribute;

}

}

export default Attributes;
Loading