Вы находитесь на странице: 1из 8

IV Iberoamerican Symposium in Computer Graphics - SIACG (2009), pp.

1–8
F. Serón, O. Rodríguez, J. Rodríguez, E. Coto (Editors)

1 GGG - UdG - Spain

2 Dept. of Computer Science - University of Bristol - UK

Abstract
In this paper we will present a real-time rain simulation of a windscreen under rainy conditions. Our model incor-
porates external forces like gravity and wind, and also simulates how the rain gets removed from the windshield by
the windscreen wipers. The used techniques are based on the Lattice-Boltzmann Method (LBM), which consists of
a regular lattice that represents the fluid in discrete locations, and equations to simulate how it flows. We perform
all the computation of the LBM using GPGPU techniques for accelerating the calculations. We render the results
of the LBM simulation using the approximate image-space approach for interactive refraction method proposed
by Wyman [Wym05], which allows the computation of refractions of a distant environment through two interfaces.

1. Introduction and simulates how the fluid flows on it. Choosing the cor-
rect parameters of the simulation, it can be proved that these
Driving simulators are really useful to help drivers to im-
methods converge into the continuous equations of Naiver-
prove their skills in the road. Even nowadays there are pro-
Stokes, which are the most important to describe the macro-
fessional drivers who make more hours training with a sim-
scopic behavior of a fluid.
ulator than with a real car, because is cheaper and easier.
There are a lot of components in a driving simulator, and We use a 2D grid, which allows us to represent the fluid
one of these is how the driver appreciates the environment as a height map with respect to the windscreen surface. We
through the windscreen. Moreover, the driver will appreci- incorporate external forces, like gravity and wind to make
ate the environment really differently if there are adverse the simulation as real as possible. Also, we add the wipers
weather conditions, like a heavy rain. to the simulation. To accelerate all calculations, we use the
capability and the potential of current graphic hardware.
The raining simulation for visibility in a car is a problem
with huge importance for road safety, which until now does
not have an accurate solution. Clearly such a simulator must 2. Previous Work
be in real time, even thought it has to be as real as possible.
In general, fluid simulations are based on two main ap-
proaches: Empiric models and accurate simulations. The
1.1. Objectives first ones are usually based on a simplified model that treats
The main objective of this work is to make accurate and real- water as particles under newtonian laws. These particles
time rain simulations on a windscreen, including flow onto a grid defined onto the object’s surface. This way,
particles are moved by wind or gravity, but collisions are
• droplets and simulation of heavy rain in general avoided by accumulating water in the cells and using the
• external forces, like gravity or wind resulting water quantity for further calculations. The re-
• how the rain gets wiped off by the windscreen wipers. sults, although not accurate, produce believable animations
[EHJGP08,KKY93]. In [GN06,GKN07] photographic mea-
1.2. Overview surements were used to simulate rain streaks and splashes.
To achieve these objectives we will use techniques based in Among simulations, we can mention molecular me-
the Lattice-Boltzmann Method (LBM), which consists of a chanics, direct Navier-Stokes simulations and the Lattice-
regular lattice that represents the fluid in discrete locations, Boltzmann Method. Molecular simulations constitute a fam-

submitted to IV Iberoamerican Symposium in Computer Graphics - SIACG (2009)

2 J. Marcó & G. Patow & E. Reinhard & X. Pueyo / Accurate Water Simulation for Visibility in Driving

ily of computer simulation techniques that consist in the ex-

act solution of statistical mechanics problems [Sad99]. In
this approach the properties of the studied systems are deter-
mined solely by the evaluation of intermolecular forces and
energies defined in the theoretical model. Two main molec-
ular simulation techniques, molecular dynamics (MD) and 0
Monte Carlo (MC) techniques implement these ideas. The
first follows a dynamical approach, utilizing Newton equa-
tions of motion, while the second a statistical mechanics
approach, using the concept of configuration space [BS01].
Unfortunately, these techniques can only be used to simulate
a fluid up to a few millimeters scale.

