Przeglądaj źródła

WebGPURenderer: Add (u)int16 Support (#28008)

* add int16 support

* fix examples

* fix
Renaud Rohlinger 1 rok temu
rodzic
commit
2309d42e7d

+ 2 - 8
examples/jsm/nodes/accessors/BatchNode.js

@@ -4,8 +4,7 @@ import { positionLocal } from './PositionNode.js';
 import { nodeProxy, vec3, mat3, mat4, int, ivec2, float } from '../shadernode/ShaderNode.js';
 import { textureLoad } from './TextureNode.js';
 import { textureSize } from './TextureSizeNode.js';
-import { Float32BufferAttribute } from 'three';
-import { bufferAttribute } from './BufferAttributeNode.js';
+import { attribute } from '../core/AttributeNode.js';
 import { tangentLocal } from './TangentNode.js';
 
 class BatchNode extends Node {
@@ -29,12 +28,7 @@ class BatchNode extends Node {
 
 		if ( this.batchingIdNode === null ) {
 
-			const batchingAttribute = this.batchMesh.geometry.getAttribute( 'batchId' );
-			const array = new Float32Array( batchingAttribute.array );
-
-			const buffer = new Float32BufferAttribute( array, 1 );
-
-			this.batchingIdNode = bufferAttribute( buffer, 'float' ).toVar();
+			this.batchingIdNode = attribute( 'batchId' );
 
 		}
 

+ 1 - 1
examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js

@@ -390,7 +390,7 @@ ${ flowData.code }
 
 			const array = dataAttribute.array;
 
-			if ( ( array instanceof Uint32Array || array instanceof Int32Array ) === false ) {
+			if ( ( array instanceof Uint32Array || array instanceof Int32Array || array instanceof Uint16Array || array instanceof Int16Array ) === false ) {
 
 				nodeType = nodeType.slice( 1 );
 

+ 1 - 1
examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js

@@ -135,7 +135,7 @@ class WebGLAttributeUtils {
 			bytesPerElement: array.BYTES_PER_ELEMENT,
 			version: attribute.version,
 			pbo: attribute.pbo,
-			isInteger: type === gl.INT || type === gl.UNSIGNED_INT || attribute.gpuType === IntType,
+			isInteger: type === gl.INT || type === gl.UNSIGNED_INT || type === gl.UNSIGNED_SHORT || attribute.gpuType === IntType,
 			id: _id ++
 		};
 

+ 25 - 0
examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js

@@ -17,7 +17,9 @@ const typedAttributeToVertexFormatPrefix = new Map( [
 
 const typeArraysToVertexFormatPrefixForItemSize1 = new Map( [
 	[ Int32Array, 'sint32' ],
+	[ Int16Array, 'sint32' ], // patch for INT16
 	[ Uint32Array, 'uint32' ],
+	[ Uint16Array, 'uint32' ], // patch for UINT16
 	[ Float32Array, 'float32' ]
 ] );
 
@@ -44,6 +46,22 @@ class WebGPUAttributeUtils {
 
 			let array = bufferAttribute.array;
 
+			// patch for INT16 and UINT16
+			if ( array.constructor === Int16Array || array.constructor === Uint16Array ) {
+
+				const tempArray = new Uint32Array( array.length );
+				for ( let i = 0; i < array.length; i ++ ) {
+
+					tempArray[ i ] = array[ i ];
+
+				}
+
+				array = tempArray;
+
+			}
+
+			bufferAttribute.array = array;
+
 			if ( ( bufferAttribute.isStorageBufferAttribute || bufferAttribute.isStorageInstancedBufferAttribute ) && bufferAttribute.itemSize === 3 ) {
 
 				bufferAttribute.itemSize = 4;
@@ -149,6 +167,13 @@ class WebGPUAttributeUtils {
 
 				}
 
+				// patch for INT16 and UINT16
+				if ( geometryAttribute.array.constructor === Int16Array || geometryAttribute.array.constructor === Uint16Array ) {
+
+					arrayStride = 4;
+
+				}
+
 				vertexBufferLayout = {
 					arrayStride,
 					attributes: [],