Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

call once CommandBuffer.DrawMesh, then the scene has two meshes,Why?

Discussion in 'Universal Render Pipeline' started by fang1994, Dec 2, 2019.

  1. fang1994

    fang1994

    Joined:
    Mar 20, 2019
    Posts:
    12
    My test code is as follows:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Rendering;
    5. public class CommandBufferTest2 : MonoBehaviour
    6. {
    7.     private CommandBuffer commandBuffer;
    8.     public Mesh sphereMesh;
    9.     public Material standardMaterial;
    10.     void Start()
    11.     {
    12.         commandBuffer = new CommandBuffer();
    13.         Camera.main.AddCommandBuffer(CameraEvent.AfterForwardOpaque, commandBuffer);
    14.         DrawMesh();
    15.     }
    16.  
    17.     public void DrawMesh()
    18.     {
    19.         Matrix4x4 matrix4X4 = Matrix4x4.TRS(Vector3.up*2f, Quaternion.identity, Vector3.one * 2f);
    20.         commandBuffer.DrawMesh(sphereMesh, matrix4X4, standardMaterial);
    21.         Debug.Log(" DrawMesh Done ");
    22.     }
    23. }
    24.  
    and got following results:
    upload_2019-12-2_16-0-37.png
    It confused me, why there are two meshes? And it not 3D.
     
  2. fang1994

    fang1994

    Joined:
    Mar 20, 2019
    Posts:
    12
    I got the answer, my own material replace the standard material, then fixed it.
    upload_2019-12-3_10-20-21.png
    But I don't know why.
    Does there need any special requirements on shader when we use commandbuffer?