About Store Forum Documentation Contact



Post Reply 
My fun with RawParticles
Author Message
RedcrowProd Offline
Member

Post: #1
My fun with RawParticles
inspired by http://www.esenthel.com/forum/showthread...wParticles

hello guy, here to talk about the RawParticles!

what is it ? RawParticles is pretty much a lighter version of Particles and for that reason have better performance.

there's little to no information in tutorials, and forum discussion.

here is my little 2 cents to help the next person interested by this

What i tried to do is to set some particles to immitate rain
it is fairly easy and looks like particles in the idea.

First i set up my class that will carry rawparticles information as i like to do.
Code:
class MyRawParticlesAttributs
{  
   // save pos for next frame update as we dont want to reset pos every frame.
   flt posx;
   flt posy;
   flt posz;
   Color myColor;
   flt myRadius;
  
   void SetRandom() // used at creation / respawn. can be improve to create particles where rain drop down.
   {
      posx=RandomF(Plr.pos().x-100, Plr.pos().x+100);
      posy=RandomF(Plr.pos().y+50, Plr.pos().y+100);
      posz=RandomF(Plr.pos().z-100, Plr.pos().z+100);
      int randomLight=Random(150, 200); int randombrightness=Random(150, 255);
      myColor=Color(randomLight, randomLight, randomLight, randombrightness);
      myRadius=RandomF(0.3, 1);
   }
   void SetLinear() // linear update of the particle
   {
      posy-=Time.rd()*50;
      posx-=0;
      posz-=0;
   }
}

C int MyRawParticleArrayNumber=5000; // setting up n° of particles wanted
RawParticles RawParticles_Atmo;
RawParticles.Particle particleArray[MyRawParticleArrayNumber];
MyRawParticlesAttributs particleArrayAttribut[MyRawParticleArrayNumber];

in create anywhere in your code : just set it up for the update to work correctly
Code:
RawParticles_Atmo.palette(false).create(UID(2049046545, 1233068177, 1469235131, 745495318));
   REP(MyRawParticleArrayNumber)particleArrayAttribut[i].SetRandom();
nb: i couldnt get palette(true) to work for some reason, so i used RM_BLEND instead.

Put this in your game update
Code:
REP(MyRawParticleArrayNumber)
   {
      particleArrayAttribut[i].SetLinear();
      if(particleArrayAttribut[i].posy<=Game.World.hmHeight(Vec2(particleArrayAttribut[i].posx, particleArrayAttribut[i].posz)))
      {
         particleArrayAttribut[i].SetRandom();
      }
      particleArray[i].radius = particleArrayAttribut[i].myRadius;
      particleArray[i].vel    = Vec(0, 0, 0); // do not care about vel
      particleArray[i].color  = particleArrayAttribut[i].myColor;
      particleArray[i].pos = Vec(particleArrayAttribut[i].posx, particleArrayAttribut[i].posy , particleArrayAttribut[i].posz);
   }
   RawParticles_Atmo.set(&particleArray[0], MyRawParticleArrayNumber);
nb : confusing about how to set them correctly, might be wrong. might be right.

in drawing
Code:
case RM_BLEND:
{
RawParticles_Atmo.draw();
}break;

some images :
Quote:[Image: 532606Rainimg1.png]

[Image: 750971imgrain2.png]
please let me know if anything is wrong/needs improvement smile

added a link to EE project here : http://www.filedropper.com/rawparticles

thanks !
(This post was last modified: 12-22-2016 07:54 AM by RedcrowProd.)
12-22-2016 07:04 AM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #2
RE: My fun with RawParticles
I'd love to test it, but I think it would be easier to upload an EsenthelProject file to dropbox so that you just have to execute the project to open it in the Editor.(christmas laziness) smile
12-22-2016 07:26 AM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #3
RE: My fun with RawParticles
ahah yeah got cha

added a project file for this smile

http://www.filedropper.com/rawparticles
(This post was last modified: 12-22-2016 07:53 AM by RedcrowProd.)
12-22-2016 07:45 AM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #4
RE: My fun with RawParticles
Code:
void SetRandom(RawParticles.Particle &p) // used at creation / respawn. can be improve to create particles where rain drop down.
   {
      Vec cpos=Cam.matrix.pos;
      p.pos.set(RandomF(cpos.x-100, cpos.x+100)
      , RandomF(cpos.y+50 , cpos.y+100)
      , RandomF(cpos.z-100, cpos.z+100));
      int randomLight=Random(150, 200); int randombrightness=Random(150, 255);
      p.color=Color(randomLight, randomLight, randomLight, randombrightness);
      p.radius=RandomF(0.3, 1);
   }
   void SetLinear(RawParticles.Particle &p) // linear update of the particle
   {
      p.pos.y-=Time.rd()*50;
      p.pos.x-=0;
      p.pos.z-=0;
   }


REP(MyRawParticleArrayNumber)
   {
      RawParticles.Particle &pp=particleArray[i];
      SetLinear(pp);
      if(pp.pos.y<=Game.World.hmHeight(pp.pos.xz()) || pp.pos.y<=0)
      {
         SetRandom(pp);
      }
      
      pp.vel = Vec(0, 0, 0); // do not care about vel
   }

I just wrote it like this, mostly since I hate having duplicate arrays wasting memory instead of having a proxy being a basically a copy of the actually used structure. smile
12-22-2016 08:14 AM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #5
RE: My fun with RawParticles
Was really fun upping it to 100k. smile overall nice job, this might let others learn very easily how to use the RawParticles. smile
12-22-2016 09:15 AM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #6
RE: My fun with RawParticles
Hah yes this could use some polishing.
(This post was last modified: 12-23-2016 02:49 AM by RedcrowProd.)
12-22-2016 09:38 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #7
RE: My fun with RawParticles
It looks cool.

But for rain effect, you'd have to set particle 'angle' member too, so for example when looking up and down, the rain drops rotate correctly.

Remember that particles rotate only in 2D space, so for true 3D rotation, you'd have to forget particles, and use VI with faces (quads).
12-23-2016 12:15 AM
Find all posts by this user Quote this message in a reply
RedcrowProd Offline
Member

Post: #8
RE: My fun with RawParticles
it is true, this was more of an exemple, and i was immitating rain as for this, but i believe this system could work fine for snow or other effect like that.

as for the problem of the rotation of the particles, you could bypass this problem , just modifying the image used after a certain camera angle, and even more, setting up different layer based on how closed it is from the camera.

i havent tried vi much atm, is the perf would be comparable to using raw particles, using vi with quads faces ?
(This post was last modified: 12-23-2016 03:01 AM by RedcrowProd.)
12-23-2016 02:46 AM
Find all posts by this user Quote this message in a reply
Zervox Offline
Member

Post: #9
RE: My fun with RawParticles
if you are first going to use VI then I'd take the step towards Geometry-Compute shader to offload everything onto the gpu and not stroke your GPU bandwidth along with it. of course that would require source access.
(This post was last modified: 12-23-2016 03:05 AM by Zervox.)
12-23-2016 03:04 AM
Find all posts by this user Quote this message in a reply
Post Reply