Single surface particles

Blitz3D Forums/Blitz3D Programming/Single surface particles

Ross C(Posted 2003) [#1]
Hey ppl! I've just finished this single surface stuff (still needs some stuff done to it tho). I know this is posted in the advanced 3d forum (prob the wrong place to post it). Well here's the code. No image files needed.

Please try this and give me your opinions/suggestions for making it faster if possible :) And could you also tell me what fps you get on the default seetings. Press the one key to generate lots more particles.

Thank you if you respond! This code *should* run at least 5 or 6 times quicker than a sprite based particle system

[EDIT, PARTICLES ONLY UPDATE ONCE EVERY FIVE FRAMES, SHOULD PROVIDE A BIG SPEED UP]
Graphics3D 800,600
SetBuffer BackBuffer()

cam=CreatePivot()

camera=CreateCamera(cam)
PositionEntity camera,0,0,-30

mesh=CreateMesh()

surface=CreateSurface(mesh)

NUM_PARTICLES=60

switch=0


Type s_part
	Field x#,y#,z#; central position for the quad
	Field index; index for the first vertex
	Field ang#; ang value. -45 for normal
	Field alpha#
	Field speed#
	Field time
	Field timer
	Field ang_speed#
	Field active
	Field pindex
End Type

g_time=1
g_timer=MilliSecs()

cpx#=0
cpy#=0
cyz#=0

ang=-45
index=0

v0=AddVertex(surface,cpx+Sin(ang),cpy+Cos(ang),cpz,0,1)
v1=AddVertex(surface,cpx+Sin(ang+90),cpy+Cos(ang+90),cpz,1,1)
v2=AddVertex(surface,cpx+Sin(ang-90),cpy+Cos(ang-90),cpz,0,0)
v3=AddVertex(surface,cpx+Sin(ang+180),cpy+Cos(ang+180),cpz,1,0)


tri=AddTriangle(surface,v0,v1,v2)
tri1=AddTriangle(surface,v1,v3,v2)


tex=CreateTexture(128,128,2)
SetBuffer TextureBuffer(tex)
Color 200,100,50
Oval 20,20,87,87
SetBuffer BackBuffer()


EntityTexture mesh,tex
EntityFX mesh,32+2
EntityBlend mesh,3

VertexColor surface,0,200,200,200;,0.8
VertexColor surface,1,200,200,200;,0
VertexColor surface,2,200,200,200;,0
VertexColor surface,3,200,200,200;,0

For loop=0 To NUM_PARTICLES
	Gosub create_spart
Next


While Not KeyHit(1)
	
	;TranslateEntity mesh,0,0.01,0,True
	TurnEntity mesh,0,0,1
	
	cx=EntityPitch(camera,True)
	cy=EntityYaw(camera,True)
	cz=0
	
	If MouseDown(1) Then ang=ang+1:Gosub rotatequad
	If MouseDown(2) Then ang=ang-1:Gosub rotatequad
	If KeyDown(203) Then cpx=cpx-0.1:Gosub rotatequad
	If KeyDown(205) Then cpx=cpx+0.1:Gosub rotatequad
	If KeyDown(200) Then cpy=cpy+0.1:Gosub rotatequad
	If KeyDown(208) Then cpy=cpy-0.1:Gosub rotatequad
	If KeyDown(2) Then Gosub create_spart
	
	If MilliSecs()>g_time+g_timer Then
										g_timer=MilliSecs()
										Gosub new_spart
	End If
	
	RotateEntity mesh,cx,cy,cz
	
	If MilliSecs()<timer+1000 Then
								frame=frame+1
	Else
								fps=frame
								frame=0
								timer=MilliSecs()
	End If
	
	Gosub update_spart
	UpdateWorld
	RenderWorld
	Text 0,0," Number of quads="+(index/4)+" fps="+fps+" trirednered="+TrisRendered()
	Flip 0
Wend
End

