Search Unity

Question How to process just before each MeshRenderer drawing.

Discussion in 'General Graphics' started by Sohma-Tanaka, Feb 27, 2023.

  1. Sohma-Tanaka

    Sohma-Tanaka

    Joined:
    Oct 13, 2021
    Posts:
    1
    What I want to do:
    Just before drawing multiple MeshRenderers attached to a specific GameObject, where multiple MeshRenderers exist, I want to perform a CommandBuffer drawing on a single RenderTexture.

    Overview:
    I want to use the result of drawing with CommandBuffer that was done to RenderTexture just before the drawing for each MeshRenderer.
    The result of drawing to RenderTexture is used as a mask to clip the display area of the mesh drawn by MeshRenderer.

    The process of using RenderTexture as a mask has already been implemented.
    All masks from the LateUpdate function are drawn to the RenderTexture, and the MeshRenderer references the specified area of that RenderTexture when it draws.

    However, this method makes it difficult to increase the resolution per mask.

    Therefore, I would like to implement a process whereby each time a mask is needed in the MeshRenderer's drawing process, the required mask is generated to fill the RenderTexture area, and the MeshRenderer uses it to draw the image.

    To achieve this, we tried drawing with "CommandBuffer.DrawMesh" from the OnWillRenderObject function to the RenderTexture.
    However, we found that with this method, the last mask drawn to RenderTexture in that frame is used by each MeshRenderer, so this method is not feasible.

    Preparing a RenderTexture for each MeshRenderer is resource-intensive.
    Therefore, each MeshRenderer should use a single RenderTexture.

    I have tried several other methods, but none of them seem to achieve the desired process.
    If you have any solutions, please let me know.

    Thank you.