Jump to content


Photo

3d Particle System Dll. And It's Pretty Darn Fast!


  • Please log in to reply
120 replies to this topic

#1 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14389 posts
  • Version:GM:Studio

Posted 04 March 2009 - 07:57 AM

Last Update: Jan 03 2012 8:20 PM

GM8.1?? Sorry guys. GM7 AND 8 ONLY

OK, I've finally done it... I converted GM particle system to 3d!!!

3 hard and tedious days of analysing gm's particle system and re-implementing it in 3d right in a dll...

Thanks to X-tra fear and score_under for unlocking GM's functions so they can be used in a dll, I was able to make a particle system that is almost as fast in 3d as the original particle system. Works in 2d too!

**NOTE, Change the room in the GMK to see the right demo (Default is now the Spore Like Galaxy)
400k. (Because of sprites) GM7... You can convert it to gm6 with LGM. GM6er's Notes

vdieo
http://www.youtube.c...h?v=rSCXA992QbU

Download
http://host-a.net/ic...GM3dPartSys.zip

implements:
part_system
part_paticles
part_type
part_emitter
part_destroyer
part_deflector (Needs tweaking)
improves some of the original gm functions

missing
part_changer
part_attractor

Can be used to draw all your 3d models in your game MUCH faster than having a draw event in your 3d object WITHOUT transparency/alpha/interpolation artefacts. A bonuse is you get x,y,z motion, x,y,z gravity, z friction and x,y,z rotation (rot speed) so you may not even need a step event for many of your objects.
Adding more support for this feature.


Posted Image

Posted Image

Updates:

Offset Draw
Faster, gm8 proper support, "Error Defining External Function" problem solved
Better Draw And 4 Effects
Added Emitter system
Model Support and floating point exception fix
Destroyers Added
Now 30% faster, Source Included
Now 25% faster still
More particle options Beyond FOG exclusion, particle cut of and suspend and grouping for effect you dont want the CPU to calculate all the time and effect can be totaly ignored when not visible
Minor improvement on last update
More Features and Fix... Friction Added and access to particle data

My HUD don't draw!!!

Edited by icuurd12b42, 04 January 2012 - 01:23 AM.

  • 0

#2 uuf6429

uuf6429

    Covac Software

  • New Member
  • 2522 posts

Posted 04 March 2009 - 11:05 AM

I'm impressed.
  • 0

#3 TheMagicNumber

TheMagicNumber

    GMC Member

  • GMC Member
  • 5247 posts
  • Version:Unknown

Posted 04 March 2009 - 11:53 AM

If it works good on my computer, then there is a massive speed improvement. Even if you used a "hack".

I can't download, Host-A seems to be down.
  • 0

#4 Tokkes

Tokkes

    GMC Member

  • New Member
  • 8 posts

Posted 04 March 2009 - 01:45 PM

download doesnt work anymore
  • 0

#5 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14389 posts
  • Version:GM:Studio

Posted 04 March 2009 - 06:39 PM

Host-a.net a back up... Link should work now
  • 0

#6 X-tra Fear

X-tra Fear

    Behemoth Creator

  • GMC Member
  • 430 posts
  • Version:GM8

Posted 04 March 2009 - 07:54 PM

Excellent! Nice to see the library put to use. :)

Wow, that is fast! :)
30 fps - 3000 particles on my mom's crappy laptop. :)
(I didn't go as high as I could, I'm sure it could have went much higher!)

Edited by X-tra Fear, 04 March 2009 - 08:04 PM.

  • 0

#7 Phantom107

Phantom107

    Engineer

  • GMC Member
  • 2592 posts
  • Version:GM:Studio

Posted 04 March 2009 - 08:12 PM

The speed is very good for d3d, but the particles look horrible if you don't give them a much higher resolution.

Keep it up!
  • 0

#8 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14389 posts
  • Version:GM:Studio

Posted 04 March 2009 - 09:34 PM

The speed is very good for d3d, but the particles look horrible if you don't give them a much higher resolution.

Keep it up!

