HLSL: vertex shader is run multiple times on 1 vertex

Started by
1 comment, last by Bosduif 13 years, 9 months ago
Hello all,

I'm making a shader that displaces vertices based on a texture and its normal. The problem is the vertex shader is used multiple times on vertices with multiple UV coordinates.

The value of the texture's color is multiplied with the normal and added to the position.
http://i26.tinypic.com/33k6omf.jpg

However, as you can see at the top of this sphere, appearantly the vertex shader is run multiple times for the top (and bottom) vertex, which I guess is due to the multiple UV coordinates.
http://i30.tinypic.com/js1wcj.jpg

How can I make it that the vertex shader is only used once on this vertex?

Thanks in advance.
Advertisement
The vertex shader is only run once per vertex. But your mesh have multiple vertices on the top of your sphere. This is because of the texture coordinates as you have already guessed. But this is more a matter of how you exported the mesh, and nothing you can do anything about afterwards, your mesh will have all those vertices if you don't do anything about it when you build up your mesh/export it.

The reason it has multiple vertices is because individual texture coordinates cannot occupy the same vertex (except for when using multiple uv-sets, but that's a whole different matter).

You basically have two options, either you make sure that top vertex share the same uv-coordinate by for example selecting them in (maya?) and scale down to the same point. Depending on what exporter you are using you may be able to get a mesh which only have one top vertex in the mesh. It will still be processed multiple times though since it will have to be sent through the vertex shader for each triangle which uses it.

The second option is to make sure the pixels (offsets) in the texture are exactly the same across the whole top line, resulting in the same offset being applied to all vertices.

You must also make sure the normals for all the top-vertices are exactly the same.
I was afraid of that. I guess option 2 is the most logical thing to do then.
Thank you.

This topic is closed to new replies.

Advertisement