Saturday
PixelJunk Shooter 2
Fluid dynamics and lighting implementation
Jaymin Kessler Q-Games Technology Team twitter: @okonomiyonda
_11. August.27.Saturday
PixelJunk Shooter 2
Fluid dynamics
_11. August.27.Saturday
gasses, and magnetics !Water cools magma to form rock, magma melts ice and rock, magma ignites gas, lasers melt rock into magma and ice into water, magnetics + water forms a poison gas !All Organically arising from physics, nothing is scripted
_11. August.27.Saturday 4
_11. August.27.Saturday
_11. August.27.Saturday
Verlet integration
!Good points !4th order accurate !Greater stability than Euler !Time-reversibility !Bad points !Bad handling of variable time steps !Needs 2 steps to start, and initial conditions are crucial !Time-corrected verlet helps
_11. August.27.Saturday 6
repulsive force !Based on the max ingression of surrounding particles !Lerp from current bias to desired bias !Bias contraction is 4x faster than expansion
_11. August.27.Saturday
_11. August.27.Saturday
Heat propagation
!Each particle carries thermal data !When particles collide, heat is propagated !Warmer to cooler !Same algorithm used for intra-particle repulsive force !Particle types have different thermal transfer values
_11. August.27.Saturday
_11. August.27.Saturday
11
_11. August.27.Saturday
12
_11. August.27.Saturday
12
window was !0.5ms on a single SPU !Two distance elds: static for walls, dynamic for destructibles, results merged into nal distance eld !One lookup gets the distance and direction to closest object !Also reused for SPU lighting
13
_11. August.27.Saturday
_11. August.27.Saturday
14
_11. August.27.Saturday
14
PixelJunk Shooter 2
Fluid rendering
_11. August.27.Saturday
15
Fluid rendering
Grouped particles must be rendered as a smooth owing uid Existing example: marching squares Currently patented? Just not by us
_11. August.27.Saturday
16
Fluid rendering
Render particles to a low-res offscreen buf with a
luminance texture Blur the offscreen buffer Scale up with bilinear lter and use the resulting brightness to color the liquid
_11. August.27.Saturday
17
Water surface
Use a smooth step function when rendering water to
an offscreen buffer Two thresholds used for water surface and for tinting
_11. August.27.Saturday
18
Cohesiveness
_11. August.27.Saturday
19
_11. August.27.Saturday
20
_11. August.27.Saturday
20
_11. August.27.Saturday
21
Depicting movement
Create a ow pattern to show movement Each particle gets a xed RG value Use a different color where RG is {0.5f, 0.5f}
_11. August.27.Saturday
22
Refraction
From water and heat rising off magma Ping-pong between offscreen buffers Degree and direction depends on particles xed UV
(RG value mentioned on the movement slide)
_11. August.27.Saturday
23
PixelJunk Shooter 2
SPU lighting
_11. August.27.Saturday
24
_11. August.27.Saturday
25
SPU lighting
Four light types Spot light (ship light suit) Point light (enemy projectiles, light balls) Wall light (also called blacklight) Ice light (different light system) Can handle 40~60 lights depending on particle load Reuses same distance eld used for uid particle collision
_11. August.27.Saturday
26
_11. August.27.Saturday
27
_11. August.27.Saturday
27
SPU lighting
Stage 1: Get ray length Gets the point on a ray where it hits its rst occluder Stage 2: Rasterize Write ray pixels out to texture (slowest pass) Stage 3: Merge with other lights Blend can be add, sub, min, max, avg, and others For rst pass, ofine-generated offset table maximizes coverage and minimizes redundant loads of source data
_11. August.27.Saturday
28
_11. August.27.Saturday
29
_11. August.27.Saturday
29
_11. August.27.Saturday
29
_11. August.27.Saturday
29
real data 0 0 42 0 1 1 1
clgtbi $6, $35, 0 gbb $29, $6 shli $6, $29, 16 clz $73, $6 a $69, $73, $45 clgt $27, $49, $73 selb $45, $69, $45, $40 or $40, $27, $40
_11. August.27.Saturday
30
real data 0 0 0 42 FF 0 0 1 1 1
clgtbi $6, $35, 0 gbb $29, $6 shli $6, $29, 16 clz $73, $6 a $69, $73, $45 clgt $27, $49, $73 selb $45, $69, $45, $40 or $40, $27, $40
FF FF FF FF FF FF FF FF FF FF FF FF
_11. August.27.Saturday
30
real data 0 0 0 42 FF 0 0 1 1 1
clgtbi $6, $35, 0 gbb $29, $6 shli $6, $29, 16 clz $73, $6 a $69, $73, $45 clgt $27, $49, $73 selb $45, $69, $45, $40 or $40, $27, $40
FF FF FF FF FF FF FF FF FF FF FF FF
0000000000000000 0010111111111111
_11. August.27.Saturday
30
real data 0 0 0 42 FF 0 0 1 1 1
clgtbi $6, $35, 0 gbb $29, $6 shli $6, $29, 16 clz $73, $6 a $69, $73, $45 clgt $27, $49, $73 selb $45, $69, $45, $40 or $40, $27, $40
FF FF FF FF FF FF FF FF FF FF FF FF
0000000000000000 0010111111111111
0010111111111111 0000000000000000
_11. August.27.Saturday
30
real data 0 0 0 42 FF 0 0 1 1 1
clgtbi $6, $35, 0 gbb $29, $6 shli $6, $29, 16 clz $73, $6 a $69, $73, $45 clgt $27, $49, $73 selb $45, $69, $45, $40 or $40, $27, $40
FF FF FF FF FF FF FF FF FF FF FF FF
0000000000000000 0010111111111111
0010111111111111 0000000000000000
_11. August.27.Saturday
30
The biggest bottleneck is writing out image data Not known at compile time if 2 pixels are in the same quadword The compiler must be conservative and read-insert-write read insert-write to avoid corrupting previously written values Optimizations Divide by angle range Create merging shufe masks
_11. August.27.Saturday
31
_11. August.27.Saturday
32
_11. August.27.Saturday
32
"x # "y
_11. August.27.Saturday
32
"x # "y
_11. August.27.Saturday
32
"x # "y
_11. August.27.Saturday
32
"x # "y
problem
problem
If two adjacent pixels in a ray can occur in the same HW vector, we must read, insert, write, read, insert, write...
_11. August.27.Saturday
32
_11. August.27.Saturday
33
non-merging masks
_11. August.27.Saturday
33
non-merging masks 8 6 7 x 8 6 x 5
_11. August.27.Saturday
33
non-merging masks 8 6 7 x 8 6 x 5
_11. August.27.Saturday
33
non-merging masks 8 6 7 x 8 6 x 5
_11. August.27.Saturday
33
non-merging masks 8 6 7 x 8 6 x 5
_11. August.27.Saturday
33
non-merging masks 8 6 7 x 8 6 x 5
merging masks
_11. August.27.Saturday
33
non-merging masks 8 6 7 x 8 6 x 5 8 6
merging masks
_11. August.27.Saturday
33
non-merging masks 8 6 7 x 8 6 x 5 8 6
merging masks
_11. August.27.Saturday
33
non-merging masks 8 6 7 x 8 6 x 5 8 6
merging masks
_11. August.27.Saturday
33
_11. August.27.Saturday
34
_11. August.27.Saturday
34
Ray marching the distance eld Huge speedup in some cases Integrating the SPA version Gave about 15%~20% back Write out linear, and swizzle later (on GPU?) SPU outputs geometry info / vertex array for light, and let the
GPU render it Line info could also help with antialiasing But the GPU is too busy
_11. August.27.Saturday
35
Frame overview
collision + update
GameMonkey
render
_11. August.27.Saturday
36
Frame overview
_11. August.27.Saturday
36
Frame overview
_11. August.27.Saturday
36
Frame overview
start uid
GameMonkey
render
_11. August.27.Saturday
36
Frame overview
start uid
GameMonkey
render
_11. August.27.Saturday
36
Tuner capture
_11. August.27.Saturday
37
Tuner capture
distance transform
_11. August.27.Saturday
37
Tuner capture
_11. August.27.Saturday
37
Tuner capture
point light
black light
_11. August.27.Saturday
37
Tuner capture
_11. August.27.Saturday
37
Tuner capture
particle fx
particle fx
particle fx
particle fx
_11. August.27.Saturday
37
Tuner capture
_11. August.27.Saturday
37
Tuner capture
antialiasing
antialiasing
_11. August.27.Saturday
37
Tuner capture
_11. August.27.Saturday
37
Tuner capture
uid particle hit test uid particle calc grid
_11. August.27.Saturday
37
_11. August.27.Saturday
38