SIGGRAPH 2011 PixelJunk Shooter 2 notes

Embed Size (px)

Citation preview

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    1/78

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    2/78

    PixelJunk Shooter 2Fluid dynamics and lighting implementation

    Jaymin Kessler

    Q-Games Technology Team

    twitter: @okonomiyonda

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    3/78

    PixelJunk Shooter 2Fluid dynamics

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    4/78

    !Environmental puzzle-based shooter

    !Puzzles based on interactions between solids, liquidgasses, and magnetics

    !

    Water cools magma to form rock, magma melts icrock, magma ignites gas, lasers melt rock into magmice into water, magnetics + water forms a poison g

    !All Organically arising from physics, nothing is scripte

    Shooter 2 for the uninitiated

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    5/78

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    6/78

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    7/78

    !

    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 cru

    !Time-corrected verlet helps

    Verlet integration

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    8/78

    !Flow is supposed to be incompressible

    !Give particles an adjustable radius bias and arepulsive force

    !Based on the max ingression of surroundingparticles

    !

    Lerp from current bias to desired bias!Bias contraction is 4x faster than expansion

    Fix for flow compression

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    9/78

    !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

    Particle type differences

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    10/78

    !Each particle carries thermal data

    !When particles collide, heat is propagated!Warmer to cooler

    !Same algorithm used for intra-particle repulsive fo

    !Particle types have different thermal transfer value

    Heat propagation

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    11/78

    !

    Collision detection, repulsive force calculation!Force unification across grid cells

    !For particles on the border of 2 or more cells

    !Verlet update

    !

    Also events, such as sudden change in fluid direction!Particle deletion (one SPU used)

    !Grid calculation for next frame

    !O(n2/k) for k!1232 cells (44x28) is better than O(n

    Fluid particle processing stages

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    12/78

    !Characters, missiles, and other in-game objects aresurrounded by special particles called interactors

    !Uses the existing particle system!Any collision can be simply detected and tracked

    Collision (via interactor particles)

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    13/78

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    14/78

    Collision (interactor particles)

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    15/78

    !

    Uses signed distance fields!256x256 Chamfer distance with a 3x3window was !0.5ms on a single SPU

    !Two distance fields: static for walls, dynamicfor destructibles, results merged into final

    distance field!One lookup gets the distance and directionto closest object

    !Also reused for SPU lighting

    Collision (via distance field)

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    16/78

    Collision (distance field)

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    17/78

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    18/78

    PixelJunk Shooter 2Fluid rendering

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    19/78

    Fluid rendering

    Grouped particles must be rendered as a smooth

    flowing fluidExisting example: marching squares

    Currently patented?

    Just not by us

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    20/78

    Fluid rendering

    Render particles to a low-res offscreen buf with a

    luminance textureBlur the offscreen buffer

    Scale up with bilinear filter and use the resultingbrightness to color the liquid

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    21/78

    Water surface

    Use a smooth step function when rendering water to

    an offscreen bufferTwo thresholds used for water surface and for tinting

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    22/78

    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

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    23/78

    Cohesiveness (in motion)

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    24/78

    Cohesiveness (in motion)

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    25/78_11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    26/78

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    27/78

    Refraction

    From water and heat rising off magma

    Ping-pong between offscreen buffersDegree and direction depends on particles fixed UV(RG value mentioned on the movement slide)

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    28/78

    PixelJunk Shooter 2SPU lighting

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    29/78

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    30/78

    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 field used for fluid particle col

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    31/78

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    32/78

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    33/78

    SPU lighting

    Stage 1: Get ray length

    Gets the point on a ray where it hits its first occlud

    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 first pass, offline-generated offset table maximizecoverage and minimizes redundant loads of source d

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    34/78

    SPU lighting: stage 1

    Ray length: 0

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    35/78

    SPU lighting: stage 1

    Ray length: 16

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    36/78

    SPU lighting: stage 1

    Ray length: 32

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    37/78

    SPU lighting: stage 1

    Ray length: 41

    _11. August.27.Saturday

    l d t f k d t (i thi

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    38/78

    clgtbi $6, $35, 0

    gbb $29, $6shli $6, $29, 16

    clz $73, $6a $69, $73, $45

    clgt $27, $49, $73selb $45, $69, $45, $40

    or $40, $27, $40

    0 0 42 0 1 1 1 1 1 1 1 1

    real data fake data (in this exa

    _11. August.27.Saturday

    l d t fake data (in this exa

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    39/78

    clgtbi $6, $35, 0

    gbb $29, $6shli $6, $29, 16

    clz $73, $6a $69, $73, $45

    clgt $27, $49, $73selb $45, $69, $45, $40

    or $40, $27, $40

    0 0 42 0 1 1 1 1 1 1 1 1

    0 0 FF 0 FF FF FF FF FF FF FF FF

    real data fake data (in this exa

    _11. August.27.Saturday

    real data fake data (in this exa

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    40/78

    clgtbi $6, $35, 0

    gbb $29, $6shli $6, $29, 16

    clz $73, $6a $69, $73, $45

    clgt $27, $49, $73selb $45, $69, $45, $40

    or $40, $27, $40

    0 0 42 0 1 1 1 1 1 1 1 1

    0 0 FF 0 FF FF FF FF FF FF FF FF

    0000000000000000 0010111111111111

    real data fake data (in this exa

    _11. August.27.Saturday

    real data fake data (in this exa

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    41/78

    clgtbi $6, $35, 0

    gbb $29, $6shli $6, $29, 16

    clz $73, $6a $69, $73, $45

    clgt $27, $49, $73selb $45, $69, $45, $40

    or $40, $27, $40

    0 0 42 0 1 1 1 1 1 1 1 1

    0 0 FF 0 FF FF FF FF FF FF FF FF

    0000000000000000 0010111111111111

    real data fake data (in this exa

    0010111111111111 0000000000000000

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    42/78

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    43/78

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    44/78

    SPU lighting stage 2: optimization16 bytes / 16 aligned

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    45/78

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    46/78

    safe angle range

    "y > "xunsafe angle range

    "x #"y

    SPU lighting stage 2: optimization16 bytes / 16 aligned

    _11. August.27.Saturday

    SPU li h i 2 i i i

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    47/78

    safe angle range

    "y > "xunsafe angle range

    "x #"y

    SPU lighting stage 2: optimization16 bytes / 16 aligned

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    48/78

    SPU li hti t 2 ti i ti

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    49/78

    safe angle range

    "y > "xunsafe angle range

    "x #"y

    If two adjacent pixels ina ray can occur in the

    same HW vector, wemust read, insert, write,read, insert, write...

    SPU lighting stage 2: optimization16 bytes / 16 aligned

    _11. August.27.Saturday

    SPU li hti t 2 ti i ti

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    50/78

    SPU lighting stage 2: optimization

    8 6 7 x 8 6 x 5

    values occur in

    different quadwords

    _11. August.27.Saturday

    SPU li hti t 2 ti i ti

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    51/78

    SPU lighting stage 2: optimization

    8 6 7 x 8 6 x 5

    non-mergingmasks

    values occur in

    different quadwords

    _11. August.27.Saturday

    SPU li hti t 2 ti i ti

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    52/78

    SPU lighting stage 2: optimization

    8 6 7 x 8 6 x 5

    non-mergingmasks

    8 6 7 x 8 6 x 5

    values occur in

    different quadwords

    _11. August.27.Saturday

    SPU li hti t 2 ti i ti

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    53/78

    SPU lighting stage 2: optimization

    8 6 7 x 8 6 x 5

    non-mergingmasks

    8 6 7 x 8 6 x 5

    values occur in

    different quadwords

    _11. August.27.Saturday

    SPU li hti t 2 ti i ti

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    54/78

    SPU lighting stage 2: optimization

    8 6 7 x 8 6 x 5

    non-mergingmasks

    8 6 7 x 8 6 x 5

    values occur in

    different quadwords

    _11. August.27.Saturday

    SPU li hti t 2 ti i ti

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    55/78

    SPU lighting stage 2: optimization

    8 6 7 x 8 6 x 5

    non-mergingmasks

    8 6 7 x 8 6 x 5

    8 6 7 x 8 6

    values occur in

    same quadwor

    values occur in

    different quadwords

    _11. August.27.Saturday

    SPU li hti t 2 ti i ti

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    56/78

    SPU lighting stage 2: optimization

    8 6 7 x 8 6 x 5

    non-mergingmasks

    8 6 7 x 8 6 x 5

    8 6 7 x 8 6

    merging masks

    values occur in

    same quadwor

    values occur in

    different quadwords

    _11. August.27.Saturday

    SPU li htin sta e 2: optimi ation

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    57/78

    SPU lighting stage 2: optimization

    8 6 7 x 8 6 x 5

    non-mergingmasks

    8 6 7 x 8 6 x 5

    8 6 7 x 8 6

    merging masks

    8 6 7 5 8 6

    values occur in

    same quadwor

    values occur in

    different quadwords

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    58/78

    SPU lighting stage 2: optimization

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    59/78

    SPU lighting stage 2: optimization

    8 6 7 x 8 6 x 5

    non-mergingmasks

    8 6 7 x 8 6 x 5

    8 6 7 x 8 6

    merging masks

    8 6 7 5 8 6

    values occur in

    same quadwor

    values occur in

    different quadwords

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    60/78

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    61/78

    _11. August.27.Saturday

    SPU Lighting: future improvement

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    62/78

    SPU Lighting: future improvement

    Ray marching the distance field

    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, andGPU render it

    Line info could also help with antialiasing

    But the GPU is too busy

    _11. August.27.Saturday

    Frame overview

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    63/78

    Frame overview

    _11. August.27.Saturday

    Frame overview

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    64/78

    Frame overview

    start dfstart light

    start particle fx

    start skinning

    _11. August.27.Saturday

    Frame overview

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    65/78

    Frame overview

    start dfstart light

    start particle fx

    start skinning

    wait

    prevfluid

    wait

    distancefield

    _11. August.27.Saturday

    Frame overview

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    66/78

    Frame overview

    start dfstart light

    start particle fx

    start skinning

    wait

    prevfluid

    wait

    distancefield

    startfluid

    _11. August.27.Saturday

    Frame overview

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    67/78

    Frame overview

    start dfstart light

    start particle fx

    start skinning

    wait

    prevfluid

    wait

    distancefield wait particle fx

    wait skinningwait li ht

    startfluid

    _11. August.27.Saturday

    Tuner capture

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    68/78

    Tuner capture

    _11. August.27.Saturday

    Tuner capture

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    69/78

    Tuner capture

    _11. August.27.Saturday

    Tuner capture

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    70/78

    Tuner capture

    _11. August.27.Saturday

    Tuner capture

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    71/78

    Tuner capture

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    72/78

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    73/78

    Tuner capture

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    74/78

    Tuner capture

    _11. August.27.Saturday

    Tuner capture

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    75/78

    Tuner capture

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    76/78

    Tuner capture

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    77/78

    Tuner capture

    _11. August.27.Saturday

  • 8/13/2019 SIGGRAPH 2011 PixelJunk Shooter 2 notes

    78/78