AnyPortrait > Manual > Not rendered Clipped Meshes
One of the most common inquiries our team has received from users is "Clipping meshes are not rendering properly".
Rendering problems are not easy to troubleshoot because even seemingly identical problems can have different causes.
For issues with clipping meshes, different causes can cause the same issue.
This page introduces typical causes and solutions based on user feedback.
In addition to the clipping mesh, the "Mask" function (Related page) also behaves in the same way, so you can find the cause on this page.
Some of the content on this page addresses issues and solutions that occur only with the "Mask" function.
This is mostly the case when using URP, or when restoring to Built-In Render Pipeline.
This is the character used on this page.
The eye and mouth meshes are set as clipping meshes.
It is set to URP in Project Settings > Graphics > Scriptable Render Pipeline Settings in Unity Editor.
After setting it to URP, use the Material Library to apply the material for URP. (Related page)
Bake and run the game, but clipping meshes are not rendered.
This is most likely caused by the Render Pipeline settings not matching the current project settings.
(1) Press the Bake button in the AnyPortrait editor.
(2) Select the Setting tab.
(3) Check if the Render Pipeline settings match the settings of the current project.
In the case of URP, it should be set to Scriptable Render Pipeline, and if you use the default render pipeline, it should be set to Default.
If you Bake and run the game, you can see that the clipping meshes are rendered normally.
(1) Let's configure the scene to have two cameras that render characters.
As above, you can see that one character is rendered twice by two cameras.
If you run the game in this state, clipping meshes will not be rendered normally for cameras other than one.
AnyPortrait's clipping rendering works by referencing cameras.
This is done by registering a command buffer to a camera for rendering or by utilizing the "View Matrix" to optimize mask quality.
However, AnyPortrait's default settings only reference a single camera.
Therefore, if two or more cameras are rendering a character, clipping rendering will not work properly unless this default setting is changed.
(1) Open the Bake dialog.
(2) Select the Setting tab.
(3) Change the VR / Multi-Camera option value to Multiple Cameras.
Now run Bake and the problem is solved.
Unfortunately, in this state, optimization of the clipping mesh is disabled.
Therefore, the problem of lowering the rendering quality due to the lower resolution clipping mask occurs.
(1) Select Mesh Group.
(2) Select a mesh to be the clipping mask.
(3) Increase the resolution of the clipping mask by changing the value of the Mask Texture Size property.
It should be decided according to the size and quality of the displayed mesh, but when optimization is off, 512 or 1024 is better in terms of quality.
If you Bake and run the game, you can see the clipping mesh is working properly.
There are additional issues when deploying multiple cameras or rendering to a Render Texture.
The following manuals may be helpful.
- Rendering with Multiple Cameras
- Rendering to Render Texture
- Build to VR
In a similar vein to the multi-camera issue, another source of problems referencing cameras is the "Layer."
Cameras only render GameObjects with a "Layer" set within the "Culling Mask."
Using this feature, AnyPortrait's main script, apPortrait, searches for cameras capable of rendering to its "layer" and attempts to establish a connection for clipping rendering.
Only after this connection is established can command buffers and other data be created for clipping rendering.
However, if apPortrait's layer is incorrectly configured, preparation for clipping rendering may fail.
Here's an example with two meshes.
The star-shaped mesh is being clipped by the circle mesh below.
Click Bake and open the Unity scene.
(1) The scene in this example contains one camera.
(2) The value of "Culling Mask" for this camera only contains the "Default" layer.
Let's reproduce the problem.
(1) Select the character's root object, i.e., the "GameObject" with "apPortrait".
(2) Change this object's layer to "UI".
(1) Select the child objects with actual meshes.
(2) Set the layer of the child objects to "Default".
When you run the game, you will see that the meshes are rendered, but the clipping rendering is not working.
Since the child meshes' layers are "Default", which matches the value of the "Culling Mask", rendering itself is performed correctly.
However, the layer of "apPortrait" that detects the camera and performs the connection is "UI", which is not included in the "Culling Mask".
In this case, regardless of whether the actual meshes are rendered, "apPortrait" incorrectly determines that "There is no camera rendering this character."
To fix this issue, you can consider either "modifying the apPortrait layer" or "modifying the Culling Mask of the camera".
If there's a reasonable cause to change the apPortrait layer, changing the camera's Culling Mask might be the right approach, but in this example, modifying the apPortrait layer seems more appropriate.
(1) Again, select the GameObject containing apPortrait.
(2) Change the layer to "Default" to match the actual mesh layer.
(3) Run the game and you'll see that the clipping issue has been resolved.
AnyPortrait's clipping mask is calculated by how it will be drawn during the update routine.
That calculation references camera and character positions, attributes, etc.
If the states of related elements when calculating the mask in the update and when actually rendering do not match, there is a possibility that the clipping mask and mesh may not be rendered properly.
Many users experience this problem when using Cinemachine, UniTask, Naninovel, etc.
There is a separate manual dealing with this issue, you can refer to it.
- Execution order problem with assets
The "Mask" feature added in "AnyPortrait v1.6.0" allows for complex masking by passing multiple mask meshes to the target mesh.
To implement this feature in shaders, existing shaders were upgraded in "AnyPortrait v1.6.0".
If you are still using the previous shaders, the mask feature will not work.
(1) This is an example of implementing clipping rendering by creating and passing a mask from two meshes to a single mesh ("Star Mesh").
(2) According to the mask function, the red star mesh ("Star Mesh") is rendered by being clipped by the two rectangular meshes below.
To reproduce the issue, let's apply a shader that doesn't support masks.
(1) Existing material presets that don't support masks have been moved to the "Legacy" submenu in "Material Library." Select and install the Material Preset that matches your current render pipeline.
(2) Create a new Material Set based on the Material Preset from the previous version.
(3) For the previous version, there are no mask-related keywords in the "Description" section of the material set.
If you do Bake in this state and run the game, you can see that the mask does not work as shown above.
To resolve this issue, you need to use the latest version of the Material Preset that supports masks.
(1) Install the latest version of Material Preset, not the "Legacy" version.
(2) Create a Material Set from a Material Preset that supports masks.
(3) You'll notice the keyword "Multi-Masks" added to the "Description" field. This keyword indicates that the material set supports multi-channel masks, and this keyword is required for the masking feature to function properly.
Note
If you use custom properties in the mask function, you must apply a shader with those properties to your character via the Material Library.
With the appropriate material set, let's Bake again and run the game.
You'll see that clipping is working properly.
AnyPotrait's clipping rendering utilizes the "Command Buffer" and "Render Texture."
If clipping issues occur, verifying that these two elements are created and functioning properly will help you identify the cause.
The "Frame Debugger," which analyzes each rendering process, can be helpful.
Launch "Window > Analysis > Frame Debugger" from the Unity Editor menu.
(The menu path may vary depending on your Unity version.)
(1) Run the game.
(2) At the time you want to analyze rendering, (3) click the Enable button in the Frame Debugger.
Now the game is paused and you can see each detailed step of rendering in sequence.
(1) Before actually rendering the meshes, you can see a rendering step named "AP...". This is a command buffer generated by AnyPortrait's clipping layer or mask system.
(2) This command buffer rendering step generates a black-and-white mask by default. The mask is saved as a "Render Texture" type, and its size and rendering ratio are determined by the camera's properties and AnyPortrait's settings.
(1) Now, let's select the stage where the mesh that receives the mask and is clipped is rendered.
(2) You can see that the mask image previously generated in the command buffer is input into a property like "_MaskTex".
(3) You can see that the clipping rendering is working properly.
As above, you can view the clipping rendering process with the Frame Debugger, and based on this, you can guess the cause when a problem occurs.
1. If the Command Buffer wasn't created or wasn't created for the number of cameras
: apPortrait may have failed to find and connect to the camera.
Check for multi-camera issues, layer mismatches, render pipeline settings, etc.
2. If the Render Texture type mask image is not generated properly
: The "Alpha Mask" shader in the Material Library may not be functioning properly.
Alternatively, if the mask mesh is "Hidden" by a modifier, the mask image may not be generated.
3. If the mask image is not input to the properties of the mesh being clipped
: The clipping shader may not have the appropriate properties, or the target property may have been incorrectly specified in the Mask function.
4. If only clipping rendering is not performed
: If all the previous steps were successful, the clipping shader may not be working properly.
Review the shader code.
Rendering issues can arise for a variety of reasons.
We've heard from users that rendering issues can be caused by compatibility issues with other assets or "Renderer Features," errors loading characters from scripts, or issues with camera manipulation.
If the instructions on this page don't solve your problem, please contact us!