• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Best way to draw cylinder

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

8 replies to this topic

### #1Yura  Members

Posted 27 February 2013 - 06:08 AM

Hi

I need some effective way to draw cylinder, many cilinders. Basicly, I'm rendering primitives on my scene,  but making cylinder from primitives is very unprofitably (especially circles) - much additional points needed. So, I'm searching alternative way to draw awesome fast-drawing cylinders.

I thought about textures, but I don't know how to make textured cylinder, which will stay cylinder when I'll rotate camera.

### #2NewDisplayName  Members

Posted 27 February 2013 - 07:47 AM

In D3d9, you can try using D3DXCreateCylinder. There are tons of working examples you can find on the web to use this method.

### #3C0lumbo  Members

Posted 27 February 2013 - 07:50 AM

You will be able to draw a hell of a lot of cylinders before you reach the point where it's too many polygons for any vaguely modern hardware. You could generate multiple LODs if necessary so cylinders far away from your camera use fewer triangles.

Otherwise, I imagine you could render quads and do some clever maths in a pixel shader to draw a cylinder, but that's much harder and probably more expensive than doing it with triangles.

You could also look at imposters, 2D sprites which you can update as your camera position changes, but only when it changes beyond a certain threshold. Again, lots of work, probably little gain, just render the triangles.

### #4nfactorial  Members

Posted 27 February 2013 - 08:05 AM

I would make a single unit-cylinder (radius = 1.0, height range from -0.5 to +0.5), and pass in the desired radius and height. Then multiply the vertex in the unit cylinder by float3( desiredRadius, desiredHeight, desiredRadius ) before the transform. Allowing you to just have one geometry block shared across all cylinders for a small memory footprint.

As someone else said, you should be able to draw an awful lot of cylinders before it becomes a problem.

n!

Edited by nfactorial, 27 February 2013 - 11:22 AM.

### #5Jason Z  Members

Posted 27 February 2013 - 09:13 AM

I see two different possibilities:

1. Define a cylinder as a your base mesh, using radius = 1.0 and height = 1.0.  Then you could use this as the instance basis, and then just pass the per-instance data that is needed to scale the cylinder and place it where you want it in the proper orientation (i.e. a transformation matrix only, since you can do a scale in Y for scaling the height, scale in X and Z for radius, then the standard rotation and translation can all be concatenated into one matrix).  This should be very efficient, with the vertex shader simply being a single transformation, and it should be faster than one draw call for each cylinder (plus a significant reduction in vertex buffer size needed).

2. You can try to use imposters if the precision isn't too strictly needed.  This is essentially rendering a few cylinders into textures, and then you use billboards to put them into the correct location within your scene.  This would be hard to get working in an acceptable quality, but could be very fast if it meets your requirements...

I would prefer #1, but your mileage may vary!

Jason Zink :: DirectX MVP

Direct3D 11 engine on CodePlex: Hieroglyph 3

Games: Lunar Rift

### #6Yura  Members

Posted 28 February 2013 - 06:01 AM

In D3d9, you can try using D3DXCreateCylinder. There are tons of working examples you can find on the web to use this method.

Can't find this method in SharpDX.. Seems it's not exist in this library

### #7Yura  Members

Posted 28 February 2013 - 06:22 AM

I'm displaying quite big 3D surface on my scene, it has enough primitives even without those cylinders (near 500 000, can be even more), so I'm quite limited in resources, even with modern hardware  .

Jason Zink

If I understood you right, you suggest (#1) not to store needed vertices, but to recalculate those cylinders with new parameters on each draw call to reduce buffer size?

Edited by Yura, 28 February 2013 - 06:25 AM.

### #8Yura  Members

Posted 28 February 2013 - 07:59 AM

I would make a single unit-cylinder (radius = 1.0, height range from -0.5 to +0.5), and pass in the desired radius and height. Then multiply the vertex in the unit cylinder by float3( desiredRadius, desiredHeight, desiredRadius ) before the transform. Allowing you to just have one geometry block shared across all cylinders for a small memory footprint.

As someone else said, you should be able to draw an awful lot of cylinders before it becomes a problem.

n!

One geometry block  shared across all cylinders - sounds nice. You wrote about initialization above, give me more information about where I need to store those points? Maybe, some code samples?

### #9Jason Z  Members

Posted 28 February 2013 - 08:49 PM

Jason Zink

If I understood you right, you suggest (#1) not to store needed vertices, but to recalculate those cylinders with new parameters on each draw call to reduce buffer size?

Basically just to use instanced rendering.  You will have a base mesh to represent your 'unit' cylinder, and then you load another vertex buffer with per-instance data (the transformation I mentioned above).  That second vertex buffer will allow you to draw all of your cylinders in one draw call, and your total memory consumption is significantly reduced.

Jason Zink :: DirectX MVP

Direct3D 11 engine on CodePlex: Hieroglyph 3

Games: Lunar Rift

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.