How can I find a position between 4 vertices in a fragment shader?

Posted by c4sh on Game Development See other posts from Game Development or by c4sh
Published on 2013-11-12T15:53:47Z Indexed on 2013/11/12 16:00 UTC
Read the original article Hit count: 350

I'm creating a shader with SharpDX (DirectX11 in C#) that takes a segment (2 points) from the output of a Vertex Shader and then passes them to a Geometry Shader, which converts this line into a rectangle (4 points) and assigns the four corners a texture coordinate.

After that I want a Fragment Shader (which recieves the interpolated position and the interpolated texture coordinates) that checks the depth at the "spine of the rectangle" (that is, in the line that passes through the middle of the rectangle.

The problem is I don't know how to extract the position of the corresponding fragment at the spine of the rectangle. This happens because I have the texture coordinates interpolated, but I don't know how to use them to get the fragment I want, because the coordinate system of a) the texture and b) the position of my fragment in screen space are not the same.

Thanks a lot for any help.

© Game Development or respective owner

Related posts about shaders

Related posts about directx11