Procházet zdrojové kódy

GTAONode: Optimize render target format. (#31883)

Michael Herzog před 4 měsíci
rodič
revize
c604c09f5e

+ 4 - 4
examples/jsm/tsl/display/GTAONode.js

@@ -1,4 +1,4 @@
-import { DataTexture, RenderTarget, RepeatWrapping, Vector2, Vector3, TempNode, QuadMesh, NodeMaterial, RendererUtils } from 'three/webgpu';
+import { DataTexture, RenderTarget, RepeatWrapping, Vector2, Vector3, TempNode, QuadMesh, NodeMaterial, RendererUtils, RedFormat } from 'three/webgpu';
 import { reference, logarithmicDepthToViewZ, viewZToPerspectiveDepth, getNormalFromDepth, getScreenPosition, getViewPosition, nodeObject, Fn, float, NodeUpdateType, uv, uniform, Loop, vec2, vec3, vec4, int, dot, max, pow, abs, If, textureSize, sin, cos, PI, texture, passTexture, mat3, add, normalize, mul, cross, div, mix, sqrt, sub, acos, clamp } from 'three/tsl';
 import { reference, logarithmicDepthToViewZ, viewZToPerspectiveDepth, getNormalFromDepth, getScreenPosition, getViewPosition, nodeObject, Fn, float, NodeUpdateType, uv, uniform, Loop, vec2, vec3, vec4, int, dot, max, pow, abs, If, textureSize, sin, cos, PI, texture, passTexture, mat3, add, normalize, mul, cross, div, mix, sqrt, sub, acos, clamp } from 'three/tsl';
 
 
 const _quadMesh = /*@__PURE__*/ new QuadMesh();
 const _quadMesh = /*@__PURE__*/ new QuadMesh();
@@ -48,7 +48,7 @@ class GTAONode extends TempNode {
 	 */
 	 */
 	constructor( depthNode, normalNode, camera ) {
 	constructor( depthNode, normalNode, camera ) {
 
 
-		super( 'vec4' );
+		super( 'float' );
 
 
 		/**
 		/**
 		 * A node that represents the scene's depth.
 		 * A node that represents the scene's depth.
@@ -90,7 +90,7 @@ class GTAONode extends TempNode {
 		 * @private
 		 * @private
 		 * @type {RenderTarget}
 		 * @type {RenderTarget}
 		 */
 		 */
-		this._aoRenderTarget = new RenderTarget( 1, 1, { depthBuffer: false } );
+		this._aoRenderTarget = new RenderTarget( 1, 1, { depthBuffer: false, format: RedFormat } );
 		this._aoRenderTarget.texture.name = 'GTAONode.AO';
 		this._aoRenderTarget.texture.name = 'GTAONode.AO';
 
 
 		// uniforms
 		// uniforms
@@ -392,7 +392,7 @@ class GTAONode extends TempNode {
 			ao.assign( clamp( ao.div( DIRECTIONS ), 0, 1 ) );
 			ao.assign( clamp( ao.div( DIRECTIONS ), 0, 1 ) );
 			ao.assign( pow( ao, this.scale ) );
 			ao.assign( pow( ao, this.scale ) );
 
 
-			return vec4( vec3( ao ), 1.0 );
+			return ao;
 
 
 		} );
 		} );
 
 

+ 3 - 3
examples/webgpu_postprocessing_ao.html

@@ -28,7 +28,7 @@
 		<script type="module">
 		<script type="module">
 
 
 			import * as THREE from 'three/webgpu';
 			import * as THREE from 'three/webgpu';
-			import { pass, mrt, output, normalView, velocity } from 'three/tsl';
+			import { pass, mrt, output, normalView, velocity, vec3, vec4 } from 'three/tsl';
 			import { ao } from 'three/addons/tsl/display/GTAONode.js';
 			import { ao } from 'three/addons/tsl/display/GTAONode.js';
 			import { traa } from 'three/addons/tsl/display/TRAANode.js';
 			import { traa } from 'three/addons/tsl/display/TRAANode.js';
 
 
@@ -112,7 +112,7 @@
 
 
 				aoPass = ao( scenePassDepth, scenePassNormal, camera );
 				aoPass = ao( scenePassDepth, scenePassNormal, camera );
 				aoPass.resolutionScale = 0.5; // running AO in half resolution is often sufficient
 				aoPass.resolutionScale = 0.5; // running AO in half resolution is often sufficient
-				blendPassAO = aoPass.getTextureNode().mul( scenePassColor );
+				blendPassAO = vec4( scenePassColor.rgb.mul( aoPass.r ), scenePassColor.a ); // the AO is stored only in the red channel
 
 
 				// traa
 				// traa
 
 
@@ -163,7 +163,7 @@
 
 
 					if ( value === true ) {
 					if ( value === true ) {
 
 
-						postProcessing.outputNode = aoPass;
+						postProcessing.outputNode = vec4( vec3( aoPass.r ), 1 );
 
 
 					} else {
 					} else {
 
 

粤ICP备19079148号