Darwinbots Forum

Code center => Darwinbots3 => Topic started by: Numsgil on July 09, 2013, 04:32:02 AM

Title: Fluid preview
Post by: Numsgil 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 (http://www.microsoft.com/en-us/download/details.aspx?id=8109).  It needs to be at least June 2010.
Title: Re: Fluid preview
Post by: Ammeh 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)
Title: Re: Fluid preview
Post by: rwill128 on July 09, 2013, 12:26:29 PM
Same as Ammeh. :(
Title: Re: Fluid preview
Post by: Pascal666 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/
Title: Re: Fluid preview
Post by: Numsgil 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 (http://www.youtube.com/watch?v=byI9yhITDsM).

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.
Title: Re: Fluid preview
Post by: Numsgil 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
Title: Re: Fluid preview
Post by: Botsareus 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?
Title: Re: Fluid preview
Post by: Numsgil 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.
Title: Re: Fluid preview
Post by: Botsareus 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.
Title: Re: Fluid preview
Post by: Numsgil 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.
Title: Re: Fluid preview
Post by: Botsareus 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.
Title: Re: Fluid preview
Post by: Numsgil 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.
Title: Re: Fluid preview
Post by: Botsareus on July 31, 2013, 11:30:28 AM
Yes, that was awsome
Title: Re: Fluid preview
Post by: Ammeh on August 02, 2013, 06:27:09 PM
Works perfectly on my laptop (Lenovo Z580), btw :)
Title: Re: Fluid preview
Post by: Peter 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?
Title: Re: Fluid preview
Post by: Numsgil on August 05, 2013, 05:40:05 PM
No idea; I haven't seen that before.  There's no networking code anywhere in the current codebase.
Title: Re: Fluid preview
Post by: Peter on August 05, 2013, 07:24:02 PM
After looking into it, it appears to be a bug (http://forums.comodo.com/firewall-help-cis/igmp-alerts-after-upgrading-to-512-t88184.0.html) in the firewall. Amazing to get a bug like that into it.
Title: Re: Fluid preview
Post by: rwill128 on January 21, 2014, 02:33:53 PM
I just tried the demo because I finally had a computer with a newer graphics card to try it on, and I got this error.
Title: Re: Fluid preview
Post by: Botsareus on January 21, 2014, 03:02:00 PM
rwill128:

Quote
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.
Title: Re: Fluid preview
Post by: Peter on January 21, 2014, 05:19:38 PM
If only windows would show it's blocking something...
Title: Re: Fluid preview
Post by: Numsgil on January 21, 2014, 11:51:33 PM
If I make any future previews I'm going to try and figure out how to package it better :/
Title: Re: Fluid preview
Post by: Botsareus on January 22, 2014, 12:23:23 PM
What are you working on now?
Title: Re: Fluid preview
Post by: Numsgil on January 22, 2014, 12:55:38 PM
Physics engine.  I've got collision detection working minus edge cases, and I'm speccing out the math for the constraint solver.