Просмотр исходного кода

NodeMaterial: Added support to custom MRT depth (#29117)

* added support to custom MRT depth

* fix tab in code
sunag 1 год назад
Родитель
Сommit
c2373ef9fe
2 измененных файлов с 14 добавлено и 4 удалено
  1. 13 3
      src/nodes/materials/NodeMaterial.js
  2. 1 1
      src/renderers/webgpu/nodes/WGSLNodeBuilder.js

+ 13 - 3
src/nodes/materials/NodeMaterial.js

@@ -206,11 +206,21 @@ class NodeMaterial extends Material {
 
 		let depthNode = this.depthNode;
 
-		if ( depthNode === null && renderer.logarithmicDepthBuffer === true ) {
+		if ( depthNode === null ) {
 
-			const fragDepth = modelViewProjection().w.add( 1 );
+			const mrt = renderer.getMRT();
 
-			depthNode = fragDepth.log2().mul( cameraLogDepth ).mul( 0.5 );
+			if ( mrt && mrt.has( 'depth' ) ) {
+
+				depthNode = mrt.get( 'depth' );
+
+			} else if ( renderer.logarithmicDepthBuffer === true ) {
+
+				const fragDepth = modelViewProjection().w.add( 1 );
+
+				depthNode = fragDepth.log2().mul( cameraLogDepth ).mul( 0.5 );
+
+			}
 
 		}
 

+ 1 - 1
src/renderers/webgpu/nodes/WGSLNodeBuilder.js

@@ -795,7 +795,7 @@ ${ flowData.code }
 
 		const builtins = this.getBuiltins( 'output' );
 
-		if ( builtins ) snippets.push( builtins );
+		if ( builtins ) snippets.push( '\t' + builtins );
 
 		return snippets.join( ',\n' );
 

粤ICP备19079148号