Jump to content


Photo

Particles in 3d


  • Please log in to reply
11 replies to this topic

#1 mads2194

mads2194

    GMC Member

  • GMC Member
  • 368 posts
  • Version:Unknown

Posted 06 July 2012 - 10:32 AM

How would you go about particles in 3d? I thought of making my own system: having a controller object which uses an array to determine where each "particle" is, particles being billboards. I haven`t figured out yet how to do billboards for my camera system (I have a top-down view).

I was thinking about efficiency as well since we all know gm is kinda slow on drawing polys and having a lot of little models won`t prove to be too fast.
  • 0

#2 RevenantGhost

RevenantGhost

    GMC Member

  • GMC Member
  • 106 posts
  • Version:GM8

Posted 06 July 2012 - 12:16 PM

particles in GM's built-in 3d are slow, i think there's no way to make it efficient...
Still, if is a top-down camera you could use normal floors, small ones; avoid to call everytime d3d_draw_floor, instead make a model at the begin with d3d_model_floor and use it for every particle, is way faster!
To get the particle position you dont need to make a lot of objects, that would lag a lot, make a single object, with a 3d array eg. ParticleArray[1,1,1]; ParticleArray[2,2,2]; ParticleArray[3,3,3] etc...
So the 1,1,1 will be xyz of the 1, 2,2,2 will be the xyz of the 2, and so on...
Atleast this would be the way i would do i case i need particles, maybe isnt the best one but give it a try!
  • 0

#3 mads2194

mads2194

    GMC Member

  • GMC Member
  • 368 posts
  • Version:Unknown

Posted 06 July 2012 - 02:27 PM

