outputStruct
A node used to structurally define and manage multiple shader outputs, which is key to implementing advanced techniques like Multiple Render Targets (MRT) and Deferred Rendering.
Core Advantages
It natively supports MRT by bundling multiple outputs like color, normals, and material properties into a clean struct. This greatly enhances code readability and maintainability while abstracting away low-level GLSL complexity, lowering the barrier to entry for advanced rendering techniques.
Common Uses
Defining the G-Buffer data structure for Deferred Rendering
Exporting custom data channels for object picking or motion blur
Generating multi-layered data inputs for advanced post-processing (e.g., SSAO)
How to adjust
Adjustments are made by changing the input nodes assigned to the struct's members. For example, switching the `normal` member's input from `normalWorld` to `normalView` changes the coordinate system of the output normal texture to suit different lighting algorithms. Adding a new `depth` member and assigning a value to it can create a new depth output channel for effects like Depth of Field (DoF) or SSAO.
Code Examples
1
2// 1. Define a G-Buffer struct "type" containing color and normal
3const GBufferStruct = outputStruct(
4 vec4().name( 'color' ),
5 vec3().name( 'normal' )
6);
7
8// 2. In shader logic, create an instance and populate it
9const gBuffer = GBufferStruct.create();
10gBuffer.color = material.color;
11gBuffer.normal = normalWorld;
12