diff --git a/examples/jsm/renderers/webgpu/nodes/WGSLNodeFunction.js b/examples/jsm/renderers/webgpu/nodes/WGSLNodeFunction.js index 1021eb6dc3037d..9bf1aea1a67f90 100644 --- a/examples/jsm/renderers/webgpu/nodes/WGSLNodeFunction.js +++ b/examples/jsm/renderers/webgpu/nodes/WGSLNodeFunction.js @@ -5,9 +5,43 @@ const declarationRegexp = /^[fn]*\s*([a-z_0-9]+)?\s*\(([\s\S]*?)\)\s*[\-\>]*\s*( const propertiesRegexp = /[a-z_0-9]+|<(.*?)>+/ig; const wgslTypeLib = { - f32: 'float' + 'f32': 'float', + 'i32': 'int', + 'u32': 'uint', + 'bool': 'bool', + + 'vec2': 'vec2', + 'vec2': 'ivec2', + 'vec2': 'uvec2', + 'vec2': 'bvec2', + + 'vec3': 'vec3', + 'vec3': 'ivec3', + 'vec3': 'uvec3', + 'vec3': 'bvec3', + + 'vec4': 'vec4', + 'vec4': 'ivec4', + 'vec4': 'uvec4', + 'vec4': 'bvec4', + + 'mat2x2': 'mat2', + 'mat2x2': 'imat2', + 'mat2x2': 'umat2', + 'mat2x2': 'bmat2', + + 'mat3x3': 'mat3', + 'mat3x3': 'imat3', + 'mat3x3': 'umat3', + 'mat3x3': 'bmat3', + + 'mat4x4': 'mat4', + 'mat4x4': 'imat4', + 'mat4x4': 'umat4', + 'mat4x4': 'bmat4' }; + const parse = ( source ) => { source = source.trim(); @@ -42,15 +76,24 @@ const parse = ( source ) => { const name = propsMatches[ i ++ ][ 0 ]; let type = propsMatches[ i ++ ][ 0 ]; - type = wgslTypeLib[ type ] || type; - // precision - if ( i < propsMatches.length && propsMatches[ i ][ 0 ].startsWith( '<' ) === true ) - i ++; + if ( i < propsMatches.length && propsMatches[ i ][ 0 ].startsWith( '<' ) === true ) { - // add input + const elementType = propsMatches[ i ++ ][ 0 ]; + + // If primitive data type + if ( ! elementType.includes( ',' ) ) { + + type += elementType; + } + + } + + type = wgslTypeLib[ type ] || type; + + // add input inputs.push( new NodeFunctionInput( type, name ) ); }