Turn ON interpolation... They are Gm's particle (Exact clones because I could not get the original sprites in the exe; they are there and they are these sprites (except for the disk and square, mine are better)). I am adding a new draw method to be set by

gmexport double part3d_system_draw_order(double ind, double oldtonew)


where oldtonew can be 0 or 1 right now; 2 will be added to draw from furthest to nearest to camera... I sort of have it working right now by sorting them by distance to cam... But I need to sort by distance to camera plane instead... Later on today I hope to post an update.


So, yes, you better use better looking sprites than GM's default because at the distance you can be from the particle, it may turn ugly, much so if interpolate is off and if you don't sort the draw.

I will add support for actual 3d objects (d3d_model) eventually.

Edited by icuurd12b42, 04 March 2009 - 09:34 PM.

  • 0

#9 mrperson

mrperson

    GMC Member

  • New Member
  • 513 posts

Posted 04 March 2009 - 10:15 PM

Wow, those pics are amazing! :) Im sure Ill have a use for this sometime. Keep up the great work!
  • 0

#10 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14389 posts
  • Version:GM:Studio

Posted 05 March 2009 - 03:55 AM

OK, I added the sort option for 3d mode from farthest to nearest as mentioned 2 posts ago... So now the particles are drawn according to the distance to the camera plane (not position) and not draw if they are behind the camera (Behind the camera plane). 2 birds in one stone... The distance to plane is fast and my pseudo optimised sort algorithm seems to be able to keep up...

part3d_system_draw_order(ind,draw order)

Draw order take the 0 and 1 (GM standard) and 2, Furthest first for 3d mode.

Added
part3d_particles_drawcount()
part3d_system_draw_alpha4()
Added angle cut off to PartSysSetCamData

Added Fire, with floating spark and smoke
Added Ground fog (Cool)
Added Fireworks
Added Particle Fountain


If you are a sort expert, I would like someone to look at my method... It's not a standard generic all purpose method...

Particle * _PDFirst = NULL;
Particle * _PDLast = NULL;
Particle * _PDLastAddedHi = NULL;
Particle * _PDLastAddedLow = NULL;
inline void AddToDList(Particle *p)
{
p->PartDPrev = NULL;
p->PartDNext = NULL;
	if(_PDFirst == NULL)
	{
		_PDFirst = p;
		_PDLast = p;
		return;
	}
	else if(p->dist <= _PDLast->dist)
	{
		_PDLast->PartDNext = p;
		p->PartDPrev = _PDLast;
		_PDLast = p;
		return;
	}
	else if(p->dist >= _PDFirst->dist)
	{
		_PDFirst->PartDPrev = p;
		p->PartDNext = _PDFirst;
		_PDFirst = p;
		return;
	}

	else if(p->dist-_PDFirst->dist < _PDLast->dist-p->dist)
	{
		Particle *i = _PDFirst;
		if(_PDLastAddedLow)
			if(_PDLastAddedLow->dist > p->dist)
				i = _PDLastAddedLow;
		while(i->dist > p->dist )
		{
			i = i->PartDNext;
			if(i==NULL) return;
		}
		Particle *first;
		Particle *second;
		Particle *third;
		first = i->PartDPrev;
		second = p;
		third = i;
		_PDLastAddedLow = p;
		if(first)
		{
			first->PartDNext = second;
		}
		if(second)
		{
			second->PartDPrev = first;
			second->PartDNext = third;
		}
		if(third)
		{
			third->PartDPrev = second;
		}
		return;
	}
	else
	{
		Particle *i = _PDLast;
		if(_PDLastAddedHi)
			if(_PDLastAddedHi->dist < p->dist)
				i = _PDLastAddedHi;

		while(i->dist < p->dist )
		{
			i = i->PartDPrev;
			if(i==NULL) return;
		}
		Particle *first;
		Particle *second;
		Particle *third;
		first = i;
		second = p;
		third = i->PartDNext;
		_PDLastAddedHi = p;
		if(first)
		{
			first->PartDNext = second;
		}
		if(second)
		{
			second->PartDPrev = first;
			second->PartDNext = third;
		}
		if(third)
		{
			third->PartDPrev = second;
		}
		return;
	}
}

