2

In a fragment shader, I need to draw a line at a given value of u. The shader is applied to a planar polygon mesh that's being drawn in the scene with a perspective camera. (It isn't a full-screen textured quad; that would be easy!)

The problem is, the thickness of the line is given in screen pixels, not in world units. How can I draw this line in my shader?

The shader is Cg, but a pseudocode answer outlining the technique is fine.

Dan Hulme
  • 6,780
  • 1
  • 16
  • 35
  • 1
    If you compute du/dx etc can you not check if the bounds of the pixel (including required line widths) include the required U value and set the colour accordingly? – Simon F Jun 30 '17 at 09:02
  • Can't you simply convert the thickness into texture coordinates? I assume you know the dimension of your planar polygon and you know your starting point in world space? If so, simply offset from that point given your thickness, than transform it into UV coordinate. You can either multiple view-projection matrix and then divide by w (perspective divide) and then convert [-1, 1] to [0, 1] by times 0.5 and then add 0.5. This should get you a UV offset from the line start. You now have your thickness. You might want to do half the thickness and offset from center (the start). – ChaoSXDemon Jul 10 '17 at 20:50

0 Answers0