Draw MeshTopology.Lines with thickness>1

Hi all,
I was able to draw a point cloud and change the size of points. This was using MeshTopology.Points and changing PSIZE parameter in VertexOutput in the shader shown below. However, when the same shader is used with MeshTopology.Lines, the thickness doesn’t change. Any help is appreciated.

CGPROGRAM
#pragmavertexvert
#pragmafragmentfrag

float_PointSize;

struct VertexInput {
float4 v : POSITION;
float4 color: COLOR;
};

struct VertexOutput {
float4pos : SV_POSITION;
float4col : COLOR;
floatsize : PSIZE;
};

VertexOutput vert(VertexInputv) {
VertexOutput o;
o.pos = mul(UNITY_MATRIX_MVP, v.v);
o.col = v.color;
o.size = _PointSize;
return o;
}

float4 frag(VertexOutput o) : COLOR {
return o.col;
}

1 Like

seeing as directx11 can handle 10^32 vertices, theoretically, you may find that you can just double the vertices… Me i am looking to change their colors. i have found a cool pic of what i want, i dont think it’s direct on the shader the color dunno:

http://elix-jp.sakura.ne.jp/wordpress/?p=882![](http://elix-jp.sakura.ne.jp/wordpress/wp-content/uploads/2013/04/topologyearth1.png)

As far as I know, you can’t just change a parameter to do this; you have to tesselate. For two vertices P1, P2 that make a line segment, a camera position C, and a “thickness” float T, calculate two vectors:

The line direction: | (P2 - P1) |
The direction to the camera: | (C - P1) |

Then calculate a new vector orthogonal to both of the previous two: | (P2 - P1) | x | (C - P1) |

Generate two new vertices:
P3 = P1 + T * ( | (P2 - P1) | x | (C - P1) | )
P4 = P2 + T * ( | (P2 - P1) | x | (C - P1) | )

So instead of rendering just P1 and P2 with MeshTopology.Lines, you would draw two triangles: (P1, P2, P3) & (P4, P3, P2). Voila – you have a thick line (essentially a billboarded quad). All of this work could be done in either a script or a geometry shader.

If you start stringing these lines together, you’ll also need to generate caps linking them, but you can probably figure that out.

1 Like

Thanks, that’s a great idea. Do you know if vectrosity generates lines in that fashion? I have managed to change the line colors. for reference to the code for triangles of different colors see here: HLSL fragment shader different color for every vertex? - Stack Overflow

Yes, I believe Vectrosity does something like this, and also draws caps between line segments, which is where things can get a bit complicated depending on how smooth you want your lines to look.

See: https://forum.libcinder.org/topic/smooth-thick-lines-using-geometry-shader

1 Like