Top Banner
Particle System - Overview Luca Mella Universit` a di Bologna [email protected] 9 dicembre 2011
38
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Particle Systems - Overview

Particle System - Overview

Luca Mella

Universita di Bologna

[email protected]

9 dicembre 2011

Page 2: Particle Systems - Overview

Outline I

Introduction

Particle systems

Newtonian ParticlesODEs evaluationParticle System Dynamics

Newtonian Particles System TaxonomyIndipendent particlesInterdependent particlesComplexity

ContraintsCollisions

DetectionReaction

Soft Constraints

Particle System DesignParticle AttributesParticle GenerationParticle DynamicsParticle ExtinctionParticle HierarchyParticle Rendering

A Particle System Model

Page 3: Particle Systems - Overview

Introduction I

Problems with classical modelling techniques

Modelling geometric objects describing them in terms of surfaces orsets of convex (planar) polygons could have limits in several cases.For instance physical objects could not fit very well with this kindsof modelling techniques, in fact model complex behaviour ornatural constraints had led to procedural modelling techniqueswich enforces an algorithmic approach that consider polygonsgeneration at least only.

Page 4: Particle Systems - Overview

Introduction II

Procedural modelling

Fractals exploiting self-similarity of this particularmathematical objects for generating complex objects.

Shape Grammars interpreting AST nodes and leaf with a graphicalbehaviour for generating complex object (even withsimple grammars)

Particle Systems systems of particles that are capable of complexbehaviors

Page 5: Particle Systems - Overview

Particle systems

An informal definitionParticle systems are collections of particles, typically point masses,in which the dynamic behavior of the particles can be determinedby the solution of sets of coupled differential equations.

Modelling capabilities

I Fluid dynamics, wave action, turbulent behavior.

I Solid objects, deformable solid can be modeled as a3-dimensional array of particles that are held together bysprings.

I Birds behaviour

I Explosions

I Smoke and fire

I . . .

Page 6: Particle Systems - Overview

Newtonian Particles I

Particles obey to Newton’s second law: f = m · aThats pretty good for calculating the state of somethingrepresentable as a point. . .In fact:

vi = pi

ai = vi = 1m · fi

whit i ∈ 1 . . . 3

So, the state of a system of n particles is governed by a set of 6nordinary differential equations (ODEs).In addition determinating system behaviour is possible through aset of forces {fk}

Page 7: Particle Systems - Overview

Newtonian Particles II

Euler methodIs a basic method for ODE solution approximation, relies oncurve’s linear approximation.

Consider p = f (p, t)∫ t+ht pdτ = p(t + h)− p(t) =

∫ t+ht f (p, τ)dτ , supposing p

closed.

if h is small is possible to approximate the value of the curvewith:

p(t + h) ≈ p(t) + h · f (p(t), t)

Approximation error results ∝ h

Page 8: Particle Systems - Overview

Newtonian Particles III

Verlet integration method

Starting from euler method is possible to directly calculate positionin one step.

Assumption: time step ∆t = (tn − tn−1) is constant

pn = pn−1 + ∆t · v(∆t), vn = vn−1 + ∆t · a(∆t)

⇒ vn = pn−pn−1

∆t , vn−1 = pn−1−pn−2

∆t

n = pn−1 + (vn−1 + a∆t)∆t = pn−1 + (pn−1−pn−2

∆t + a∆t)∆t

and then . . .

pn = 2pn−1 − pn−2 + a(∆t)∆t2

With this equation we avoid to keep track of particle velocity,saving precious memory.NOTE: particles calculation is recently moving to GPU, somemory’s consumption issue is relevant

Page 9: Particle Systems - Overview

Newtonian Particles IV

Particle system dynamics

So the system might be described in this way:{p(t) = v(t) ⇒ p(tn+1) ≈ p(tn) + (tn+1 − tn)v(tn+1)

v(t) = 1m f (t) ⇒ v(tn+1) ≈ v(tn) + (tn+1−tn)

m f (tn+1)

Where

p : R3 → R3, location differential form

v : R3 → R3, velocity differential form

f : R3 → R3, force differential form

m ∈ R , mass scalar

t ∈ R , time scalar

Page 10: Particle Systems - Overview

Newtonian Particles V

Skeleton of a particle System Dynamics

float time, delta; float state[6 ∗ n], force[3 ∗ n];state=getInitialState();for(time=t0; time¡timeFinal; time+=delta){

/* compute forces */

force=forceFunction(state, time);

/* apply standard differential equation solver */

state=ode(force, state, time, delta);

/* display result */

render(state, time);

}NOTE 1: this is a possible skeleton for particle dinamics calculation, particle systemdesign is more compex and will be discussed further

NOTE 2: force computing routine might be considered a key component of the

system.

Page 11: Particle Systems - Overview

Newtonian Particles System Taxonomy I

A possible taxonomy of newtonian particle system might be doneconsidering the type of relation needed between particles

Indipendent particles , no relations between particles

Interdependent particles , relations between particles

Page 12: Particle Systems - Overview

Indipendent particles I

Indipendent particles

This is the basic and simplest particles type to manage, each ofthem will evolve indipendently.A representative instance could be Fireworks explosion, where:

I accelleration is a const field a =

0−g0

I lifetime of particles is random

I initial position is known

I initial velosity is random

More generally we have can describe in similar way a lot ofphemomen’s classes, like explosions, bullets or rain (richochetsmight require additional considerations)

Page 13: Particle Systems - Overview

Interdependent particles I

Interdependent particles

More complex system to manage, each particle is in relation withother particles.A good case study for this kind of systems is represented bydeformable objects like clothes, where:

I particles are meant as mesh vertices.

I external force fields act on each particles (eg. gravity,wind. . . )

I forces between adjacent particles is considered, at least till thefirst ring (eg. f = ks(p2− p1))

Page 14: Particle Systems - Overview

Interdependent particles II

Hooke’s Law, Particles and MeshesA better description of the interaction between particles could bedone by this way:

s = resting length of the “spring”

p, q ∈ R3 as particle position (eg. adjacent particles)

d = pq as spring force direction’s

ks spring constant

f = −ks(‖d‖ − s) · d as the force, with d = d‖d‖ (versor)

Page 15: Particle Systems - Overview

Interdependent particles III

A little considerationWe could also consider friction in order to better modelling thiskind of interaction. . .

d = p − q as velocity difference between particles.

kd damping constant

ff = −(ks(‖d‖ − s) + kd d ·d‖d‖) · d

. . . Other forcesWe might consider also other forces, for instance attractive orrepulsive radial force fields. . .This could be good for simulating planet interaction forces forinstance

kr radial constant

f = −kr d‖d‖3 d

Page 16: Particle Systems - Overview

Interdependent particles IV

Complexity

Considering couples of particles will increase drastically problemcomplexity, in fact we have O(n2) forces to calculate.Data structure might be used in order to keep complexity undercontrol. Do you remember few lesson ago? Buonding volumes,space partitioning. . .

Page 17: Particle Systems - Overview

Contraints I

Implementing a group of particles that interact each according to aset of ODEs migh not be enough to model all the real-worldbehaviour. In fact, model object’s collision with particles andODEs could be not so easy in reasonable times.A possible solution is to introduce contraints in our particlesystem.

Hard Constraint , constraints that have to be satisfied exactly, likeball bounce.

Soft Constraint , need only to come close to satisfying, forexemple contraints on particle separation or distance.

Page 18: Particle Systems - Overview

Collisions I

CollisionsIn order to better model this typical situation we should consider 2phases in collision management:

I Detection

I Reaction

Page 19: Particle Systems - Overview

Collisions II

Detection

a priori algorithms which will be able to predict the trajectories ofthe physical particles. The instants of collision arecalculated with high precision, and objects neveractually interpenetrate. (not so easy in real-timescenario)

a posteriori algorithms check if any objects are intersectingsomething. At each simulation step, a list of allintersecting objects is created, positions and velocityof these objects will be “fixed”.

NOTE: real time graphics uses massively a posteriori algorithms

Page 20: Particle Systems - Overview

Collisions III

Detection optimization

Collision detection is an issue already discussed during globalillumination lectures, in particular we found the same problem onraytracing algorithms.A way to speed-up detection is to use smart data structures andtecnhiques, like space partitioning (Octree, Binary SpacePartition tree. . . ).

Page 21: Particle Systems - Overview

Collisions IV

ReactionCollision reaction is similar to what happens when light reflectsfrom a surface. In other word:

Po is particle position

Pc is previous position

~v = Po − Pc or also we might use velocity vector directly

n is the surface’s normal

~r = ~v − 2(n · ~v)n

This equation might be good in case of elastic collision, wherequantity of motion (m~v) is constant before and after collision, butin case of inelastic collision is at least necessary to consider acoefficient of restitution as fraction of the normal velocityretained after the collision.

Page 22: Particle Systems - Overview

Soft Constraints I

Soft ConstraintsImplementing hard constraints might result computationally hard,and maybe not feasible in real-time scenario.Another approach to implement physical laws is by relaxingcontraints and, for instance, use penality function in order tomake particles approximate in a good way the target law.With this approach could be possible to implement constraints interm of minimization of common energy functions like potential orkinetic energy in particle systems.

Page 23: Particle Systems - Overview

Particle System Design I

Particle System Design

Untill now we have discussed about what is a particle system andwhich physics is needed in order do model realistic phenomena,now we will describe what a particle system need and how could bemodelled via software. In detail we need to model this aspects:

I Particle Attributes

I Particle Generation

I Particle Dynamics Eng

I Particle Extinction

I Particle Hierarchy

I Particle Rendering

Page 24: Particle Systems - Overview

Particle Attributes I

Particle Attributesa particle is a particular object that is characterizer by:

I position =

px

py

pz

I velocity =

vxvyvz

(applied vector in position)

I mass ∈ R+

I color =[a r g b

]I shape: classical sprite or an arbitrary graphical object (mesh,

plane, line. . . )

I lifetime

Page 25: Particle Systems - Overview

Particle Generation I

Particle GenerationSeveral way can be chosen to generate particle, but consideringgeneration a stochastic process could led to better effects. Heresome example of generation:

I NPartsf = MeanPartsf + rnd(−1.0,+1.0) · VarPartsfIn this example particles generated at frame f are calculatedconsidering a mean rate and a semi-random variance.

I NPartsAf = NPartsf · PSScreenAreafConsidering particle system’s screen area as generation scalefactor, in this way if particle system cover a little region of thescreen there is no need to generate a lot of particles.

I A trick to control particle system intensity during generationmight be enforced by over time the mean number of particlesgenerated per frame.MeanPartsf = InitMeanParts + DeltaMeanParts · (f − f 0)

Page 26: Particle Systems - Overview

Particle Dynamics I

Particle Dynamics

As seen before, this is the core of all particle system. Here forcesare considered and new particles position and velocity arecalculated.Shapes and colour variation could be calculated too, maybethrough a stochastic model.

Page 27: Particle Systems - Overview

Particle Extinction I

Particle ExtinctionSeveral policies could be adopted in order to remove particles, forinstance we can consider lifetime value, or maybe particle colorintensity/transparency or also considering dinstance fromparticular objects.

Page 28: Particle Systems - Overview

Particle Hierarchy I

Particle Hierarchy

I Key concept: particles might be particles system too.

In this scenario parent’s variations (velocity,position,color. . . )might be used as reference value for child particles system’stransformations.Through this approach is possible to realize complex particlesystem, for instance clouds might be modelled as an hierarchywhere the root particle attribute’s defines clouds global behaviourand child particle system’s could model regions of water particlesthat evolve depending by root state (meant as position andvelocity).

Page 29: Particle Systems - Overview

Particle Rendering I

Particle Rendering

Several techniques could be used, for instance:

I Single pixels or light source

I Triangles/quads or mesh

I Alpha blended sprites

I Marching cubes algorithms

Page 30: Particle Systems - Overview

Particle Rendering II

Alpha blended sprites

Typically particles are rendered as alphablended sprite into the scene, and in case ofparticles that map to the same pixels, they areconsidered additive (eg.total colour of the pixelas sum of particles color).The disadvantage though is that particles arealways axis-aligned and do not have a 2Drotation about the screen space z axis. Toovercome this limitation, a 2D rotation e couldbe applied to the texture coordinates (maybeinside pixel shader).

Page 31: Particle Systems - Overview

Particle Rendering III

Soft ParticlesUsing particles to draw dynamic fog withsprites is not so trivial. In fact Z-bufferbehaviour might lead to artifact: due to pixelsis visible or not, depth values of particles areinconsistent with the true nature smoke’scloud.A solution to this problem could be reach byaccessing depth values for additionalprocessing:

I if sprite is close to background, then fadesprite with background.

I if sprite is away from background, thensprite will be opaque.

I if sprite is behind background, thenignore it.

Page 32: Particle Systems - Overview

Particle Rendering IV

Marching cubes algorithms

This class of algorithm reconstrunct isosurfaces from voxels (3dpixels).Rendering particles system through isosurfaces reconstructionmight be pretty good when using particles to simulate fluidsdynamics.

Page 33: Particle Systems - Overview

A Particle System Model I

And now some structural schema that might be a starting point fora Particle System implementation. . .

Modules

Page 34: Particle Systems - Overview

A Particle System Model II

Particle System

Page 35: Particle Systems - Overview

A Particle System Model III

Particle Manager

Page 36: Particle Systems - Overview

References I

William T. ReevesParticle SystemsmA Technique for Modeling a Class of FuzzyObjectsIGraphics, Vol. 2, No. 2, April 1983.

Edward AngelInteractive Computer Graphics: A Top-down Approach UsingOpenGLAddison-Wesley, 5th Edition (2008).

Tristan LorachSoft ParticlesNvidia

Simon GreenParticle-based Fluid SimulationNvidia

Page 37: Particle Systems - Overview

References II

Lutz LattaBuilding a Million Particle SystemMy Game Developers Conference 2004

Page 38: Particle Systems - Overview

Questions

?