Jump to content
  • Advertisement
Sign in to follow this  
Unfadable

HLSL Pixel position/direction relative to triangle center

This topic is 4062 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

Does anyone have a smooth trick for determining a pixels position/direction relative to the current triangle center in the pixel shader? I was thinking of baking this info into a texture, but it'd be preferable to derive this in the shader if possible. Oh yes, I should add that the triangles are part of a mesh, and the mesh is rendered using an index buffer.

Share this post


Link to post
Share on other sites
Advertisement
I would add a texture coordinate set to the vertices (perhaps computed by the vertex shader to save bandwidth) that encoded barycentric coordinates at the vertices. As the barycentric coordinates are interpolated across the triangle, you'll know where you are w.r.t. the triangle vertices at any given pixel. If you need to know the *actual* location, as opposed to the relative location, of a pixel w.r.t. the triangles then you'll also have to pass in the vertex position(s) as texture coordinate set(s) to compute the position from the barycentric coordinates. At which point, you might as well just skip the whole barycentric coordinate business and use the interpolated position directly.

Share this post


Link to post
Share on other sites
I think that using an indexed triangle list will make any per-vertex solution difficult. When a vertex is shared by several triangles, it's impossible to code into it any information which is supposed to be different for different triangles. Baking such information into a texture sounds to me like the only solution in this case.

In DX10 you can use the geometry shader to calculate such information.

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!