Skip to content

WebGPURenderer: Auto-MRT#28833

Merged
sunag merged 25 commits intomrdoob:devfrom
sunag:dev-mrt
Jul 10, 2024
Merged

WebGPURenderer: Auto-MRT#28833
sunag merged 25 commits intomrdoob:devfrom
sunag:dev-mrt

Conversation

@sunag
Copy link
Copy Markdown
Collaborator

@sunag sunag commented Jul 8, 2024

Related issue: #28749

Description

This PR starts the implementation of Auto-MRT, this will allow any RenderObject to be rendered as output (beauty), keeping the original code with extra outputs customized in the same draw.

Below shows how simple the process is to create automatic MRT, it is also possible to add more complex operations such as tslFn within the mrt() inputs.

renderTarget = new THREE.RenderTarget(
	window.innerWidth * window.devicePixelRatio,
	window.innerHeight * window.devicePixelRatio,
	{ count: 2, minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter }
);

renderTarget.textures[ 0 ].name = 'output';
renderTarget.textures[ 1 ].name = 'normal';
	
renderer.setMRT( mrt( {
	'output': output,
	'normal': directionToColor( normalWorld )
} ) );

Examples of approach

  1. Approach using names
renderer.setMRT( mrt( {
	'output': output,
	'normal': directionToColor( normalWorld )
} ) );
  1. Approach using indexes
renderer.setMRT( mrt( [
	output,
	directionToColor( normalWorld )
] ) );

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jul 8, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Filesize dev Filesize PR Diff
683.5 kB (169.2 kB) 683.5 kB (169.2 kB) +0 B

🌳 Bundle size after tree-shaking

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

Filesize dev Filesize PR Diff
460.7 kB (111.1 kB) 460.7 kB (111.1 kB) +0 B

Comment thread examples/webgpu_multiple_rendertargets.html Fixed
Comment thread src/renderers/common/Renderer.js
@sunag
Copy link
Copy Markdown
Collaborator Author

sunag commented Jul 9, 2024

Added a MRT example

Live example

image

Comment thread src/nodes/display/PassNode.js Fixed
Comment thread src/nodes/display/PassNode.js Fixed
Comment thread src/nodes/display/PassNode.js Fixed
Comment thread src/nodes/display/PassNode.js Fixed
@sunag sunag added this to the r167 milestone Jul 9, 2024
@Mugen87
Copy link
Copy Markdown
Collaborator

Mugen87 commented Jul 9, 2024

The new example is awesome!

@sunag
Copy link
Copy Markdown
Collaborator Author

sunag commented Jul 9, 2024

Added mask example for material.mrtNode demonstration.

image

@sunag sunag marked this pull request as ready for review July 9, 2024 20:13
@Mugen87
Copy link
Copy Markdown
Collaborator

Mugen87 commented Jul 31, 2025

@sunag I have deleted my previous comments since I have found solution for my problem 😇 .

Still, can you check if below code is okay if I want two MRT outputs for an internal FX pass?

https://github.com/Mugen87/three.js/blob/7b6a2ed63a7feab7061578dcb628789dc0e31ade/examples/jsm/tsl/display/DepthOfFieldNode.js#L186-L206

I had to abuse colorNode so I can write values into the output properties.

@sunag
Copy link
Copy Markdown
Collaborator Author

sunag commented Jul 31, 2025

Still, can you check if below code is okay if I want two MRT outputs for an internal FX pass?

Could you use CoC() returning vec2( nearField, farField ) and use only one texture to save bandwidth since they are just two floats?

However, it shouldn't be a compatibility issue to use sub-MRT in rendering.

@sunag
Copy link
Copy Markdown
Collaborator Author

sunag commented Jul 31, 2025

Could you use CoC() returning vec2( nearField, farField ) and use only one texture to save bandwidth since they are just two floats?

Reading it again now I noticed you're using RedFormat, so I can't confirm without benchmarking whether that will improve as well.

The code looks great to me. 👍

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.

3 participants