mrt
A 'terminal' node that implements Multiple Render Targets (MRT). It allows a fragment shader to write multiple, completely different data sets—such as color, normal, and depth—to several separate textures in parallel within a single render pass.
Core Advantages
Dramatically improves performance by generating a G-buffer (multiple textures containing color, normals, material properties, etc.) in a single draw call. It is the cornerstone of Deferred Shading and efficient, complex post-processing, significantly reducing draw calls.
Common Uses
Generating G-buffers for Deferred Shading
Creating multi-layered data for complex post-processing effects (e.g., bloom, motion blur)
Simultaneously outputting and visualizing various data like normals, UVs, and depth for debugging
How to adjust
Adjustments are made by modifying the object passed to `mrt`. You can add or remove key-value pairs to change the number and type of output targets, such as adding a `velocity` output for motion blur. You can also change the data content of an output channel by replacing the TSL node assigned to a key, for instance, swapping `normalWorld` for `normalView` to suit different subsequent rendering algorithms.
Code Examples
1
2mrt({
3 // Output 0: Traditional shading result (color)
4 color: material.colorNode,
5
6 // Output 1: World-space normal (remapped to 0-1 range)
7 normal: normalWorld.remap( { from: new Vector3( -1, -1, -1 ), to: new Vector3( 0, 0, 0 ) } ),
8
9 // Output 2: Depth value
10 depth: depth( { from: 0, to: 1 } ),
11
12 // Output 3: Material's roughness value
13 roughness: roughness
14})
15