1px line using triangles

• 09-21-2012, 12:57 AM
phdr_hroch
1px line using triangles
Hi,
I have geometry (or fallback vertex only) shader, that generates lines with custom width and pass float uniform into shader.
For lines that are more than 1px thick, it works great. But if I want to draw nonantialliased line with 1px width, it looks ugly, especialy when line is not perpendicular to screen.
Any options ?
Problem is that I have only one definition of some geometry and wants to draw it with different line widths many times
Thank you
• 09-21-2012, 01:48 AM
thokra
Quote:

it looks ugly
• 09-21-2012, 02:07 AM
phdr_hroch
Attachment 876
in 45 degrees rotation the line (created by two triangles) is 2px wide instead of 1px
• 09-21-2012, 02:12 AM
thokra
• 09-21-2012, 02:55 AM
phdr_hroch
Code :

```geometry shader line draw function: // make thick line // from : transformed point (by modelviewprojectionmatrix) // to : trasformed point // colorfrom : first point color // colorto : second point color void makeLine(in vec4 from, in vec4 to, in vec4 colorfrom, in vec4 colorto) { // triangle positions vec4 position1 = from; vec4 position2 = from; vec4 position3 = to; vec4 position4 = to;   // direction of line vec2 line2d = position3.xy - position1.xy;   // normalized direction vec2 direction = normalize(line2d);   // shift vector vec2 vector;   // make vector perpendicular to line vector.x = direction.y / screen.x; vector.y = -direction.x / screen.y;     // normalizedwidthdiv2 : global variable width normalized from px width to normalized coords // vec2 normalizedwidthdiv2 = width / screen; // uniform vec2 screen; // screen size in px // uniform vec2 width; // width of line in px   vec2 shift = normalizedwidthdiv2 * vector;   // shift positions position1.xy -= shift; position2.xy += shift; position3.xy -= shift; position4.xy += shift;   // emit triangles gl_Position = position1; gl_FrontColor = colorfrom; EmitVertex();   gl_Position = position3; gl_FrontColor = colorto; EmitVertex();   gl_Position = position4; gl_FrontColor = colorto; EmitVertex();   EndPrimitive();   gl_Position = position1; gl_FrontColor = colorfrom; EmitVertex();   gl_Position = position2; gl_FrontColor = colorfrom; EmitVertex();   gl_Position = position4; gl_FrontColor = colorto; EmitVertex();   EndPrimitive(); }```
• 09-21-2012, 06:05 PM
Dark Photon
Please use [ code ] ... [ /code ] blocks. Preserves the indentation. I inserted them for you.
• 09-23-2012, 06:55 PM
michagl
Is it guaranteed that a consumer card can do this with pixel perfect precision?

Quote:

Originally Posted by Dark Photon
Please use [ code ] ... [ /code ] blocks. Preserves the indentation. I inserted them for you.

I guess that makes Dark Photon a mod-and-or-admin then.