3
\$\begingroup\$

I am building a game in XNA that features colored laser beams in 3D space.

The beams are defined as:

  1. Segment start position
  2. Segment end position
  3. Line width

For rendering, I am using 3 quads:

  1. Start point billboard
  2. End point billboard
  3. Middle section quad whose forward vector is the slope of the line and whose normal points to the camera

The problem is that using additive blending, the end points and middle section overlap, which looks quite jarring. However, I need the endpoints in case the laser is pointing towards the camera!

See the blue laser in particular: XNA Laser Demo Screenshot

\$\endgroup\$
2
  • \$\begingroup\$ Wouldn't the laser end point only be placed on top of an object? Or are lasers ending in the middle of open space? It seems like the problem would be what to do when the camera slices a laser. \$\endgroup\$
    – House
    Oct 25, 2013 at 16:30
  • 1
    \$\begingroup\$ They end in open space. The game takes place in a tron-like environment. \$\endgroup\$
    – user36159
    Oct 25, 2013 at 16:42

2 Answers 2

1
\$\begingroup\$

I'm afraid there is no "correct" solution to this problem without using multipass rendering, which would probably be awfully slow.

What you can do is draw an oriented hemicircle in both ends. See the picture below: Laser with hemicircle endpoints

This should give pretty good results overall. Where this approach fails is when the laser is pointing towards the camera, especially if the projection of the line is smaller than the radius of the circle. See the picture below for what would happen:

Bad case

Even with this issue, this should be a better solution than the one you are currently using. There is no overdraw, yet there is still some effort to draw the end points the way you want.

\$\endgroup\$
0
\$\begingroup\$

You could use normalized vectors to check to see if the laser is pointing at the camera, and then only draw the end points if it is. If the angle allows you could stop drawing the mid section the instant it starts pointing at the camera and drawing the end section.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .