advanced 3d computer graphics behzad akbari professor burton ma cse 4431, winter 2011 particle...

31
Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

Upload: ernest-parrish

Post on 01-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

Advanced 3D Computer GraphicsBehzad akbari

Professor Burton Ma

CSE 4431, Winter 2011

PARTICLE SYSTEMS

Page 2: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

HISTORY OF PARTICLE SYSTEMS:

For the first time in 1978 in a short movie” Asteroids”

in “Star Trek II: The Wrath of Kahn” 1983 it used ,

they used planetary fire wall.

The first CG paper about particle systems by William T. Reeves published in that year. [4]

Page 3: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

What is particle system?a system to control collection of a number of individual elements (points, line, triangle or Sprit texture) which act independently but share some common attributes: [6]• position (3D)

•velocity (vector: speed and direction)

•color +(transparency)

•lifetime

•size, shape

Page 4: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

Applications solution to modeling fuzzy, amorphous(changeable), dynamic and fluid objects like

smoke,fire,sparks,Rain,snow,Water spray,explosions, Galaxies

Page 5: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

Process Steps for Particle System

Random Generator: the input of Emitter

Emitter: source of particles and its position determine where they are generated. Controls number of particles, direction and other global settings

Update: Particles attributes are updated before Dead(extinction) some unctions define behavior of particles as they move through the scene

Page 6: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

Process Steps for Particle System(cont)

Render: How particles are displayed on screen?

• Points

• Lines (from last position to current position)

• Sprites (textured quad’s facing the camera)

• Geometry (small objects…)

Page 7: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

Basic particle system physics Particles in 3D space affected by forces (e.g. gravity or wind) which accelerate a Particle and acceleration changes velocity and Velocity changes position. We have two integration about movement:

a)Euler Integration

[14]

Page 8: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

Basic particle system physics(cont.)

b)Verlet Integration [15]

Integrate acceleration to position:

This formula needs no storage of particle velocity but time step needs to be (almost) constant.(complex velocity operations like collision reaction )

Page 9: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

Particle Simulation on the GPU

In the graphic systems we have 2 type of particle systems:

● Stateless simulation

It only can use for simple effects.

The Simulation is in vertex shader

(possible on first generation programmable GPUs)

● State-preserving (iterative) simulation

Simulation with textures and pixel shaders

(can execute only on recent generation GPUs)

Page 10: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

Stateless particle systems

• No storage of varying particle data

• Evaluation of closed form function describing movement/attribute changes

• Computed data depends only on initial values and static environment description

Page 11: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

Constant acceleration (cont)[1]

When a is constant:[1]

2000

00

0

2

1ttdt

tdt

avrvr

avav

aa

2

2

dt

d

dt

d

dt

d

t

rva

rv

rr

Page 12: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

Attributes

● Position depends on initial position, initial velocity and gravity:

● Orientation depends on initial orientation and rotation velocity:

●Color and transparency depend on linear function with four key (k0,k1,to,t1) variables

Page 13: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

Algorithm of Stateless PS in GLSL

We change Particles in 2 stages:

Page 14: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

Computing Particle Attributes

• Global time is “0”

• How long a particle is active?

time = globalTime – tInitial;

• Final Position :

pFinal = pInitial + vInitial * t + 0.5 * acceleration * t * t;

• Color and size functions of time (Random) or static functions

Compute the new :

• Xnew = Xold + Vold * Time change;

• Vnew = Vold + a * Time change;

Page 15: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

State Preserving Simulation

● Position and velocity stored in textures

● From these textures each simulation step renders into equally sized other textures

● Fragment shader performs iterative integration

● Position textures are “re-interpreted” as vertex data

● Rendering of point sprites/triangles/quads

Page 16: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

Storage of particle data in SP • Position and velocity stored in 2D textures.

• Textures treated as 1D array. Precision can be position 32bit FP, velocity 16bit FP .

• Static information are:

Time of birth,

type ID.

Page 17: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

Algorithm for one time step(preserve state)

1. Process birth and death

2. Velocity operations (forces, collisions, dampening)

3. Position operations

4. Sorting for alpha blending (optional)

5. Transfer pixel to vertex data

6. Rendering

Page 18: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

Birth of a particle/allocation[1]

● Perform allocation on the CPU:

– Determine next free index

– Determine initial particle values

– Render initial values as pixel-size points

Page 19: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

DEATH OF PARTICLES

● Processed independently on CPU and GPU

