Drawing with a custom render pass

This page contains statements regarding the beta version.

With the Cubism 5 SDK for Unity R5 beta 3’s support for Universal Render Pipeline (URP), the drawing process for all Cubism models will be performed on a custom render pass.

Overview for custom render passes

Custom render passes in Cubism SDK for Unity are registered in RenderGraph under the name Cubism URP Render Pass.
RenderPassEvent is set to RenderPassEvent.BeforeRenderingTransparents and is processed before a transparent object is drawn.

public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameData)
{
    const string renderCustomPass = "Cubism URP Render Pass";

    ~~~~~~
}


public override void Create()
{
    _mScriptablePass = new CubismRenderPass
    {
        // Configures where the render pass should be injected.
        renderPassEvent = RenderPassEvent.BeforeRenderingTransparents
    };
}

Set a RenderPassEvent that is easy to use in each project.

The processing being performed by and the load of a custom render pass

A custom render pass brings together the processes used to draw the model.

Main resources to be reserved in a custom render pass

The following resources are new to the Cubism 5 SDK for Unity R5 beta 3 and have a particular impact on performance.

  • Texture on which the model is drawn
  • Texture used as a temporary drawing destination when using advanced blend mode
  • Texture to draw masks

These resources are allocated as texture handles, and textures are generated on the basis of the render target information of the camera rendering the Cubism model.

Process flow

The drawing process for each frame in a custom render pass proceeds as follows:

  1. Resource allocation and data acquisition required for drawing
  2. Calculation of draw order
  3. Drawing of each model
  4. Application of the drawing result to the camera’s render target

1. Resource allocation and data acquisition required for drawing

The following textures are declared as necessary resources for drawing.

  • Active color texture
  • Active depth texture
  • Texture on which the model is drawn
  • Texture used as a temporary drawing destination when using advanced blend mode
  • Texture to draw masks

The following data required for the drawing process is saved as CubismRenderPass.PassData.

  • CubismRenderControllers for all models used for rendering
  • Grouped Sorting Index and an array of CubismRenderControllers grouped by Grouped Sorting Index
  • Camera data passed from URP
  • Resource data passed from URP
  • Mask drawing texture handle
  • Active color texture handle
  • Active depth texture handle
  • Handle of the texture on which the model is drawn
  • Handle of the texture used as a temporary drawing destination when using advanced blend mode

2. Calculation of draw order

The draw order is updated when the distance from the camera (with the draw order sorting index and SortByDepth in use) is different from the previous frame, etc.
After the update, this process also checks which Drawable is the last one to be drawn and sets the flag.

3. Drawing of each model

First, the drawing target is switched to the texture on which the model will be drawn.

Then, before drawable objects in the model are drawn, this process checks whether each drawable object is to be drawn.
Once it determines which objects are to be drawn, the necessary drawing process is called according to the draw order.

In addition, before and after the drawing process call of each drawable object, the drawing interrupt function is used to call the process.
See “Drawing interrupt function” for details.

4. Application of the drawing result to the camera’s render target

By default, drawing results are applied to the camera’s render target by Grouped Sorting Index (hereafter referred to as “group”).
Please see “About Grouped Sorting Index” for more information about the Grouped Sorting Index function.

The ability to apply drawing results to the camera’s render target by Grouped Sorting Index (hereafter referred to as “group”) is provided to prevent the blend mode from affecting drawable objects (models) that are not in the same group.

When this setting is disabled, the blend mode affects already drawn objects (models) regardless of whether they are in the same group, but the process performance improves if the number of groups is large.
For details, please refer to “About load.”

Note that regardless of the setting, the blend mode will affect drawable objects in the same group regardless of whether they are drawable objects for different models or not.

About Grouped Sorting Index

This is a unique feature of Cubism SDK for Unity that divides models into groups for drawing processing. The draw order for each model is controlled by CubismRenderController.GroupedSortingIndex.
If models have different CubismRenderController.GroupedSortingIndex values, their draw orders will not change back and forth even when a change is made to CubismRenderController.SortingOrder or the coordinates.

In Cubism 5 SDK for Unity R4_1 and earlier, the draw order was controlled only by CubismRenderController.SortingOrder and coordinates, and CubismRenderController.SortingOrder values had to be set far apart to prevent models from intersecting each other, especially when SortingByOrder was used.
This is because the draw order is changed when CubismRenderController.SortingOrder, which is the draw order for the entire model, is added to CubismRenderer.SortingOrder, which is SortingOrder for each Drawable of the model.

In Cubism 5 SDK for Unity R5 beta 3, Grouped Sorting Index allows you to set the forward/backward relationship between models independently of CubismRenderController.SortingOrder.

About load

The items that affect performance in a custom render pass are as follows:

Grouped Sorting Index

With the default setting (enabled), DrawMesh is executed for each Grouped Sorting Index to apply the drawing results to the camera’s render target.
The effect of this is to increase draw calls by the number of unique Grouped Sorting Indexes.

To toggle this setting, manipulate the flag CubismRenderControllerGroup.IsCopiedToCameraTexture.
The default value is true.

If this setting is disabled, the DrawMesh application for each Grouped Sorting Index will be skipped and applied only once to the camera’s render target after all models have been drawn.
The blend mode affects already drawn drawable objects, but the more unique Grouped Sorting Indexes that are drawn, the better the performance compared to when the setting is enabled.

Scene view

In Unity Editor, there are areas where additional processing is performed due to the scene view’s drawing characteristics.
This increases the drawing load somewhat on Unity Editor.

Was this article helpful?
YesNo
Please let us know what you think about this article.