Der Schmale – David Lenaerts’s blog

Flash Platform Experiments

Smoke/fluids simulation using Pixel Bender – part III

Tags: , , , , , , , ,

smoke-v3The third pass at smoke/fluids simulation again looks quite different from the previous two attempts, but this time it’s stable both when keeping still as while moving. Not surprisingly, as the current approach is more like Stam’s fluid solver. The downside is that it’s much less processor-friendly: every new step (adding forces, diffusion, advection, updating boundaries, …) needs the previous step to be completed over the entire velocity or pressure field. As a result, this simulation is using 9 different Pixel Bender kernels. In total, 49 pixel bender filters are executed per frame, some more intense as others, along with some BitmapData methods. Consequently, the grid size needs to be scaled down a lot  (64×128 in the example). All in all, I’m still surprised that it doesn’t slow down to a crawl!

The FluidBitmap class has some properties such as timeStep, buoyancy and viscosity, which can influence the look and tempo of the fluid, but can affect the stability of the solver due to precision errors using BitmapData. There is support for forces, encoded in a BitmapData, similar to the velocity field (red = x, green = y). Maybe some day, I’ll make working with these forces a bit easier, but for now I’ll focus on other things than fluids ;)  

The demo – A smoke simulation using positive buoyancy. Click to show the red and green channels representing the velocity field.

The source

Oh, and a happy new year! :)

Share and Enjoy:
  • Digg
  • TwitThis
  • del.icio.us
  • Facebook
  • Reddit
  • Netvibes
  • Technorati
  • Google

Tags: , , , , , , , ,

18 Responses to “Smoke/fluids simulation using Pixel Bender – part III”


  1. foreground
    on Jan 2nd, 2009
    @ 3:52 pm

    It is interested smoke. It visually more beautiful. But my computer had braked with mouse moving. In Process Explorer FF shows ~30% CPU. I don’t know why slow down had been 8-)


  2. Taha
    on Jan 7th, 2009
    @ 5:48 pm

    Amazing work… but CPU is a lil high


  3. Stephane
    on Jan 9th, 2009
    @ 9:44 am

    Wow David, beautiful looking smoke.


  4. David
    on Jan 9th, 2009
    @ 10:49 am

    Thanks all!

    Foreground: only 30%? That’s quite a surprise, mine is pretty much maxing out!
    Taha: Yeah it’s rather intensive. Tuning down the grid size wouldn’t be a bad idea :)


  5. kevin goldsmith
    on Jan 9th, 2009
    @ 6:56 pm

    this is really impressive!


  6. subblue
    on Jan 9th, 2009
    @ 11:15 pm

    Excellent work – the view all channels mode is visually very interesting.


  7. foreground
    on Jan 10th, 2009
    @ 9:27 am

    I wanted to check again. . but your server got me this:

    response-head: HTTP/1.1 404 Not Found
    Date: Sat, 10 Jan 2009 08:20:48 GMT
    Server: Apache
    X-Powered-By: PHP/5.2.8
    X-Pingback: http://www.derschmale.com/blog/xmlrpc.php
    Expires: Wed, 11 Jan 1984 05:00:00 GMT
    Last-Modified: Sat, 10 Jan 2009 08:20:48 GMT


  8. David
    on Jan 10th, 2009
    @ 2:19 pm

    kevin: thanks! (and thanks for PB in general ;) )
    Subblue: Thx, I thought it’d be interesting to show what’s under the hood; it turned out rather trippy :)
    Foreground: Hmm, guess it was something temporary, it seems to work again.


  9. Druiven
    on Jan 10th, 2009
    @ 3:09 pm

    Great, and feeling like i realy have to dive in pixel bender. CPU of firefox/flash always takes it all


  10. Joe Cutting
    on Jan 13th, 2009
    @ 3:55 pm

    David,
    I can get the demo to work in FireFox. All I get is the “Der Schmale” logo. Works fine in Internet Explorer (6.0)
    I’m using FireFox 3.05 on Windows XP. Flash version 10.0.12.36. I suspect its something to do with the Flash detection you’re using.

    Still once I got it working its a really impressive demo. Well done.

    Cheers

    Joe


  11. David
    on Jan 13th, 2009
    @ 8:39 pm

    Joe: Hmm that’s strange, I have the exact same configuration here. The version detection is straight from what Flex Builder 4.0 builds (tho I have had issues with the Flex 3’s version detection before) :/


  12. Joe Cutting
    on Jan 14th, 2009
    @ 1:37 pm

    David,
    Hmm, works now in FireFox. It prompted me to update my flash player and then updated it again to 10.0.12.36 and now works. I don’t know if you changed anything but many thanks :)

    J


  13. David
    on Jan 15th, 2009
    @ 11:42 am

    Hi Joe,
    Great news! I made a small change, but I didn’t know whether it would fix anything :D


  14. kris
    on Feb 7th, 2009
    @ 1:11 am

    hi there,

    nice way of using pb. have you thought about a addition displacement-like map so the cursor creates turbulences as well?
    just thought of that because that was a damn cool effect in a snow simulation of mine years ago ;D

    cheerio


  15. David
    on Feb 7th, 2009
    @ 9:38 am

    Hi Kris, instead of using a displacement map you could manipulate the force bitmapdata to create windflow caused by your cursor. It could take some effort, but it should have a more realistic impact on the smoke flow tho :)


  16. James
    on Mar 8th, 2009
    @ 8:46 pm

    Anyone know if this could be converted to work in After Effects?


  17. David
    on Mar 9th, 2009
    @ 3:08 pm

    James: I’m not sure about exactly what you can do using Pixel Bender in After Effects, but seeing as there’s quite a bit of Actionscript logic behind the simulation, I fear that a conversion could be quite difficult.


  18. Experimenting with Alchemy: of Smoke, Milk, and Ink | Der Schmale - David Lenaerts's blog
    on Mar 23rd, 2009
    @ 5:06 pm

    [...] below, I decided to try it all in C and see how far Alchemy can be pushed. The grid is bigger than before, while the framerate is steady around 20 on my machine. Ralph has suggested some improvements for [...]

Leave a Reply

© 2009 Der Schmale – David Lenaerts’s blog. All Rights Reserved.

This blog is powered by Wordpress and Magatheme by Bryan Helmig.