Author Topic: [OpenGL] Vector line glow options?  (Read 14271 times)

0 Members and 1 Guest are viewing this topic.

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
[OpenGL] Vector line glow options?
« on: June 03, 2011 »
The Wireframe competition has sparked my interest in making some glowing vector type games.

I'm currently using OpenGL to render the crude wireframe primatives (circa 1983 style).
Some time ago I had a little line drawing algorithem that produced very nice results by stretching a glowing transparent line texture.

Picture of Blitzmax method.


Thread for old example (.exe)
http://www.dbfinteractive.com/forum/index.php?topic=4493.0

My question is how do I do something like this in true 3D with OpenGL?
Obveously the 2d screen coordinate of the 3D shapes are sort of off limits to the programmer unless they keep track of them manually. Can I work in true 3d with OpenGl and still get this strong of a glow effect as seen above? Above I used a stretched set of textures (a middle shape and two end caps)

I know of OpenGL shaders (no clue on how they work) but I don't know if a shader can produce a result like the one above. Doesn't a shader mostly work with post process raster effect?
« Last Edit: June 03, 2011 by Pixel_Outlaw »
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: [OpenGL] Vector line glow options?
« Reply #1 on: June 03, 2011 »
Do you draw the bright dots separately or is it part of the texture and the polygons are actually much larger than the lines make you think ?

Quote from: Pixel_Outlaw
Obveously the 2d screen coordinate of the 3D shapes are sort of off limits to the programmer unless they keep track of them manually.
No, that's exactly what's the vertex shader does.
You "just" have to face your polygons towards the camera.

Alternatives:
- Render to texture and apply a post-processing blur filter.
- Draw multiple sets of antialiased lines, each with different line-width and opacity.
Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Re: [OpenGL] Vector line glow options?
« Reply #2 on: June 03, 2011 »
Do you draw the bright dots separately or is it part of the texture and the polygons are actually much larger than the lines make you think ?

Well each line in my old method is composed of 3 textures. Two end caps and a stretchable center that gets rotated to face the line. These are drawn with transparency and additive blending for glow as they overlap. The 3 part line image looks like the following. Now if this could be transposed into OpenGL that would be awesome!



I do know about using fat lines in OpenGL but they create very ugly joints at corners.

Edit: The line texture is below so you can see how I use it.

   V
« Last Edit: June 03, 2011 by Pixel_Outlaw »
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: [OpenGL] Vector line glow options?
« Reply #3 on: June 04, 2011 »
What you want to do is create a quad with texture coordinates along a line (v1,v2):


As the vertex shader creates exactly one vertex for each incoming vertex, you have to store a bit of additional information for each vertex of the quad:
You need the originating line-vertex (v1 or v2), the direction to the other line-vertex (v2 or v1) and a texture coordinate:
Code: [Select]
   // encode other vertex-position normal
   glNormal3fv( v2 );
   glTexCoord2f(1,0); glVertex3fv( v1 );
   glTexCoord2f(0,0); glVertex3fv( v1 );

   glNormal3fv( v1 );
   glTexCoord2f(0,1); glVertex3fv( v2 );
   glTexCoord2f(1,1); glVertex3fv( v2 );

The vertex-shader can now extrude the quad along the perpendicular of (v2-v1) of the 2d-transformed vertices in camera space.
The orientation of the extrusion can be read from the texture-coordinates (which is either 0 or 1):
Code: [Select]
   // vertex positions of the line in camera space
   vec4 csPos1= gl_ModelViewProjectionMatrix * gl_Vertex;
   vec4 csPos2= gl_ModelViewProjectionMatrix * vec4(gl_Normal, 1.0);
   
   // 2d projected vertex positions
   vec2 p1= csPos1.xy / csPos1.z;
   vec2 p2= csPos2.xy / csPos2.z;
   
   // normalized direction
   vec2 left= normalize(p1 - p2);
   
   // orthogonal
   vec4 up= vec4(-left.y, left.x, 0.0, 0.0);
   
   // depending on assigned texture coordinate, extrude to one side or the other
   float x= (gl_MultiTexCoord0.x-0.5) * lineWidth;
   gl_Position = csPos1 + up * x;

To incorporate the caps you can simply subdivide the quad into three segments.
« Last Edit: June 04, 2011 by hellfire »
Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Re: [OpenGL] Vector line glow options?
« Reply #4 on: June 04, 2011 »
Thank you so much!
Have a karmoid!
Challenge Trophies Won:

Offline ferris

  • Pentium
  • *****
  • Posts: 841
  • Karma: 84
    • View Profile
    • Youth Uprising Home
Re: [OpenGL] Vector line glow options?
« Reply #5 on: June 04, 2011 »
hellfire: great post!
http://iamferris.com/
http://youth-uprising.com/

Where the fun's at.
Challenge Trophies Won: