Browse Source

WebGPURenderer: Restore instanced multi-draw API and add WebGPU support (#28759)

* WebGPURenderer: Restore instanced multi-draw API and WebGPU compatibility

* fix firefox since gl_drawID is not mandatory for custom usage
Renaud Rohlinger 1 year ago
parent
commit
a98611acf5

+ 5 - 1
examples/jsm/renderers/webgl/WebGLBackend.js

@@ -704,7 +704,11 @@ class WebGLBackend extends Backend {
 
 		if ( object.isBatchedMesh ) {
 
-			if ( ! this.hasFeature( 'WEBGL_multi_draw' ) ) {
+			if ( object._multiDrawInstances !== null ) {
+
+				renderer.renderMultiDrawInstances( object._multiDrawStarts, object._multiDrawCounts, object._multiDrawCount, object._multiDrawInstances );
+
+			} else if ( ! this.hasFeature( 'WEBGL_multi_draw' ) ) {
 
 				warnOnce( 'THREE.WebGLRenderer: WEBGL_multi_draw not supported.' );
 

+ 5 - 1
examples/jsm/renderers/webgpu/WebGPUBackend.js

@@ -923,12 +923,16 @@ class WebGPUBackend extends Backend {
 			const starts = object._multiDrawStarts;
 			const counts = object._multiDrawCounts;
 			const drawCount = object._multiDrawCount;
+			const drawInstances = object._multiDrawInstances;
 
 			const bytesPerElement = index.bytesPerElement || 1;
 
 			for ( let i = 0; i < drawCount; i ++ ) {
 
-				passEncoderGPU.drawIndexed( counts[ i ] / bytesPerElement, 1, starts[ i ] / 4, 0, i );
+				const count = drawInstances ? drawInstances[ i ] : 1;
+				const firstInstance = count > 1 ? 0 : i;
+
+				passEncoderGPU.drawIndexed( counts[ i ] / bytesPerElement, count, starts[ i ] / 4, 0, firstInstance );
 
 			}