draw
DrawCount = 0;
//ddebug("Draw",0);
			Particle *p = PartFirst; 
			//Particle *n = NULL;
			_PDFirst = NULL;
			_PDLastAddedLow = NULL;
			_PDLastAddedHi = NULL;
			while (p) 
			{
				p->dist = camplanedistance(p->x,p->y,p->z);
				if(p->dist>0) 
				{
					AddToDList(p);
					DrawCount++;
				}
				p = p->PartNext;
			}

			p = _PDFirst; 

			while (p) 
			{
				if(p->dist>0)
				{
					p->Draw();
				}
				p = p->PartDNext;
			}

Edited by icuurd12b42, 06 March 2009 - 03:19 AM.

  • 0

#11 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14389 posts
  • Version:GM:Studio

Posted 06 March 2009 - 10:15 PM

UPDATE:

Tested all functions, most passed
Added the emitter system
  • 0

#12 Sindarin

Sindarin

    Indie Game Developer

  • New Member
  • 1644 posts
  • Version:GM:HTML5

Posted 06 March 2009 - 11:39 PM

ERROR in
action number 1
of Create Event
for object DemoObj:

Error defining an external function.


Are you sure you included the correct dll?
  • 0

#13 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14389 posts
  • Version:GM:Studio

Posted 06 March 2009 - 11:59 PM

ERROR in
action number 1
of Create Event
for object DemoObj:

Error defining an external function.


Are you sure you included the correct dll?


Try again... It's the right dll. maybe you got a corrupted extract.

Reboot your system too. This is a common GM7 problem with all the dlls I have used and made. When GM starts to complain about a working dll, you basically have to reboot.

Though if you would provide the info/step you took, it would help. Did you convert to gm6 for example... Did you previously run another GMK that also used a DLL prior...
  • 0

#14 Tepi

Tepi

    GMC Member

  • Global Moderators
  • 4201 posts
  • Version:GM8.1

Posted 07 March 2009 - 12:17 AM

For GM6'ers: There are things to do after getting the editable LGM'd to gm6. There is in one part constant c_orange used. In many parts there is a constant ps_distr_invgaussian (what is its value?). You can fix this by throwing random values for the constants if you don't happen to know c_orange and that. There are luckily nothing more that'd need to be changed.

I ran into the same problems as I had run before with your camera system. It took me some time, but I managed to frame the problem into the few variables that limit the movement variables. I ignored them by doing argument0 instead of median(min,max,argument0) in those parts. And it worked. :D

-------------------

This is freaking awesome, dude! The particles run amazingly fast (as described), they look like the ones in 2D (just that in 3D), and the engine is incredibly easy to use! :D

I checked out some functions and I was surprised how well and easy you made the function controlling in 3D space. For example that the gravity works using a vector, and that the direction works with the yaw - pitch -system so to say. And if there indeed are equivalents for every single particle function, all I can say is wow. You've also commented the scripts very well, so that this could be used for anyone. I like it.

I'll surely know what to point to when someone comes asking again for how to make a 3D particle system. I'll say: you don't need to, it's been done for you, and it has been done very well. I'll most probably use this engine in my future games. And I'd rather not use anyone else's engines, that tells how good this is (and you'll be credited). :P

Perfection! Is there something it's missing?
  • 0

#15 Sindarin

Sindarin

    Indie Game Developer

  • New Member
  • 1644 posts
  • Version:GM:HTML5

Posted 07 March 2009 - 12:33 AM

Reboot your system too. This is a common GM7 problem with all the dlls I have used and made. When GM starts to complain about a working dll, you basically have to reboot.


Weird, never had that. In what environment do you compile? XP or Vista?

I know GM7 does funny things to DLLs but are you sure it's not a function/memory related problem?

Edited by Sindarin, 07 March 2009 - 12:36 AM.

  • 0

