Tuesday, December 10, 2013

Voxel Physics

Voxels are typically associated with creating content. As it turns out, they are quite useful when the time comes for destruction.

Voxels make it easier to break things. Imagine you fire a rocket into a column. You can blast a hole where the rocket hit. Using the column's voxels you could create several fragments of debris. If the column's ability to stand or support other things is compromised, voxels can tell you that. At this point you get even more fragments, which could impact other voxels generating more fragments and so on.

Since you are looking at volumetric data, computing the mass and other dynamic properties of these fragments is much easier. Imagine you have a very irregular shape, made of many different materials. For a proper physics simulation you need to figure out how much the thing weights. This is a trivial process if you are using voxels. Each voxel has a material assigned to it, the material's density tells you how much the voxel weights. The weight of the fragment is the sum of the weight of its voxels. And it is more than that, you can figure out where the mass center is. Imagine a fragment that is half rock, half styrofoam. The object's center of gravity is where the rock is concentrated. The styrofoam adds very little weight.

Here is a video showing a little bit of destruction. This is still in an early stage but hopefully you will get an idea of the potential.


This video was captured on my old PC, with an Intel i5 and an ATI 4770.

60 comments:

  1. Out of the blue... Wow, just wow. Makes total sense, and yet further than my wildest hopes for Voxel Farm. Outstanding!

    ReplyDelete
  2. well, I guess that answers my question! now all you need is for objects to detect stress, and be able to settle / revoxelize, and this will be an amazing 3d scorched earth engine :)

    ReplyDelete
    Replies
    1. Sorry if I'm a bit slow on the uptake, but I take it that once part of the voxel space becomes detached, it gets converted into a mesh and its tumbling/translation is 'physicsed' in the traditional way... Is it beyond the realms of current computing power to maintain the detached object as voxels and rotate/translate it without converting to a mesh?

      Delete
    2. John Gill, you can use separate voxel-space instead of polygon mesh, but it almost the same thing, so there are no point.

      What you want to do is mathematically impossible without losing information about object. Because of aliasing or something like that.

      Delete
  3. And people told me it was impossible.

    ReplyDelete
  4. All this voxel building and destroying makes me think about conservation of mass and how it is totally violated here.

    ReplyDelete
    Replies
    1. It is not violated. The mass leaks into another universe.

      Delete
    2. What a funny universe would it be.

      Delete
    3. But, mass isn't conserved, it can be turned into energy =D, the question is, where does the energy go? Well, the energy creates a miniature, perfectly calibrated wormhole, which sends then energy away to the edge of the universe, where it gathers until it has enough energy, to pierce the side of the universe and create a new big bang =D. (This is what nobody actually believes)

      Delete
    4. considering we are only able to convert a minute amount of mass directly into energy through fusion / fission, and this is small fist size chunks, there must be some massive nuclear scale energy releases every time you "destroy" a cube.

      Delete
    5. Hence why it creates a wormhole and dissapears, rather than creating an actual hole the size of London each time you remove a block =P. Also, with fusion and fission you're not even turning the entire mass into energy, I believe you do that with a matter-antimatter reaction, now THAT is a bang =D.

      Delete
  5. Very nice!

    How big objects can the engine detect as detached?

    ReplyDelete
    Replies
    1. I was thinking of when you cut of a large terrain feature so it becomes a floater and should be turned into a separate mesh. You would have to keep some kind of graph of connected volumes?

      Delete
    2. So could you cut off the Golem at the ankles and it would *not* fall?

      Delete
    3. The Golem falls when you cut both ankles.

      Delete
    4. So... how big IS the voxel size again?

      Delete
    5. But the golem is bigger than 30 CM it it not? Hell, the head is bigger than 30 CMx30CMx30CM, (Or about that big), so then how does that work?

      Delete
    6. I would imagine it iterates through the voxel tree when triggered by editing, and, when discovering that it does not connect to the base terrain, copies those voxels to the new object and removes them from static space.

      Delete
    7. Miguel means that smallest detachable object is about voxel size, not largest... I can picture how perfectly this physics could affect performance. Imagine the giant fall down the cliff shattering into small pieces, them into even smaller and so on... :D Or siply building a lot of detachable parts.

      Delete
  6. What happened to the voxel chunks you cut off that went rolling downhill? I mean, if they get too far away do they disappear? Or freeze in place until the player gets back in range? Or do you create a process for them to keep updating them as long as they have velocity? So many questions.

    So much awesome.

    Get back to water, man! Get back to water!

    :P

    ReplyDelete
    Replies
    1. I think this might be an intermediate step towards water, to create *Dramatic pause* PHYSICS WATER!

      Delete
  7. Wow, that looks incredible.
    I konw this is an early stage, but how far does the physics go or is going to be? Does it only apply on objects floating in the air or does it also work on stability of the objects, like they fall over if there is too much weight on one side or collapse if the base is not stable enough etc.

    ReplyDelete
    Replies
    1. It seems, judging by how the head of the Golem moved, that as long as it is not connected to the world/a big enough object, full physics are applied to it, in other words, if bits are heavier, they'll fall down. It would be nice to see a bi-material object fall though, just to see how it works.

      Delete
  8. Wow. To be honest I wasn't really hoping for believable physics and now this; it already looks good at this early stage of development, I can only barely imagine the variety of emergent gameplay this will create considering what people did with cubic voxels with barely any physics worth mentioning.

    Now I really want to know what you're gonna do with fluid masses.

    ReplyDelete
  9. So how is this witchcraft working? Do you have dynamic voxels? Or is this a polygonal representation? Can you blow a chunk out of a tumbling item? Also, if you make a chain of connected loops, does the computation bog down? How long of a chain can you make?

    ReplyDelete
    Replies
    1. You can keep the voxels if you like. There is a mesh envelope that is fed to the physics solver. If you shoot some bits off the tumbling voxels you contour again and obtain a new mesh.

      I did not try a large chain yet. Good suggestion.

      Delete
    2. What do you mean by envelope? is it accurate to the mesh or just wrapping it? Don't know if you're willing to answer how you did this part, but would really like to know for a research project I'm working on.

      Delete
  10. how does it come that you every time implement the things i just dream of?

    first time i was dissapointed by Minecraft's limitness... bam VoxelFarm
    then there were the missing water, i hoped for it, now you begun with it

    and yet physics.
    i nearly given up in search for a voxel engine with physics and tought about kickstarting my own, too bad i have no clue of actual coding, only coarse ideas

    you are again one step closer to a real Matrix! :D


    -TC


    ReplyDelete
  11. So how long until I can drive my voxel monster truck over a voxel stream full of voxel fish and then crash into a voxel tree hard enough that said tree falls over and my voxel air bags deploy before I am eaten by a voxel bear while wandering lost through the voxel wilderness trying to get my voxel gps to work?

    ReplyDelete
    Replies
    1. Don't forget that the terrain deforms as said voxel monster truck rips up the soil.

      Delete
  12. Chopping down trees should be fun if you have zoxel physics. May I recommend that axes have the effect of adding a heavy, 1 or 0 hit point invisible mass to the other side of the tree or just above the first cut so there is some control where it falls. Dropping a tree on a dozen goblins is so satisfying. A placeable gadget that turns off physics with in an area would help also. I may re post on the EQL forum too.

    ReplyDelete
    Replies
    1. Imagine having voxel stress! When the tree falls over, branches will snap/bend under the weight of the tree.

      Delete
    2. Actually, you don't need to add artificial mass to things, just cut in a wedge-shape, which is also what lumberjacks do, then once you remove the last connection, it'll drop down a bit, and it SHOULD fall in the direction of the wedge =P.

      Delete
    3. this ist not so perfect. it should fall before you cut the last bit! in that moment, where the remaining structure cant hold the physical forces

      -TC

      Delete
    4. I was just saying how it would work in the current system =P. I don't know what Miguel has going on his in brilliant brain, and thus will only say thing based on what he did and said =P.

      Ofcourse stress-physics would be awesome, as it would prevent silly constructions that under no circumstance should be able to stand =P. Unless you make a "Ignore stress physics" tool, for the cases when people DO want to make silly and stupid things =D.

      Delete
    5. I sort of imagine the way converting stuff into a separate physics shape would be something like a separate octree where a voxel cloud expanding over time (small time frame), and after it reaches a certain state it could start to preform actions. Example, High force saved in the tension would make a diffrence operation.
      Which would if an axe laid out an tensions with an volume, the tension would first do an instant removing of the "Axes cut" then it would trigger a tension that could make the small area remaining in the tree break. resulting in making it fall and so on,
      A tension could be a really small octree containing a general variables for example, external force, temperature and so on.
      I tried something like this some years ago but with a grid, I just had a small selection for active Actions, and a background world checker for example world temperature, gravity pull.

      Delete
    6. Or use CA methods to add force vectors that carry through voxels to create a map of stress, and break voxels with a stress calculated to be higher than the given material allows.

      I imagine the axe hitting the wood could be made to not simply carve the voxels in the shape of its path but rather increase the density and compression attributes of the surrounding voxels to represent the fact that an axe, as a wedge, actually compresses the material around it. If friction is implemented correctly, this could even simulate the very real annoyance of having one's axe become stuck in the wood, for better or for worse. Possibly as a disincentive for players always using excessive force!

      Delete
  13. I hope one of the companies that licences your technology is Team17, so they can do a proper 3d worms game. One where you can take damage from both weapons, and the collapsing terrain.

    ReplyDelete
    Replies
    1. Yes! yes! yes! yes! yes!

      Delete
    2. Or imagine a dragon ball rpg with an infinite destructible open world.

      Delete
  14. This is an awesome feature to watch in action. Keep up the good work!

    ReplyDelete
  15. Show us some water physics! :D

    ReplyDelete
  16. Until now, there is any way to make a cut, but not complete, that compromise the integrity of an structure?

    ReplyDelete
  17. Is gravity simply a downward force or is there anyway to create actual attractors? Astronomical n-body sims use a "force tree" called PKDGrav http://www.star.bris.ac.uk/stefan/pkdgrav.html

    I'm just wondering how VoxelFarm would function in a space environment. Is "No Man's Sky" using VF by any chance?

    ReplyDelete
    Replies
    1. Defining gravity (or even lack of it) is up to the application. So yes, you could have the gravity field change depending on world position and other factors.

      No Man's Sky is not using Voxel Farm.

      Delete
  18. Have you implemented your own physics engine or is it an already existing one?

    ReplyDelete
    Replies
    1. In part yes, in part no. There are things like simulating moving solids we can offload to a traditional physics engine like Bullet or PhysX. There are other things that need to happen at the voxel level, for these there is not much out there we can leverage so we have to come up with our own solutions.

      Delete
    2. Can you explain little bit more in detail how do you split voxels to solids?

      Delete
    3. You can think of it as a flood-fill. Imagine you drop some dye in a few places you know they are supported, like the ground itself. Whatever gets colored by the dye is connected and thus supported, the sections that did not get any dye can be considered as floating in air.

      Delete
  19. Soft bodies? https://research.ncl.ac.uk/game/research/publications/Real-Time%20Deformable%20Soft-Body%20Simulation.pdf

    Do it. I believe in you Peter Pan.

    ReplyDelete
  20. This definitely screams potential, but I noticed that when the mesh finally gets cut off from the main object, the UVs seem to change.

    Is this because it's using some kind of generated texture coordinates based on the object dimension? You've probably thought of all this, but a possible solution would be to use global coordinates, ignoring the object scale and dimensions.

    This would mean all rocks have the same texture density no matter how large they are, but create obvious repeating textures. It seems you've fixed this issue in other areas like the ground since previous videos, but to avoid it more just create multiple layers of increasing texture size, so that when one texture is repeating, a larger one creates the variance.

    I guess another option would be to somehow transfer the texture coordinates to the broken geometry, but I have a feeling this might not work in real-time.

    ReplyDelete
    Replies
    1. If you used a global coordinate system, wouldn't the texture slide across the broken off geometry?

      Delete
    2. The voxels that break off get their own coordinate system. If UV is derived from that, like it is for this particular renderer which uses triplanar mapping, you can make it so the new system is initially aligned with the original system. Any further rotation and translation of the object will modify its coordinate system so the texturing stays in place.

      In this video you see a jump because I did not spend time making sure the new system aligned properly with the original one.

      Delete
  21. This http://www.youtube.com/watch?v=asxD8DYfGS8
    + Voxelfarm would be just glorius

    ReplyDelete