How to check edges in vertex shader?

Started by
8 comments, last by Jason Z 12 years, 8 months ago
I want to handle seam edges in texture space, but I really do not know how to check edges in 3D that are parametrized in texture space because as I know, vertex shader just handle only one vertex at a time. So how to do it.

Is there anybody experienced this sort of situation, please help me?. Thank in advance.
Advertisement
Maybe geometry shader is the only way.
You could do this by putting the vertex data into a texture buffer and inside the vertex shader you'd be able to read out all the vertices associated with the primitive. The vertex shader can then generate appropriate output to feed to the rasteriser stage.

In the limit (although I wouldn't recommend it for performance reasons) your vertex shader can now access the data for the entire model, not even limited to just the current primitive.

Your input to the drawing command is then several copies of an "instanced" primitive (whose vertex coords aren't used in the final output). This will then provide an instance number (which tells you which tri or quad you're drawing) and you can supply a corner number as one of the parts of your input vertex so you know which corner you're generating in this run of the vertex shader.

This has an advantage in that you probably shouldn't have to change the format of the main VBO, just attach it to a texture lookup instead of using it as the drawing input so there'd be very little impact to the host code.

The risk is that by doing multiple texture reads inside the vertex shader, it will slow that down. However modern GPUs are actually extremely good at doing the texture data fetches and actually those fetches will be far outnumbered by the fetches to do your texture mapping during rasterisation.
Thank you robotech_er, let me try, and is there any way to check that an edge cross a chart boundary in the sense that 1 vertex located in a chart and the other located in another one?

You could do this by putting the vertex data into a texture buffer and inside the vertex shader you'd be able to read out all the vertices associated with the primitive. The vertex shader can then generate appropriate output to feed to the rasteriser stage.

In the limit (although I wouldn't recommend it for performance reasons) your vertex shader can now access the data for the entire model, not even limited to just the current primitive.

Your input to the drawing command is then several copies of an "instanced" primitive (whose vertex coords aren't used in the final output). This will then provide an instance number (which tells you which tri or quad you're drawing) and you can supply a corner number as one of the parts of your input vertex so you know which corner you're generating in this run of the vertex shader.

This has an advantage in that you probably shouldn't have to change the format of the main VBO, just attach it to a texture lookup instead of using it as the drawing input so there'd be very little impact to the host code.

The risk is that by doing multiple texture reads inside the vertex shader, it will slow that down. However modern GPUs are actually extremely good at doing the texture data fetches and actually those fetches will be far outnumbered by the fetches to do your texture mapping during rasterisation.


Thank you so much, you probably has lots of experience with GPU programming. I will try all of methods I can.
And I think that to check an edge continue in surface but discontinue in texture space, and edge in surface is always continue, the distance is one unit, in meanwhile the distance in texture space is greater than one. Is that right, everybody?
The fast silhouettes article linked in my signature has a method to do it without geometry shaders, but you need to put in some additional per-vertex data to make it work. Still, it might give you some inspiration for other ideas on how to get it working.

The fast silhouettes article linked in my signature has a method to do it without geometry shaders, but you need to put in some additional per-vertex data to make it work. Still, it might give you some inspiration for other ideas on how to get it working.


404....

It could be interesting, because I need a fast backfacing edge algorithm, so I'd check it out.

[quote name='Jason Z' timestamp='1313091994' post='4847861']
The fast silhouettes article linked in my signature has a method to do it without geometry shaders, but you need to put in some additional per-vertex data to make it work. Still, it might give you some inspiration for other ideas on how to get it working.


404....

It could be interesting, because I need a fast backfacing edge algorithm, so I'd check it out.
[/quote]

I'll report it to the GDNet guys... it is hosted here on gamedev (or should be anyways...)
The link is fixed now - you can get to it through my signature again.

This topic is closed to new replies.

Advertisement