GDC08_ParticleFluids

Embed Size (px)

Citation preview

  • 7/30/2019 GDC08_ParticleFluids

    1/33

    -

    February 2008

  • 7/30/2019 GDC08_ParticleFluids

    2/33

    Overview

    Fluid Simulation Techni ues

    A Brief History of Interactive Fluid SimulationCUDA particle simulation

    Spatial subdivision techniques

    Rendering methodsFuture

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    3/33

    Fluid Simulation Techniques

    Various a roaches:

    Grid based (Eulerian)

    Stable fluids

    Particle level set

    SPH (smoothed particle hydrodynamics)

    MPS (Moving-Particle Semi-Implicit)

    Height fieldFFT (Tessendorf)

    NVIDIA Corporation 2008

    . .

  • 7/30/2019 GDC08_ParticleFluids

    4/33

    History: 2D Waves

    Old demo-scene trick

    2D wave equationFirst implemented on GPU

    by Greg James, 2003

    GeForce 3.

    Used register combiners and

    texture shader

    8-bit fixed point

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    5/33

    2D Fluid Flow

    Mark Harris GPU Gems 1

    2D Navier-Stokes solverbased on Jos Stams

    a e u s

    GeForce FX

    Cg shaders

    Multiple passes to solve

    for pressure

    Texture interpolation used

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    6/33

    GPU Particle Systems

    Buildin a Mill ion Particle S stem

    Lutz Latta, GDC 2004Position and velocity

    s ore n ex ures

    Simple interactions with

    terrain hei ht field and

    implicit shapes

    Emitters done on CPU

    Particles rendered usingrender-to-vertex array

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    7/33

    3D Fluids - Box of Smoke Demo

    G80 launch demo

    Written by Keenan Crane3D Navier-Stokes solver

    Used tiled 2D textures

    Also tracked free surfaces for waterBFECC advection scheme

    Ray cast rendering

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    8/33

    NVIDIA SDK Smoke Demo

    3D Navier-Stokes solver

    DirectX 10Used render to 3D

    texture

    Includes interaction

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    9/33

    CUDA N-Body Demo

    Computes gravitational attraction between n bodies

    Computes all n2

    interactionsUses shared memory to reduce memory bandwidth

    16K bodies @ 44 FPS

    x 20 FLOPS / interaction

    x 16K2 interactions /frame

    = s

    GeForce 8800 GTX

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    10/33

    Particle Systems

    Particle S stems: A Techni ue for Modelin a Class

    of Fuzzy Objects, Reeves 1983

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    11/33

    Particle-based Fluid Simulation

    Advanta es

    Conservation of mass is trivialEasy to track free surface

    Not necessarily constrained to a finite grid

    Easy to parallelize

    Disadvantages

    ar o ex rac smoo sur ace rom par c esRequires large number of particles for realistic results

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    12/33

    Particle Fluid Simulation Papers

    Particle-Based Fluid

    Simulation for InteractiveApplications,

    . ,

    3000 particles, 5fps

    Particle-based Viscoelastic Fluid Simulation,

    Clavet et al, 2005

    1000 particles, 10fps20,000 particles,

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    13/33

    CUDA SDK Particles Demo

    Particles with sim le

    collisionsUses uniform grid

    ase on sor ng

    Uses fast CUDA radix

    sort

    Current performance:

    >100 fps for 65Kinteracting particles

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    14/33

    Uniform Grid

    Particle interaction requires finding neighbouringparticles

    Exhaustive search requires n^2 comparisons

    Uniform grid is simplest possible subdivision

    Divide world into cubical gr id (cell size = particle size)Put particles in cells

    Only have to compare each particle with the particles inneighbouring cells

    Building data structures is hard on data parallelmachines like the GPU

    possible in OpenGL (using stencil routing technique)

    NVIDIA Corporation 2008

    easier using CUDA (fast sorting, scattered writes)

  • 7/30/2019 GDC08_ParticleFluids

    15/33

    Uniform Grid using Sorting

    Grid is built from scratch each frameFuture work: incremental updates?

    Algorithm:

    center)

    Calculate cell index

    Find start of each bucket in sorted list (store in array)

    Process coll isions by looking at 3x3x3 = 27 neighbouringrid cells of each article

    Advantagessupports unlimited number of particles per grid cell

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    16/33

    Example: Grid using Sorting

    0 1 2 3 unsorted list sorted by cell start

    4 5 6 7

    3

    2

    1

    45

    ,

    0: (9, 0)1: (6, 1)

    0: (4, 3)1: (4, 5)

    0: -1: -

    0

    12 13 14 15

    02: 6, 23: (4, 3)

    4: (6, 4)5: 4 5

    2: 6, 13: (6, 2)

    4: (6, 4)5: 9 0

    2: -3: -

    4: 05: -6: 27: -8: -

    :10: -...15: -

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    17/33

    Spatial Hashing (Infinite Grid)

    For ames we dont want articles to be

    constrained to a finite gridSolution: use a fixed number of grid buckets, and

    s ore par c es n uc e s ase on as unc on o

    grid position

    Pro: Allows rid to be effectivel infinite

    Con: Hash collisions (multiple positions hashing to

    same bucket) causes inefficiency

    Choice of hash function can have big impactSee: Optimized Spatial Hashing for Coll ision

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    18/33

    Example Hash Function

    __device__ uint calcGridHash(int3 gridPos)

    {

    const uint p1 = 73856093; // some large primes

    const uint p2 = 19349663;

    const uint p3 = 83492791;

    int n = p1*gridPos.x ^ p2*gridPos.y ^ p3*gridPos.z;

    n %= numBuckets;

    return n;

    }

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    19/33

    Smoothed Particle Hydrodynamics

    Particle based fluid simulation techniqueOriginally developed for astrophysics simulations

    Interpolates fluid attributes over

    For games, we can often get away

    with simpler simulationscom ne so par c e co s ons wattractive forces

    NVIDIA Corporation 2008

    Image courtesy Matthew Bate

  • 7/30/2019 GDC08_ParticleFluids

    20/33

    Fluid Rendering Methods

    3D isosurface extraction marchin cubes

    2.5D isosurfaces (Ageia screen-space meshes)3D texture ray marching (expensive)

    Image-space tricks (blur normals in screen space)

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    21/33

    Marching Cubes

    Standard method for extractin

    isosurfaces from volume dataCUDA marching cubes uses

    scan unc ons rom

    library for stream compaction

    Up to 8x faster than OpenGLgeometry shader implementation

    using marching tetrahedra

    But stil l re uires evaluatin f ield

    function at every point in spaceE.g. 1283 = 2M points

    NVIDIA Corporation 2008

    ery expens ve

  • 7/30/2019 GDC08_ParticleFluids

    22/33

    Ray Marching

    Volume renderin

    techniqueVoxelize particles

    n o ex ure

    Requires several

    passes for thickness

    Ray march through

    3D texture in pixel

    Can shade based

    on optical thickness

    NVIDIA Corporation 2008

    ery n ens ve

  • 7/30/2019 GDC08_ParticleFluids

    23/33

    Density-based Shading

    Can calculate er- article densit and normal based

    on field functionSPH simulations often already have this data

    . .

    cells) to get good results expensive

    Can use density and normal for point sprite shadingNormal only well defined when particles are close to

    each other

    . .

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    24/33

    Particle Density

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    25/33

    Particle Normal

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    26/33

    Flat Shaded Point Sprites

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    27/33

    Blended Points Sprites (Splats)

    Scale u oint size

    so they overlapAdd alpha to points

    w auss an a o

    Requires sorting

    from back to front

    Has effect of

    interpolating shading

    e ween po n sFill-rate intensive,

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    28/33

    Alternative Shading (Lava)

    Modifies article

    color based ondensity

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    29/33

    Motion Blur

    Create uads between revious and current article

    positionUsing geometry shader

    ry an or en qua owar s v ew rec on

    Improves look of rapidly moving fluids (eliminates

    a s between articles

    p

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    30/33

    Spheres

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    31/33

    Motion Blurred Spheres

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    32/33

    Oriented Discs

    NVIDIA Corporation 2008

  • 7/30/2019 GDC08_ParticleFluids

    33/33

    The Future

    Practical ame fluids will need to combine article

    height field, and grid techniques

    GPU performance continues to double every

    mon s

    NVIDIA Corporation 2008

    Two way coupled SPH and particle level set fluid simulation,Losasso, F., Talton, J., Kwatra, N. and Fedkiw, R

    Adaptively Sampled Particle Fluids, Adams 2007