● CPU: Free particle index, re-add it to allocator

● GPU: Move particles to infinity (or very far away)

● or particles fall out of view,

Page 20: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

Velocity operations

● Update velocity textures with various operations:

– Global forces(gravity)

– Local forces

– Dampening

– Collisions

– Flow field

[12]

Page 21: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

Global and local forces

● Global forces are position-invariant: Gravity, wind

● Local forces fall off based on distance: Magnet, orbiting, turbulence, Fall off with

● change scale effect based on mass, air resistance etc.

Page 22: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

GLOBAL AND LOCAL FORCES (CONT.)

● Add all forces to one force vector

● Convert force to acceleration (f = m.a )

( identical if all particles have unit mass)

Page 23: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

Dampening and Un-dampening

– Scale down velocity vector

– Simulates slow down in viscous (sticky) materials

● Un-dampening:

– Scale up velocity vector

– Simulates self-moving objects, e.g. bee swarm

Page 24: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

Collision

● Collision on GPU limited for efficiency:

● Algorithm:

1. Detect collision with expected new position

2. Determine surface normal at approximate

point

3. React on collision, i.e. alter velocity

● Split velocity (relative to collider) into normal vn and tangential vt component:[1]

Page 25: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

Position update

● Euler integration:

– Simply apply velocity

● Verlet integration:

– Apply acceleration caused by forces

– Apply other effects like dampening and collision.

Page 26: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

SORTING FOR ALPHA-BLENDING

● Alpha-blended particles show artifacts when rendered unsorted

The GPU can sort nowadays...

– Put viewer-distance and index into a texture

– Sort this texture (at least partially)

Page 27: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

Sorting networks

GPU needs parallel sorting We need to use a data-independent algorithm..Efficient algorithm is Odd-Even Merge Sort which is like this:

[1]

Page 28: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

Transfer particle to sprites

• we need to transfer particle positions to geometry data.

• Point sprites allow most efficient transfer only one vertex per particle.

• Triangles or quads need replicated vertices.

• Several methods to transfer texture data to vertices exist:Über-Buffer

• It can Store any data in graphics card memory. Copy from one buffer (here texture) to another buffer (here vertex buffer).

• Available on (GFFX, R9xxx).OpenGL-only, OpenGL extensions: ARB_super_buffer, NV_pixel_buffer_object, NV_pixel_data_range.

Page 29: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

Multiple particle textures

We can Combine several textures as sub-textures of one larger texture

– Adjust texture coords. accordingly

– For point sprites: Transform tex.coords. in fragment shader

Page 30: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

RENDERING

Particles display as(OpenGL points, (Textured) billboarded quads, Point sprites[6])

Sample code:glTexEnvf(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);

glEnable(GL_POINT_SPRITE);

glBegin(GL_POINTS);

glVertex3f(position.x, position.y, position.z);

glEnd();

glDisable(GL_POINT_SPRITE);

Page 31: Advanced 3D Computer Graphics Behzad akbari Professor Burton Ma CSE 4431, Winter 2011 PARTICLE SYSTEMS

Reference:• [1][Building a Million Particle System Lutz Latta Massive Development GmbH] http://www.2ld.de/gdc2004/MegaParticlesSlides.pdf

• [2]OpenGL Extensions & Advanced rendering https://home.zhaw.ch/~frp/CGr/Unterlagen/12_OpenGL_Advanced.pdf]

• [3] Implementing Particle Systems in OpenGL SPSU (southern polytechnic state university)

• [4]http://www.lri.fr/~mbl/ENS/IG2/devoir2/files/docs/fuzzyParticles.pdf

• [5] http://www.naturewizard.com/tutorial08.html

• [6] Jürgen P. Schulze, Ph.D.University of California, San Diego Fall Quarter 2011, Lecture #18

• [7]Computer Graphics Lecture Notes University of Toronto November 24, 2006

• [8]lecture on Advanced Computer Graphics by Bas Zalmstra and Marries van de Hoef

• [9] Procedural Smoke Particle System with OpenGL 2.0 Tommy Hinks – [email protected]

• [10]http://en.wikipedia.org/wiki/Particle_system

• [11] http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter06.html

• [12]Particle Animation and Rendering Using Data Parallel Computation Karl Sims

• [14] http://en.wikipedia.org/wiki/Euler_equations_(fluid_dynamics)

• [15] http://en.wikipedia.org/wiki/Verlet_integration