600 likes | 819 Views
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.
E N D
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
Tech overview • Why on the GPU? • Some background • Simulation • Sorting • Rendering
Why on the GPU? No Synchronisation Headaches
Why on the GPU? Performance
Why on the GPU? Code Specialisation
Background: The Xbox 360 • VS_OUTPUT vs_main( int ix : INDEX ) • { • int index = (ix+0.5)/a_const.x; • float4 pos; • float2uv; • asm • { • vfetch pos, index, position0; • vfetchuv, index, texcoord0; • }; • /* .... snip .... */ • } Flexible fetching
Background: The Xbox 360 Memory Export Main Memory DIP ME ME
Simulation • voidsimulation_shader( int ix : INDEX ) • { • Particlep = • 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 : Position-dependent random force Per-system scale/bias Scale/bias position into “turbulence 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 (e.g. 10:11:11) • Sort the particles
Simulation Collision detection (spheres, planes, height fields)
Simulation Emission float4rnd; float x = (ix+rnd_offset)% rnd_size; asm{ tfetch1D rnd, x, rnd_tex, UnnormalizedTextureCoords=true }; Particle newp = create_particle(rnd); rnd = ix > half_N ? rnd.xyzw : rnd.wzyx;
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 3 8 12 1 6 7 10 2 8 1 7 3 12 6 10 2 1 7 3 6 12 10 8 1 7 2 8 3 10 6 12 1 3 2 6 7 10 8 12
Sorting Odd-Even merge sort
Sorting Odd-Even merge sort Nested algorithm, needs manual flattening for parallelism: Instant Insanity!
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 Point sprites
Rendering Geometry Amplification Produce N vertices for each particle ... Index Buffer ... ParticleBuffer
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
almost ^ An Complete XBox 360 GPU Particle System: Tech & Pipeline Sebastian Sylvan & Dr Simon Scarle Rare MGS
Old System • Artist wants a new particle system • Artist talks to Programmer • Programmer implements code/shaders to produce the effect • Artist looks at particles and wants it exactly the same only completely different • 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