Skip to content

Commit c604c09

Browse files
authored
GTAONode: Optimize render target format. (#31883)
1 parent 7085e35 commit c604c09

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

examples/jsm/tsl/display/GTAONode.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DataTexture, RenderTarget, RepeatWrapping, Vector2, Vector3, TempNode, QuadMesh, NodeMaterial, RendererUtils } from 'three/webgpu';
1+
import { DataTexture, RenderTarget, RepeatWrapping, Vector2, Vector3, TempNode, QuadMesh, NodeMaterial, RendererUtils, RedFormat } from 'three/webgpu';
22
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';
33

44
const _quadMesh = /*@__PURE__*/ new QuadMesh();
@@ -48,7 +48,7 @@ class GTAONode extends TempNode {
4848
*/
4949
constructor( depthNode, normalNode, camera ) {
5050

51-
super( 'vec4' );
51+
super( 'float' );
5252

5353
/**
5454
* A node that represents the scene's depth.
@@ -90,7 +90,7 @@ class GTAONode extends TempNode {
9090
* @private
9191
* @type {RenderTarget}
9292
*/
93-
this._aoRenderTarget = new RenderTarget( 1, 1, { depthBuffer: false } );
93+
this._aoRenderTarget = new RenderTarget( 1, 1, { depthBuffer: false, format: RedFormat } );
9494
this._aoRenderTarget.texture.name = 'GTAONode.AO';
9595

9696
// uniforms
@@ -392,7 +392,7 @@ class GTAONode extends TempNode {
392392
ao.assign( clamp( ao.div( DIRECTIONS ), 0, 1 ) );
393393
ao.assign( pow( ao, this.scale ) );
394394

395-
return vec4( vec3( ao ), 1.0 );
395+
return ao;
396396

397397
} );
398398

examples/webgpu_postprocessing_ao.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<script type="module">
2929

3030
import * as THREE from 'three/webgpu';
31-
import { pass, mrt, output, normalView, velocity } from 'three/tsl';
31+
import { pass, mrt, output, normalView, velocity, vec3, vec4 } from 'three/tsl';
3232
import { ao } from 'three/addons/tsl/display/GTAONode.js';
3333
import { traa } from 'three/addons/tsl/display/TRAANode.js';
3434

@@ -112,7 +112,7 @@
112112

113113
aoPass = ao( scenePassDepth, scenePassNormal, camera );
114114
aoPass.resolutionScale = 0.5; // running AO in half resolution is often sufficient
115-
blendPassAO = aoPass.getTextureNode().mul( scenePassColor );
115+
blendPassAO = vec4( scenePassColor.rgb.mul( aoPass.r ), scenePassColor.a ); // the AO is stored only in the red channel
116116

117117
// traa
118118

@@ -163,7 +163,7 @@
163163

164164
if ( value === true ) {
165165

166-
postProcessing.outputNode = aoPass;
166+
postProcessing.outputNode = vec4( vec3( aoPass.r ), 1 );
167167

168168
} else {
169169

0 commit comments

Comments
 (0)