Detecting Boundaries in triangles with adjacency

Started by
2 comments, last by sensate 8 years, 2 months ago

I have been working with geometry shaders and triangles with adjacency for a number of years.

I only just had the case where I want to detect boundaries (-1 in indices 1, 3, 5, given triangle with adjacency indices 0,1,2,3,4,5)...

I am wondering what the input assembler does with invalid (value -1) indices and what is the best way to go about detecting them would be?

I haven't found anything in the OpenGL or D3D11 docs regarding this, and a few tests including:

- Comparing epsilon in distance(input[index0], index[index0+1]) < 1e-6f (I.e., for edge 0, indices 0, 1)

- Comparing epsilon in distance(input[index2], index[index0+1]) < 1e-6f (I.e., for edge 0, indices 2, 1)

- Comparing epsilon in distance(input[index0+1], input[index2+1])) < 1e-6f (I.e., for edge 0, indices 1 and 3).

- Testing for NAN in incoming positions in indices 1, 3, 5. I.e., input[index0+1].worldPosition != input[index0+1].worldPosition, or isnan(input[index0+1].x)

These tests haven't yielded any output for what should be boundary indices.

Obviously, I can scan my adjacency buffer on the system side for -1, and set invalid adjacency indices to [index-1], but I'm now kinda curious as to what the input assembler is doing.

Does anyone know how to test for this?

Adjacency Ref:

adjacencies.jpg

Advertisement

In D3D11 a index of -1 has a special meaning (see here, last paragraph "Generating Multiple Strips"). IIRC in OpenGL you can define that value arbitrarily. I wonder if you even get something in the geometry shader then, since it operates on primitives. If that is the case, try another number, e.g. -2.

You can grab the index in the vertex shader with SV_VertexID and pass it along. Maybe that helps.

You can grab the index in the vertex shader with SV_VertexID and pass it along. Maybe that helps.

Interesting thought.

The vertex shader would only run on vertices present in the vertex buffer though :p.

What I'm really interested in is what the gpu does with indices that are -1 when forming the input vertices for triangleadj:


[maxvertexcount(MAX_VERTEX_COUNT)]
void gs( triangleadj vertex input[6], inout TriangleStream<vertex> triStream )

Mind you, this approach would definitely be a faster method of testing if I were to replace the -1 adjacency indices with index-1 when I compute the adjacency buffer.


for (uint id = 0; id<6; id+=2)
{
    uint index0 = (uint)fmod( id, 6.0f );
    if (input[index0].vertexId == input[index0+1].vertexId)
        emitLine();
}

I finally found some time to check on this.

For the curious:

My assumption that -1 was being set for invalid adjacency indices was incorrect.

For invalid adjacencies, DirectXMesh will set invalid adjacency indices to:


indicesAdj[ outputi ] = indices[ face * 3 + ( ( point+2 ) % 3 ) ];

The boundary check is:


uint invalidAdjId = ( uint )fmod( ( index1+4 ), 6.0f );
if ( vecDistance( worldPosition[ index1+1 ], worldPosition[ invalidAdjId ] ) < 1e-6f )
    emitLine();

This topic is closed to new replies.

Advertisement