Advertisement

How to make a Line renderer using OpenGL

Started by November 22, 2019 04:28 PM
6 comments, last by Zakwayda 5 years, 1 month ago

I want to know how would i go about making a 3D line renderer, it can be either a 3D or 2D-billboard line renderer. I don't want it to be static, i would like to add vertices to the line and extend it however i want to. To give an idea of what i want it to be/look like, Think of the Gauss Gun from Half life 1 and Half Life 2. I would want to make it reflect off the walls. I know i would need to do calculations to determine how to reflect off walls, i am just asking how would i go about making a 2D/3D line renderer. Please send me some online resources i can read upon.

Thank you for your help!

Maybe I'm missing something, but is there a reason your question is tagged both 'Unity' and 'OpenGL'? And 'C++' for that matter (which isn't, I don't think, the language most commonly used with Unity).

Can you clarify what tools/APIs/languages you're using?

Advertisement
On 11/22/2019 at 12:10 PM, Zakwayda said:

Maybe I'm missing something, but is there a reason your question is tagged both 'Unity' and 'OpenGL'? And 'C++' for that matter (which isn't, I don't think, the language most commonly used with Unity).

Can you clarify what tools/APIs/languages you're using?

Oh i apologize, I am using OpenGL as my low level programming API. i tagged it Unity cause i want the line renderer to be similar/exact to Unity's. the programming language im using is C++

41 minutes ago, Trexioas Xavier said:

Oh i apologize, I am using OpenGL as my low level programming API. i tagged it Unity cause i want the line renderer to be similar/exact to Unity's. the programming language im using is C++

I see. I've played Half Life 1 and 2, but I'm not sure off the top of my head what effect you have in mind. By '2D-billboard line renderer', do you mean something like a series of line segments, where each segment is a long rectangular billboard oriented towards the camera? Also, is it the mathematics of constructing the geometry you're asking about, or are you asking specifically how best to render the geometry using OpenGL? (Or both?)

Also, I don't know if you could find something like this, but if you could post an image or two showing the kind of effect you want, that could be helpful.

This is ancient at this point but it might still be a useful or interesting starting point: https://developer.download.nvidia.com/SDK/9.5/Samples/DEMOS/OpenGL/src/cg_VolumeLine/docs/VolumeLine.pdf

SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Zakwayda said:
41 minutes ago, Trexioas Xavier said:

Oh i apologize, I am using OpenGL as my low level programming API. i tagged it Unity cause i want the line renderer to be similar/exact to Unity's. the programming language im using is C++

I see. I've played Half Life 1 and 2, but I'm not sure off the top of my head what effect you have in mind. By '2D-billboard line renderer', do you mean something like a series of line segments, where each segment is a long rectangular billboard oriented towards the camera? Also, is it the mathematics of constructing the geometry you're asking about, or are you asking specifically how best to render the geometry using OpenGL? (Or both?)

Also, I don't know if you could find something like this, but if you could post an image or two showing the kind of effect you want, that could be helpful.

Both actually, i would like to learn what would be the best way to render it and what kind of mathematics i should use to construct it.

Advertisement
Trexioas Xavier said:
Both actually, i would like to learn what would be the best way to render it and what kind of mathematics i should use to construct it.

Regarding rendering it with OpenGL, I'm not sure what the best approach is, but because there would likely be relatively little geometry and pixel coverage involved, it may not matter that much how you do it. In e.g. OpenGL ES or earlier versions of OpenGL I'd probably just use streaming geometry and a dynamically modified mesh (which could be appropriate given that you said you want to be able to modify the effect dynamically). There might be more sophisticated techniques you could use in newer versions of OpenGL, but I've mostly been using ES 2 and haven't really kept up on those features.

For the geometry, the first thing that comes to mind is to use standard billboarding techniques for each segment. You could alpha-fade the end of each segment to avoid obvious discontinuities at the nodes.

It's been a while since I've done the math for that type of billboarding, but I think it might be something like this. One axis for the billboard is parallel to the line segment direction, which is easy. For the 'side' axis, compute the normalized cross product of the first axis and a vector from the billboard center to the camera position. The 'face' axis (perpendicular to the billboard surface) is then the cross product of the first two axes.

Whether or not I got the math right, the idea is to align the billboard 'as much as possible' towards the camera. (With other billboard types you can align towards the camera exactly, but with this type of billboard there's an additional constraint.) Note that if the billboard direction axis is pointed (more or less) straight at the camera, the math may fail, so that should be checked for (in that case you could just skip the billboard, or choose an arbitrary 'spin' orientation for it).

This topic is closed to new replies.

Advertisement