Jump to content
  • Advertisement
Sign in to follow this  
Bosduif

HLSL: vertex shader is run multiple times on 1 vertex

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!