Author Topic: Fluid preview  (Read 3178 times)

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7715
    • View Profile
Fluid preview
« on: July 09, 2013, 04:32:02 AM »
It's been about 5 years since I started serious work on DB3.  I currently have about 100K lines of code and not a great deal to show for it...  nevertheless, to mark the anniversary I've decided to release one of the more graphic experiments I've been toying around with.

The attached EXE is the test application I've been using to test fluid.  It has a spinning square that moves back and forth, and little particles (circles) that react to the fluid-like forces that the box imparts on the surrounding fluid.  There are 1000 particles and 24 'panels' (which are the cyan/yellow rectangles on the brown square around the edges.  They're all that the fluid simulation actually knows about).

You can use left click+drag to move the camera around.  The mouse wheel will zoom in and out. 

There are three buttons to control the speed of the simulation.  Pause is obvious, 'single step' will take a single simulation step forward in time.  'Frame lock' will cap the frame rate at 60 FPS.  If you uncheck that box, it will go as fast as your computer is able.  The 'reset' button on the bottom will warp everything back to the starting positions.

The core simulation is running single threaded, but the UI and graphics are all on separate threads, which is something that's important to me for DB3 so I've been experimenting with how it'll work.  At the moment it's kind of hacked in there, but it works.

For the record, this is against revision 953 in the SVN repository.

...

Also, be sure that you've downloaded and installed the latest DirectX runtime: DX Runtime.  It needs to be at least June 2010.
« Last Edit: July 16, 2013, 12:49:08 AM by Numsgil »

Offline Ammeh

  • Queen of the Internets
  • Bot Destroyer
  • ***
  • Posts: 169
    • View Profile
