Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it really so difficult to draw smooth lines in Unity?

I been trying for a while to draw smooth lines in Unity but with Line Renderer I obtained only jagged lines with the corners not rounded, in particular when the angle of curvature is really small . I incresed the value of antialiasing in quality settings and tried different materials but nothing changed. I also tried to instantiate a sphere every time the mouse move but it creates some gaps between the various spheres, in particular when the mouse go fast. I know there is a plugin called Vectrosity for this but there is a way to achieve this whitout it?

like image 385
rickyxd Avatar asked Apr 21 '17 16:04

rickyxd


1 Answers

You can get some good results by generating a mesh from a set of points.

The algorithm for it is as follows:

  1. You have a set of points, could be generated with bezier curve.

enter image description here

  1. For each point, take a directional vector to the next point v = (p2 - p1) (marked in blue). Then rotate that vector by 90 degrees normal = v.y, -v.x marked in red.

enter image description here

  1. This illustrates that we will use each normal from the point position. You can now multiply this vector in both directions by the desired width of the line.

enter image description here

  1. Create the vertices at those positions.

enter image description here

  1. Add indices to form triangles. It will be something like [i, w/2 + i, w/2 + i + 1] where i is the current index, and w is the total number of vertices.

enter image description here

  1. Create the other triangles. Again something like [i, w/2 * i + 1, i + 1]

enter image description here

  1. And the final result. You can add more points to make the line smoother.

enter image description here

like image 187
Iggy Avatar answered Sep 22 '22 19:09

Iggy