Browse Source

WebGPUNodeBuilder: Clean up (#25768)

* WebGPUNodeBuilder.getUniforms(): Clean up

* More clean up
Levi Pesin 2 years ago
parent
commit
58ed2c5c73
1 changed files with 15 additions and 34 deletions
  1. 15 34
      examples/jsm/renderers/webgpu/nodes/WebGPUNodeBuilder.js

+ 15 - 34
examples/jsm/renderers/webgpu/nodes/WebGPUNodeBuilder.js

@@ -418,13 +418,13 @@ class WebGPUNodeBuilder extends NodeBuilder {
 
 		const snippets = [];
 
-		if ( shaderStage === 'vertex' || shaderStage === 'compute' ) {
+		if ( shaderStage === 'compute' ) {
 
-			if ( shaderStage === 'compute' ) {
+			this.getBuiltin( 'global_invocation_id', 'id', 'vec3<u32>', 'attribute' );
 
-				this.getBuiltin( 'global_invocation_id', 'id', 'vec3<u32>', 'attribute' );
+		}
 
-			}
+		if ( shaderStage === 'vertex' || shaderStage === 'compute' ) {
 
 			for ( const { name, property, type } of this.builtins.attribute.values() ) {
 
@@ -477,26 +477,9 @@ class WebGPUNodeBuilder extends NodeBuilder {
 
 			this.getBuiltin( 'position', 'Vertex', 'vec4<f32>', 'vertex' );
 
-			const varyings = this.varyings;
-			const vars = this.vars[ shaderStage ];
-
-			for ( let index = 0; index < varyings.length; index ++ ) {
-
-				const varying = varyings[ index ];
-
-				if ( varying.needsInterpolation ) {
-
-					snippets.push( `@location( ${index} ) ${ varying.name } : ${ this.getType( varying.type ) }` );
-
-				} else if ( vars.includes( varying ) === false ) {
-
-					vars.push( varying );
-
-				}
-
-			}
+		}
 
-		} else if ( shaderStage === 'fragment' ) {
+		if ( shaderStage === 'vertex' || shaderStage === 'fragment' ) {
 
 			const varyings = this.varyings;
 			const vars = this.vars[ shaderStage ];
@@ -543,7 +526,7 @@ class WebGPUNodeBuilder extends NodeBuilder {
 
 		for ( const uniform of uniforms ) {
 
-			if ( uniform.type === 'texture' ) {
+			if ( uniform.type === 'texture' || uniform.type === 'cubeTexture' ) {
 
 				if ( shaderStage === 'fragment' ) {
 
@@ -553,25 +536,23 @@ class WebGPUNodeBuilder extends NodeBuilder {
 
 				const texture = uniform.node.value;
 
-				if ( texture.isVideoTexture === true ) {
-
-					bindingSnippets.push( `@group( 0 ) @binding( ${index ++} ) var ${uniform.name} : texture_external;` );
+				let textureType;
 
-				} else {
+				if ( texture.isCubeTexture === true ) {
 
-					bindingSnippets.push( `@group( 0 ) @binding( ${index ++} ) var ${uniform.name} : texture_2d<f32>;` );
+					textureType = 'texture_cube<f32>';
 
-				}
+				} else if ( texture.isVideoTexture === true ) {
 
-			} else if ( uniform.type === 'cubeTexture' ) {
+					textureType = 'texture_external';
 
-				if ( shaderStage === 'fragment' ) {
+				} else {
 
-					bindingSnippets.push( `@group( 0 ) @binding( ${index ++} ) var ${uniform.name}_sampler : sampler;` );
+					textureType = 'texture_2d<f32>';
 
 				}
 
-				bindingSnippets.push( `@group( 0 ) @binding( ${index ++} ) var ${uniform.name} : texture_cube<f32>;` );
+				bindingSnippets.push( `@group( 0 ) @binding( ${index ++} ) var ${uniform.name} : ${textureType};` );
 
 			} else if ( uniform.type === 'buffer' || uniform.type === 'storageBuffer' ) {