.rotatequad
VertexCoords(surface,0,cpx+Sin(ang),cpy+Cos(ang),cpz)
VertexCoords(surface,1,cpx+Sin(ang+90),cpy+Cos(ang+90),cpz)
VertexCoords(surface,2,cpx+Sin(ang-90),cpy+Cos(ang-90),cpz)
VertexCoords(surface,3,cpx+Sin(ang+180),cpy+Cos(ang+180),cpz)
Return

.create_spart
	p.s_part=New s_part
	p\pindex=index
	index=index+4
	p\x=Rnd(-2,2)
	p\y=0;Rnd(-4,4)
	p\z=Rnd(-2,2)
	p\speed=Rnd(0.01,0.1)
	p\time=Int(Rnd(500,2000))
	p\ang_speed=Rnd(0.1,2)
	p\ang=Rnd(-45,135)	
	v0=AddVertex(surface,p\x+Sin(p\ang),p\y+Cos(p\ang),p\z,0,1)
	v1=AddVertex(surface,p\x+Sin(p\ang+90),p\y+Cos(p\ang+90),p\z,1,1)
	v2=AddVertex(surface,p\x+Sin(p\ang-90),p\y+Cos(p\ang-90),p\z,0,0)
	v3=AddVertex(surface,p\x+Sin(p\ang+180),p\y+Cos(p\ang+180),p\z,1,0)
	tri=AddTriangle(surface,v0,v1,v2)
	tri1=AddTriangle(surface,v1,v3,v2)
Return

.update_spart
	switch=switch+1
	If switch>5 Then switch=0
	If switch=0 Then
		For p.s_part=Each s_part
			If p\active=1 Then
				p\y=p\y+p\speed
				p\ang=p\ang+p\ang_speed
				VertexCoords(surface,p\pindex+0,p\x+Sin(p\ang),p\y+Cos(p\ang),p\z)
				VertexCoords(surface,p\pindex+1,p\x+Sin(p\ang+90),p\y+Cos(p\ang+90),p\z)
				VertexCoords(surface,p\pindex+2,p\x+Sin(p\ang-90),p\y+Cos(p\ang-90),p\z)
				VertexCoords(surface,p\pindex+3,p\x+Sin(p\ang+180),p\y+Cos(p\ang+180),p\z)
				If MilliSecs()>p\time+p\timer Then
												p\active=0
												VertexColor surface,p\pindex+0,200,200,200,0
												VertexColor surface,p\pindex+1,200,200,200,0
												VertexColor surface,p\pindex+2,200,200,200,0
												VertexColor surface,p\pindex+3,200,200,200,0
				End If
			End If
		Next
	End If
Return

.new_spart
	loop_exit=0
	For p.s_part=Each s_part
		If p\active=0 Then
			VertexColor surface,p\pindex+0,200,200,200,1
			VertexColor surface,p\pindex+1,200,200,200,1
			VertexColor surface,p\pindex+2,200,200,200,1
			VertexColor surface,p\pindex+3,200,200,200,1
			p\active=1
			p\y=0
			p\speed=Rnd(0.01,0.1)
			p\timer=MilliSecs()
			p\time=Int(Rnd(500,2000))
			p\ang_speed=Rnd(0.01,0.3)
			p\ang=Rnd(-45,135)
			p\x=Rnd(-2,2)
			p\z=Rnd(-2,2)
			loop_exit=1
			VertexCoords(surface,p\pindex+0,p\x+Sin(p\ang),p\y+Cos(p\ang),p\z)
			VertexCoords(surface,p\pindex+1,p\x+Sin(p\ang+90),p\y+Cos(p\ang+90),p\z)
			VertexCoords(surface,p\pindex+2,p\x+Sin(p\ang-90),p\y+Cos(p\ang-90),p\z)
			VertexCoords(surface,p\pindex+3,p\x+Sin(p\ang+180),p\y+Cos(p\ang+180),p\z)
		End If
		If loop_exit=1 Then Exit
	Next
Return


And use this for anything you want to.
:D


