ID:2776707
 
Applies to:DM Language
Status: Open

Issue hasn't been assigned a status value.
I've been playing with these new particles. Potent stuff! Making a starfield effect appear as though you are traveling through space is pretty easy with particles and setting velocity to a circle generator, but there's one issue. The stars appear to slow down as they reach the edge of the image area. This isn't proper parallax. They should increase in velocity as they fly past you. The solution is simple, but not currently possible: A negative value for the friction parameter.

So... how about it? I see no other way to influence these particles in this manner, and who cares if negative friction isn't a real world phenomena? I wants it, my precious!

~X
I'd like to see it added anyway, but I don't really think this is what you want for the effect you're talking about. Negative friction would mean exponential speed increase, which I don't think would look right (though I haven't checked).
But particles can already be placed and moved through 3D space, so you don't need any special tricks to get this effect. You just need the right projection matrix.
I haven't had the courage yet to mess with matrices. Maths aren't my strongest skillset, and the matrix is scary. Too many Agent Smiths.... Kinda sad we lost our Neo. Tom would know how to deal with them.

Wait... does that make Dan Trinity, or Morpheus?
I threw this together actually before I made that last post in order to make sure I wasn't wrong. I had intended to make it less bad before posting it, but that didn't happen.

/particles/starfield
width = 480
height = 480
color = "red"
spawning = 5
bound1 = list(-240, -240, 0)
bound2 = list(240, 240, 240)
position = generator("box", list(-240, -240), list(240, 240), UNIFORM_RAND)
velocity = list(0, 0, 24)
transform = list(
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 0, -1 / 240,
0, 0, 0, 1
)

Needs actual sprites and a lot of number tweaking to be any good, but it works.
So the bounds setup a 480x480x240 unit space coming out to the camera from the origin 0,0,0. The position generator seeds the side of the box furthest from the camera, a 480x480x1 unit space, with particles. The velocity moves the particles toward the camera at 24 units per tick, and the projection matrix adds additional velocity towards the camera at about 0.004 units per tick (or is that per tick per tick?). Is that correct? I'm not on my laptop right now, so I can't mess with this.

Why is the zz value in your projection matrix set to 0 and not 1?
The projection matrix isn't adding velocity, it's forming a projection. The -1 / 240 serves to make it so that W approaches zero as Z approaches 240. It's kind of hard to explain.
ZZ is zero because it doesn't matter unless you care about layering. Since these are just single pixels, layering doesn't matter, but you're right, it shouldn't be zero if you're using actual sprites. It shouldn't be one either because the Z value isn't supposed to exceed 100 after projection and it gets up to 240 before projection, but any positive value less than or equal to 1 / 2.4 would work.
Ah, so the projection does a scaling transformation on the sprites depending on their z value? I think I see now.
Yep. In general, a projection matrix defines how to convert 3D coordinates in some space into 2D coordinates on a screen. (There is still a Z axis in the output, but it only defines layering.) This particular one is a very simple version of the type you might use in a first-person game. In its case, there's no scaling of the X and Y axes, the near clipping plane is right at the camera, and the field of view is 90 degrees.