Transcript Document

Game Physics
1
Introduction to Game Physics

Traditional Game Physics
– Particle system
– Rigid body dynamics
– Flexible body dynamics

Some State-of-art Topics
– Car physics
– Fluid dynamics
– Rag-doll physics

Physics
–
–
–
–
–
Rigid body kinematics
Newton’s Laws
Forces
Momenta
Energy
2
Basic Concepts from Physics (1/2)

Newton’s Laws
– 1st Law
» “靜者恆靜,動者恆成等速度運動”
– 2nd Law
» F = ma = mdv/dt
– 3rd Law
» 作用力與反作用力

Forces
– Gravity / Spring forces / Friction / Viscosity
– Torque
»=rXF
– Equilibrium
3
Basic Concepts from Physics (2/2)

Momenta
– Linear momentum
– Angular momentum
– Moment of inertia
4
Particle Dynamics


Particles are objects with
– Mass
– Position
– Velocity
– Respond to forces
But no spatial extent (no size!)
– Point mass

Based on Newton Laws
– f = ma
..
– x=f/m
.
.
– v = f / m, x = v
5
Basic Particle System
typedef struct {
float m;
/*
float *x;
/*
float *v;
/*
float *f;
/*
} *Particle;
mass */
position */
velocity */
force accumulator */
x
v
f
m
states
typedef struct {
Particle *p /* array of pointers to particles */
int n;
/* number of particles */
float t;
/* simulation clock */
} *ParticleSystem;
Particle n time
x
v
f
m
x
v
f
m
x
v
f
m
x
x
v … v
f
f
m
m
6
/* gather states from the particles */
void ParticleGetState(ParticleSystem p, float *dst)
{
int i;
for (i = 0; i < p->n; i++) {
*(dst++) = p->p[I]->x[0];
*(dst++) = p->p[I]->x[1];
*(dst++) = p->p[I]->x[2];
*(dst++) = p->p[I]->v[0];
*(dst++) = p->p[I]->v[1];
*(dst++) = p->p[I]->v[2];
}
}
7
/* scatter states into the particles */
void ParticleSetState(ParticleSystem p, float *src)
{
int i;
for (i = 0; i < p->n; i++) {
p->p[i]->x[0] = *(src++);
p->p[i]->x[1] = *(src++);
p->p[i]->x[2] = *(src++);
p->p[i]->v[0] = *(src++);
p->p[i]->v[1] = *(src++);
p->p[i]->v[2] = *(src++);
}
}
8
/* calculate derivative, place in dst */
void ParticleDerivative(ParticleSystem p, float *dst)
{
int i;
ClearForce(p);
ComputeForce(p);
for (i = 0;
*(dst++)
*(dst++)
*(dst++)
*(dst++)
*(dst++)
*(dst++)
}
i
=
=
=
=
=
=
< p->n; i++) {
p->p[i]->v[0];
p->p[i]->v[1];
p->p[i]->v[2];
p->p[i]->f[0]/p->p[i]->m;
p->p[i]->f[1]/p->p[i]->m;
p->p[i]->f[2]/p->p[i]->m;
}
9
/* Euler Solver */
void EulerStep(ParticleSystem p, float DeltaT)
{
ParticleDeriv(p, temp1);
ScaleVector(temp1, DeltaT);
ParticleGetState(p, temp2);
AddVector(temp1, temp2, temp2);
ParticleSetState(p, temp2);
p->t += DeltaT;
}
10
Rigid Body Dynamics

Mass of a Body
– Mass center

Force
– Linear momentum
– P(t) = M v(t)
– Velocity (v)

Torque
– Angular momentum
– L(t) = I w(t)
– Local rotation (w)


Inertia Tensor
Reference
– www-2.cs.cmu.edu/afs/cs/user/baraff/www/pbm
11
Flexible Body Dynamics (1/2)

Particle-Spring Model
–
–
–
–
F=kx
Not a stress-strain model
Lack of Elasticity, Plasticity, & Viscous-Elasticity
Can be unstable
12
Flexible Body Dynamics (2/2)

Finite Element Method
–
–
–
–
–

Solver for ODE/PDE
Boundary conditions
Energy equation
Stress-strain model
Very complicated computing process
Conservation of Energy
13
Advanced Topics in Game Physics




Fracture Mechanics (破壞力學模擬)
Fluid Dynamics (流體力學)
Car Dynamics (車輛動力學)
Rag-doll Physics (人體物理模擬)
14
Game FX
15
Introduction to Game FX


Improve the Visual & Sound Game Effects
Includes
–
–
–
–
–

Combat FX
Environment FX
Character FX
Scene FX
Sound FX
FX Editor Needed
– General 3D animation can not do it
» Key-frame system is nor working
» FX animation is always



Procedurally
Related to the previous frame
Small Work But Large Effect
16
FX Editing Tool
17
Combat FX

During the Combat
– Weapon motion blur
– Weapon effect
– Skill effect

After the Combat
– Damage effect

FX Editor
18
Combat FX Example
19
Motion Blur – Image Solution

Computer Animation :
– Image solution
– Blending rendered image sequence
»
»
»
»
Render too many frames
Divide the frames
Average
Done!
20
Motion Blur – Geometry Solution


In Games, Use Transparent Objects to Simulate the
Motion Blur
“False” Motion Blur
– Tracking the motion path of the object
– Connecting them as a triangular mesh
– Use time-dependent semi-transparency to simulate the
“blur”
– The path can be smoothed using Catmull-Rom spline
» Local stability of the curve
21
FX Uses Texture Animation


Almost All Game FXs Use this Trick
Geometry Object on which the Texture Animation
Playing
–
–
–
–
–


Billboard
3D Plate
Cylinder
Sphere
Revolving a cross section curve
Texture Sequence with Color-key
Semi-transparent Textures
– Alpha blending
» Source color added to background

Demo!!!!
22
Particle System for FXs in Combat

The FXs
– Fire / exposure / smoke / dust


Initial Value + Time dependency
Combined with Billboard FX
– Billboard to play the texture animation
– Particle system to calculate the motion path


Gravity is the major force used
Emitter pattern
– Single emitter
– Area emitter
– Emitter on vertices

Demo !!!
23
Environment FX

Weather
– Use particle system
» Rain
» Snow
» Wind

Fog
– Traditional fog
» From near to far
» Hardware standard feature
– Volume fog
» Layered fog
» Use vertex shader

Day & Night
24
Character FX

Fatality
– Case by case and need creative solutions

Rendering Effects on Skins
–
–
–
–

Environment mapping
Bump map
Normal map
Multiple texture map
Flexible body
– Flexible body dynamics

Fur
– Real-time fur rendering

…
25
Scene FX – Sky Box



Use a very large box or dome-like model to surround
the whole game scene
Use textures on the box or dome as the backdrop
Use multiple textures and texture coordinates
animation to simulate the moving of the clouds
26
Scene FX – Len’s Flare


Runtime calculate the position and orientation of
the camera with the sun
Put textures to simulate the len’s flare
27
Scene FX – Light Scattering


Atmospheric Light Scattering
Caused by dust, molecules, or water vapor
– These can cause light to be:
» Scattered into the line of sight (in-scattering)
» Scattered out of the line of sight (out-scattering)
» Absorbed altogether (absorption)


Skylight and sun light
Can be Implemented by Vertex Shader
28
Scene FX – Light Scattering Examples
Without scattering
With scattering
29