mgear
m
5 posts

#5031
Particles (episode 156) 3 years ago
Hi,
Been playing around with the particle system from episodes 155156, and having one problem with the dispersion:
So, if my CelCenter density = 1 and CelLeft density = 0 and CelCenter density = 1 and CelRight density = 0, then it means they wont get pushed sideways at all (as the Dispersion.x will become 0)? Gif image of whats happening: (not getting pushed to sides) http://pasteboard.co/1CPjpMTT.gif Am I getting something wrong, or should it push particles to left or right at all, if current cell density is 1 and left & right cells have same densities? thanks! 
cmuratori
Casey Muratori
812 posts
/ 1 project
Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero. 
#5032
Particles (episode 156) 3 years ago
I don't believe you are doing something wrong, that is just a consequence of doing central differencing for particle diffusion and nothing else. The physical interpretation of what's going on here is that the particles are pulled equally in both the left and right directions, and thus they stay where they are.
There are a number of ways you can choose to overcome this limitation, but again, this kind of gets into more advanced continuum dynamics stuff (what we did on HH with particle systems was super brief, and just meant to be the barest of introductions). The simplest thing to do, although it is not necessarily the most performant, is just increase the density of the grid.  Casey 
mgear
m
5 posts

#5033
Particles (episode 156) 3 years ago
Ok, thanks!
Got it bit nicer by checking which side the particle is from the spawner x, so if its more to the left, it gets pushed that way more than right (when both sides have same density) 
Pseudonym
Andrew Bromage
184 posts
/ 1 project
Research engineer, resident maths nerd (Erdős number 3). 
#5037
Particles (episode 156) 3 years ago
One thing you might want to try is to use a density gradient estimate at the location of the particle, rather than just at the cel in which the particle lives.
To understand what's going on in your code, consider this code snippet:
This is the same as:
Two of the terms cancel to give:
A similar cancellation happens in the y direction. The upshot of this is that the density at CelCenter is never actually used. Only four density samples are being used, not five, and the one that's ignored is the one that's closest to the particle! I can't remember how HMH did this, and don't have time to look it up right now, but suppose we record densities this way:
(I know there's a scale and offset applied to the x and y coordinates; I'm ignoring that for simplicity.) The cel at integer coordinates (X,Y) records all particles whose x coordinate is in the range [X,X+1) and y coordinate is in the range [Y,Y+1). So you can think of the cel as a square centred at (X+0.5,Y+0.5). In a sense, this point is where the density is defined. So in the same way that we did texture mapping, you can calculate the density gradient at a point using bilinear interpolation on the four surrounding samples:
So you're using the same number of density samples (four), but you're actually using the four that are closest to the particle this time. This should avoid numeric smoothing. If you're curious and want to get into the vector calculus a bit more, I recommend a tutorial on the MAC grid method. This one looks pretty good. sub f{($f)[email protected]_;print"$f(q{$f});";}f(q{sub f{($f)[email protected]_;print"$f(q{$f});";}f}); 
mgear
m
5 posts

#5038
Particles (episode 156) 3 years ago Edited by m on Oct. 26, 2015, 10:18 p.m.
Ok, it does change a bit, but its getting pushing more to the right at "dDdx * v3(1,0,0)", didnt had the time to check yet why. (and I do suck at math)
I modified these, if sampling should be done on each corner cell from the center?
So the idea would then basically be, taking average direction from those 4 cells and use that as pushing force  or, getting direction towards lowest density from the 4 samples? but will keep testing :) Next trying to add shared grid array, so that multiple particle systems would collide each other.. (in this image they dont yet) 
Pseudonym
Andrew Bromage
184 posts
/ 1 project
Research engineer, resident maths nerd (Erdős number 3). 
#5039
Particles (episode 156) 3 years ago mgear As noted, it's untested code. There's likely to be a bug in it somewhere. mgear The thing to note here is that you're not consulting cel [Y][X], which is the one closest to the particle. sub f{($f)[email protected]_;print"$f(q{$f});";}f(q{sub f{($f)[email protected]_;print"$f(q{$f});";}f}); 