Skip to content

Commit

Permalink
Revert "draft"
Browse files Browse the repository at this point in the history
This reverts commit d425fe2.
  • Loading branch information
sunag committed Nov 4, 2023
1 parent d425fe2 commit f1c2eda
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 37 deletions.
2 changes: 0 additions & 2 deletions examples/jsm/nodes/core/UniformNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ class UniformNode extends InputNode {

this.isUniformNode = true;

this.group = 'TEST';

}

getUniformHash( builder ) {
Expand Down
30 changes: 9 additions & 21 deletions examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class WGSLNodeBuilder extends NodeBuilder {

} else {

return node.node.group + '.' + name;
return `NodeUniforms.${name}`;

}

Expand Down Expand Up @@ -345,17 +345,14 @@ class WGSLNodeBuilder extends NodeBuilder {

} else {

const uniformsStage = this.uniforms[ shaderStage ] || ( this.uniforms[ shaderStage ] = {} );
const uniformsGroupName = node.group;

let uniformsGroup = uniformsStage[ uniformsGroupName ];
let uniformsGroup = this.uniformsGroup[ shaderStage ];

if ( uniformsGroup === undefined ) {

uniformsGroup = new UniformsGroup( uniformsGroupName );
uniformsGroup = new UniformsGroup( 'nodeUniforms' );
uniformsGroup.setVisibility( gpuShaderStageLib[ shaderStage ] );

uniformsStage[ uniformsGroupName ] = uniformsGroup;
this.uniformsGroup[ shaderStage ] = uniformsGroup;

bindings.push( uniformsGroup );

Expand Down Expand Up @@ -656,9 +653,7 @@ ${ flowData.code }

const bindingSnippets = [];
const bufferSnippets = [];
const structSnippets = [];

const uniformGroups = {};
const groupSnippets = [];

let index = this.bindingsOffset[ shaderStage ];

Expand Down Expand Up @@ -725,9 +720,6 @@ ${ flowData.code }
} else {

const vectorType = this.getType( this.getVectorType( uniform.type ) );
const groupName = uniform.node.group;

const groupSnippets = uniformGroups[ groupName ] || ( uniformGroups[ groupName ] = [] );

if ( Array.isArray( uniform.value ) === true ) {

Expand All @@ -745,18 +737,15 @@ ${ flowData.code }

}

for ( const group in uniformGroups ) {
let code = bindingSnippets.join( '\n' );
code += bufferSnippets.join( '\n' );

const groupSnippets = uniformGroups[ group ];
if ( groupSnippets.length > 0 ) {

structSnippets.push( this._getWGSLStructBinding( group, groupSnippets.join( ',\n' ), 'uniform', index ++ ) );
code += this._getWGSLStructBinding( 'NodeUniforms', groupSnippets.join( ',\n' ), 'uniform', index ++ );

}

let code = bindingSnippets.join( '\n' );
code += bufferSnippets.join( '\n' );
code += structSnippets.join( '\n' );

return code;

}
Expand Down Expand Up @@ -826,7 +815,6 @@ ${ flowData.code }

this.vertexShader = this._getWGSLVertexCode( shadersData.vertex );
this.fragmentShader = this._getWGSLFragmentCode( shadersData.fragment );
console.log( this.fragmentShader );

} else {

Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class WebGPUBindingUtils {
}

updateBinding( binding ) {
console.log( binding );

const backend = this.backend;
const device = backend.device;

Expand Down
20 changes: 7 additions & 13 deletions examples/webgpu_sandbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<script type="module">

import * as THREE from 'three';
import { timerLocal, vec2, uv, texture, mix, checker, uniform, normalLocal, positionLocal, color, oscSine, attribute, MeshBasicNodeMaterial, PointsNodeMaterial, LineBasicNodeMaterial } from 'three/nodes';
import { timerLocal, vec2, uv, texture, mix, checker, normalLocal, positionLocal, color, oscSine, attribute, MeshBasicNodeMaterial, PointsNodeMaterial, LineBasicNodeMaterial } from 'three/nodes';

import { KTX2Loader } from 'three/addons/loaders/KTX2Loader.js';

Expand Down Expand Up @@ -91,13 +91,7 @@

const textureNode = texture( uvTexture, animateUV );

//materialBox.colorNode = mix( textureNode, checker( animateUV ), 0.5 );
const a = uniform( new THREE.Color( 0x066FF ) );
const b = uniform( new THREE.Color( 0x229900 ) );
a.group = 'FRAME';
b.group = 'GROUP';

materialBox.colorNode = a.add( b );
materialBox.colorNode = mix( textureNode, checker( animateUV ), 0.5 );

// test uv 2
//geometryBox.setAttribute( 'uv1', geometryBox.getAttribute( 'uv' ) );
Expand All @@ -121,7 +115,7 @@

const sphere = new THREE.Mesh( geometrySphere, materialSphere );
sphere.position.set( - 2, - 1, 0 );
//scene.add( sphere );
scene.add( sphere );

// data texture

Expand All @@ -132,7 +126,7 @@

const plane = new THREE.Mesh( geometryPlane, materialPlane );
plane.position.set( 0, - 1, 0 );
//scene.add( plane );
scene.add( plane );

// compressed texture

Expand All @@ -145,7 +139,7 @@
const geo = flipY( new THREE.PlaneGeometry() );
const planeCompressed = new THREE.Mesh( geo, materialCompressed );
planeCompressed.position.set( - 2, 1, 0 );
//scene.add( planeCompressed );
scene.add( planeCompressed );

// points

Expand All @@ -165,7 +159,7 @@

const pointCloud = new THREE.Points( geometryPoints, materialPoints );
pointCloud.position.set( 2, - 1, 0 );
//scene.add( pointCloud );
scene.add( pointCloud );

// lines

Expand All @@ -184,7 +178,7 @@

const line = new THREE.Line( geometryLine, materialLine );
line.position.set( 2, 1, 0 );
//scene.add( line );
scene.add( line );

window.addEventListener( 'resize', onWindowResize );

Expand Down

0 comments on commit f1c2eda

Please sign in to comment.