2

say, I have two rays given in 3D model space starting from the same center P but with different directions D and E:

A = ( P, D )

B = ( P, E )

I form the half-angle ray from both of these:

H = ( P, ( D + E ) / 2 )

Now say that A' and B' are the same rays, but transformed to screen space (MVP matrix multiplication, perspective divide, viewport scaling etc.). The ray H' refers to the half-angle vector of these in screen-space respectively.

Now my question: Can the vector H' be derived from the vector H just using the above mentioned operations, or do I have to calculate A' and B' and calculate H' from them?

Regards

user5024425
  • 397
  • 3
  • 14

1 Answers1

0

You have to calculate A' and B' and calculate H' from them. The reason is that the midpoint of two points in 3D space will not necessarily the midpoint (in 2D) between the 2D projections of those points. The half-angle ray is defined in terms of the midpoint of D and E.

For example think of your A and B vectors as being two sides of a V painted onto a wall that you are standing next to and looking down. Due to perspective, the 3D midpoint of the two tips of the V will be closer to the further tip when projected into 2D.

samgak
  • 23,944
  • 4
  • 60
  • 82
  • I see. Then I have a follow up question: To convert a direction unit vector from model space to screen space you just have to apply the usual transforms (MVP matrix multiplication, perspective divide, viewport scaling etc.) but with a w coordinate of 0 in homogeneous coordinates, right? – user5024425 Dec 12 '16 at 09:10
  • @user5024425: you're better to describe what's the real problem you're trying to solve. – Yakov Galka Dec 12 '16 at 11:10
  • What I actually want to do is to render a quad strip from a line strip, that means I want to turn every line segment to a quad, then move the vertices in the vertex shader so I have a closed sequence of quads. My plan is to create six vertices for one line segment using indexed rendering, then move the vertices to form trapezes that look like thick line segments. In order to move the vertices correctly, I need to calculate their coordinates in pixel coordinates within the vertex shader. The half angle vector was intended to move the corner vertices to create a smooth transition between quads. – user5024425 Dec 12 '16 at 13:01
  • Check out the answers to this question: http://stackoverflow.com/questions/15276454/is-it-possible-to-draw-line-thickness-in-a-fragment-shader – samgak Dec 12 '16 at 19:02
  • This answer only proposes solutions with geometry and fragment shaders, not vertex shaders. Nevertheless, the original question has been answered so I will mark it as done. Thanks everyone. – user5024425 Dec 13 '16 at 11:22