Sign in to follow this  
cebugdev

laser/electric effect

Recommended Posts

cebugdev    635

Hi all,

 

How do lasers drawn using directx 10/11, are they drawn using particles?

by laser i ment things like this;

 

http://getintopc.com/wp-content/uploads/2013/04/download-command-and-conquer-generals-free-game-full-version.jpg

or this

http://www.videogamer.com/xbox360/command_conquer_3/screenshot-51.html

 

what are the technical knowhow that needs to be learned and look at for these kind of effect?

 

thanks,

 

Share this post


Link to post
Share on other sites
Hodgman    51234

The terminology differs a bit with special effects. I'd call them an "oriented billboard" or a "ribbon".

 

You've got a start point A and an end point B for the beam, and you want to draw a quad from A to B. The problem is the orientation of the quad. If, say you choose your 4 points of the quad to be slightly to the left & right of A & B, then when viewed from perfectly side-on, the quad won't be visible. When viewed from side on, you want to choose your 4 points to be slightly above & below of A & B...

So, you need to procedurally calculate some offset, which you can add to A & B to expand this line into a quad, so that it look good from every view angle. We want our offset to be tangental to the direction of the line (i.e. the direction "normalize(B-A)" should be pointing 90º from our offset direction), but also tangential to the direction that the camera is looking.

You'd want to be comfortable with the basics of linear algebra to make these kinds of effects, some specific tools you'd use are the dot product and cross product.

If you calculate the cross product of the direction of the laser and the direction of the view (and normalize the result), this will produce the tangential direction that you're looking for, which can be used as an offset to expand your line into a quad.

Share this post


Link to post
Share on other sites
Amr0    2230

They are also called volumetric lines sometimes. There was an NVidia paper about them, and I had written a C++ DX9 sample based on it. The sample is here, and the paper is in the Nvidia SDK here (search for volume lines).

Share this post


Link to post
Share on other sites
eppo    4877

Also called 'cylindrical billboards'.

 

They work similar to standard billboards, in that you want one specific vector of the billboard's orientation (say its y-axis) to always point in the direction of the camera. The difference is you also want the laser to keep pointing in the direction of its tangent line (say the z-axis). Because of this you only have the freedom to reorient the billboard around its z-axis. So towards whatever direction you re-orient the y-axis, it needs the be orthogonal in respect to the z-axis. You can do this by orthonormalizing the camera-vertex vector in respect to the tangent vector.

 

So the three vectors that form a billboard matrix' orthogonal base are:

 

y: normalize(cameraVertex - tangent * dot(tangent, cameraVertex))

z: tangent
x: cross(y, z)
Edited by eppo

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this