A Complete XBox 360 GPU
Particle System: Tech & Pipeline
Sebastian Sylvan & Dr Simon Scarle
Rare
MGS
A Complete XBox 360 GPU
Particle System: Tech & Pipeline
Sebastian Sylvan & Dr Simon Scarle
Rare
MGS
A Note on
Applicability
What is a
Particle
System?
Tech overview
• Why on the GPU?
• Some background
• Simulation
• Sorting
• Rendering
Why on the
GPU?
Why on the GPU?
No
Synchronisation
Headaches
Why on the GPU?
Performance
Why on the GPU?
Code
Specialisation
Background :
The Xbox 360
Background: The Xbox 360
VS_OUTPUT vs_main( int ix : INDEX )
{
int index = (ix+0.5)/a_const.x;
float4 pos;
float2 uv;
asm
{
vfetch pos, index, position0;
vfetch uv, index, texcoord0;
};
/* .... snip .... */
}
Flexible
fetching
Background: The Xbox 360
Memory Export
Pixel
Shader
ME
ME
DIP
Vertex
Shader
Main Memory
Frame
Buffer
Simulation
void simulation_shader( int ix : INDEX )
{
Particle p =
decompress(fetch_particle(ix));
Particle newp =
simulate( p, ix, delta_time );
write_particle( ix, compress(newp) );
}
Simulation
Newtonian
motion
// a = (sum of forces) / mass
newp.vel = p.vel + dt*a;
newp.pos = p.pos + p.vel*dt;
Simulation
Turbulence
:
Scale/bias
Per-system
position into
Position-dependent
scale/bias
“turbulence
random force
space”
a += f(tex3D(turb_tex, g(p.pos)));
Simulation
Turbulence:
Holy Cache
Thrashing, Batman!
Simulation
Alleviating Cache
Thrashing
•Use small texture
•Use “thin” format
•Sort the particles
(e.g. 10:11:11)
Simulation
Collision
detection
(spheres, planes, height fields)
Simulation
float4 rnd;
float x = (ix+rnd_offset) % rnd_size;
asm{
tfetch1D rnd, x, rnd_tex,
UnnormalizedTextureCoords=true
};
rnd = ix > half_N ? rnd.xyzw : rnd.wzyx;
Particle newp = create_particle(rnd);
Emission
Sorting
Sorting
Why sort?
• Cache coherency
• Non-commutative rendering
Sorting
Why sort?
Sorting
Need parallel sort for
parallel hardware
Parallelize standard algorithms?
Sorting networks?
Sorting
Sorting Networks
(Bitonic merge sort, odd-even
merge sort)
Sorting
Merge the two halves
of the array s
Odd-Even merge
merge(s)
{
n = size(s)
if ( n == 2 )
{
return CAS(s(0),s(1))
}
else
{
odds = s(1,3,..,n-1)
evens = s(0,2,..,n-2)
result =
interleave( merge(evens),
merge(odds))
for ( i = (1,3,..,n-2) )
{
(x,y) =
CAS(result(i),
result(i+1))
result(i)= x
result(i+i)= y
}
}
}
Sorting
Odd-Even merge
2
8
2
2
3
1
6
7
3
7
3
8
2
1
1
3
8
7
12
7
1
1
8
12
6
7
10
6
6
10
12
3
2
10
10
8
6
12
12
10
Sorting
Odd-Even merge sort
Sorting
Odd-Even merge sort
Nested algorithm, needs manual
flattening for parallelism:
Instant
Sorting
Advice for staying sane
• Write “twin” version in GPPL
• Debugging: step through PIX and
your “twin” simultaneously
Sorting
Or, just copy my
stuff!
Google: “Particle System Simulation
and Rendering on the Xbox 360 GPU“
Sorting
Sorting for cache coherency
Sorting
Sorting performance
Sorting
When incremental
sorting fails
Whenever there the position changes
too quickly
Prime example: Respawns
Solution: Delay simulation/rendering of newly spawned
particle for a few frames for sorting
Rendering
Rendering
Point sprites
Rendering
Geometry
Amplification
Produce N vertices for each particle
Index Buffer
Particle Buffer
...
...
Results
Results
Results
Results
A Complete XBox 360 GPU
Particle System: Tech & Pipeline
Sebastian Sylvan & Dr Simon Scarle
Rare
MGS
A Complete XBox 360 GPU
Particle System: Tech & Pipeline
Sebastian Sylvan & Dr Simon Scarle
Rare
MGS
An Complete XBox 360 GPU
Particle System: Tech & Pipeline
Sebastian Sylvan & Dr Simon Scarle
Rare
MGS
Old System
1. Artist wants a new particle system
2. Artist talks to Programmer
3. Programmer implements code/shaders to
produce the effect
4. Artist looks at particles and wants it exactly
the same only completely different
5. Goto 2 : Rinse & Repeat
New System
• Rare usually takes an Art Driven approach
• Creation of particle effects via art tool
• Sebastian's Tech demos implemented in our
pipeline with this in mind
– highly customisable
– efficiency
Overview
Artist Input
Interim Build
Format
Runtime Asset
Artist Input
• Particle.mb produced by Maya
– Main art package at Rare
– Use Maya particle options as base
• Extend
– custom attributes on particle nodes
• Random Scaling/orientation
• Soft Particles
• Timing
Interim Build Format
• Parse particle data from artist input
– Rparticle
• Currently undergoing a de-Maya-ification
process
– i.e. add another rparticle producer
– rparticle objects produced in WorldBuilder/Viewer
Rparticle
• Collection of arrays of custom data storage
classes
– RparticleObject
– RparticleEmitter
– RparticleField
– RparticleRamp
• And a couple of R1 data classes
– RmodelShader
– RmodelNurbsCurve
Runtime Asset
Simulation
Shader
Render Shader
(Sorting Shader)
Parameters
Simulation Shader
• Lego-ized/modular construction
• “Death to the Über-Particle by meta-coding”
• RparticleObject is parsed into two lists of
ISimulationFragment
– Initialisation
– Simulation
• Fragments output needed HLSL to build up
the shader
Simulation Shader
• Helper mini-fragments
• Initialisation Frags
– Create a new particle
– Depends on emitter
•
•
•
•
Directional
Omni-directional
Volume
Curve/Texture
• Simulation Frags
– Euler integration for
Newtonian motion
– Fields
•
•
•
•
Gravity/Uniform
Drag
radial
vortex
– Collisions
• Sphere
• plane
InitFragmentOmni
initcode << GetRandomNumGenerator() <<
‘’
void InitParticle( int index, inout Part particle ){‘’
‘’
float4 rnd = Random( index );’’
’’
particle.pos = float3( 0, 0, 0);’’
‘’
float3 buildVel = 2 * ( rnd.x – 0.5 );“
“
float fac = sqrt ( 1 - buildVel.z* buildVel.z );”
<< SinCos( ‘’theta’’, ‘’2* PI* rnd.y’’ )<<
“
buildVel.x = fac* cosTheta;"
“
buildVel.y = fac* sinTheta;”
“
particle. Vel = buildVel;“;
initcode << OffSetMinMaxDistance( m_emitter->GetMinDist(), m_emitter>GetMaxDist() )<<
“
particle.vel *= ( 2* rnd.w - 1) *”
<< m_emitter->GetSpeedRandom() <<‘’ +’’ << m_emitter->GetSpeed() <<‘’;’’
<< Epilogue( 0, pdesc );
Simulation Shader
• Very easy to add new types of emitter and
dynamics
– implement HLSL code in a ISimulationFragment
• Not a huge Über-shader
– Only the Code needed
• Slight problem adding a new Feature to an
“Active” Asset
– Shader rebuild not just a parameter tweak
Render Shader
• Three customizations of our standard shader
builder
– no Über-shader again
– Easy use of current special effects
• Three standard base types
– Pointsprites
– Line / Streaks
– Quad / billboards / sprites
Render Shader
• geometry amplification for non-point sprite
primitives
– Use velocity to get 2nd vertex for line particles
– Produce further vertices for camera facing quads
• Once again only required parts of shader are
present
• Line fade / colour change
• ramp textures to rotate/scale sprites
Parameters
• Broadest sense
– Parameters/Data for effects
• Softness
• Spread
• Emitter transform
– Position, direction
– Textures
• Ramps
– scaleX, scaleY, rotation, RGBA
• Curve / texture emitters
DEMONSTRATION
DEMONSTRATION
• Emitters
– Directional
– Omni-directional
– Volume
•
•
•
•
•
Box
Sphere
Cylinder
Cone
torus
– Curve
• Visual Effects
– Normal map
– Cube Map
– Projection Textures
• Fields
–
–
–
–
Gravity
Radial
Vortex
Drag
• Ramps
– Scaling
– Rotation
– RGBA
Descargar

A Complete XBox 360 GPU Particle System: Tech & Pipeline