SHP Fluid particles for Blitz3D

Blitz3D Forums/Blitz3D Userlibs/SHP Fluid particles for Blitz3D

ZJP(Posted 2010) [#1]
Hi,

W.I.P for Blitz3D

]


JP


Oiduts Studios(Posted 2010) [#2]
Sweet mama flapjacks, where can I receive the power to do this?


GIB3D(Posted 2010) [#3]
Sour papa slaphacks, you must give us this ability!


Xors Team(Posted 2010) [#4]
Hmm.. maybe SPH (Smoothed-particle hydrodynamics)?
Any statistics about the calculation time?


puki(Posted 2010) [#5]
I took one look at that and thought of oranges - now I have a craving to eat an orange - I cannot fulfill the craving though.


GIB3D(Posted 2010) [#6]
If it used meta-balls that would be awesome.


ZJP(Posted 2010) [#7]
Hmm.. maybe SPH (Smoothed-particle hydrodynamics)?

Yes. SPH. Sorry i can't edit the post title


@Puki
Lol. There is a "magical" key : 'C' ;)

@GIB3D. Yes but...Any Blitz source for?

It's not optimised yet and i'm working on a Cuda version.

JP


_PJ_(Posted 2010) [#8]
Wow!
Looks really, impressive, but I'm guessing there's a lotta processing involved.
How's it coming along, what kinda levels of 'intensiveness' is it at the mo, and where do you hope to get it down too?


ZJP(Posted 2010) [#9]
Hi,

I'm not a specialist. I'm try to translate the stuff of the Dr Rama HOETZLEIN in a sort of "general customizable DLL". Not really easy. Even with these mails ;)

Jp

PS :
To the webmaster :
Can you change "SHP" to "SPH" in the title please?


GIB3D(Posted 2010) [#10]
There's a meta ball thread around here somewhere.. I'll go find it.

Edit:
Here it is http://blitzbasic.com/Community/posts.php?topic=89213#1013027




Blitzplotter(Posted 2010) [#11]
Sweet mother of a lurvly thing. That looks good! Gawd I'm glad I'm over my animating a clucking train in (aaargh) 2D for my studies.....


Oiduts Studios(Posted 2010) [#12]
Metaballs would be REALLY impressive with this but the code posted above is pretty slow even when you mess with the threshold, around 10 balls and it gets slow on my computer. Anyone tried to optimize it yet?


Rroff(Posted 2010) [#13]
Make sure you have debug off - I can get upto 60 balls before performance seriously starts to drop off with my 3.825gig Q9550, with debug on it hits about 400ms.


ZJP(Posted 2010) [#14]
Hi,

For now, the demos are hard-coded into the DLL. Next step: Setting the parameters (from Blitz3d) for building your own scenes;)

Post your config and FPS please.

JP


_PJ_(Posted 2010) [#15]
Im pretty sure my GPU isn't CUDA capable,
Anywho...

ATI HD4350 (1Gb)
3.0GHz Athlon quad-core
Windows XP (SP3)
4Gb RAM (of which 3.2 G accessible)

I got quite a varied fps display, between 26 up to 50 with a modal value around 30 (capped at 60)


ZJP(Posted 2010) [#16]
Btw, the B3d source. ;)
For CUDA, replace
Fluid_Init with Fluid_CUDA_Init
Fluid_SetPart with Fluid_CUDA_SetPart etc... See the .DECLS

JP

AppTitle "FluidSHP (c) 2010 ZJP. test solo"

Const RRED   = 16
Const RGREEN = 8
Const RBLUE  = 0	

Global PartMax%=4000

Graphics3D 800,600,32,2
SetBuffer BackBuffer() 
AmbientLight 200,200,200

demo%=7

camera=CreateCamera()
CameraClsColor camera,0,0,250
PositionEntity camera, 0,50,-50
RotateEntity camera,45,0,0

Global FPS_TimeTarget
Global FPS_Count
Global FPS_FPS

Global posx# = 0
Global posy# = 0
Global posz# = 0

light=CreateLight() 
RotateEntity light,90,0,0 

Dim Part(PartMax%)

Fluid_Init(PartMax)

Particule = CreateSphere(3) 
ScaleEntity  Particule,1.4,1.4,1.4
EntityFX particule,17 ; or ???

For i=0 To PartMax%-1
	Part(i) = CopyEntity(Particule)
	Fluid_SetPart(i,Part(i)); Need the entity pointer.
Next

Fluid_Demo(demo)

While Not KeyDown( 1 ) 

	If KeyHit(32) Then
		demo%=demo%+1
		If demo%>10 Then demo%=0
		Fluid_Demo(demo)
	EndIf
	
	
	If KeyDown(205 ) Then posx= 1 : Fluid_POS(posx#,posy#,posz#)
	If KeyDown(203 ) Then posx=-1 : Fluid_POS(posx#,posy#,posz#)

	If KeyDown(200 ) Then posy= 1 : Fluid_POS(posx#,posy#,posz#)
	If KeyDown(208 ) Then posy=-1 : Fluid_POS(posx#,posy#,posz#)

	If KeyDown(201 ) Then posz= 1 : Fluid_POS(posx#,posy#,posz#)
	If KeyDown(209 ) Then posz=-1 : Fluid_POS(posx#,posy#,posz#)

	Fluid_Run ; Compute and move DIRECTLY the entitys. Peek/poke ;) ;)

	; Color Get. Loose 10fps only. 
	For i=0 To PartMax%-1
		co=Fluid_GetColor(i)
		EntityColor Part(i),RColor(co,RRED  ),RColor(co,RGREEN ),RColor(co,RBLUE )
	Next 

	RenderWorld 
	;Cls

	Text 10,10,"[D] next demo. Arrows move emitter"
	Text 10,30,FPS_Get%()

	Flip 0
Wend 

End 

Function FPS_Get%()	
	If MilliSecs() < FPS_TimeTarget Then
		FPS_Count	= FPS_Count + 1
	Else
		FPS_TimeTarget	= MilliSecs() + 1000
		FPS_FPS		= FPS_Count
		FPS_Count	= 0
	EndIf
	Return FPS_FPS
End Function

Function RColor%(c%,d%) ; thx Nilium
	Return c Shr d And 255 Shl 0
End Function



Jiffy(Posted 2010) [#17]
I don't understand. What would be the point of this 'source'? to re-skin the hard-coded demo in the dll?
You've released so much neat code before I'm wondering who hacked your account and posted this. Keep it secret, or not- this 'in-between thing' is not exactly useful. I guess 'thanks' just the same.

This based off FLUIDS v.2?

Just wondering as I'm impressed how well it converted- though how much you did outside of blitz would be interesting to know.


puki(Posted 2010) [#18]
He's French - you get used to them doing stuff 'arse about face'.


ZJP(Posted 2010) [#19]
For now, the demos are hard-coded into the DLL. Next step: Setting the parameters (from Blitz3d) for building your own scenes;)

This is a w.i.p projet. :)


I'm wondering who hacked your account and posted this....

It's me :)


This based off FLUIDS v.2?

Yes. FluidS V2 by Dr Rama Hoetzlein.
This is one mail i'm sending to him
Hello Mr. Hoetzlein.     


I made a DLL from your source fluids V2 (here: http://forum.unity3d.com/viewtopic.php?t=46371)
 and I must confess that I NOT understand this part ...etc etc..


Response

Hi Jean-Pierre,

You call this function, CreateExample, with a number indicating which
demo to run. Each case sets up a particular demo by setting simulation
paramers.

The example you want to try, with the hole, is case #8.. You can cycle
through each demo using the '[' and ']' keys.. Notice that the boundary
conditions are hard-coded into the simulator, so you can't currently set
up arbitrary scenes and collision. Here is the line below thats important:
  m_Toggle [ DRAIN_BARRIER ] = true;
This tells the simulator to turn on a horizontal plane boundary with a
hole in it.. Sorry i dont have an documentation yet. The other
parameters adjust different aspects of the simulation.

Hope this helps,
-Rama






..how much you did outside of blitz would be interesting to know...

a) Send the entity pointer to the Dll with these lines
For i=0 To PartMax%-1
	Part(i) = CopyEntity(Particule)
	Fluid_SetPart(i,Part(i)); The DLL need the entity pointer.
Next

b)
Update the blitz3D entity position with these lines
	buf = Entity[n] + 64; // Blit3D Entity PosX
	pos = p->pos.x; // Fluid particle PosX
	(*(float *)(buf) = (pos)); // poke float

	buf = Entity[n] + 68; //  Blit3D Entity PosY
	pos = p->pos.z; // Y and Z inversed !!!!
	(*(float *)(buf) = (pos));

	buf = Entity[n] + 72; // Blit3D Entity PosZ
	pos = p->pos.y;
	(*(float *)(buf) = (pos));

	buf = Entity[n] + 44; // Valid the move. Blitz3D stuff
	(*(int *)(buf) = (3)); // poke int




He's French - you get used to them doing stuff 'arse about face'.

Indee (Teal'c)

JP


Jiffy(Posted 2010) [#20]
Ah, Ok. Sounds good- was just wondering, as it didn't seem your usual 'style'.
(nod)


ZJP(Posted 2010) [#21]
;)


Oiduts Studios(Posted 2010) [#22]
I love this thing. I kind of messed around with it.



GIB3D(Posted 2010) [#23]
Looks like it's a Waterverse or Water Galaxy.


ZJP(Posted 2010) [#24]
Nice BM ;)

New version. ALL others version are removed. Sorry.
+++++++++++++++++++++++++++++++++++++++++++++++
http://www.zinfo972.net/avatar/FluidB3D_DLL.ZIP
+++++++++++++++++++++++++++++++++++++++++++++++
Parameterizing scenes possible. (W.I.P)

I renamed the DLL, because there will be 3 basic versions :

1) A Blitz3D version (FluidSHP_B3D.dll) that alters directly the positions of Blitz3D entities

2) A Unity3D version (FluidSHP_UNI.dll) that alters directly the positions of Unity3D's particles

2) A general version (FluidSHP.dll) for all other engine. The position of the particles can be set with a sort of
        For i = 0 To MaxPart
            Particle(i).PosX = FluidSHP_GetX(i)
            Particle(i).PosY = FluidSHP_GetY(i)
            Particle(i).PosZ = FluidSHP_GetZ(i)
        Next

I am also working on a CUDA version. The performance will by 60% ;)

JP



AppTitle "FluidSHP B3D no CUDA version"

Const RRED   = 16 ; Global for the Nilium color routine ;)
Const RGREEN = 8
Const RBLUE  = 0	

Global PartMax% = 5000 ; 100 to 10000

Graphics3D 800,600,32,2
SetBuffer BackBuffer() 

camera = CreateCamera()
CameraClsColor camera, 0,0,200
PositionEntity camera, 0,70,-35
RotateEntity   camera, 45,0,0

Global FPS_TimeTarget ; Global for FPS routine
Global FPS_Count
Global FPS_FPS

Global posx# = 0 ; global for emitter
Global posy# = 0
Global posz# = 0

Dim Part(PartMax%)

FluidB3D_Init(PartMax) ; Init the engine

cube=CreateCube()
ScaleEntity    cube,1,20,1
; Particle. sphere or other. Quad?!?
Particule = CreateSphere(2) 
PositionEntity Particule,0,0,0
ScaleEntity    Particule,1.6,1.6,1.6 
MoveEntity     Particule,1000,1000,1000

EntityFX particule,1

; For the B3D Dll version. Need the handle for each particle. The Dll can move directly the B3D entity. ;)
For i=0 To PartMax%-1
	Part(i) = CopyEntity(Particule)
	FluidB3D_SetPart(i,Part(i))
Next
;create scene parameter. W.I.P!!!!!
Const SPH_RESET        = 0 ; IMPORTANT. FIRST PARAMETER !!!!!
Const SPH_READY        = 100 ; IMPORTANT. LAST PARAMETER !!!!!
Const SPH_VOLMIN       = 1
Const SPH_VOLMAX       = 2
Const SPH_INITMIN      = 3
Const SPH_INITMAX      = 4
Const FORCE_XMIN_SIN   = 5
Const BOUND_ZMIN_SLOPE = 6
Const PLANE_GRAV_DIR   = 7
Const FORCE_XMAX_SIN   = 8
Const EMIT_POS         = 9
Const EMIT_RATE        = 10
Const EMIT_ANG         = 11
Const WALL_BARRIER     = 13
Const WRAP_X           = 14

; Wave pool scene
;FluidB3D_Scene(SPH_RESET        ,   0,  0,   0) ; Reset the scene
;FluidB3D_Scene(SPH_VOLMIN       , -30,  0, -40) ; boundary of the scene X Y Z
;FluidB3D_Scene(SPH_VOLMAX       ,  40, 40,  40)
;FluidB3D_Scene(SPH_INITMIN      , -30, 10, -36) ; boundary of the "init drop flow"
;FluidB3D_Scene(SPH_INITMAX      ,  30, 40,  36)
;FluidB3D_Scene(FORCE_XMIN_SIN   ,   8,  0,   0) ; Force apply to -X
;FluidB3D_Scene(BOUND_ZMIN_SLOPE ,   0.03,  0,   0) ; Plane Inclination
;FluidB3D_Scene(PLANE_GRAV_DIR   ,   0,-9.8,   0) ; Gravity X Y Z
;FluidB3D_Scene(SPH_READY        ,   0,  0,   0) ; Scene is ready


;Dam break scene
;FluidB3D_Scene(SPH_RESET        ,   0,   0,   0) ; Reset the scene
;FluidB3D_Scene(SPH_VOLMIN       , -30,   0, -14)
;FluidB3D_Scene(SPH_VOLMAX       ,  30,  60,  14)
;FluidB3D_Scene(SPH_INITMIN      ,   0,   0, -13)
;FluidB3D_Scene(SPH_INITMAX      ,  29,  30,  13)
;FluidB3D_Scene(PLANE_GRAV_DIR   ,   0,-9.8,   0) ; Gravity X Y Z
;FluidB3D_Scene(SPH_READY        ,   0,   0,   0) ; Scene is ready


; Dual Wave pool scene
;FluidB3D_Scene(SPH_RESET        ,   0,   0,  0) ; Reset the scene
;FluidB3D_Scene(SPH_VOLMIN       , -60,   0, -5)
;FluidB3D_Scene(SPH_VOLMAX       ,  60,  50,  5)
;FluidB3D_Scene(SPH_INITMIN      , -46,   0, -5)
;FluidB3D_Scene(SPH_INITMAX      ,  46,  15,  5)
;FluidB3D_Scene(FORCE_XMIN_SIN   ,   8,   0,  0) ; Force apply to -X
;FluidB3D_Scene(FORCE_XMAX_SIN   ,  15,   0,  0) ; Force apply to X
;FluidB3D_Scene(PLANE_GRAV_DIR   ,   0,-9.8,  0)
;FluidB3D_Scene(SPH_READY        ,   0,   0,  0) ; Scene is ready


; Swirl Stream
;FluidB3D_Scene(SPH_RESET        ,   0,   0,   0) ; Reset the scene
;FluidB3D_Scene(SPH_VOLMIN       , -30,   0, -30)
;FluidB3D_Scene(SPH_VOLMAX       ,  30,  50,  30)
;FluidB3D_Scene(SPH_INITMIN      , -30,   0, -30)
;FluidB3D_Scene(SPH_INITMAX      ,  30,  40,  30)
;FluidB3D_Scene(EMIT_POS         ,   -10,  10,   0) ; Flow emitter POS
;FluidB3D_Scene(EMIT_RATE        ,   1,   0,   5) ; Freq,,Nb Stream
;FluidB3D_Scene(EMIT_ANG         ,   0,   2, 120) ; Emit Angle
;FluidB3D_Scene(PLANE_GRAV_DIR   ,   0,-9.8,   0)
;FluidB3D_Scene(SPH_READY        ,   0,   0,   0) ; Scene is ready

; Shockwave not finish yet !!!!
FluidB3D_Scene(SPH_RESET        ,   0,   0,   0) ; Reset the scene
FluidB3D_Scene(SPH_VOLMIN       , -60,   0, -15)
FluidB3D_Scene(SPH_VOLMAX       ,  60,  50,  15)
FluidB3D_Scene(SPH_INITMIN      , -59,   0, -14)
FluidB3D_Scene(SPH_INITMAX      ,  59,  30,  14)
FluidB3D_Scene(WALL_BARRIER    ,   1,   0,   0)
FluidB3D_Scene(WRAP_X           ,   1,   8,   0) ; Left Wrap and 
FluidB3D_Scene(PLANE_GRAV_DIR   ,   0,-9.8,   0)
FluidB3D_Scene(SPH_READY        ,   0,   0,   0) ; Scene is ready

FluidB3D_SetColorMode(1); Color of the particle. 0 = Pressure, other = Velocity

While Not KeyDown( 1 ) 

	If KeyDown(205 ) Then posx= 1 : FluidB3D_POS(posx#,posy#,posz#)
	If KeyDown(203 ) Then posx=-1 : FluidB3D_POS(posx#,posy#,posz#)

	If KeyDown(200 ) Then posy= 1 : FluidB3D_POS(posx#,posy#,posz#)
	If KeyDown(208 ) Then posy=-1 : FluidB3D_POS(posx#,posy#,posz#)

	If KeyDown(201 ) Then posz= 1 : FluidB3D_POS(posx#,posy#,posz#)
	If KeyDown(209 ) Then posz=-1 : FluidB3D_POS(posx#,posy#,posz#)
	If KeyDown(57) Then FluidB3D_Scene(PLANE_GRAV_DIR ,0,0,0)

	FluidB3D_Run ; Advance the calcul and PositionEntity by the Dll.

	; Get color
	For i=0 To PartMax%-1
		co=FluidB3D_GetColor(i) ; Get color of each particle. 
		EntityColor Part(i),RColor(co,RRED  ),RColor(co,RGREEN ),RColor(co,RBLUE )
	Next 

	RenderWorld 
	;Cls
	Text 10,10,"Fps  : "+FPS_Get%()
	Text 10,30,"Tris : "+TrisRendered()
	Flip 0
Wend 

End 
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function FPS_Get%()	
	If MilliSecs() < FPS_TimeTarget Then
		FPS_Count	= FPS_Count + 1
	Else
		FPS_TimeTarget	= MilliSecs() + 1000
		FPS_FPS		= FPS_Count
		FPS_Count	= 0
	EndIf
	Return FPS_FPS
End Function
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++
; Nilium Function color
Function RColor%(c%,d%)
	Return (c Shr d And 255 Shl 0)
End Function
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++



Noobody(Posted 2010) [#25]
Metaballs would be REALLY impressive with this but the code posted above is pretty slow even when you mess with the threshold

As Ross C already pointed out, Debug mode has to be disabled. But still, metaballs are clearly not an option for 3D SPH. There are simply too many particles to polygonize. As I stated in the other thread, I never really intended the metaballs code for real-time use, rather than for a fancy little demo.

As for rendering, I'd recommend a point splatting approach. It *should* still look nice while computational overhead is kept minimal. The only problem is that the particles have to be sorted back-to-front, and I'm not sure if there are algorithms out there capable of doing that in realtime. But I guess it's worth a shot :)