# OpenGL Detecting Boundaries in triangles with adjacency

This topic is 1038 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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?

Edited by TheKreature

##### Share on other sites

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.

##### Share on other sites

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();
}


##### Share on other sites

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.

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();


1. 1
2. 2
Rutin
19
3. 3
khawk
19
4. 4
5. 5
A4L
11

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633771
• Total Posts
3013761
×