The equations of motion of an incompressible, Newtonian Figure 1: Left: the D3Q19 model. Right: D2Q9 Model
fluid -Ű usually called Navier-Stokes equations [Bri08] have
been traditionally used for accurate simulations, but their
complexity makes them unfeasible for real-time simulations 3.2. LBM details
of large volumes/surfaces [WMT05].
The lattice Boltzmann methods work on a lattice. Several
variations of the LBM exist, and are named DXQY , where X
is the dimension and Y is the number of lattice velocities or
3. Lattice Boltzmann vectors. All cells are updated each time step by simple rules,
that take into account the state of the surrounding cells. In
The aim of this section is to give an overview of the Lat- our project we used the D2Q9 model.
tice Boltzmann Method. We will firstly introduce the evolu-
tion from the Boltzmann equation to the lattice Boltzmann A lattice vector is referred to as ei where i is the lattice
method [Wag08, LFWK05]. vector number. In our model the lattice vectors are e0 Ű- e8 .
At each lattice site ~x and time t, fluid particles moving at ar-
bitrary velocities are modelled by particle distribution func-
tions fi (~x,t). Each fi (~x,t) is the expected number of parti-
3.1. Introduction cles moving along a lattice direction vector ei . Note that, the
particles are allowed to move only along the lattice velocity
The Boltzmann equation describes the behavior of gas on vectors. The magnitude of velocity vectors e1 through e4 is
a microscopic level using kinetic theory. First proposed 1 lattice unit per time √ step. The magnitude of velocity vec-
by [MZ88], the lattice Boltzmann method replaced the tors e5 through e8 is 2 lattice units per time step. Also,
boolean particle number in a lattice direction with the den- the vector with the number 0 has length zero, and amounts
sity distribution function to reduce statistical noise. The for particles resting in this cell. These particles are not mov-
practical viability of simulating in three dimensions came ing anywhere in the next time step, but some of them may
with [HJ89]. [QL92] suggest enhanced collisions for the be accelerated due to collisions with other particles, so the
LBM that allow simulations with low viscous fluids. They amount of resting particles can change.
eliminate collisions from the LBM so that only the con-
sequence of collisions matters. [QL92, CCM92] suggest a From the particle distribution functions two important
final improvement to the collision operator known as the physical values can be calculated. By summing up all 9 dis-
Bhatnagar-Gross-Krook approximation. This version of the tribution functions, the density for the volume of this cell
LBM is known as the lattice-BGK model (LBGK) and pro- can be calculated, assuming that all particles have the same
vides a single time relaxation. The LBGK is the most popu- mass of 1. As the distribution functions contain the amount
lar LBM used today due to its simplicity and efficiency. The of particles moving in a certain direction for each cell, the
LBM is inherently compressible. Consequently, it models sum of all particles in a single cell is its density:
the compressible Navier-Stokes equation. Fluid compress- 8
ibility is a main feature of the LBM and is what gives it a per- ρ= ∑ fi (1)
i=0
formance advantage over other methods. However, [HL97]
recognized there is also a need for incompressible fluid and
Another important information for each cell is the velocity
introduced an incompressible variant of the lattice Boltz-
and overall direction in which the particles of one cell move:
mann model. One limitation that comes with the incompress-
ible LBM is the fluid speed must be kept low in order to min-
8
imize the compressibility effect. In our case, as we are going 1
~v = ∑ fi~ei (2)
to model water, we will make use of this approximation. ρ0 i=0

submitted to IV Iberoamerican Symposium in Computer Graphics - SIACG (2009)

CHAPTER 2. LBM FOR COMPUTER SCIENTISTS
J. Marcó & G. Patow & E. Reinhard & X. Pueyo / Accurate
7 Water Simulation for Visibility in Driving 3

with τ=1.5

distribution functions local equilibrium distribution functions

after streaming distribution functions after collision

Figure 2.3: During the collide step the distribution functions from the stream step are used to
Figure 2: Collision step
calculate the velocity in each cell, which is necessary for the local equilibrium distribution functions.
Thse are weighted with the parameter τ to yield the distribution functions for the next stream step.

