3D Accelerated... Lines?

Started by
16 comments, last by webmunkey 22 years, 5 months ago
Okay, I was just wondering how I can use Direct3d 8 to draw 3d lines. I am aware that DrawPrimitive does have a draw line function that uses a vertex buffer to draw a line using like LINELIST. This is all just great, but I the lines I''m drawing are going to be have constantly different vertices. That would mean locking and unlocking the vertex buffer each time I wanted to draw a line, right? Well, that''s way too slow, I might as well just lock the surface and plot pixels on my own. Can anyone think of a fast way around the problem? Basically I want to be able to draw lots of pixel thick lines with widly varying vertices as quick as computerly possible. Any ideas would be greatly welcomed! Also how fast is the ''hack'' of using the clear function and passing it a rectangle? Cheers, -Jesse
Advertisement
clear is pretty darn fast...

Also, I''m usually telling everyone not to lock, mainly because many people lock instead of doing simple transforms. However, there are some cases where you just have to. If that''s the case, then it''s really not *that* slow, and it''s probably much much faster than locking and drawing individual pixels. If you set everything up correctly, locking the buffer should still be very acceptable - don''t discount it. But remember, if you''re just doing simple translations, rotations, and scaling, you are better off with the matrices...

The one issue is that DX8 doesn''t really have a line width setting. If you want wider lines, set up the basic lines and then render more than once, "jittering" thine lines with matrices. There are a couple of ways of doing this, but the jittering way allows you to play with transparency for antialiasing effects.
Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials
It seems that the all mighty "clear hack" do draw pixel thick lines without locking is incredibly slow when it comes to calling it 3200 times or so , god I love voxel engines. I was thinking about having a vertex buffer that had a vertex for every pixel on the screen in a vertical fashion so that the engine could call the two verticies it wants to draw the line between, or is that just an incredibly unrealistic idea memory wise? We're talking about resolutions of 640x480 to 800x600 here, so... Does anyone else have any other ideas? I really don't want to lock buffers if it can be avoided, and remeber, speed is key here.
Thanks,
-Jesse

[Edit: I'm an idiot, don't pay attention]

Edited by - webmunkey on November 5, 2001 6:28:36 PM
Code up some different line draw engines and see. Each should only take a little while, like a couple of hours. Streaming into a VB is probably the fastest for the newer video cards.
WebMonkey,

Could u pls supply me the code to draw lines in Direct3D?

My email is NSZeroOne@Hotmail.com

Thanks.

Downloads, D3DXSprite tutorial, New platform game: .-= The ZeroOne Realm =-.

Downloads, Free GoldLib game library, D3DXSprite tutorial, New platform game: .-= The ZeroOne Realm =-.

Locking is probably much faster/easier/saner than keeping a vertex for every pixel! Remember, some cards have a vertex buffer limit of 65K - much less than every pixel.

If you can''t accomplish what you need with the transforms, then you probably have to lock. The speed it runs is the speed it runs.

One question - what are you doing?? Sometime people say they are just translating points. That''s a matrix problem. Others are doing things that may be solved with shaders, some have to lock... Whatcha doin?
Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials
I am currently building a super-fast voxel engine, I just think that it could be faster if I could plot 3d accelerated lines because, while locking surface with directdraw and plotting pixels using asm is fast, its ugly and unflexible. D3D lines open up all sorts of texture blending effects and lighting transformations and all that fun stuff. But I still can't figure out how to draw fast d3d lines. I've tried clear rects, d3d linestrips and good old fashion pixel plotting and so far, pixel plotting is ripping the other two methods to shreds speed wise, much to my dismay.
Anarchi: Drawing lines isn't hard, but I'll send you a small tutorial nonetheless. It's poorly documented in the DX8 docs, but it is there, in the DrawPrimitive function. My email sucks, so it could take a day or two for it to reach you. I'm going to assume that you want lines in a 2d environment.

Anyone else who has any suggestions for fast line drawing, please post.

Cheers,
-Jesse

Edited by - webmunkey on November 6, 2001 8:13:25 PM
You should try using DrawPrimitiveUP so that you don''t have to lock your VB''s. Just change the vertices. I have gotten pretty good speed with this also.

*** Triality ***
*** Triality ***
The reason locking is slow is because you are moving data around. The UP functions do that implicitly. Conventional wisdom is that the UP functions should be avoided at all costs...
Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials
If the UP function should be avoided, then what should I use? Keep in mind that I'm always drawing vertical lines. Can I offset a line's vertices with a matrix, so that I could grab a, say, 50-pixel long line, move it over 20, and down 50 without locking/unlocking? Maybe this could be acheived through manipulation of the view matrices? I'm not quite sure, this is about the extent of my Direct3d knowledge, I've always just used two matrices for my custom 3d-engines, but d3d has 3. Anyway, any other ideas would welcomed as well. Thanks to everyone who has contributed to the post so far,
Cheers,
-Jesse

Edited by - webmunkey on November 7, 2001 4:52:08 PM

This topic is closed to new replies.

Advertisement