Hi,
I’m trying to draw a mesh on the GPU based on quads.
I’m using Graphics.DrawProcedural and specifying a Quad Topology.
The problem is the result is exactly the same for Triangles and Quads.
I tried to change the order of the vertices but no matter what, the shader only draw one triangle and not a quad.
Here is my script:
using UnityEngine;
using System.Collections.Generic;
using System.Runtime.InteropServices;
public class Test : MonoBehaviour
{
public Material material;
private ComputeBuffer buffer;
private Vector2[] vertices;
private void Start()
{
vertices = new Vector2[]
{
new Vector2(0,0),
new Vector2(0,1),
new Vector2(1,1),
new Vector2(1,0),
};
buffer = new ComputeBuffer(vertices.Length, Marshal.SizeOf(vertices.GetType().GetElementType()));
buffer.SetData(vertices);
material.SetBuffer("_vertices", buffer);
}
private void OnPostRender()
{
material.SetPass(0);
Graphics.DrawProcedural(MeshTopology.Quads, vertices.Length);
}
private void OnDestroy()
{
buffer.Dispose();
}
}
And the shader
Shader "Test/ProceduralQuads"
{
Properties
{
_Color("Color", Color) = (1,0,0,1)
}
SubShader
{
Tags{ "RenderType" = "Opaque" "Queue" = "Overlay+10"}
LOD 100
Pass
{
CGPROGRAM
#include "UnityCG.cginc"
#pragma target 3.5
#pragma vertex vert
#pragma fragment frag
uniform float4 _Color;
uniform StructuredBuffer<float2> _vertices;
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 vertex : SV_POSITION;
};
v2f vert(appdata v, uint vid : SV_VertexID)
{
v2f o;
o.vertex = float4(_vertices[vid],0,1);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
return _Color;
}
ENDCG
}
}
}
I only see one triangle on screen. No quad.
Is it a bug or am i doing something wrong ?