Jump to content
  • Advertisement
Sign in to follow this  

Doing this without quite so much data per laser beam

This topic is 2821 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


I'm drawing individual laser beams like this,

public class LaserLight : AbstractRenderable3D
public Vector3 Start;
public Vector3 End;
public VertexPositionNormalTexture[] Buffer;
public int[] IndicesBuffer;
public int BufferUsed;
public LaserLight()
this.Start = new Vector3(100, 10, 100);
this.End = new Vector3(0, 10, 0);
Buffer = new VertexPositionNormalTexture[8];
IndicesBuffer = new int[24] { 0, 1, 2, 1, 3, 2, 4, 5, 6, 5, 7, 6, 2, 1, 0, 2, 3, 1, 6, 5, 4, 6, 7, 5 };
this.Material = new ResourceHolder<CustomMaterial>("laser", new CustomMaterial("laser", "Projectile"));
public override void Draw(float delta, Renderer3D r)
var distance = Start - End;
var ndistance = distance; ndistance.Normalize();
var left = Vector3.Cross(ndistance, Vector3.Up);
var right = -left;
var up = Vector3.Cross(ndistance, left);
var down = -up;
float diameter = 0.1f;
Buffer[0].Position = Start + (left * diameter);
Buffer[1].Position = End + (left * diameter);
Buffer[2].Position = Start + (right * diameter);
Buffer[3].Position = End + (right * diameter);
Buffer[4].Position = Start + (up * diameter);
Buffer[5].Position = End + (up * diameter);
Buffer[6].Position = Start + (down * diameter);
Buffer[7].Position = End + (down * diameter);
r.GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, Buffer, 0, Buffer.Count(), IndicesBuffer, 0, 8);

I'm going to batch up these calls into a single call to DrawUserIndexedPrimitiives but I don't want to have quite so much data. My strategy for batching up things like this is to have a large buffer which I fill up and then make a single draw call, and then repeat until I've drawn all the data.

I don't want to have to go over a large buffer setting the Position data of each point, nor do I want to have so many indices in the index buffer; 24 per beam seems like far too many. I render a few hundred laser beams. Does anybody have any suggestions for how to batch this up without doing that?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!