change, with no further interaction. However, in a real fluid, the particles are constantly colliding,
scattering other particles into different directions and due to their chaotic movement influencing
adjacent layers of fluid. The collide step does not change the density or velocity of a cell, it only Figure 3: The streaming step on the GPU, where we read
A simulation consists of two steps, streaming and colli-
changes the distribution of the particles for all particle distribution functions.
the particles distribution from the cell neighbors.
sion, that are repeated for each time step. The streaming step
Consider, for example, a cell [i, j, k] where the fluid moves along the positive x-axis. It will not
lose any particles during collision, but the movement will be scattered to other lattice velocities
is the simplest one, it consists in moving particles from one
that point in direction of the positive x-axis. The ones pointing into the opposite directions will
become smaller. In the next stream step, neighboring cells with x coordinate i + 1 will receive a
cell to another.
slightly larger particle distribution function from cell [i, j, k], while cell at i − 1 will receive slightly
smaller ones. In the collide step several parameters are necessary, for which a formal justification
will be given in Chapter 3. The relaxation time ω, that can have values in the range of 0 and 2, that is, the fragment shaders only use gather operations. Re-
In the collision step, particles arrive at a cell and collide
determines the viscosity of the fluid. For small values (< 1) the fluid will behave more like honey,
while values close to 2 will result in very turbulent and chaotic behavior (resembling fluids like member that gather operations can read data from arbitrary
with other particles. Figure 2 depicts this step graphically.
water). The density of the cell will be denoted by ρ while the velocity vector is ~u = (u1 , u2 , u3 )T .
The lattice velocity vectors from Figure 2.1 are ~e0..18 , each one having a weight wi . The derivation locations, but are able only to write in a fixed location.
The collision step does not change the density or velocity of
of these weights is explained in more detail in Chapter 3. For colliding the equilibrium distribution
function has to be calculated from density and velocity first :
a cell, it only changes the particle distributions in a cell. If we remember the LBM equations, we realize they are
· ¸
(0) 3 9 written in the scatter way. Therefore we have to adapt the
fi = wi ρ − (~u)2 + 3(~ ei · ~u)2
ei · ~u) + (~ (2.1)
To model this behavior, the equilibrium distribution func-
2 2
eq L.M. equation to be gathering operations. We can rewrite
tion,
with w =fi forand
i i = 0, new
1
3 w = distribution
i for i = 1..6 and w =functions
1
18
1 must
for the remaining
i 36
be calculated.
i = 7..18. This formula can
be derived by a Taylor expansion of the Maxwell distribution. The three scalar products between the equations as:
[HL97]
the velocity suggest thatcan
and lattice vectors thebe equilibrium distribution
calculated easily. They need to be scaledfunction
accordingly and
then summed up to be adjusted by the
according weight and density. Now, depending on ω the fluid 

reaches this equilibrium faster or slower. 3 9
The new particle distribution functions f 3 calculated
are 0 • Density: Changing Equation 1 to
eq
ei ·~v) + 4 (~ei · v)2 − 2 (~v ·~v)
i

