Using the Graphics Compositor
To open the Graphics Compositor window in the Unity Editor, select Window > Render Pipeline > Graphics Compositor from the menu. From this window, you can control the Graphics Compositor configuration. The first time you open the Graphics Compositor window, it automatically uses a default "pass-through" composition profile that forwards the output of the main Camera to the final composed frame. You can edit this profile or you can load another one from disk. For information on the properties in the Compositor window, see Compositor window.
Layer Types
The Graphics Compositor tool typically handles two types of layers:
- Composition Layers: Which you define in the Composition Graph. The Composition Graph defines the number of layers and how to combine them but does not define each layer's content.
- Sub-layers: Which you define in the Graphics Compositor window, in the Render Schedule section. You use stack Sub-layers to define the content of a Composition Layer.
Composition Graph
To specify the output image, the Graphics Compositor uses a graph of compositing operations. Specifically, the Graphics Compositor uses the Shader Graph with an Unlit Master Node as its target. To specify the output image, the Compositor uses the value you connect to the Color port. You do not need to connect any other ports on the Master Node.
Note: When the output of the composition is to a render target, the Material you create from the Master Node must be double-sided.
When you create a Composition Graph, there are two main types of input property you can expose:
- Composition Layer: Any Texture2D properties act as Composition Layers which correspond to a layer the graph composites to generate the final frame. These properties appear automatically as Composition Layers in the Render Schedule section of the Graphics Compositor window. The Mode option for them in Shader Graph corresponds to the default value the Shader uses when you toggle off the visibility of the layer in the Render Schedule list.
Note: By default, this value is set to white, but for many compositing operations and behaviors, you may want to set this to black instead. - Composition Parameters: This refers to any exposed property that is not a Texture2D. Composition Parameters can control various aspects of the composition. Examples of Composition Parameters include a Float input to control the overall brightness or a Color input to tint a Texture2D. These properties appear automatically in the Composition Parameters section of the Graphics Compositor window.
The following graph contains examples of the property types described above. The Logo property is an example of a Composition Layer and the Opacity property is an example of an input property to control an aspect of the composition:
Unity saves the Graphics Compositor properties in a .asset file with the same name as the Composition Graph. When the Graphics Compositor loads a Composition Graph, it also loads the properties from the corresponding Asset file if one exists, otherwise, it creates a new Asset with default settings.
Adding and removing Composition Layer
To add a new Composition Layer, create a new Texture2D input property in the Composition Graph. When you next save the Composition Graph, the new layer appears automatically in the Render Schedule section of the Graphics Compositor window. From there, you can control the layer properties and specify how to fill the layer with content.
Similarly, to delete a Composition Layer, remove the corresponding Texture 2D property from the Composition Graph.
Sub-layers: Adding content to Composition Layers
Each Composition Layer can source its content from one or more Sub-layers. There are three types of Sub-layer:
- Camera Sub-layer: The source of the content is a Unity Camera. You can select which Camera to use in the properties of the Sub-layer.
- Video Sub-layer: The source of the content is a Unity Video Player. You can select which Video Player to use in the properties of the Sub-layer.
- Image Sub-layer: The source of the content is a static image. You can select which image to use in the properties of the Sub-layer.
To add a Sub-layer to a Composition Layer, select the Composition Layer and click the Add drop-down button. From the drop-down, you can select the type of Sub-layer.
To remove a Sub-layer, select the Sub-layer and click the Delete button.
Note: You can only delete Sub-layers this way and not Composition Layers. Instead, to delete a Composition Layer, remove the corresponding Texture2D property from the Composition Graph.
Camera Stacking
When you use more than one Sub-layer to specify the content of a Composition Layer, this "stacks" the Sub-layers on top of the same render target. To specify the size and format of the composition, you use the properties of the parent Composition Layer. The Sub-layers inherit the size and format from their parent Composition Layer and you cannot change these properties independently for a particular Sub-layer. This means every stacked Camera/Sub-layer has the same size and format. To change the stacking order, re-arrange the Sub-layers in the Render Schedule section of the Graphics Compositor window.
The Sub-layer Properties section controls the type of stacking operation.
Render Schedule
The Render Schedule is a re-orderable list of Composition Layers and Sub-layers. Sub-layers appear indented below their corresponding parent Composition Layer, which makes it easier to see the hierarchical relationship. When multiple Sub-layers appear below a parent layer, they form a camera stack. Unity renders layers at the top first. To re-order the list, you can click and move both Composition Layers and Sub-layers. You can use this to change the rendering order in a camera stack or move a Sub-layer from one parent Composition Layer to another.
Composition Parameters
This section shows every exposed property that is not an input Composition Layer (for example, a Float to control the brightness of the final composition or a Color to tint a Texture2D). In this section, the window allows you to edit each property value outside of the Composition Graph. It is good practice to expose properties from the graph to the Graphics Compositor window, instead of hard-coding their values. This helps you to share composition profiles between Projects because those you do not need to open the Composition Graph to edit any values.
Composition of screen-space UI
You can use the Graphics Compositor to compose screen-space canvas (UI) elements. However, in this case, the camera sub-layer that draws the UI:
- Should have a unique camera assigned to it. You should not use this camera in any other sub-layer.
- Should not override any camera state (antialiasing, culling mask, volume mask, etc). You can change these properties in the source camera that the sub-layer uses.