Drawing simple mesh with triangles from Compute and Vert Frag Shader

Hi all,

I hate to ask simple questions here, but I’m hitting a wall. I’ll keep trying to figure it out.
I’m trying to generate a really simple mesh using vertices from a compute shader being passed to vert shader.

When I run I get a cube of intersecting triangles instead of a flat plane (which it should be because y is always 0).

I’ve tried changing the mesh topology. As far as I can tell it’s not an issue where float3 is being read as float4 and stealing the first value from the next float3…

Here’s the code, I cut out irrelevant/obvious things.

Can anyone see what I’m doing wrong here?

Main CS:

void Start() {
     static int stride = Marshal.SizeOf(typeof(Vector3));
     vertexBuffer = new ComputeBuffer(triVertCount, stride, ComputeBufferType.Default);
     ...
     compute.SetBuffer(kernel_generateMesh, "vertexBuffer", vertexBuffer);
     material.SetBuffer("vertexBuffer", vertexBuffer);

     compute.Dispatch(kernel_generateMesh, Mathf.Max(1, sideWidth / 8), Mathf.Max(1, sideWidth / 8), 1);
}

void OnRenderObject() {
    material.SetPass( 0 );
    Graphics.DrawProceduralNow(MeshTopology.Triangles, triVertCount );
}

Compute Shader:

RWStructuredBuffer<float3> vertexBuffer;
[numthreads(8,8,1)]
void calc (uint3 id : SV_DispatchThreadID)
{
      float3 vA = float3(id.x, 0, id.y+1);
      float3 vB = float3(id.x+1, 0, id.y);
      float3 vC = float3(id.x, 0, id.y);
      float3 vD = float3(id.x+1, 0, id.y+1);

      vertexBuffer[idx] = vA;
      vertexBuffer[idx+1] = vB;
      vertexBuffer[idx+2] = vC;

      vertexBuffer[idx+3] = vA;
      vertexBuffer[idx+4] = vD;
      vertexBuffer[idx+5] = vB;
}

Frag Shader:

StructuredBuffer<float4> vertexBuffer;

struct v2f {
      float4 pos : SV_POSITION;
};

v2f Vert( uint id : SV_VertexID ) {
      v2f o;
      float3 worldPos = vertexBuffer[id];
      float4 pos = UnityObjectToClipPos(float4(worldPos, 1));
      o.pos = pos;
     return o;
}

fixed4 Frag( v2f i ) : SV_Target {
      return fixed4( 1, 1, 0, 1 ); // Yellow
}

Dam, I figured it out as soon as I posted it… I was right about misreading float3s as float4s…

Frag shader has buffer as StructuredBuffer but it was meant to be a float3. Changed that, all working now!