50,000 particles possible?

Blitz3D Forums/Blitz3D Beginners Area/50,000 particles possible?

VP(Posted 2005) [#1]
I think I might be falling at the first hurdle when it comes to writing my Spheres of Chaos clone.

SoC chucks over 100K particles around the screen at about 20fps (estimated) and isn't really breaking a sweat.

If I use WritePixelFast I can also chuck around over 100K pixels without slowdown (admiteddly, I have a fast PC, but I was aiming for about 50K, not 100K).

I don't want 1 pixel particles though, I want something a little larger that will show up far better at high resolution. I'm aiming for the game to scale up to 1920x1080 for use on very expensive HDTV displays.

I've tried 2D images and 3D sprites and I max out at somewhere between 2000 and 3000 particles, and this is before any game logic is in there.

Does anyone know of a method I could use to accelerate things?


Ross C(Posted 2005) [#2]
100,000 particles on screen on a 2D screen is over kill tbh... Writing that much data to the screen is going to be slow...


VP(Posted 2005) [#3]
Sure is overkill :) Can do some pretty pschedelic stuff though.

No doubt, I will come up with something.


Wayne(Posted 2005) [#4]
I'd think single surface triangles be your best bet.

I create this crazy example to display alot of sprites:




LineOf7s(Posted 2005) [#5]
Way back when, Beaker did a 'Spheres Of Blitz' thing just to show that conceptually a Spheres of Chaos clone done in Blitz (I think it was even plain ole 2D Blitz) wasn't quite as impossible as some people had been claiming at the time (to do with the inability to use 8-bit palletised colour etc etc).

If I had issues with making a Spheres of Chaos clone in Blitz, he'd be the first person I'd try to contact. He may have an email address in his profile (I haven't looked), but he's usually lurking around in #blitzbasic on irc.blitzed.org


VP(Posted 2005) [#6]
Thanks guys. I'm really starting to like this Blitz community :)


VP(Posted 2005) [#7]
I've tried the sprites thing and it was only as fast as using images in 2D mode.

To get 2x2 pixels I could just use repetitions of WritePixelFast and I would end up being able to render about 12.5K particles on a high-end system. I just feel that this isn't the way to go though.

throwing pixels around in the screen in a predetermined way should be something that would not tax a modern CPU (or display device) too much.

I might have to really delve deep and make an external DLL (not that I know C++ on the PC, yet).

Emulating SoC's unique colouring system should not be too difficult either. Use a 16-bit display and apply a filter every fram that darkens and then lightens the whole screen. This should effectively remove an adjustable amount of colour data and make the gfx card's dithering more pronounced. Assuming that the gfx card renders at 16-bit internally ;)


Ross C(Posted 2005) [#8]
In blitz, throughing around pixels is pretty slow though. Single surface particles would work though. i can get about 10,000 of them running on my system. 50,000 is really pushing it though. In fact, you wouldn't get 50,000 on a single surface because of the DX vertex limit. I also don't see plotting 2x2.

Here's a rough example: press escape to bring up the fps

Const gh = 600
Graphics gw,gh
SetBuffer BackBuffer()


Global frames = 0
Global fps = 0
Global timer = MilliSecs()
Global number = 1
Global size = 1
Global fps_update# = 1000

.start_point
Cls
Flip

number = Input("number of particles: ")
size = Input("size: ")

While Not KeyHit(1)

	Cls

	For loop = 1 To number
		Rect Rand(gw),Rand(gh),size,size
		Color Rand(0,255),Rand(0,255),Rand(0,255)
	Next
	
	frames = frames + 1
	If MilliSecs() - timer > fps_update Then
		fps = frames
		frames = 0
		timer = MilliSecs()
	End If
	
	Flip 0
	
Wend

Cls
Color 255,255,255
Text 0,0,"Fps = "+fps
Text 0,10," press SPACE bar to re-run, or ESCAPE to end"
Flip

While Not KeyHit(57)


	If KeyHit(1) Then End
	
Wend
Goto start_point



Who was John Galt?(Posted 2005) [#9]
Spheres of Chaos - love that game!

SoC only uses 8 bit gfx - I assume you're using 32 so you're pushing 4x as much data just to plot pixels. You could maybe do some tricks if you can live with only updating the position of half the particles each frame - or you could plot your pixels at quarter resolution on a textured quad and stretch it to fit the screen. Not ideal solutions, but possibilities.


Wayne(Posted 2005) [#10]
10k Sprites
Try this code I robbed from Rob.
Replace fire1.png with your own png.




VP(Posted 2005) [#11]
@Nomen luni:

50k pixels are only going to load the bus with 16MB/s of data (a bare minimum, I admit). Even weak systems (like my P3-750 laptop) should be able to handle that kind of load. SoC's frame rate is reasonably low, but it still manages over 100k pixels. They may be 8-bit, but I was under the impression that 32 (and 64-bit) CPU's handled 8-bit data at the same, or slower speed as 32-bit data?

Where things fall down for my project are with B3D's compilation adding a fair amount of overhead. I am far more bound by CPU power than bus bandwidth or gfx card capability.

I've dug up this... http://www.blitzbasic.com/codearcs/codearcs.php?code=1104#comments which speeds things up a fair amount. Works wonderfully for the single-pixel problem.

Asking a high-end PC to render 50K particles 85 times a second is reasonable.

The perfect outcome for my project would be to dynamically scale the number of particles depending on available horsepower (or configurable by the user). This will happen eventually.

@Wayne:

That code is pretty damn fast! I will probably end up going with a solution like that just to bring SoC into the 21st century (i.e. not using the CPU to do all the graphical stuff).


All,

It seems that the only proper way of doing this would be to go down the C++ route, which I'm not really prepared to do right now. I know far too little about C++ on the PC to attempt it.

If someone in the UK has a C++ (dealing with Visual C++ and OpenGL) book they no longer need, I'll trade you a beer for it ;)


P.S. A kludge has just occurred to me. Perhaps using a number of sprites where 1 sprite loops a small animation of 4 particles... Wouldn't be graphically 'perfect' but with a lot going on, it might just pass inspection. Hmm. One for the weekend I think (back to work tomorrow, then it's Liverpool V Chelsea, so I'll get nothing done!).


Who was John Galt?(Posted 2005) [#12]
vinylpusher-

I can't see 8 bit data being slower - at worst it would be the same but DX probably ships it over in 32 bit chunks anyway. I used to have 'Windows games programming for Dummies' by Andre Lamothe - I got it because I read something by the guy behind SoC and he said he learned Windows programming from it and used some of the routines in there as a base to develop on. It's DX rather than OGL based stuff. I took a look at the demos that came with the book, realised I could write better stuff in Blitz (and easier) and didn't bother with it.


big10p(Posted 2005) [#13]
I've just had a look at the PC demo of SoC to get an idea of what you're after. Wow, it really does have tons of particles. Too many for my liking - I couldn't even see what was going on, half the time. :P

However, SoC does seem to be using a feedback effect on the particle layer to make it seem like there are more particles on-screen than there actually are.

You could probably simulate this effect in one of the blitz languages well enough to get the appearance of loads of particles, but still probably not quite as many as SoC is using.


VP(Posted 2005) [#14]
@nomen luni:

I've got an OpenGL book from that same series. Frankly, it scares me but I did pick it up last night for a bit of bedtime reading ;)

I had a quick blast with my '4 particles to one sprite' idea last night also, it looked reasonable. Got a bit of a feedback effect going and it really did look a bit crazy =)

@big10p:

The feedback effect is just a slow fade-to-black type of effect. Nothing that can't be kludged with an alpha blend :)