Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nodes: Cache linear depth and viewZ of depth textures in PassNode #28922

Merged
merged 6 commits into from
Jul 24, 2024

Conversation

cmhhelgeson
Copy link
Contributor

@cmhhelgeson cmhhelgeson commented Jul 20, 2024

Description

Following on from some work I'm doing porting the outline pass, this PR allows the user to access the linear depth and viewZ of multiple relevant depth textures within any class that extends PassNode. This can be helpful for debugging or accessing the linear depth of relevant depth passes to be forwarded to other post-processing steps.

Example usage below:

// Create a class that extends PassNodee
class PostPassNode extends PassNode {

	constructor( scene, camera ) {

		super( 'color', scene, camera );

		// Create Render Target Pass with color and depth
		let passName;

		this._prePassRT = new RenderTarget();
		passName = 'PostPassNode.prePassColor';
		this._prePassRT.texture.name = passName;
		this._textures[ passName ] = this._prePassRT.texture;

	        const prePassDepth = new DepthTexture();
	        passName = 'PostPassNode.prePassDepth';
		prePassDepth.name = passName;
	        prePassDepth.isRenderTargetTexture = true;
		this._prePassRT.depthTexture = prePassDepth;
		this._textures[ passName ] = this._prePassRT.depthTexture;

	}

	updateBefore( frame ) {

		const { renderer } = frame;
		const { scene, camera } = this;

		// Random configuration

		// Render to any number of render targets
		renderer.setRenderTarget( this._prePassRT );
		renderer.setMRT( null );
		renderer.render( scene, camera );

		// Render to final output
		renderer.setRenderTarget( this.renderTarget );
		renderer.setMRT( this._mrt );
		renderer.render( scene, camera );

	}

	setup() {

		// # Use Case 1: Debug depth output of texture

		return super.getLinearDepthNode(  'PostPassNode.prePassDepth'  );
                // return postProcess( ..... )

		// # Use Case 2: Apply depth or linear depth to shader post process node

		const color = super.getTextureNode( 'output' );
		const depth = super.getTextureNode( 'depth' ); 
                const linearDepth = super.getLinearDepth(); // 
		const prePassDepth = super.getTextureNode(  this._prePassRT.depthTexture.name );
		const prePassLinearDepth = super.getLinearDepthNode( this._prePassRT.depthTexture.name );

		return postProcess( color, depth, linearDepth, prePassDepth, prePassLinearDepth, uniformX, ...etc );

	}

}

Copy link

github-actions bot commented Jul 20, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Filesize dev Filesize PR Diff
684 kB (169.4 kB) 684 kB (169.4 kB) +0 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Filesize dev Filesize PR Diff
460.9 kB (111.2 kB) 460.9 kB (111.2 kB) +0 B

@cmhhelgeson cmhhelgeson changed the title Nodes: Add name identifier argument to getViewZNode() and getLinearDepthNode() Nodes: Add depth texture 'name' argument to getViewZNode() and getLinearDepthNode() Jul 20, 2024
@cmhhelgeson cmhhelgeson changed the title Nodes: Add depth texture 'name' argument to getViewZNode() and getLinearDepthNode() Nodes: Cache linear depth and viewZ of depth textures in PassNode Jul 20, 2024
@sunag sunag added this to the r167 milestone Jul 24, 2024
@sunag sunag merged commit f5eaae8 into mrdoob:dev Jul 24, 2024
12 checks passed
@cmhhelgeson cmhhelgeson deleted the webgpu_passnode_adjust branch July 24, 2024 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants