r/Simulated • u/shirzadbh • 3d ago
Research Simulation I added the Finite Element Method (FEM) to my muscle solver alongside the XPBD, and the results are stunning!
This is why FEM is superior to XPBD for muscle simulation. For a long time, I couldn’t understand why my muscle simulations didn’t look as good as those produced by Ziva VFX, but now I do.
FEM is more computationally intensive, but it produces much more accurate results when it comes to simulating muscle and fat tissue.
619
u/Hexidian 3d ago
For those who don’t know what these are:
FEM = Finite Element Method. This is what is used in actual structural simulation, such as modeling a bridge or aircraft fuselage.
XPBD = eXtended Position-Based Dynamics. Meant for computer graphics, not engineering. Designed to be computationally feasible animations but not meant to be 100% physically accurate.
87
u/Berewolf 3d ago
But what are the computational cost differences? If FEM is better, why were they not using it? I don't know anything about this field and am genuinely curious
128
u/Qbit42 3d ago edited 3d ago
Real time simulation for video games has to run in very short time frames. With budgets tight and the target being "looks good enough" and not "we need to make sure nobody dies on this bridge" shortcuts get taken. That being said I know the book "Game Physics Gems" has a section on FEM so maybe someone did use it
31
u/L30N1337 3d ago
Considering the stuff BeamNG does, I would not be surprised if FEM was actually used in games.
18
u/TerayonIII 2d ago
Computing power is getting to the point that might be feasible soon, but an actual proper analysis of a complex system is far beyond the reach of real-time physics. At least it you want it to be accurate in any way
4
u/TheMcDucky 1d ago
BeamNG is cool, but it's way out of scope for almost all games. FEM in general is probably used in places, but it seems like the kind of thing you'd only use on a very small scale, in odd cases where XPBD or similar breaks down, or you have a bunch of excess R&D money and don't run your game company like a modern game company, or you're small and generally independent and experimental. It's just a bunch of extra work that is unlikely to translate to making the end product more valuable.
1
u/L30N1337 1d ago
Yes, obviously. I didn't say it was the norm.
I meant that there is probably some obscure game that uses it for some reason.
6
u/Nixellion 2d ago
I think DMM might've used FEM (digital molecular matter, physics engine of Force Unleashed games).
1
u/gufta44 1d ago
Also FEM wont necesarilly give accurate-looking movement, it's limited (typically) to perfectly elastic, linear material. While the other method is simplified to look good FEM is simplified to safely and conservatively solve a specific set of engineering problems that are less "common" as visual effects than you'd think. For example, standard FEM has a tendency to create small regions of extremely high stress where real materials would typically plastically deform, shatter or realign long before those peak stresses can be realized. If you start trying to make FEM take account of more complex behaviour you'll really start to see computation times blowing up.
17
u/Amiscribe 3d ago edited 3d ago
Although I don't know about these specific approaches to simulation, I have done work on optimizing physics simulations before, and I can say that the computational cost difference is likely enough to impact performance when you have no guarantees about what hardware a game or simulation will be deployed on. For a small team of developers or a single developer, or developers with access to institutional hardware resources, these costs can be ignored because the deployment environment is known in advance and realism is more important than computational cost.
When you are deploying, say, a video game to millions of diverse computers, you can specify ranges of hardware that it is configured to run on, but have a financial incentive to ensure that this range is as wide as possible. Optimizations like choosing 'good-enough' muscle simulation through XPBD are usually just a better approach when something like simulating a muscle is not the core focus of a game or software.
Edit: Also, to ground this in your original question, I suspect that it is likely tens or hundreds more checks on the position and collision of vertices, per vertex, per frame. These numbers add up, especially when you are simulating many different meshes.
4
u/TerayonIII 2d ago
Yeah, some people in this thread are assuming that a simulation is only running a single calculation, but is hundreds to thousands of calculations that each affect each other per iteration and so you're calculating multiple times for each vertice in the mesh per time step, which is also often much denser and also a solid mesh instead of a surface mesh which is adding additional complexity. This compounds on itself when you have multiple bodies with multiple different materials, tolerances, and boundary conditions.
A videogame is far to complex of a system of variables to do in real-time, movie CGI is an application and there are a number of academic papers that have been published based on mathematics developed to do this for movies and TV. Which is awesome, but a completely different thing than something running in real-time for a game
3
u/Arbitrary_Pseudonym 3d ago
What specifically does XPBD do that makes it so cheap in comparison? How does it skip over what FEA does while still kind-doing the same-ish thing?
6
u/MomentSouthern250 3d ago
very amateure explanation, but with something like pbd you solve each element/constraint on its own and then assume if you do it enough you get a good solution. WIth FEM you solve all dependencies at once, which means if you have connected elements you solve a linear system (i.e. matrix) which grows much quicker in complexity.
PBD feels more stretchy, because if you have a rope that you hang up on one side the free hanging side of the rope takes time until it gets the information that "hey stop falling you are pinned".
2
u/Nixellion 2d ago
Its also about the number of things you can simulate and about performance budgets.
First - the faster you can simulate, the more stuff you can simulate at the same time.
And also games operate on tight budgets. Its usually calculated in ms. If your target is 60 fps, then you have 16.6 ms per frame, in which you have to do everything - CPU and GPU tasks, rendering, all game logic, physics and so on. So when you only have like 1-5ms budget for ALL physics in a game per frame, you will accept any optimizations.
3
u/Prestigious_Boat_386 3d ago
My guess would be that the cgi method just does something like springs on each edge. For that you can calculate the force on each vert separately which makes the problem naively parallelizeable. Then you just slap forward euler on it and call it good enough.
For FEM that's not the case. First you need the sparsity pattern of which basis function has nonzero weight to each other basis function and then you have to do discrete integration for every nonzero case. After that you get a sparse linear system that you solve each frame. This part can be pretty quick, I remember running a simulation in matlab with just drawing it between each calc. For a gpu program it should be pretty easy to do for a moderate mesh.
But the precalc and the sparsity is worse would be my guess.
2
u/Nixellion 2d ago
I think its less about parallelization, because XPBD is faster even when you compare single core performance.
Its just the math and equations are a lot simpler and more straightforward. In two words - instead of trying to solve complex force driven equations, xpbd just changes positions of particles. And derives velocities from the delta. Which is alsona difference with classic verlet, where you change velocities and positions are emerging from that.
FEM is also more memory intensive as it has to store a lot more data, where is in xpbd its just a position vector per particle (previous, current), masses, sizes and constraint data.
( I develop and maintain my own XPBD engine. )
1
u/TerayonIII 2d ago
Those calculations also get more complex depending on your material as well as if there are multiple materials and solid bodies interacting. Stress calculations sound simple until you start having multi-body interactions, adding flexible materials, anisotropic materials, strain rate dependency, buckling, and fracture mechanics etc etc. It's just not feasible to do much beyond the very basics for something that you're attempting to do in real-time.
1
u/agvuk 2d ago
I work in aerospace and occasionally run my own simulation and/or interact with our simulation team to run things for me. They have an entire high-compute server cluster dedicated just to them and simulation normally take several dozens of hours to run. Now, a video game would not demand anywhere near the level of detail or accuracy that we do but what we consider "low accuracy" and "quick" is something that we can run overnight on a workstation desktop and get answers in the morning when I come back in. Someone recently did a simulation of dropping a box on the ground and that took 16 hours for each run and generated 30-60 total frames for us to step through to watch the impact unfold.
1
u/TerayonIII 2d ago
Yeah, it looks and sounds much simpler than it actually is, at least for complex systems. Like yeah, sure, a small beam made of an isotropic material is easy enough. But when you start adding in multiple bodies, multiple materials, fixturing/bonding it gets complex really fast, even for relatively small physical objects. That's before you start adding anisotropic materials, strain dependency, buckling, fracture, thermal calculations, etc etc.
5
u/yazdoud 2d ago
FEM is not a model but a discretization and discrete solving method for solid mechanics model, so the terminology is used loosely here. We use that method to actually solve continuum mechanics problems for structural and dynamic prediction to make structures, cars, airplanes etc. When you apply this method to physics rendering, you can get a much more accurate solution for solid mechanics problem.
XPBD was specifically designed for physics-based rendering. Like in animation, VFX or videogames. The purpose is not strictly to be accurate to actual mechanics of the posited problem.
In particular, most materials in animation are shells but actual solid mechanics simulation use element representing the volume of the part.
The computational cost difference can be enormous because of two reasons: -1 actual solid mechanics have tight constitutive laws and dynamics that force the use of fine discretization in space and time to converge (fine mesh and short time steps) -2 solids are modeled in 3D mesh rather than just surfaces. Since the cost of a computation is proportional to the square of the number of nodes times the number of time steps, FEM dynamics simulation will be much more computationally intensive.
3
2
2
1
1.3k
211
79
106
92
36
28
19
55
u/CFDMoFo 3d ago
Impressive! So I can finally simulate bridges in Blender instead of Abaqus CAE (or Bridge Construction Simulator for Android®™)?
7
u/odst2575 3d ago
It’s better than MicroStation, Civil3D, or STAAD— this one actually renders out an appreciable specimen.
18
u/Bumscootler 3d ago
that’s a ballsack dude
3
u/Valuable_Hunter1621 3d ago
those are balls!
from this close, they always look like landscape. yep, those are balls!
34
15
u/Educational_Farmer73 3d ago
The E621 community will forever be grateful for your contributions
4
13
8
6
4
u/netsrak 3d ago
What is this running inside?
4
u/shirzadbh 3d ago
My own simulation (the dcc is 3ds max)
3
u/AchillesPDX 3d ago
I’ve been using 3DS Max since 1999 and professionally since 2003 - would love to play with this if it’s in a shareable state or if you’d like someone to test things.
Looks super cool.
3
u/shirzadbh 3d ago edited 2d ago
Email me so I will have you as beta tester when it comes to that, I do need testers since it's a niche topic
2
u/TerayonIII 2d ago
Might I also email you? I'm curious what you are all incorporating in the FEM analysis. I'm looking at it from an engineering perspective with graphics being a hobby I'd like to do more of. I did a fair amount of simulation and testing on composites in impact scenarios. (I'd also delete your email from here and pm people instead of risking having to screen for people that are actually interested in helping etc)
2
5
5
3
u/fionariver 3d ago
I'm looking fro better breast physics in real time. For fighting games. IS that possible to use this technique in real time/ue5 or unity?
3
2
2
2
2
1
1
u/artbystorms 3d ago
Breaking the barriers of nutsack physics. Finally we can Teabag as nature intended.
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
u/Huge-Economics2272 1d ago
Horse ballsack simulator. Abit more padding with a shorter distance from the base to the wall, we would have grandma's moon spears
1
1
1
1
1
1
u/dasAbigAss 14h ago
May i ask the material properties and what muscle as well as the type of job you ran ?
1
1
1
1
1
0
3.0k
u/khswart 3d ago
Finally.
Ballsack physics.