Преглед изворни кода

WebGPURenderer: Handle interleaved instanced buffers correctly. (#26304)

* add support for meshPhongNodeMaterial

* move stepMode determination into AttributeUtils and handle
instancedinterleaved buffers.

---------

Co-authored-by: aardgoose <[email protected]>
aardgoose пре 2 година
родитељ
комит
ff39ae9c0a

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

@@ -1,4 +1,5 @@
 import { Float16BufferAttribute } from 'three';
+import { GPUInputStepMode } from './WebGPUConstants.js';
 
 const typedArraysToVertexFormatPrefix = new Map( [
 	[ Int8Array, [ 'sint8', 'snorm8' ]],
@@ -106,6 +107,7 @@ class WebGPUAttributeUtils {
 
 			let arrayStride = geometryAttribute.itemSize * bytesPerElement;
 			let offset = 0;
+			let stepMode = geometryAttribute.isInstancedBufferAttribute ? GPUInputStepMode.Instance : GPUInputStepMode.Vertex;
 
 			if ( geometryAttribute.isInterleavedBufferAttribute === true ) {
 
@@ -113,12 +115,14 @@ class WebGPUAttributeUtils {
 
 				arrayStride = geometryAttribute.data.stride * bytesPerElement;
 				offset = geometryAttribute.offset * bytesPerElement;
+				if ( geometryAttribute.data.isInstancedInterleavedBuffer ) stepMode = GPUInputStepMode.Instance;
 
 			}
 
 			shaderAttributes.push( {
 				geometryAttribute,
 				arrayStride,
+				stepMode,
 				offset,
 				format,
 				slot

+ 2 - 5
examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js

@@ -1,7 +1,7 @@
 import { BlendColorFactor, OneMinusBlendColorFactor, } from '../../common/Constants.js';
 
 import {
-	GPUInputStepMode, GPUFrontFace, GPUCullMode, GPUColorWriteFlags, GPUCompareFunction, GPUBlendFactor, GPUBlendOperation, GPUIndexFormat, GPUStencilOperation
+	GPUFrontFace, GPUCullMode, GPUColorWriteFlags, GPUCompareFunction, GPUBlendFactor, GPUBlendOperation, GPUIndexFormat, GPUStencilOperation
 } from './WebGPUConstants.js';
 
 import {
@@ -44,13 +44,10 @@ class WebGPUPipelineUtils {
 
 		for ( const attribute of shaderAttributes ) {
 
-			const geometryAttribute = attribute.geometryAttribute;
-			const stepMode = ( geometryAttribute !== undefined && geometryAttribute.isInstancedBufferAttribute ) ? GPUInputStepMode.Instance : GPUInputStepMode.Vertex;
-
 			vertexBuffers.push( {
 				arrayStride: attribute.arrayStride,
 				attributes: [ { shaderLocation: attribute.slot, offset: attribute.offset, format: attribute.format } ],
-				stepMode: stepMode
+				stepMode: attribute.stepMode
 			} );
 
 		}