sigi(Posted 2003) [#2]
Hi,
930 fps with my Ati 9500 Pro and 600 fps with debug on.

P4 2GH
512 DDR Ram


Ross C(Posted 2003) [#3]
Cool, thanks, plz keep em coming :)


AbbaRue(Posted 2003) [#4]
I get 620 fps with debug enabled.
And 760 fps with debug disabled.
Puzzled how sigi is getting over 900 fps.
I'm using radeon 9800. Should be at least as fast
as a 9500 pro. Do I need to change some video card settings?


Tom(Posted 2003) [#5]
32bit mode:
650 normal, 650 debug

16bit mode:
1350 normal, 1350 debug

Odd :)

Tom
AMD XP 2ghz, 512meg, GF4 Ti4200 with softquadro4 patch


Ross C(Posted 2003) [#6]
apologies to you Abbarue, i changes the code so you didn't need a media file, because ppl could use a different sized texture which would affect results. I first put in a 256x256 texture, then changed it to 128x128, after you have done the test. Sorry bout that!!


Perturbatio(Posted 2003) [#7]
@16 bpp :
DEBUG ON: 612 fps
DEBUG OFF: 2053 fps

@32bpp
DEBUG ON: 602 fps
DEBUG OFF: 1170 fps


Extron(Posted 2003) [#8]
16 bit
DEBUG ON: Min 1210 Max 1257
DEBUG OFF: Min 2188 Max 2205

32 bit
DEBUG ON: Min 1209 Max 1272
DEBUG OFF: Min 2188 Max 2282

No great difference for me between the 2 mode. :)

---------------------------------------------------------
P4 3.06 hyperthreading / GeForce FX5900 128Mo / Ram 1 Go DDR400


Ross C(Posted 2003) [#9]
that's some system you got :)


Ice9(Posted 2003) [#10]
@16 bpp :
DEBUG ON: 696 fps
DEBUG OFF: 2552 fps

@32bpp
DEBUG ON: 696 fps
DEBUG OFF: 1230 fps

XP2500 512M Ti4400 128M


Ross C(Posted 2003) [#11]
Cool, thanks for taking the time to test this. Very helpful. Is there anyone tho, who isn't using a newish graphics card? Like say a gf2 or earlier sort of card? Could any of those ppl give this a whirl?


Extron(Posted 2003) [#12]
Sorry! :)
Windows Xp pro Sp1 DX9.0b


Gjeret(Posted 2003) [#13]
860ish --32 bit
850ish --16 bit

2.2 Intel 756 MB of ram WunXP Pro DX9a GeForce FX 5600 (256mb, non-ultra)

19 --32 bit
19 -- 16 bit

Mobile AMD 1500+ 512 total ram 480MB of System Ram S3 Graphics Twister K + S3 hotkey 32MB (Shared with System) DX9a

-Gj-


Gjeret(Posted 2003) [#14]
And Wife's Box...

250 for both 16 and 32 bit

AMD XP 1700 256MB ram XP SP1 DX9a...
GeForce2 MX 64MB

And it looked Really goofy on a Flat Panel Display (words were under the flames...)


podperson(Posted 2003) [#15]
1200-1400 fps on my FX 5600 Ultra.
780 fps (windowed) in debug mode.


Tranz(Posted 2003) [#16]
"Is there anyone tho, who isn't using a newish graphics card? Like say a gf2 or earlier sort of card? Could any of those ppl give this a whirl? "

I tried it on an old 633mhz Celeron with 64megs of RAM and a GF2...it ran at 150 FPS.


smilertoo(Posted 2003) [#17]
on the default settings (32bit) i get 1900fps with debug off and 1160 with debug on.


Ross C(Posted 2003) [#18]
mmmm, interesting results. Seems processor speed mean squat. Tried running it on the college computers (2.4 ghz, 256 Mb ram, onboard graphics) and the results were about 100 fps :S

I don't see how many more corners i can cut with this. I suppose only using a triangle instead of a quad may boost the speed of it.


19 --32 bit
19 -- 16 bit

Mobile AMD 1500+ 512 total ram 480MB of System Ram S3 Graphics Twister K + S3 hotkey 32MB (Shared with System) DX9a


Thats sorta sucks. Have you tried running any 3d games on that laptop?

And thank you all for sparing a few moments to test this!


Gjeret(Posted 2003) [#19]
/quote
mmmm, interesting results. Seems processor speed mean squat. Tried running it on the college computers (2.4 ghz, 256 Mb ram, onboard graphics) and the results were about 100 fps :S

I don't see how many more corners i can cut with this. I suppose only using a triangle instead of a quad may boost the speed of it.



19 --32 bit
19 -- 16 bit

Mobile AMD 1500+ 512 total ram 480MB of System Ram S3 Graphics Twister K + S3 hotkey 32MB (Shared with System) DX9a



Thats sorta sucks. Have you tried running any 3d games on that laptop?

And thank you all for sparing a few moments to test this!
quote\

Yeah.. The laptop's video kinda... sucks... I could play (reasonablly well) UT2 Demo, it was getting mid 30fps for that program...

Morrowind would NOT play on it... (10 min just to bring up the menu to close the program) so I'm thinking it's a problem with the graphic card. Havn't played too many other 3d games on it (AoE II is 2D I'm pretty sure)


Rob(Posted 2003) [#20]
I don't see how many more corners i can cut with this. I suppose only using a triangle instead of a quad may boost the speed of it.

Wrong. It increases the fillrate as you need to have a much larger surface area in order to correctly display a texture.

To speed it up, try ignoring rotations behind the camera and other simple tricks.


Gjeret(Posted 2003) [#21]
Ok.. looks Vid Card related, Just compiled, tossed it up to an empty new server I'm building and ran it...

27-28 FPS

PowerEdge 400SC,2.4GHZ/512K Cache, P4, 800FSB
1256MB DDR, ECC, 333MHz, 2X128MB, 2X512 PowerEdge 400SC
40GB, 1 inch IDE Hard Drive for PowerEdge 400SC
IDE RAID CONTROLLER, ATA100 / 4Channel for the PowerEdge 400SC
Windows 2000 Server
C6, Add-in RAID Card for RAID 1 Level,Configuration

Graphic Card is Rage XL PCI 8 MB

More Food for thought :P


Ross C(Posted 2003) [#22]
Cheers for them tips Rob, appreciated :o)

@Gjeret, thanks again m8 for testing this on another computer, Defintely to many stuff going on for older cards to run properly. I'll be back with some more optimised stuff :)


Ross C(Posted 2003) [#23]
Updated the test. Please try the test again. This time there are 600 quads, but the code is only updated once every 5 frames.


Gjeret(Posted 2003) [#24]
uh... sorry nope...

Same PowerEdge Server...

9 FPS :(


Ross C(Posted 2003) [#25]
This time? i've updated it again :)


Caff(Posted 2003) [#26]
455 average

P700, 256mb Ram, 64mb Geforce3 3dBlaster, Win2k


Gjeret(Posted 2003) [#27]
My laptop's framerate has increased to 21 FPS...

I'll check my Server when I make it to work tommorow!


Ross C(Posted 2003) [#28]
Right, thanks alot Gjeret for all your help testing this. Put a wee mention in for ya :)


Extron(Posted 2003) [#29]
16 bit
DEBUG ON: Min 1574 Max 1614
DEBUG OFF: Min 2452 Max 2557

32 bit
DEBUG ON: Min 1577 Max 1606
DEBUG OFF: Min 2471 Max 2560

300 fps better than the previous test. :)

---------------------------------------------------------
P4 3.06 hyperthreading / GeForce FX5900 128Mo / Ram 1 Go DDR400 Windows Xp pro Sp1 DX9.0b


Ross C(Posted 2003) [#30]
good stuff, good to know the changes are effecting other computers. :)


Gjeret(Posted 2003) [#31]
Ok.. Sorry for the Delay...

the PowerEdge Server...

52 FPS... I'd say Big Improvement!


Ross C(Posted 2003) [#32]
Good stuff! Only problem being that this is only the particles running. When i add in level geometry and gameplay code, god knows what the end FPS result will be.

Again, thanks for your testing :D