Re: Fluid preview
« Reply #1 on: July 09, 2013, 07:27:35 AM »
:(
Code: [Select]
Unhandled Exception: System.Reflection.TargetInvocationException: Exception has
been thrown by the target of an invocation. ---> SharpDX.SharpDXException: d3dco
mpiler_43.dll
   at SharpDX.Utilities.LoadLibrary(String dllName)
   at SharpDX.D3DCompiler.D3D.get_DllHandle0()
   at SharpDX.D3DCompiler.D3D.get_D3DPreprocess_()
   at SharpDX.D3DCompiler.D3D.Preprocess(IntPtr srcDataRef, PointerSize srcDataS
ize, String sourceNameRef, ShaderMacro[] definesRef, IntPtr includeRef, Blob& co
deTextOut, Blob& errorMsgsOut)
   at SharpDX.D3DCompiler.ShaderBytecode.Preprocess(IntPtr shaderSourcePtr, Int3
2 shaderSourceLength, ShaderMacro[] defines, Include include, String& compilatio
nErrors)
   at SharpDX.D3DCompiler.ShaderBytecode.Preprocess(String shaderSource, ShaderM
acro[] defines, Include include, String& compilationErrors)
   at Blacklight.SharpDX9.Module..ctor()
   --- End of inner exception stack trace ---
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOn
ly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Bo
olean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipChec
kThis, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean s
kipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at ModuleManager.ModuleManager`1.GetModule(String moduleName)
   at Slipstream.Testbed.Program.Main(String[] args)

Offline rwill128

  • Bot Builder
  • **
  • Posts: 67
    • View Profile
Re: Fluid preview
« Reply #2 on: July 09, 2013, 12:26:29 PM »
Same as Ammeh. :(

Offline Pascal666

  • Bot Neophyte
  • *
  • Posts: 25
    • View Profile
Re: Fluid preview
« Reply #3 on: July 09, 2013, 01:17:43 PM »
It works here, but shouldn't there be more velocity added to the surrounding particles?
Like this: http://nerget.com/fluidSim/

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7715
    • View Profile
Re: Fluid preview
« Reply #4 on: July 09, 2013, 04:46:05 PM »
:(
Code: [Select]
Unhandled Exception: System.Reflection.TargetInvocationException: Exception has
been thrown by the target of an invocation. ---> SharpDX.SharpDXException: d3dco
mpiler_43.dll
   at SharpDX.Utilities.LoadLibrary(String dllName)
   at SharpDX.D3DCompiler.D3D.get_DllHandle0()
   at SharpDX.D3DCompiler.D3D.get_D3DPreprocess_()
   at SharpDX.D3DCompiler.D3D.Preprocess(IntPtr srcDataRef, PointerSize srcDataS
ize, String sourceNameRef, ShaderMacro[] definesRef, IntPtr includeRef, Blob& co
deTextOut, Blob& errorMsgsOut)
   at SharpDX.D3DCompiler.ShaderBytecode.Preprocess(IntPtr shaderSourcePtr, Int3
2 shaderSourceLength, ShaderMacro[] defines, Include include, String& compilatio
nErrors)
   at SharpDX.D3DCompiler.ShaderBytecode.Preprocess(String shaderSource, ShaderM
acro[] defines, Include include, String& compilationErrors)
   at Blacklight.SharpDX9.Module..ctor()
   --- End of inner exception stack trace ---
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOn
ly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Bo
olean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipChec
kThis, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean s
kipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at ModuleManager.ModuleManager`1.GetModule(String moduleName)
   at Slipstream.Testbed.Program.Main(String[] args)

That would be the video card shader issue I mentioned.  Your video card isn't new enough :/  When I have some spare energy I'll make the shader simpler, but I'm not sure when I'll get around to it.

...
Quote
It works here, but shouldn't there be more velocity added to the surrounding particles?

The fluid sim in that link is a "Velocity based Eulerian grid".  Mine is a "Vorticity based Lagrangian particle" sim.  Which is a fancy way of saying they work differently, at a very fundamental level, even though they're both trying to simulate the same thing.

For mine, there's no increased cost or decreased fidelity as the sim gets bigger (spatially).  The particles you see are purely for visual effect and don't change the behavior of the underlying fluid at all.  The behavior of the fluid is only influenced by the 24 panels you see on the square, which themselves can only attract or repel particles (imagine the panels are bar magnets, and the particles are iron flakes).  It actually shares a lot in common with N-body gravity sims like this.

The downside is that you don't get any of the inertia you get from a normal grid sim.  Once the body stops moving through the fluid, all the particles stop moving instantaneously.  It's possible to add in fake, invisible bodies to the sim whose job is to keep the intertia of the sim going, but they're expensive, so I might just ignore them entirely.  The fluid ends up behaving a little oddly, but it's really really fast.  In the final DB3, the cost would scale only with the number of bots, which is my primary goal.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7715
    • View Profile
Re: Fluid preview
« Reply #5 on: July 16, 2013, 12:53:21 AM »
Okay, I "fixed" the graphics problem.  Turns out, at least on my laptop, I just had to install the June 2010 DirectX runtime.

You can check if you have it or not by seeing if there's a d3dcompiler_43.dll in C:\windows\system32.  If not... you need to install the runtime.

I checked out the shader, and I think even in its present shape it should work on 99% of people's machines, so if anyone has a problem after this let me know. :D

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
    • DJ Paul Kononov
Re: Fluid preview
« Reply #6 on: July 21, 2013, 04:01:57 PM »
oh great, I just downloaded the DX runtime patch and have like 50 library to install. I got to run, I guess I'll end up checking it out next Saturday.



It is cool the way you organize your code into .dll files. Does using a dynamic link vs having the code in the .exe have any impact on performance?

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7715
    • View Profile
Re: Fluid preview
« Reply #7 on: July 21, 2013, 04:24:21 PM »
Quote
It is cool the way you organize your code into .dll files. Does using a dynamic link vs having the code in the .exe have any impact on performance?

No, all the executable code has to get copied to main memory anyway, so whether it comes from one file or a dozen there's no difference.  At the extreme, if every class had its own DLL the startup time would be a bit slower, since all the DLLs have to be opened, and opening a huge number of files at once can take a while.

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
    • DJ Paul Kononov
Re: Fluid preview
« Reply #8 on: July 27, 2013, 01:50:41 PM »
Hey Numsgil, I got a chance to figure out how to update DirectX but it still not working.

Here is a picture with as much information as I can figure out how to give you.

thx.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7715
    • View Profile
Re: Fluid preview
« Reply #9 on: July 27, 2013, 04:08:47 PM »
You have to tell windows that this is a trusted executable.  When you download the zip, right click on it and go to properties.  At the bottom there's an "unblock" button.  You'll need to click that.

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
    • DJ Paul Kononov
Re: Fluid preview
« Reply #10 on: July 29, 2013, 09:17:29 AM »
I got it to work :) It is pretty cool as a demo of concept. Needs a hell more work though, I can not even instruct the box to move a certain way. It is just scanning the screen horizontally.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7715
    • View Profile
Re: Fluid preview
« Reply #11 on: July 29, 2013, 05:04:59 PM »
Yes, still a lot more work to do.  It's mostly a proof of concept that I can simulate reasonable looking fluid fast enough to be practical for Darwinbots.  Things like multibots swimming using frog kicks.

It's also the first practical example of the graphics engine I'm building.  If you notice you can zoom in and out arbitrarily deep and it doesn't look pixelated.

Offline Botsareus

  • Society makes it all backwards - there is a good reason for that
  • Bot God
  • *****
  • Posts: 4483
    • View Profile
    • DJ Paul Kononov
Re: Fluid preview
« Reply #12 on: July 31, 2013, 11:30:28 AM »
Yes, that was awsome

Offline Ammeh

  • Queen of the Internets
  • Bot Destroyer
  • ***
  • Posts: 169
    • View Profile
Re: Fluid preview
« Reply #13 on: August 02, 2013, 06:27:09 PM »
Works perfectly on my laptop (Lenovo Z580), btw :)

Offline Peter

  • Bot God
  • *****
  • Posts: 1177
    • View Profile
Re: Fluid preview
« Reply #14 on: August 05, 2013, 03:46:03 PM »
It works!

It tries to connect with 224.0.0.22, is there a reason why it does that?
Oh my god, who the hell cares.