Search Unity

Bug why draw quad is so hard on Unity

Discussion in 'General Graphics' started by wechat_os_Qy06eaOhICF9NcZoMWMLtv5cI, Dec 4, 2022.

  1. wechat_os_Qy06eaOhICF9NcZoMWMLtv5cI

    wechat_os_Qy06eaOhICF9NcZoMWMLtv5cI

    Joined:
    Feb 1, 2018
    Posts:
    33
    I have basic settings for quad.(just use this quad as tessellation patcher,default quad doesn't work.I imported plane with four vertices,one face ,and keep quad in import settings doesn't work too. )
    Code (CSharp):
    1.  Vector3[] vertices = new Vector3[4]
    2.         {
    3.             new Vector3(0, 0, 0),
    4.             new Vector3(width, 0, 0),
    5.             new Vector3(0, 0, height),
    6.             new Vector3(width, 0, height)
    7.         };
    8.  
    9.         Vector2[] uv = new Vector2[4]
    10.         {
    11.             new Vector2(0, 0),
    12.             new Vector2(1, 0),
    13.             new Vector2(0, 1),
    14.             new Vector2(1, 1)
    15.         };
    16. int[] quads = new int[4] { 0, 2, 3, 1 };
    This quad can only be done by invoke mesh.SetIndices(quads, 0, quads.Length, MeshTopology.Quads, 0);and set this mesh to MeshFilter.

    But It will fail when you Invoke DrawMeshInstanceIndicrect even if I choose this quad as mesh parameter.Unity only rendering one triangles.Same situation for Graphics.RenderPrimitivesIndexed(rp, MeshTopology.Quads even if I set parameter to Quads.
    Why???I just want to draw a quad...Why not allow me to draw it ????
    Unity version 2021 LTS.
     
  2. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    675
    If you want a fullscreen quad, you can just do this:

    Code (CSharp):
    1. struct VsToPs
    2. {
    3.     float4 position : SV_Position;
    4.     float2 texCoord : TEXCOORD0;
    5. };
    6.  
    7. VsToPs vs(uint vertexID : SV_VertexID)
    8. {
    9.     VsToPs outData;
    10.     outData.texCoord = float2((vertexID << 1) & 2, vertexID & 2);
    11.     outData.position = float4(outData.texCoord * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f), 0.0f, 1.0f);
    12.     return outData;
    13. }
    in combination with
    CommandBuffer.DrawProcedural(Matrix4x4.Identity, material, 0, MeshTopology.Triangles, 3);


    This actually just renders a triangle which is clipped to a quad by the GPU.

    Alternatively, you can also use the full screen quad mesh that's in the post-processing package, IIRC.
     
  3. wechat_os_Qy06eaOhICF9NcZoMWMLtv5cI

    wechat_os_Qy06eaOhICF9NcZoMWMLtv5cI

    Joined:
    Feb 1, 2018
    Posts:
    33
    No luckly!I used the quad mesh in default library.I can see It's quad topology.But my tessellation code only work to the quad by mesh.SetIndices.Otherwise ,even if it can be tessellation but uv are mess!