i (ρ,~v) = wi ρ + ρ0 c2 (~
fwith: 8
f = (1 − ω)f + ωf 2c 2c (2.2)
0 (0)

ρ∗ =
i i i

0
These f ’s are then stored in the corresponding cell. When all cells have been collided the next
i
(3) ∑ fi (~x + ~e j ,t) (5)
stream step can be performed.
works well for incompressible flow behavior. The weights i=0
The streaming and collide step can be combined to one formula, which is often found in literature
i depend
wabout LBM: on the length of the velocity vector ´ [HL97].
• Velocity: Changing Equation 2 to
1³ (0)
fi (~x + e~i 4t, t + 4t) − fi (~x, t) = − fi − fi (2.3)
τ
Usually, streaming and collision are often combined into 8
1
As the time step 4t was set to 1 in the other formulas, it did not yet appear. The left hand side of
one formula
this equations known
accounts as the
for the stream step,Lattice-Boltzmann equation,
as ~x + e~ directly points to the distribution
i function of
~v∗ = ∑ fi (~x + ~e j )~ei (6)
another cell. The right hand side can be recognized as the combination of the current distribution
ρ0 i=0
function
new and the local equilibrium. eq
fi (~x,t) − fi (~x +~ei ,t + 1) = (1 − ω) fi (~x,t) + ω fi (ρ,~v) • Collision and streaming steps: Changing Equation 4 to
(4)
finew (~x+~e j ,t)− fi (~x,t +1) = (1−ω) fi (~x+~e j ,t)+ω fi (ρ∗ ,~v∗ )
eq
with ω = 2/(6ν + 1). The left hand side of this equations ac-
counts for the stream step. The right hand side can be recog- (7)
nized as the combination of the current distribution function
and the local equilibrium. 4.2. Implementation of the LBM
The simulation of the LBM then proceeds as follows: As we explained in Section 3, the lattice-Boltzmann method
1. Compute density according to Equation 1. requires the program to keep track of 9 particle distribution
2. Compute velocity (Equation 2). functions fi , density ρ, and velocity ~v for each cell. So, we
3. Compute equilibrium distribution (Equation 3). need to keep in each time step 12 floats. Therefore, we need
4. Update distribution by Equation 4. 3 RGBA floating point textures to store all the needed infor-
5. Go back to step 1. mation. Figure 4 shows how we store each value.
An LBM implementation consists of four operations:
4. Accurate Water Simulation streaming, boundary detection, velocity and density com-
putation, and collision (see Figure 5). All these operations
In this Section we present our algorithm. As we said before,
are implemented in one fragment shader, combined with the
we have to simulate the rain, how it falls on the car wind-
"ping pong" technique and Multiple Render Targets. now,
screen, how it is affected by wind, and how the wipers take
we will explain in more detail each one of the 4 operations:
off that water from the windscreen.
• Streaming The streaming step for non-boundary cells is
accomplished by swapping channels in a texture. This op-
4.1. Adapting the LBM equations to gathering
eration is really easy to do in the fragment shader: we just
operations
need to read the data stored in the correct neighbor. For
Here we will adapt the LBM equations explained in Section example, to stream f1 and f2 (the red and purple arrows
3 to fulfill the restrictions of the programming on the GPU, in Figure 6), the following Cg code is used:

submitted to IV Iberoamerican Symposium in Computer Graphics - SIACG (2009)

4 J. Marcó & G. Patow & E. Reinhard & X. Pueyo / Accurate Water Simulation for Visibility in Driving

Te
xtur
eDa
taf
orf
i
velocity
boundary  external
f
0 f
1 f
2 f
3
Streaming
detection
and
forces
collision
density

f
4 f
5 f
6 f
7

f
8 r
ho v
x v
y

Figure 7: Boundary conditions implemented

Figure 4: Particle Distribution Function, velocity and den- compute

create
create geometry of
create
Normal  Depth  Render
sity storage in 3 textures LBM
Map
the surface water
Buffer

Figure 8: The main operations for rendering
boundary  velocity and
Streaming collision
detection density

Figure 5: Operations for computing the LBM

4.2.1. Negative densities
During a LBM simulation, there will be some cells with no
density. As a result, and after applying the equilibrium dis-
fNew1 = tex2D(texture1, tribution function (Equation 3), there will be cells with nega-
coords + float2(-1.0,0.0)).g tive densities. In [CT05] suggest adding a parameter α to the
fNew2 = tex2D(texture1, advection term to reduce advection in areas with low densi-
coords + float2(1.0,0.0)).b ties. The new equilibrium distribution function, then, is
For f0 , the following Cg code is used: fNew0 = eq
 
3 9 3

tex2D(texture1,coords.r). fi (ρ,~v) = wi ρ + αρ0 2 (~ei ·~v) + 4 (~ei · v)2 − 2 (~v ·~v)
c 2c 2c
• Boundary detection In our case, we need to implement (8)
a boundary condition that allows the water to leave in the The variable α is defined by the well known
boundaries. The idea of this conditions is represented by Smoothstep(0,λ,ρ), where λ is a user specified value:
Figure 7, where we can see all the particles in a boundary Smoothstep() will set α to 0 when there is no water, causing
cell will be removed from the simulation in the next step. no advection to occur, but otherwise α will be greater
• Velocity and density computations After streaming all than zero. In our case and based on our experiments,
the particle distribution functions, we calculate the new 0.1 ≤ λ ≤ 0.6 works well.
velocity and density: using equations 1 and 2.
• Collision The final step in the fluid simulation is calcu-
lating the new distribution functions after collision. The 4.3. Render Algorithm
shader uses the incompressible variant of the LBM, given
by equation 3. First we calculate the equilibrium distribu- In this section we will explain how we render the results of
tion function with equation 4, to find the new distribution the LBM simulation. To render the water, he have an issue
functions. Then the shader saves the new fi into the tex- that makes our visualization more difficult, and it is that we
ture for usage in the next time step. are inside and not outside the car. If we were outside the car,
we just could directly render a normal map of the water sur-
face, but, unluckily, we have to compute a first refraction of
the light on the windscreen and then through the water be-
fore we can get the final refraction direction (see Figure 10).
f f
Our algorithm is based on [Wym05] and the basic rendering
0 1 f
2 f
3
pipeline can be seen in Figure 8.
f
1

f
2
4.3.1. Modelling the windscreen
f
3

The windscreen has a curvature and an angle α of inclina-

tion with respect to the plane X/Z. To take curvature into
Figure 6: Streaming step on the GPU account, in a pre-process stage we store the windshield sur-
face normals in object space in a new texture.

submitted to IV Iberoamerican Symposium in Computer Graphics - SIACG (2009)

J. Marcó & G. Patow & E. Reinhard & X. Pueyo / Accurate Water Simulation for Visibility in Driving 5

4.3.2. Creating a smoothed Normal Map of the water

surface
To create a normal map of the surface we need its geometry.
In fact, LBM gives the quantity of particles of water in each
cell and, we will take this quantity to be proportional to the
height of water in each cell. So we have a height field on the
windscreen, from which we compute a Normal Map using a
Sobel Filter as described in [Zim07].

4.3.3. Building the geometry of the water surface from

the simulation results
At this point we want to create the geometry of the water
surface. To do that we need three things: the height Map Figure 10: We are inside the car, so vector ~V hits the surface
from the LBM, a mesh of triangles which lie on the wind- ~1 based upon the incident an-
at P1 and refracts in direction T
screen and the smoothed normal map of the water on the ~
gle θi with the normal N1 . Physically accurate computations
windscreen. We will use a mesh with one vertex (and thus, lead to a further refraction at P2 . The method refracts ap-
two triangles) for each cell. We store this mesh in a Vertex proximating the location of P2 using distances d~N and d~V .
Buffer Object. See Figure 9.

Height Map Surface water geometry

hit point P1 (see Figure 10). The behavior of refracted rays
2.3 3.1 2.1 1.7 1.0 follows Snell’s Law, given by
3.0 4.3 2.1 1.7 1.0 ni sinθi = nt sinθt (9)

1.0 1.0 1.0 1.0 1.0 When ray tracing, refracting through complex objects is
trivial, as refracted rays are independently intersected with
1.0 1.0 1.0 1.0 1.0
the geometry, with subsequent applications of Snell’s Law.
1.0 1.0 1.0 1.0 1.0 Since GPU ray tracing techniques are relatively slow, multi-
ple bounce refractions for complex polygonal objects are not
interactive. Instead, Wyman’s algorithm [Wym05] proposes
Figure 9: Inputs for the geometry of the water surface to approximate the necessary information to refract through
two interfaces with values easily computable via rasteriza-
To change the geometry of the mesh, we will use a vertex tion. Consider the information known after rasterization. For
2.3 3.1
shader. As for each vertex we know the height of the cor- each pixel, we can easily find:
responding texel and its normal,
2.3 the shader 3.1
will change the • the incident direction ~V ,
coordinates of the input vertex adding to its 3D coordinates • the hitpoint P1 , and
the height times the normal for this texel. • the surface normal N1 at P1 .

4.3.4. Creating the Depth Buffer from the surface water Using this information, the transmitted direction T ~1 is eas-
ily computable via Snell’s Law. To compute T ~2 , only T~1 , the
After modifying the geometry of the water surface we are ~
point P2 , and the normal N2 are necessary. Since finding T ~1
able to create the depth-buffer of the surface, needed for is straightforward, we have to know the P2 and N ~2 . Once
Wyman’s algorithm [Wym05]. This is done simply by stor- again, we use an approximate point P2 and normal N2 since
ing the depth component when rendering the geometry gen- accurately determining them requires per-pixel ray tracing.
erated for the water surface. After finding T2 , we assume we can index into an infinite
3.1 3.1
environment map to find the refracted color.
4.3.5. Refraction algorithm
2.3 , , 2.3 , · the
In 3.1
following we will explain in more detail the two
The method requires two passes on a GPU, and allows re- , · 2.3 big deals of this method: an approximation of the P2 , and
fraction of a distant environment through two interfaces. In the computation of N2 .
our case the two interfaces will be the water and air, because
we ignore theBefore After
glass of the windscreen, because a perfect • Approximating the point P2
glass will not distort the light. Consider the parametrization of a ray Porigin + t~Vdirection . In
Computing refractions through a single interface is rela- our case, we can write this as: P2 = P1 + d T ~1 , where d is
tively simple given basic information about the surface at the the distance kP2 − P1 k. Knowing P1 and T ~1 , approximating

submitted to IV Iberoamerican Symposium in Computer Graphics - SIACG (2009)

6 J. Marcó & G. Patow & E. Reinhard & X. Pueyo / Accurate Water Simulation for Visibility in Driving

location Pe2 simply requires finding an approximate distance add

compute
Boundaries
compute
create
Normal
create geometry
of the surface
create
Depth  Render
water LBM
e such that: wipers Map water Buffer
d,

~1 ≈ P1 + d T
Pe2 = P1 + deT ~1 Figure 11: Operations for render, now with a new shader
The easiest approximation deis the non-refracted distance d~V for compute the boundaries of the wipers
between front and back facing geometry. This can be eas-
ily computed by rendering the refractive geometry with the
depth test reversed, storing the z-buffer in a texture, render- 4.5. Making rain
ing normally, and computing the distance using the z values
from the two z-buffers. We have to precompute d~N for every We know how much water we have in each cell, because in
vertex, and interpolate using: each cell we have the number of particles of water, which,
  summing it up, gives the density ρ. So, to add new water in
θt θt the simulation, we only need to choose a cell or a set of cells
de= d~V + 1 − d~N (10)
θi θi and add more particles. To chose cells, we do it randomly.
• Determining the Normal ~N2 We created a new shader which we execute before the
~2 LBM. This shader receives as input the three textures used
After approximating Pe2 , the last requirement to compute T
~2 . We rasterize the geometry in two passes: for LBM, and the coordinates of the cell where we will add
is the normal N
new water. We need to distribute the new water among the
one culling front faces and one culling back faces. If we ren-
9 particle distribution functions fi , according to the force of
der the first pass to texture using the surface normal as color,
the wind and gravity. So, we modify the three textures of
during the second pass we can project our approximate out-
LBM adding in each fi their respective new water.
going point Pe2 into texture space and index into the texture
to find the normal. Now, we just use N ~2 to find the reflected
color using the environment map. 4.6. Wipers
In fact, the wipers are kind of boundaries but with movement
4.4. Gravity and wind instead of being fixed. To add the wipers, there are two main
In this subsection we will explain how we add external issues: the visualization and computation of the boundaries,
forces like gravity and wind. and how we change the LBM to take them into account.

• Gravity There are many ways to add external forces to the • Rendering the wipers and computing the boundaries
LBM. We modify the calculated velocity in each cell in We define the wiper with four points (rectangle) and an angle
the collision step. Thus, the local equilibrium is calculated ω, that represents its inclination, updated at each time step.
with a modified velocity ~v∗ that is given by: We render the wipers in a texture which will tell us at the
~v∗ =~v + τF
~g (11) texel level where we have a wiper and where not.

We will insert a new operation between the computation Maybe one of the texels in the simulation results has a
of the velocity and density, and the collision step. The wiper over it can still have water. Thus, we have to decide
force term is F~g = (0.0, mg sin(α)), where m is the mass in which neighbor we will move the remaining water. To do
of water in a cell. that we created a shader and executed it before computing
the LBM (see Figure 11). In this shader we modify the tex-
• Wind To introduce the force of wind in the model, we will ture created before: We write the coordinates (0, 1 or -1),
do it in the same way as we added gravity: We will modify with respect to the center texel, of the closest neighbor that
the velocity adding an acceleration. We did an assumption receives the water. To choose a neighbor, we use the one
to make this operation simpler: wind will have the same with smallest angle between the wiper perpendicular vector
direction and force for all points on the windscreen. We and the ei direction of the distribution functions fi .
allow the user to modify the direction and the force of the
wind during the simulation using the keyboard. • Modifying the Lattice Boltzmann Method
The force of the wind is a 3D vector, but our simulation Now we have a new input for our shader, the texture with the
is in two dimensions: we have to compute, for each texel, location of the wipers. Three things can happen: The texel
the tangential component of the vector (~Ft ) over the wind- we are looking at, it has a wiper over, it does not have a
screen. In each texel, we calculate the net force of the wiper over but one of its neighbors has a wiper, or the texel
wind with ~Ft = ~Fwind − ~N(~N · ~Fwind ), where ~Fwind , is a vec- does not have a wiper over and neither of its neighbors has
tor which represents the force of the windscreen, and ~N is a wiper (Figure 12). The third case is a standard texel. In the
the surface normal. When we have the tangential force, two other cases we deal as follows:
and we add it in the same way as we did with gravity:
• Texels covered by a wiper If we have water in the texel
~v∗∗ =~v∗ + ~Ft (12) we make its new density in the next time step will be zero.

submitted to IV Iberoamerican Symposium in Computer Graphics - SIACG (2009)

J. Marcó & G. Patow & E. Reinhard & X. Pueyo / Accurate Water Simulation for Visibility in Driving 7
Wiper position at time t Situacion between the two positions Wiper position at time t+1

Wiper cell
Cell without water

Cell with water with boundaries conditions
Cell with water
Cell with water, which have to leave because
the wiper will be cover it.
The arrow point to the cell that the water
will go

Direction of the wipers

Figure 12: Wipers

(a) 1 drop per step (b) 3 drops per step (c) 4 drops per step

Figure 14: Differences between 1 (a), 3 (b) and 4 drops (c)

All of this water will move to the closest neighbor depend-
ing on the perpendicular to the wiper.
• Texels not covered by wipers but one of it neighbors is • A simulation of raining with gravity and the boundary
a wiper Firstly, we apply a free slip boundary conditions condition, Figure 13. The simulation is performed in a tex-
on these texels. Afterwards, we read its 8 neighbors, and ture of 512x512. As we can see in Figure 13, the rain starts
check for a wiper over them. Then, we pick up the water and then we have a “curtain"’ of water on the windscreen.
of a neighbor that still has water and in this time step will • Difference between the intensity of the rain, Figure 14.
be covered by a wiper. In this case, we add the neighbor’s • A simulation with wind, Figure 15, from the situation
water to our own cell. when we have wind in the same direction as gravity (a)to
what would happen when we are driving fast (d).
5. Results • With the wipers turned on, Figure 16. This simulation
shows the effect of the wipers and how they take off the
In this section we will show our results. All simulations are water. The effect of the wipers is not as real as can be
executed on a PCI-E nVidia GeForce 8600 GT. because when the wipers take off the water, and there is
another drop which falls in a location where we suppos-
edly do not have water, the drop is still doing the same
effect as if there would be water. This is because we have
not implemented surface tension.

Figure 13: A simulation of rain, with gravity and the bound-

ary conditions which permit to leave the water at the sides. (a) Without (b) Right (c) Left (d) Up
In a texture 512x512
Figure 15: Wind simulation: without (a), from right (b), from
left (c) and upwards (d)
Texture-size 16 32 128 512 1024
FPS 240 180 120 31 9.5

Table 1: The table shows the evolution of the FPS depending 6. Conclusions
on the sizes of the texture. We have developed a real-time, accurate water simulation
on a car windscreen using the Lattice-Boltzmann Method.
Also we have successfully implemented external forces like
As we can see in Table 1, the FPS decrease while the size gravity and wind. Moreover, we implemented boundary con-
of the texture grows. This is a typical result of GPGPU sim- ditions to try to simulate as real as possible a car windscreen.
ulations. However, observe that for texture under 512x512, Also, we implemented an easy solution of wipers to take off
more than 30 FPS are achieved. the water on the windscreen. About the results on the render,
Now we will show some results of the simulation in differ- we can said that we get good results.
ent situations and conditions. In these results, the windscreen
is forming a right angle with the floor (90ž) because in this
7. Future Work
position we will better appreciate the water effects. Also, in
these examples, the windscreen has a square shape, just to The main objective of this project is to implement the LBM
better fit the textures that have the same width and height. in real-time, adding forces like gravity and wind, the visu-

submitted to IV Iberoamerican Symposium in Computer Graphics - SIACG (2009)

8 J. Marcó & G. Patow & E. Reinhard & X. Pueyo / Accurate Water Simulation for Visibility in Driving

Figure 16: A simulation of the wipers. In a texture 512x512

alization and the wipers. So the main future works in this [HJ89] H IGUERA F., J IMENEZ J.: Boltzmann approach to
project will be to focus in the simulation: lattice gas simulations. Europhys. Lett. 9, 663 (1989).
• Implementation the surface tension. It is important if we [HL97] H E X., L UO L.-S.: Lattice boltzmann model for
do not yet have water on the screen, and a drop falls (the the incompressible navierŰstokes equation. J. Stat. Phys.
situation when the wiper passes). 88, 927 (1997).
• Improve the implementation of the wipers. In our current [KKY93] K ANEDA K., K AGAWA T., YAMASHITA H.:
implementation, all the water which is in a cell is moved to Animation of water droplets on a glass plate. In Proceed-
only one neighbor (the closest). We should move in more ings Computer Animation (1993), pp. 177–189.
than one direction.
• Improve the rendering of the water. We could compute the [LFWK05] L I W., FAN Z., W EI X., K AUFMAN A.: Flow
Fresnel term in a pre-process stage. Simulation with Complex Boundaries. in GPU Gems 2:
• Improvement of the FPS of the simulation. Different im- Programming Techniques for High-Performance Graph-
plementation aspects could be considered in order to ics and General-Purpose Computation (Gpu Gems).
speed it up. Addison-Wesley Professional, 2005.
[Mar08] M ARCÓ J.: Accurate Water Simulation for Visi-
8. Acknowledgements bility in Driving. Master’s thesis, Universitat de Girona,
Spain, September 2008.
This work was done with grant TIN2007-67120 from the
Spanish Government. [MZ88] M C NAMARA G. R., Z ANETTI G.: Use of
the boltzmann equation to simulate lattice-gas automata.
Phys. Rev. Lett. 61, 20 (Nov 1988), 2332–2335.
References
[QL92] Q UIAN Y. H. D . D., L ALLEMAND P.: Lattice bgk
[Bri08] B RIDSON R.: Fluid Simulation for Computer models for navier-stokes equation. Europhys. Lett. 17, 6
Graphics. AK Peters, 2008. (1992).
[BS01] B UKOWSKY R., S ZALEWICZ K.: Monte carlo
[Sad99] S ADUS R. J.: Molecular Simulation of Fluids:
simulations for gaseous and liquid argon with complete
Theory, Algorithms and Object-Orientation. Elsevier Sci-
ab initio nonadditive potential. J. Chem. Phys. (2001).
ence Inc., New York, NY, USA, 1999.
[CCM92] C HEN H., C HEN S., M ATTHAEUS W. H.: Re-
[Wag08] WAGNER A. J.: A Practical Introduction to the
covery of the navier-stokes equations using a lattice-gas
Lattice Boltzmann Method. Department of Physics North
boltzmann method. Phys. Rev. A 45, 8 (Apr 1992),
Dakota State University, March 2008.
R5339–R5342.
[CT05] C HU N. S.-H., TAI C.-L.: Moxi: real-time ink [WMT05] WANG H., M UCHA P. J., T URK G.: Water
dispersion in absorbent paper. ACM Trans. Graph. 24, 3 drops on surfaces. In SIGGRAPH ’05: ACM SIGGRAPH
(2005), 504–511. 2005 Papers (2005), pp. 921–929.

[EHJGP08] E L H AJJAR J.-F., J OLIVET V., G HAZAN - [Wym05] W YMAN C.: An approximate image-space ap-
FARPOUR D., P UEYO X.: A model for real-time on- proach for interactive refraction. In SIGGRAPH ’05:
surface flows, 2008. ACM SIGGRAPH 2005 Papers (New York, NY, USA,
2005), ACM, pp. 1050–1053.
[GKN07] G ARG K., K RISHNAN G., NAYAR S.: Mate-
rial Based Splashing of Water Drops. In Proceedings of [Zim07] Z IMA C.: Converting displace-
Eurographics Symposium on Rendering (June 2007). ment maps into normal maps in hlsl.
http://catalinzima.spaces.live.com/blog/
[GN06] G ARG K., NAYAR S.: Photorealistic Rendering
cns!3d9ecae1f2dc56ef!223.entry, September 2007.
of Rain Streaks. ACM Trans. on Graphics (also Proc. of
ACM SIGGRAPH) (Jul 2006).