A new particles system use gpu

Software: Away3D 4.x

Avatar
Cheng Liao, Administrator
Posted: 08 December 2011 03:52 AM   Total Posts: 116   [ # 31 ]

Hi,
The ColorTextureByLifeGlobal is the best flexible ,if you want to implement complex color changement,use it instead.Now it’s a global action because it’s used as a 1D texture.You can extends it to 2D texture so that you can make a local action.

If you need all action with the same ease ,you can controll the container’s time to implement it.If you need every action with a different ease,I think you can override these actions’ AGALCode function so that the action’s calculation base on a special time.Of course I think this not very easy.Now I have no a good idea for this.
Cheers!

 

   

Avatar
Cheng Liao, Administrator
Posted: 21 February 2012 01:53 AM   Total Posts: 116   [ # 32 ]

A gui editor for this system:
http://liaocheng.github.com/particles_editor.html
both have been updated for away3d beta.cool smile

 

   

inSertCodE, Sr. Member
Posted: 21 February 2012 05:01 PM   Total Posts: 105   [ # 33 ]

I wrote down a function that could go well with the particle system.
I call it GradientBitmapMaterialConstructor.
The main idea is that you throw at it a black’n'white picture(bitmap data) and enter 2 colors for the lowest and highest color and it returns for you a bitmap data that you can use as material. It will be more clear when you see the attachment. smile

The construction of the class is the following:

Construct(bitmap_base:BitmapDatahigh_color:uintlow_color:uintalpha_ease:Boolean truealphaTreshold:Number 0.25

- bitmap_base is the bitmap data of the black’n'white gradient picture.
- high_color is the color that will replace the whitest color in the bitmap.
- low_color is the color that will replace the darkest color in the bitmap above 0. Pure black color (0,0,0) will be transparent. The colors between them will be transforming from one to another.
- alpha_ease if set to true will make the colors included in the threshold fade away with alpha(transparency). default is 1/4, so if the highest color is 255,255,255 and the lowest is 1,1,1 colors below 63,63,63 till 1,1,1 will fade away in transparency.
- alphaTreshold should be decimal from 0 to 1. Default is 0.25 which is 1/4. If you want the transparency fading to start right from the highest color it should be 1. This works only if alpha_ease is true.

Now the example in the attachment:
1. First picture is the main input bitmap that is used for construction.
2. Second picture is without alpha fading (alpha_ease is set to false)

material_constructor.Construct(new BasicMaterial().bitmapData0xffcc000xff3600false); 

3. Third picture is same colors as second but with alpha fading using the default 0.25 threshold.

material_constructor.Construct(new BasicMaterial().bitmapData0xffcc000xff3600true); 

4.5. Forth and fifth picture is same settings as third with different colors.

material_constructor.Construct(new BasicMaterial().bitmapData0xdadffa0x24399btrue); 
material_constructor.Construct(new BasicMaterial().bitmapData0x42ff000xff00a8true); 

6. Sixth is same like third but with 0.9 threshold which means transparent fading starts almost right away.

material_constructor.Construct(new BasicMaterial().bitmapData, 0xffcc00, 0xff3600, true, 0.9);

With this function you can make many different materials with the same basic picture and if you decide to tweak the colors its as simple as changing two values.

 

   

inSertCodE, Sr. Member
Posted: 21 February 2012 05:08 PM   Total Posts: 105   [ # 34 ]

How to use.

Just declare the GradientBitmapMaterialConstructor

var material_constructor:GradientBitmapMaterialConstructor = new GradientBitmapMaterialConstructor

and then use it to construct bitmap data for materials

BitmapDataForMaterial material_constructor.Construct(new BasicMaterial().bitmapData0xffcc000xff3600true); 

where “BasicMaterial” is the embeded b’n'w picture used for construction.

PS.change and putt the class in whichever package you want.

 

File Attachments
GradientBitmapMaterialConstructor.zip  (File Size: 2KB - Downloads: 378)
   

Avatar
Matse, Sr. Member
Posted: 21 February 2012 08:00 PM   Total Posts: 149   [ # 35 ]

Nice posts !

Didn’t play with those particles yet but I’ll surely do in the coming weeks ^^

@inSertCodE maybe try .zip ? You can use the free (and great) 7zip for this. I think .7z doesn’t work though… the only way that I’m sure works is - strangely enough - uploading a self extracting archive (.exe) but it’ll only work on windows I guess : in winrar you have a “create SFX archive” (not sure about the exact text as I’m using a french version) checkbox to do that in the main tab.

 

   

inSertCodE, Sr. Member
Posted: 21 February 2012 09:50 PM   Total Posts: 105   [ # 36 ]
Matse - 21 February 2012 08:00 PM

@inSertCodE maybe try .zip ?

lol, yeh thanks. If i’ve spend time to read under attachments I would have seen that zip is supported :D
Class is uploaded in the post above.

PS. another example in the attachment to play with some colors.

 

   

Avatar
Cheng Liao, Administrator
Posted: 22 February 2012 11:00 AM   Total Posts: 116   [ # 37 ]

Cool!I think creating the bitmapData at gpu stage may pay a heavy load to gpu.But it’s a good idea to create a uv animation action for this consecutive bitmapData.

 

   

inSertCodE, Sr. Member
Posted: 22 February 2012 12:28 PM   Total Posts: 105   [ # 38 ]

The functions currently uses BitmapData’s function Get and Set Pixels. I think those are CPU calculated. Anyway CPU or GPU, calculating many particle’s animation separately will be heavy.
My main idea was not to be animated. I was planing it for static billboard particles in different colors. But when you mentioned it uv animation is a great idea.
Would you be interested in making and adding the uv animation to the particle system if I make a function that will supply a sprite-sheet of animated particles.
Anyway I think that uv animated particles from sprite-sheet would be great addition to your system just by itself wink

 

   

Avatar
Cheng Liao, Administrator
Posted: 22 February 2012 04:45 PM   Total Posts: 116   [ # 39 ]

It’s interesting.I will write a uv action so that a particle can change its texture by the sequence bitmapData.In addition I will implement this in the gui editor
http://liaocheng.github.com/particles_editor.html
wink

 

   

Avatar
Cheng Liao, Administrator
Posted: 23 February 2012 02:55 PM   Total Posts: 116   [ # 40 ]

I have created a sequence bitmap action for it.
There is a example for the editor.
It’s not wonderful ,just for proving the function .wink

 

File Attachments
Sequence.zip  (File Size: 4KB - Downloads: 335)
   

John Brookes, Moderator
Posted: 23 February 2012 03:20 PM   Total Posts: 732   [ # 41 ]

liao
The forum is not allowing the download.

 

   

Avatar
Cheng Liao, Administrator
Posted: 23 February 2012 03:26 PM   Total Posts: 116   [ # 42 ]

Fix it.Only zip file can donwload.red face

 

   

Avatar
Matse, Sr. Member
Posted: 23 February 2012 03:26 PM   Total Posts: 149   [ # 43 ]

Yeah, liao can you upload a .zip ?

You can use 7zip (free) : http://www.7-zip.org/

Oh and by the way : thank you so much for all the stuff you provide ! Just played a bit with your editor so far and it looks great, can’t wait to put some FXs in my game project wink

edit : sorry, we posted at the same time ^^

 

   

inSertCodE, Sr. Member
Posted: 23 February 2012 04:36 PM   Total Posts: 105   [ # 44 ]
liaocheng - 23 February 2012 02:55 PM

I have created a sequence bitmap action for it.
There is a example for the editor.
It’s not wonderful ,just for proving the function .wink

Way to go man! Less than a day from the request. wink

Whats the read structure of the sprite sheet?... I mean how many sprites go in a row and how many columns? x*y

PS. Didn’t check if you have it yet but a good option would be to animate according to particle lifetime. Something like the color change option you have.

Great work again and thanks…

 

   

inSertCodE, Sr. Member
Posted: 23 February 2012 04:57 PM   Total Posts: 105   [ # 45 ]

I’ve just tested it and it works great. Just some suggestion.
*see the image in attachment to be more clear*

Since the texture needs to be power of 2 why not use the whole space.
You set the sequence with 2 parameters.
1st is “Sprites_In_Row” which in the attachment example will be 5. When you get the width of a single sprite you use the same for height for a single sprite.
2nd is “Total_Sprites” which will be 7 in the example. You add a check that the total sprites number can be maximum Sprites_In_Row X Sprites_In_Row which is 25 in example.

So the animation logic will go like this…
Play from first… when it reaches end of row move 1 column down and at beginning of row. When it reaches final sprite goes back to 1st if set to loop.

However this will brake your “smooth” option :(  but I think its a good compensation.

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X