0
\$\begingroup\$

I'm using Unitys DrawProceduralIndirect function to directly render the content of a ComputeShader.

I setup the argumentBuffer for this function as follows:

    int[] csArgs = new int[] { ptsOnLine, 2, 0, 0};
    argsBuffer = new ComputeBuffer(4, 4, ComputeBufferType.IndirectArguments);

So every instance consists of ptsOnLine (lets say 10) vertices.

My vertexShader then looks like this:

fsInput vert(uint id : SV_VertexID, uint instanceId : SV_InstanceId)
{
    fsInput fsIn;
    float3 worldPos = linePoints[id + (instanceId * 10)];
    fsIn.pos = mul(UNITY_MATRIX_VP, float4(worldPos, 1.0f));
    return fsIn;
}

The question is simple. My problem is: (instanceId * 10). Is there a built in variable telling me the length of one instance? I couldn't find anything. I mean, its in the argument buffer so it shouldn't be too much of a problem? I could forward this value from the compute buffer but thats ugly. :)

Help is much appreciated!

\$\endgroup\$
0

1 Answer 1

1
\$\begingroup\$

The "built in" variable is contained in the args buffer.

From the unity docs "Buffer with arguments, bufferWithArgs, has to have four integer numbers at given argsOffset offset: vertex count per instance, instance count, start vertex location, start instance location."

So make sure you pass that argsBuffer to your shader and then use the first index.

\$\endgroup\$
1
  • \$\begingroup\$ Feels a bit redundant to pass it explicitly to the shader when it is already passed to DrawProceduralIndirect. Nevertheless, it seems that there is no built in variable, so this is the way to go. Thanks a lot! \$\endgroup\$
    – Christoph
    Commented Aug 17, 2017 at 14:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .