Jump to content

  • Log In with Google      Sign In   
  • Create Account


Light Trails


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.

  • You cannot reply to this topic
9 replies to this topic

#1 ekba89   Members   -  Reputation: 427

Like
0Likes
Like

Posted 11 June 2011 - 11:28 AM

I'm trying to create light trails using DirectX. My main purpose is to emit light trails from character's eyes. Now i'm doing this with point sprites and alpha blending. But i dont get good results. So my question is how can i create light trails? Thanks.

Sponsor:

#2 rdragon1   Crossbones+   -  Reputation: 1195

Like
0Likes
Like

Posted 11 June 2011 - 12:05 PM

What do your current trails look like, and what makes it "not good"? What are you trying to achieve instead?

#3 ekba89   Members   -  Reputation: 427

Like
0Likes
Like

Posted 11 June 2011 - 12:37 PM

Thanks for reply. I attached screenshots. As you can see it just looks like point array :D. I want something like beam.

Attached Thumbnails

  • ss1.jpg
  • ss2.jpg


#4 andur   Members   -  Reputation: 564

Like
1Likes
Like

Posted 11 June 2011 - 08:56 PM

Thanks for reply. I attached screenshots. As you can see it just looks like point array :D. I want something like beam.



If you want to create a beam, you'll want to create a continous strip of triangles instead of using particle effects. Each frame, add on a new quad that joins onto the quad from the previous frame. When you reach the maximum number of segments that you want, start removing the old ones. To make it fade off, you can set an alpha value on the vertices that fades to 0 as they approach the end of the beam.

#5 ekba89   Members   -  Reputation: 427

Like
0Likes
Like

Posted 12 June 2011 - 05:22 AM

Thanks for reply. But with quads i have to make them always look to screen. Is there a easy way to do this or should i calculate each frame what wil be the rotation angles.

#6 Hodgman   Moderators   -  Reputation: 28772

Like
0Likes
Like

Posted 12 June 2011 - 05:37 AM

This "stream of billboard quads" is quite common in a lot of games (things like smoke trails behind projectiles, etc). Sometimes you see it referred to as "particle ribbons".
Before vertex shaders, you'd manually have to rotate the quad's verts to face the camera each frame, but these days you can do it in a shader.

In either case, the logic behind it is quite simple: the cross-product of the camera's forward direction, and the direction from one particle's position to the next gives you a direction that's perpendicular to both of those. i.e. the resulting direction will stick out sideways at 90º from the ribbon, and be 90º from the camera, so it's always facing the camera.

In top-down ASCII art form:
   x->----x->----x->



   	^
   	|
   	C
The 'x's are your particles. The arrows pointing to the right represent the direction from one 'x' to the next one.
The 'C' is the camera, and the arrow pointing up is the direction it's looking in.
If you get the cross product of those two directions, the result points towards you, out of the monitor (or into the monitor if you swap the order of the inputs to the cross product equation).
Each 'x' then becomes two vertices, one shifted out of the monitor (in this case), and the other shifted into the monitor. In this case, that gives us 6 vertices, which we can stitch together into a ribbon of quads which face the camera.

#7 ekba89   Members   -  Reputation: 427

Like
0Likes
Like

Posted 12 June 2011 - 06:00 AM

Thanks. Nice explanation :D. But what if we have something like
^
|
x
^
|
x


^
|
C

i have to use camera right vector don't i?

#8 ekba89   Members   -  Reputation: 427

Like
0Likes
Like

Posted 12 June 2011 - 06:14 AM

By the way now i was trying to get nice beam looking light by using point size (d3dfvf_psize). It looks nice but i have another problem.As you can see in the second screenshot they are drawing top of each other. How can i make them draw according to how close they are to the camera. I'm planning to save a float for minimum distance from particle to camera and update it every frame. When adding new particle i will check if it is less than min distance ill push it front of the list and update the min distance if not push it back to the list. Is there a more efficient way?

Attached Thumbnails

  • ss1.jpg
  • ss2.jpg


#9 Hodgman   Moderators   -  Reputation: 28772

Like
0Likes
Like

Posted 12 June 2011 - 07:33 AM

But what if we have something like ...

If the camera is looking in the exact same direction as the ribbon, the illusion breaks down, yeah... (simply using the camera's right-vector won't fix it either)
Often this simply isn't a problem because the player won't notice ;), but if it is easy for the player to get the camera into such a situation, you can often work-around this issue by drawing regular point-sprites as well as the ribbon (as an extension, you can fade the ribbon out as you approach this angle, and fade the point-sprites in).

Regarding your sorting -- you could simply turn off the depth test so that they all draw over the top of each other no matter the order. Depending on your blending mode this might cause artifacts of it's own though.
Alternatively, sorting a list of a few dozen to a few hundred items every frame is actually pretty cheap.

#10 ekba89   Members   -  Reputation: 427

Like
0Likes
Like

Posted 12 June 2011 - 08:32 AM

Thanks with z test disabled it looks nice but i cant lower their size because when i do that it doesnt look like continous. I think if i can draw all particles with big size then resize all of them like they are one big particle my problem will be solved. Also ill definitely check particle ribbons to see if i can get better results .Thanks for pointing that out.




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.



PARTNERS