Dark Bit Factory & Gravity
PROGRAMMING => General coding questions => Topic started by: Pixel_Outlaw 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.
(http://img97.imageshack.us/img97/9427/ihatecats.png) (http://imageshack.us/photo/my-images/97/ihatecats.png/)
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?
-
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 ?
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.
-
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!
(http://img691.imageshack.us/img691/7636/lineshl.th.png) (http://imageshack.us/photo/my-images/691/lineshl.png/)
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
-
What you want to do is create a quad with texture coordinates along a line (v1,v2):
(http://www.abload.de/img/line5jhx.png)
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:
// 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):
// 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.
-
Thank you so much!
Have a karmoid!
-
hellfire: great post!