Anda di halaman 1dari 78

_11. August.27.

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

Shooter 2 for the uninitiated

!Environmental puzzle-based shooter !Puzzles based on interactions between solids, liquids,

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

Fix for ow compression


!Flow is supposed to be incompressible !Give particles an adjustable radius bias and a

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

Particle type differences


!Different masses !Some have rigid bodies and some dont !For different combinations of particle types (magma +
water, magma + rock, etc) !Different force of repulsion values !Different force of repulsion values !Different chemical reactions simulated !Different heat propagation

_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

Fluid particle processing stages


!Collision detection, repulsive force calculation !Force unication across grid cells !For particles on the border of 2 or more cells !Verlet update !Also events, such as sudden change in uid direction !Particle deletion (one SPU used) !Grid calculation for next frame 2 2 !O(n /k) for k!1232 cells (44x28) is better than O(n )
_11. August.27.Saturday 10

Collision (via interactor particles)


!Characters, missiles, and other in-game objects are
surrounded by special particles called interactors !Uses the existing particle system !Any collision can be simply detected and tracked

_11. August.27.Saturday

11

Collision (interactor particles)

_11. August.27.Saturday

12

Collision (interactor particles)

_11. August.27.Saturday

12

Collision (via distance eld)


!Uses signed distance elds !256x256 Chamfer distance with a 3x3

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

Collision (distance eld)

_11. August.27.Saturday

14

Collision (distance eld)

_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

Particles move too far apart from each other in free


falling liquid Liquid loses cohesiveness Opposite problem as compression Fixed by not fully clearing the buffer Image lag effect maintains cohesiveness

_11. August.27.Saturday

19

Cohesiveness (in motion)

_11. August.27.Saturday

20

Cohesiveness (in motion)

_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

SPU lighting: stage 1


Ray length: 0

_11. August.27.Saturday

29

SPU lighting: stage 1


Ray length: 16

_11. August.27.Saturday

29

SPU lighting: stage 1


Ray length: 32

_11. August.27.Saturday

29

SPU lighting: stage 1


Ray length: 41

_11. August.27.Saturday

29

real data 0 0 42 0 1 1 1

fake data (in this example) 1 1 1 1 1 1 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

fake data (in this example) 1 1 1 1 1 1 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

fake data (in this example) 1 1 1 1 1 1 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

fake data (in this example) 1 1 1 1 1 1 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

fake data (in this example) 1 1 1 1 1 1 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

SPU lighting stage 2

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

SPU lighting stage 2: optimizations


16 bytes / 16 aligned

_11. August.27.Saturday

32

SPU lighting stage 2: optimizations


16 bytes / 16 aligned

safe angle range "y > "x

_11. August.27.Saturday

32

SPU lighting stage 2: optimizations


16 bytes / 16 aligned

safe angle range "y > "x


unsafe angle range

"x # "y

_11. August.27.Saturday

32

SPU lighting stage 2: optimizations


16 bytes / 16 aligned

safe angle range "y > "x


unsafe angle range

"x # "y

_11. August.27.Saturday

32

SPU lighting stage 2: optimizations


16 bytes / 16 aligned

safe angle range "y > "x


unsafe angle range

"x # "y

_11. August.27.Saturday

32

SPU lighting stage 2: optimizations


16 bytes / 16 aligned

safe angle range "y > "x


unsafe angle range

"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

SPU lighting stage 2: optimizations


values occur in different quadwords
8 6 7 x 8 6 x 5

_11. August.27.Saturday

33

SPU lighting stage 2: optimizations


values occur in different quadwords
8 6 7 x 8 6 x 5

non-merging masks

_11. August.27.Saturday

33

SPU lighting stage 2: optimizations


values occur in different quadwords
8 6 7 x 8 6 x 5

non-merging masks 8 6 7 x 8 6 x 5

_11. August.27.Saturday

33

SPU lighting stage 2: optimizations


values occur in different quadwords
8 6 7 x 8 6 x 5

non-merging masks 8 6 7 x 8 6 x 5

_11. August.27.Saturday

33

SPU lighting stage 2: optimizations


values occur in different quadwords
8 6 7 x 8 6 x 5

non-merging masks 8 6 7 x 8 6 x 5

_11. August.27.Saturday

33

SPU lighting stage 2: optimizations


values occur in different quadwords
8 6 7 x 8 6 x 5 8

values occur in same quadword


6 7 x 8 6 x 5

non-merging masks 8 6 7 x 8 6 x 5

_11. August.27.Saturday

33

SPU lighting stage 2: optimizations


values occur in different quadwords
8 6 7 x 8 6 x 5 8

values occur in same quadword


6 7 x 8 6 x 5

non-merging masks 8 6 7 x 8 6 x 5

merging masks

_11. August.27.Saturday

33

SPU lighting stage 2: optimizations


values occur in different quadwords
8 6 7 x 8 6 x 5 8

values occur in same quadword


6 7 x 8 6 x 5

non-merging masks 8 6 7 x 8 6 x 5 8 6

merging masks

_11. August.27.Saturday

33

SPU lighting stage 2: optimizations


values occur in different quadwords
8 6 7 x 8 6 x 5 8

values occur in same quadword


6 7 x 8 6 x 5

non-merging masks 8 6 7 x 8 6 x 5 8 6

merging masks

_11. August.27.Saturday

33

SPU lighting stage 2: optimizations


values occur in different quadwords
8 6 7 x 8 6 x 5 8

values occur in same quadword


6 7 x 8 6 x 5

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

SPU Lighting: future improvements

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

start df start light start skinning start particle fx


collision + update GameMonkey render

_11. August.27.Saturday

36

Frame overview

start df start light start skinning start particle fx


collision + update GameMonkey render

wait prev uid

wait distance eld

_11. August.27.Saturday

36

Frame overview
start uid

start df start light start skinning start particle fx


collision + update

GameMonkey

render

wait prev uid

wait distance eld

_11. August.27.Saturday

36

Frame overview
start uid

start df start light start skinning start particle fx


collision + update

GameMonkey

render

wait prev uid

wait distance eld

wait light wait skinning wait particle fx

_11. August.27.Saturday

36

Tuner capture

_11. August.27.Saturday

37

Tuner capture

distance transform

distance xform post process

_11. August.27.Saturday

37

Tuner capture

_11. August.27.Saturday

37

Tuner capture

point light

point light merge

black light

black light merge

_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

mesh skinning mesh skinning

_11. August.27.Saturday

37

Tuner capture

_11. August.27.Saturday

37

Tuner capture
uid particle hit test uid particle calc grid

uid particle update

uid particle draw

uid particle merge acc

uid particle delete

_11. August.27.Saturday

37

_11. August.27.Saturday

38

Anda mungkin juga menyukai