AnyPortrait > Script > Command Buffer

Command Buffer


These are the functions to use Unity's Command Buffer as a target for AnyPortrait's characters.
The following functions belong to the apCustomCommandBuffer class, not apPortrait.
For instructions on how to write the code, please refer to the example code at the bottom of the page or the following page that explains an example of using the command buffer.
- Writing Command Buffer


You can also check the Unity official manual below for a detailed explanation of Unity's command buffer.
- Extending the Built-in Render Pipeline with CommandBuffers
- Scheduling and executing rendering commands in the Scriptable Render Pipeline
- CommandBuffer API
- CameraEvent API


public apCustomCommandBuffer Camera ( camera, apPortrait portrait, string commandBufferName )
1.4.0
Description

   Create a command buffer class targeting apPortrait.


Parameters

   Camera camera : Camera to render
   apPortrait portrait : apPortrait for rendering
   string commandBufferName : The name of the command buffer registered to the camera


public void Destory ()
1.4.0
Description

   Removes the command buffer from the registered camera.
   You must call this function if any of the camera, apPortrait character or command buffer classes cease to exist.


public void AddToCamera ( UnityEngine.Rendering.CameraEvent cameraEvent )
1.4.0
Description

   Sets the timing that rendering is performed to the camera.
   This function should be called when using the built-in rendering pipeline.


Parameters

   UnityEngine.Rendering.CameraEvent cameraEvent : An enum variable for rendering time


public void AddToCameraSRP ( apCustomCommandBuffer.SRPRenderEvent srpRenderEvent )
1.4.0
Description

   Sets the timing that rendering is performed to the camera.
   This function should be called when using the Scriptable Render Pipeline (SRP).
   This function is only supported in Unity 2019.1 or later versions that officially support SRP.


Parameters

   apCustomCommandBuffer.SRPRenderEvent srpRenderEvent : Render time in SRP


public void CreateAlternativeMaterials ( Material alternativeMaterial )
public void CreateAlternativeMaterials ( Dictionary<string, Material> imageNameToAlterMaterialMap, Material unmatchedMaterial )
1.4.0
Description

   Specifies that a different material is applied when rendering the character using the command buffer.
   The properties of the Material input as an argument are duplicated and reserved to be used for rendering, but "_MainTex" and "_Color" are not duplicated.
   The shader of the material being replaced must follow the rules as "Custom Shader".
   After this function is called, a drawing request must be made using the "DrawAllMeshesWithAlternativeMaterials" function.
   If you specify materials as a Dictionary-type variable, different materials can be applied and rendered for multiple images of a character.


Parameters

   Material alternativeMaterial : Material to be replaced when rendering by the command buffer
   Dictionary<string, Material> imageNameToAlterMaterialMap : Mapping variable assigned to replace different materials based on image name
   Material unmatchedMaterial : Commonly applied material when no replacement target material can be found


public void ClearCommands ()
1.4.0
Description

   Initializes the contents of the command buffer.


public void SetRenderTarget ( RenderTexture renderTexture )
1.4.0
Description

   Sets the result of rendering the character with the camera to be saved in "Render Texture".


Parameters

   RenderTexture renderTexture : The texture to which the rendering result will be saved


public void ClearRenderTarget ( bool clearDepth, bool clearColor, Color backgroundColor, float depth )
1.4.0
Description

   Initializes the color or depth value of the set render target.
   A function that can be called from a built-in rendering pipeline.


Parameters

   bool clearDepth : Whether to initialize the depth value
   bool clearColor : Whether to initialize the color value
   Color backgroundColor : Color that is initialized when clearColor is true
   float depth : When clearDepth is true, the initialized depth value (default value is 1.0f)


public void ClearRenderTarget ( UnityEngine.Rendering.RTClearFlags clearFlags, Color backgroundColor, float depth, uint stencil )
1.4.0
Description

   Initializes the color or depth value of the set render target.
   A function that can be called from the Scriptable Render Pipeline (SRP).
   This function is only supported in Unity 2019.1 or later versions that officially support SRP.


Parameters

   UnityEngine.Rendering.RTClearFlags clearFlags : Flag variable that specifies the type of value to be initialized
   Color backgroundColor : Color to be initialized
   float depth : Initialized depth value (default is 1.0f)
   uint stencil : Initialized stencil value (default is 0)


public void SetViewMatrix ()
public void SetViewMatrix ( Matrix4x4 customViewMatrix )
1.4.0
Description

   Specifies which value to be applied as the View Matrix to the command buffer when rendering.
   If no argument is specified, the same value as the target camera's View Matrix is used for rendering.
   This function is only supported in Unity 2019.1 or later, and this function must be called in that version.


Parameters

   Matrix4x4 customViewMatrix : View Matrix applied differently from camera settings


public void SetProjectionMatrix ()
public void SetProjectionMatrix ( Matrix4x4 customProjectionMatrix )
1.4.0
Description

   Specifies which value to be applied as the Projection Matrix when rendering to the command buffer.
   If no parameters are specified, the same value as the target camera's Projection Matrix is used for rendering.
   This function is only supported in Unity 2019.1 or later, and this function must be called in that version.


Parameters

   Matrix4x4 customProjectionMatrix : Projection Matrix applied differently from camera settings


public void DrawMesh ( apOptTransform optTransform )
public void DrawMesh ( apOptTransform optTransform, Material material )
DrawMesh apOptTransform optTransform, ( Matrix4x4 localToWorldMatrix )
public void DrawMesh ( apOptTransform optTransform, Matrix4x4 localToWorldMatrix, Material material )
1.4.0
Description

   Specifies that the mesh of the apOptTransform should be rendered.
   The "apPortrait.GetOptTransform" function will help.
   You can render with arbitrary changes to the Material or the World Matrix.


Parameters

   apOptTransform optTransform : apOptTransform with mesh to be rendered
   Material material : Alternative material to be rendered
   Matrix4x4 localToWorldMatrix : User-specified World Matrix


public void DrawAllMeshes ( bool sortOrder, bool excludeClippedChildMeshes )
public void DrawAllMeshes ( Material material, bool sortOrder, bool excludeClippedChildMeshes )
1.4.0
Description

   Specifies that all meshes of apPortrait currently displayed on the screen are to be rendered.


Parameters

   bool sortOrder : Whether to recalculate the rendering order
   bool excludeClippedChildMeshes : Whether to exclude from rendering clipped meshes that are not compatible with the command buffer.
   Material material : Alternative material used when rendering


public void DrawAllMeshesWithAlternativeMaterials ( bool sortOrder, bool excludeClippedChildMeshes )
1.4.0
Description

   It performs the same role as the "DrawAllMeshes" function, which specifies that all meshes of apPortrait displayed on the screen are to be rendered, but the alternative materials registered from the "CreateAlternativeMaterials" function are used.


Parameters

   bool sortOrder : Whether to recalculate the rendering order
   bool excludeClippedChildMeshes : Whether to exclude from rendering clipped meshes that are not compatible with the command buffer.


public UnityEngine.Rendering.CommandBuffer GetCommandBuffer ()
1.4.0
Description

   Returns the Unity's command buffer instance.


Return

   UnityEngine.Rendering.CommandBuffer : Command buffer instance