Yeah, but my problem with this solution is that I don`t have the slightest clue how to make a billboard for my camera system.
  • 0

#4 PoniesForPeace

PoniesForPeace

    puzzling

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

Posted 06 July 2012 - 03:07 PM

particles in GM's built-in 3d are slow, i think there's no way to make it efficient...
Still, if is a top-down camera you could use normal floors, small ones; avoid to call everytime d3d_draw_floor, instead make a model at the begin with d3d_model_floor and use it for every particle, is way faster!
To get the particle position you dont need to make a lot of objects, that would lag a lot, make a single object, with a 3d array eg. ParticleArray[1,1,1]; ParticleArray[2,2,2]; ParticleArray[3,3,3] etc...
So the 1,1,1 will be xyz of the 1, 2,2,2 will be the xyz of the 2, and so on...
Atleast this would be the way i would do i case i need particles, maybe isnt the best one but give it a try!

Iccurd told me that objects aren't the main source of particle lag, so using an array wouldn't help. He said the lag is the seperate calls to d3d_draw_ floor.

He goes into more detail here, and posts an idea of how to speed things up: http://gmc.yoyogames...l=&fromsearch=1
  • 0

#5 Gamer3D

Gamer3D

    Human* me = this;

  • GMC Member
  • 1591 posts
  • Version:GM8.1

Posted 06 July 2012 - 06:23 PM

Iccurd told me that objects aren't the main source of particle lag, so using an array wouldn't help. He said the lag is the seperate calls to d3d_draw_ floor.

Despite that, don't make too many objects. in GM, even empty objects slightly slow your game. If they have sprites/use collision detect, the problem is far, far worse.

He goes into more detail here, and posts an idea of how to speed things up: http://gmc.yoyogames...l=&fromsearch=1

One thing to notice is that you can make a single "particle" model facing toward the camera at the beginning of each draw phase, then draw it for each particle without rotation or translation. Scaling can be used for changing particle size.

Some other things to note: icuurd's solution checks visibility for every particle, every step, even after they are too far away to be seen. Consider destroying each particle as it leaves the visible area.
  • 0

#6 Pandaboy

Pandaboy

    GMC Member

  • GMC Member
  • 518 posts

Posted 15 July 2012 - 01:41 PM

@RevenantGhost
Just want to clarify one thing, array[x,y,z] don't work that way. the [x,y,z] values in the array refers to the position in a 3d array where a value is stored, the [x,y,z] are not the actual values.
if he were to make an array to store the values, it would look like this:

particle[0,0] = x
particle[0,1] = y
particle[0,2] = z
particle[1,0] = xx
particle[1,1] = yy
particle[1,2] = zz

the first argument in the array refers to which particle we are defining the position of, and the second one refers to if it's x, y, or z that we are defining.

Edited by Pandaboy, 15 July 2012 - 01:46 PM.

  • 0

#7 RevenantGhost

RevenantGhost

    GMC Member

  • GMC Member
  • 106 posts
  • Version:GM8

Posted 16 July 2012 - 08:42 AM

@RevenantGhost
Just want to clarify one thing, array[x,y,z] don't work that way. the [x,y,z] values in the array refers to the position in a 3d array where a value is stored, the [x,y,z] are not the actual values.
if he were to make an array to store the values, it would look like this:

particle[0,0] = x
particle[0,1] = y
particle[0,2] = z
particle[1,0] = xx
particle[1,1] = yy
particle[1,2] = zz

the first argument in the array refers to which particle we are defining the position of, and the second one refers to if it's x, y, or z that we are defining.

Really? Isnt particle[0] a value, Isnt particle[0,0] another, Isnt particle[0,0,0] another one? :|
  • 0

#8 Pandaboy

Pandaboy

    GMC Member

  • GMC Member
  • 518 posts

Posted 18 July 2012 - 12:09 AM


@RevenantGhost
Just want to clarify one thing, array[x,y,z] don't work that way. the [x,y,z] values in the array refers to the position in a 3d array where a value is stored, the [x,y,z] are not the actual values.
if he were to make an array to store the values, it would look like this:

particle[0,0] = x
particle[0,1] = y
particle[0,2] = z
particle[1,0] = xx
particle[1,1] = yy
particle[1,2] = zz

the first argument in the array refers to which particle we are defining the position of, and the second one refers to if it's x, y, or z that we are defining.

Really? Isnt particle[0] a value, Isnt particle[0,0] another, Isnt particle[0,0,0] another one? :|


yes, and no. particle[0] and particle[0,0] can never be part of the same array, because particle[0] is a one-dimensional array and particle[0,0] is two-dimensional.


A one dimensional array, written as array[a], is like a list. the number inside the [] is the row on the list where the value is stored. for example:
//Create event!

array[0] = "Peter Griffin";
array[1] = 47;
array[2] = "beer"

show_message("hi, my name is "+array[0]+", I'm "+string(array[1])+" years old and I like "+array[2]);
//This will show the message: "Hi, my name is Peter Griffin, I'm 47 years old and I like beer"


A two-dimensional array is like a grid, written as array[a,b], where a,b is the coordinates on the grid where the value is stored. You can see it as a collection of different lists, where A is the list number, and B is the row of the currently selected list. So each particle will have it's own "list" (A), and a bunch of different "rows" (B) on that list that tell them x, y, z, color, size, opacity, etc.

so to create 10 different circles, at different positions, with different sizes and colors, this is what you do (and the same way you would keep track of the particle x,y and z, and even color and size if you wanted to):
//CREATE EVENT
//Creating a 2 dimensional array that will be used to draw 10 different circles
var i;
i = 0;

repeat(10) {

    array[i,0] = random(room_width); //x
    array[i,1] = random(room_height); //y
    array[i,2] = random_range(4,16); //size
    array[i,3] = make_color_rgb(random(255),random(255),random(255)); //color
    
    i += 1; 

}

//DRAW EVENT
//Drawing 10 circles from the values in the 2D array
var i, size, color;
i = 0;

repeat(10) {

    x = array[i,0];
    y = array[i,1];
    size = array[i,2];
    color = array[i,3];
    
    draw_circle_color(x,y,size,color,color,false);
    
    i += 1;
    
}

3-dimensional arrays, written as array[a,b,c], are rarely used, because a 2-dimensional array is almost always enough. so I won't talk a lot about them ;p

hope that clears it up a bit :P

Edited by Pandaboy, 18 July 2012 - 12:18 AM.

  • 0

#9 RevenantGhost

RevenantGhost

    GMC Member

  • GMC Member
  • 106 posts
  • Version:GM8

Posted 18 July 2012 - 12:03 PM

Oh, then sorry :D I was wrong =)
  • 0

#10 slayer 64

slayer 64

    GMC Member

  • GMC Member
  • 3278 posts
  • Version:GM8.1

Posted 19 July 2012 - 11:33 PM

this models a bunch of particles together and loops through the models after to display them. the first explosion is slow but once the models are made, looping through them is fast.

http://sandbox.yoyog...frame-animation
  • 0

#11 Pandaboy

Pandaboy

    GMC Member

  • GMC Member
  • 518 posts

Posted 26 July 2012 - 01:46 AM

Oh, then sorry :D I was wrong =)


hehe that's fine, just thought I would clear it up, I also thought arrays worked like that back before I learned how to actually use them ^^!
  • 0

#12 bob_gmae

bob_gmae

    GMC Member

  • GMC Member
  • 22 posts
  • Version:GM8

Posted 14 August 2012 - 05:40 PM

how is the pitch calculated in a d3d_set_projection code. as you can see in the game bellow, the smoke particles and flame particles are not billboards(wall objects that face the camera) and really lag the game.

Posted Image

Posted Image

Posted Image
I'ts like EBAY... Only Free!
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users