Sign in to follow this  

HLSL Pixel position/direction relative to triangle center

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

This topic is 3725 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this