#16 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14389 posts
  • Version:GM:Studio

Posted 07 March 2009 - 01:01 AM

For GM6'ers: There are things to do after getting the editable LGM'd to gm6. There is in one part constant c_orange used. In many parts there is a constant ps_distr_invgaussian (what is its value?). You can fix this by throwing random values for the constants if you don't happen to know c_orange and that. There are luckily nothing more that'd need to be changed.

I ran into the same problems as I had run before with your camera system. It took me some time, but I managed to frame the problem into the few variables that limit the movement variables. I ignored them by doing argument0 instead of median(min,max,argument0) in those parts. And it worked. :D


define c_orange 4235519
define ps_distr_invgaussian 2

in your constants

weird the invert gaussian is not in gm6

As for the camera median problem... I have no clue why GM6 would act differently... So going through all the camera scripts and removing those seems to do the job. Chances are, everyone would have his own cam anyway.

-------------------

This is freaking awesome, dude! The particles run amazingly fast (as described), they look like the ones in 2D (just that in 3D), and the engine is incredibly easy to use! :D

I checked out some functions and I was surprised how well and easy you made the function controlling in 3D space. For example that the gravity works using a vector, and that the direction works with the yaw - pitch -system so to say. And if there indeed are equivalents for every single particle function, all I can say is wow. You've also commented the scripts very well, so that this could be used for anyone. I like it.

I'll surely know what to point to when someone comes asking again for how to make a 3D particle system. I'll say: you don't need to, it's been done for you, and it has been done very well. I'll most probably use this engine in my future games. And I'd rather not use anyone else's engines, that tells how good this is (and you'll be credited). :P

Perfection! Is there something it's missing?


It's missing the destructors, deflectors, atractors and changers... But I may add them.

Some functions like the speed and direction, I am not 100% sure if it works 100% like the original. I would not mind someone taking a second look at that. For the direction, i'm not sure the step deviation is right and the wobble though as is, it does look like it's working and should do the job fine...

Some functions have extented features like the sprite function.

I plan to add model support and add a flag to NOT TILT the sprite towards the players but keep it oriented in the orientation and movement direction specified.


Oh and I managed to find a pretty fast metod to detect if the particle is in view BTW...

Distance to cam plane = adj, point_distance_3d = hyp... arcsin and you have an angle cutoff.
p->dist = camplanedistance(p->x,p->y,p->z);
				if(p->dist>0) 
				{
					if(asin(p->dist/point_distance_3d(p->x,p->y,p->z,camx,camy,camz))>anglecutoff)
					{
						AddToDList(p);
						DrawCount++;
					}
				}
				p = p->PartNext;

Works well enough... You can change the angle cut off if you plan to have huge stretched particles. Since the sprite is always oriented to the camera plane, worst case you set angle cut off to 0, you will never see anything appear out of nowhere while turning arround. Anything behind the cam will still be cut off. It works because, again, of the spite orientation. So I dont need to take the size of the particle into account.

With models, it's will be different though.


Reboot your system too. This is a common GM7 problem with all the dlls I have used and made. When GM starts to complain about a working dll, you basically have to reboot.


Weird, never had that. In what environment do you compile? XP or Vista?

I know GM7 does funny things to DLLs but are you sure it's not a function/memory related problem?


I have that happen quite a lot since I do a lot of dlls... Less now that I know the causes
1) If I convert a gm6 example with a dll, and forget to save as gmk before runing, I have a 30% chance of getting this error.. And I am screwed for any other gmk that use a dll.

2) If I run a gmk that uses a dll and it had an error (The game has GML error, variable does not sxist for example) and I abort (Quits without unloading the dll), the next run has increased chances of getting the error... When it does happen, I have to reboot. So, TIP, if you use a dll and you have an error, try to ignore it before quitting

3) I also have the error reported eroneously, clicking ignore and many times the dll was actually loaded and the game works fine when passed the errors.

I use dev c++ and it makes dll that have no dependencies but the last cause
4) MS compiled dlls that require undocumanted dll not everyone has one their system... That, my dlls do NOT suffer from.

