I was leaning towards this approach anyway - Erin mentioned it early in the thread, and my own experiments in this area lead me to similar conclusions. To hear you talk about using sensors in this way just adds weight to it.
Much as I think the TestBed is a great way to show off a bunch of the capabilities of Box2D, I don't think how it renders should ever be a consideration as to whether to try something or not. The debug rendering is about the most naive way it's possible to use OpenGL, and whilst it makes for simple debugging code, any rendering engine worth its salt has more sophisticated optimisations. So yes, slow debug drawing of sensors is not a problem, in my opinion.
This is a really interesting topic I want to look into in more detail later. Although the solid-core particles aren't "correct" in terms of modelling the interaction between fluids and solids, I haven't yet found a better way to do it. The SPH article in Game Programming Gems 6 states that between fluids and static objects, the static object should just exert a big enough force along its collision normal to push the particle back out (which I'm pretty sure is exactly what Box2D does anyway). For collision with dynamic rigid body objects it seems to advocate an approach based on what looks like Verlet integration - which is obviously never going to work with Box2D, since it users Euler. I currently have no better answer for this than to do exactly what your code is doing now.
I know you can make the numbers bigger to cope with the number of pairs, but I wonder if doing so is an unwarranted waste of CPU cycles and/or memory, if we don't care about pairs for fluid/fluid interactions. That's why I'm wondering if they can be turned off, but to my mind that's the only special change that should need to happen in the engine (and, arguably, the engine should work that way anyway).
I suppose this is the argument for keeping the pairs in. Processing things pair-by-pair seems like an easy way to halve (or nearly halve) the processing time involved. Perhaps this is the solution, then? To accept the consequences of having to tune the maximum number of pairs to be very high, in order to then use those pairs to resolve SPH in a more efficient way? If that seems like a reasonable trade-off (as I say, I still don't know enough about the internals to know whether or not it is), then we've got the ability to do full, fast SPH without having to change a single line of Box2D.
I'd love to hear Erin's thoughts on this. As I say, I'm quite happy to try making adjustments to the engine if they're needed, but if it turns out that the best solution is to leave everything as it is, then that's great - I'll get right on it and see what the results are.
Quote:
1) With the JBox2d testbed's software renderer, it's way too expensive to draw all the sensors (like, 10 fps vs. 50 fps expensive)....
Much as I think the TestBed is a great way to show off a bunch of the capabilities of Box2D, I don't think how it renders should ever be a consideration as to whether to try something or not. The debug rendering is about the most naive way it's possible to use OpenGL, and whilst it makes for simple debugging code, any rendering engine worth its salt has more sophisticated optimisations. So yes, slow debug drawing of sensors is not a problem, in my opinion.
Quote:
2) Fluid-solid interactions need to be handled properly if the particles don't have solid cores.
This is a really interesting topic I want to look into in more detail later. Although the solid-core particles aren't "correct" in terms of modelling the interaction between fluids and solids, I haven't yet found a better way to do it. The SPH article in Game Programming Gems 6 states that between fluids and static objects, the static object should just exert a big enough force along its collision normal to push the particle back out (which I'm pretty sure is exactly what Box2D does anyway). For collision with dynamic rigid body objects it seems to advocate an approach based on what looks like Verlet integration - which is obviously never going to work with Box2D, since it users Euler. I currently have no better answer for this than to do exactly what your code is doing now.
Quote:
3) There are a lot of pairs, so the maxPairs setting needs to be set pretty high (not a problem at all).
I know you can make the numbers bigger to cope with the number of pairs, but I wonder if doing so is an unwarranted waste of CPU cycles and/or memory, if we don't care about pairs for fluid/fluid interactions. That's why I'm wondering if they can be turned off, but to my mind that's the only special change that should need to happen in the engine (and, arguably, the engine should work that way anyway).
Quote:
What you'd do is just make the sensors have half the size of the neighborhood that you're looking at. Storing some of the SPH fields on each particle might help, too, as the pressure calculation step could then proceed pair-by-pair instead of particle-by-particle (which doubles the number of operations, hitting each pair twice).
I suppose this is the argument for keeping the pairs in. Processing things pair-by-pair seems like an easy way to halve (or nearly halve) the processing time involved. Perhaps this is the solution, then? To accept the consequences of having to tune the maximum number of pairs to be very high, in order to then use those pairs to resolve SPH in a more efficient way? If that seems like a reasonable trade-off (as I say, I still don't know enough about the internals to know whether or not it is), then we've got the ability to do full, fast SPH without having to change a single line of Box2D.
I'd love to hear Erin's thoughts on this. As I say, I'm quite happy to try making adjustments to the engine if they're needed, but if it turns out that the best solution is to leave everything as it is, then that's great - I'll get right on it and see what the results are.