Graphics Reference
In-Depth Information
4.4.1 Rasterizing Kernel Functions
To update the velocity on the grid, we need to transfer both the density of the
particles—to compute pressure—and their velocity. Hence, the first step in our
algorithm is to rasterize the smooth kernel function (red in Figure 4.1) and the
weighted velocity of each particle. We render the particles as points and create
quad slices—spanning a cube—in the geometry shader. For each corner vertex
x i , we write the distance d =
to the center of the particle x p ,and
let the rasterizer perform the interpolation between vertices. Then, in a pixel
shader, we render the smooth kernel value w ( d, r ) to the alpha channel, and the
weighted velocity w ( d, r ) u p to the other three channels—in an additive fashion.
Finally, the density on the grid can be sampled by multiplying the sum of kernel
weights by the mass, and the velocity by dividing the sum of weighted velocities
by the sum of weights:
x i
x p
u ( x i )= p w (
ρ ( x i )= m i
p
x i
x p
,r ) u p
p w (
w (
x i
x p
,r ) ,
,
x i
x p
,r )
where i denotes texture indices, p particle indices, and r the kernel radius. We
used the following convolution kernel:
w ( d, r )= 1
3
d 2
r 2
.
Next we update the velocity field on the grid to make the particles move in a
direction that keeps them from compressing, by computing a pressure force from
the density of particles and adding it to the velocity.
4.5 Grid Pass
In the grid pass, we update the splatted velocity field with the pressure force,
gravity, and artificial pressure for obstacles (see Section 4.7). We compute the
pressure gradient using a finite difference approximation and add forces to the
velocity field using forward Euler integration:
Δ t P ( x i +1 )
,
P ( x i− 1 )
Δ x
, P ( x j +1 )
P ( x j− 1 )
u n +1 = u n
Δ y
where Δ t is the time step, Δ x the spatial resolution of grid, and n the temporal
state of the simulation.
While we update the velocity, we set the velocity on the boundary cells of
the grid to a no-slip boundary condition by setting the component of the velocity
that is normal to the boundary to 0. This is a simple boundary test; before
writing the final velocity value, we check if the neighbor is a boundary and set
the component of the velocity in that direction to 0.
Search WWH ::




Custom Search