I have gm7 and Vista

Edited by icuurd12b42, 07 March 2009 - 01:14 AM.

  • 0

#17 Sindarin

Sindarin

    Indie Game Developer

  • New Member
  • 1644 posts
  • Version:GM:HTML5

Posted 07 March 2009 - 01:36 AM

I just moved the folder from my Desktop folder to a folder in my external drive and it worked.

It's like the dll cannot get directory names like Desktop, My Documents etc. I had the same problem when running GM games under Japanese locale and GM could not return the filename because Japanese Windows uses the Yen symbol to mark path slashes.
I currently have Greek locale on but I have no problems with other GM games or dlls. Maybe change the language in the version info of the dll or something?

Btw, this is really good looking and fast!
  • 0

#18 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • Global Moderators
  • 14389 posts
  • Version:GM:Studio

Posted 07 March 2009 - 01:56 AM

I just moved the folder from my Desktop folder to a folder in my external drive and it worked.

It's like the dll cannot get directory names like Desktop, My Documents etc. I had the same problem when running GM games under Japanese locale and GM could not return the filename because Japanese Windows uses the Yen symbol to mark path slashes.
I currently have Greek locale on but I have no problems with other GM games or dlls. Maybe change the language in the version info of the dll or something?

Btw, this is really good looking and fast!

I have yet to figure how to make Devc++ compile resource (.rc files) under Vista (A bug) to insert version info and stuff... Do me a favor, can you try any of my other dlls? Like the GMBinFile or even the GMFMODSimple.gmk and tell me if they have the trouble (links in tools in sig).... They should if the reasoning is right here.

In any case, directory stuff, that is beyond what my dll does. So the error must be with GM failing to see the dll to load it... Are you sure other dll gmks work? From the same folder mine failed?


[update]
Support For Models Added
Includes special scripts for placing static models in the game at a rotation angle and roation speed, so you can have noninterative stuff handled by the particle system (More 3d stuff is a great thing to have) as well as move the model arround like a normal particle
Changed the dll to use doubles all over instead of floats (GM was triggering silent floating point exception and would exit it'd own draw leaving the game running without updating the screen). So it should be a little slower now.

Edited by icuurd12b42, 07 March 2009 - 07:46 AM.

  • 0

#19 HaRRiKiRi

HaRRiKiRi

    GMC Member

  • GMC Member
  • 1364 posts

Posted 08 March 2009 - 06:06 PM

Absolutely fantastic. Works beautifully and very fast. Aren't the particles drawn with the GM D3d? If yes, then is stunning how many things can GM actually draw in a 3d space. There was constant fps of 30 even with 3000 particles drawn on screen, and 6k total in the room. Thou there is some blending problems, I know that it is a GM problem thou. Like the smoke cloud in the sky blends beautifully with other particles, but the fog on the ground sometimes makes particles behind it disappear.
  • 0

#20 Tepi

Tepi

    GMC Member

  • Global Moderators
  • 4201 posts
  • Version:GM8.1

Posted 08 March 2009 - 08:18 PM

Absolutely fantastic. Works beautifully and very fast. Aren't the particles drawn with the GM D3d?

Doesn't seem like it:
//gmexport double part3d_system_drawit(double ind) 
//This functions draws the particles in the system. You only have to call this when drawing is not automatic. It should be called in the draw event of some object.
with(argument0)
{
	external_call(global.dll_part3d_system_drawit,ind);
}

Thou there is some blending problems, I know that it is a GM problem thou. Like the smoke cloud in the sky blends beautifully with other particles, but the fog on the ground sometimes makes particles behind it disappear.

The blending problems aren't generally GM's fault. They occur in any and every tool and language you'll try to render the 3D with some transparency. Also, it's explained in the code comments:
//this sets the depth so particle systems draw "relatively" in order 
//thought their individual particles may interact badly with particles
//from other systems, Usually, it work well since particles are
//usually localized in an area of the map...
There's alot useful information in the comments. :D
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users