sound wave propagation applied in games.pdf

9
Sound Wave Propagation Applied in Games Marcelo Zamith, Erick Passos, Diego Brand˜ ao, Anselmo Montenegro, Esteban Clua, Mauricio Kischinhevsky, Regina C.P. Leal-Toledo Computation Institute Federal Fluminense University Niter´ oi, Brazil {mzamith, epassos, dbrandao, anselmo, esteban, kisch, leal}@ic.uff.br Abstract—Many games and other interactive virtual envi- ronments are known for their focus in rendering natural phenomena, such as accurate visuals and physics, in the most believable manner. Several advances in the aforementioned fields took place during the last decade but, unfortunately, this effort has not been reflected in libraries for spatial audio. These libraries traditionally do not accurately simulate sound wave propagation through the virtual environment, never taking into consideration the speed of sound, reflection and absorbency by scene geometry, phenomena whose simulation could be used to render many interesting effects in real time. In this paper, we propose the use of a sound wave propagation simulation based on the finite difference method, running on the GPU, that can be used to compute how a sound pulse spreads through a virtual environment. In the prototypes implemented, the simulation data is interactively used to determine the perceived direction of a sound source in a closed building, and rendering a mimic of a shock-wave in an open scene. Keywords-sound wave propagation; finite difference method; GPU; I. I NTRODUCTION Many electronic games, specially those that are classified as simulation-games, rely on the modeling of natural phe- nomena in order to immerse the player into a suspension of disbelief state. However, simulating sound wave propagation has not been considered a priority, partially due to its computational complexity. It is true that positional audio libraries are a valuable effort in this field, but the focus of the industry, and also of many academic previous and current research, has always been on providing for more realistic graphics and, to some extent, rigid-body physics. Although positional audio libraries are now a commodity, current implementations focus only on calculating intensity and pan, based on the relative position and orientation of the sound source and the virtual listener. These libraries do not consider important issues, such as the time sound takes to travel over the environment (i.e. air) or reflection and absorbency of the objects present at the scene. Taking scene geometry into account could greatly increase the immersion experience, because it affects the way sound travels through the virtual environment, possibly changing the perceived direction from which the listener hears the generated sound. For instance, a stealth game, such as the Metal Gear franchise [1], could use such simulation to adjust the perceived source position of the original sound. Besides the aforementioned example, there are many other interesting applications of more accurate methods for sound wave propagation simulation in games. Possible uses in- clude, but are not restricted to: mimicking an earthquake propagation on volume geometry, possibly generating force vectors for the physics engine; providing animation data for particle-based effects, such as a shock-wave; and many others. Despite the obvious benefits, simulation methods for such phenomena are computationally intensive, and running them in real-time, concurrently with all other expensive tasks, has not been a viable option. However, current GPU technology has the computing power to run an implementation of a simulation like this in real-time, without compromising the overall performance, i.e., the GPU works as mathematics coprocessor. Considering the fact that GPUs are faster than CPU, the proposed work does not aim at showing the speed up between the technology. In this paper, we describe how we implemented and opti- mized a sound wave propagation kernel in CUDA, based on a Finite Difference Method, and used it to simulate how a sound pulse, such as a gunshot or an explosion, propagates through a complex scene geometry. The related works are analyzed in Section 2, the method and details of the GPU implementation are described in Section 3. The basic data- structures are lattices to represent the velocity field and the sound wave amplitude of the environment. This simulation kernel was developed to be completely independent of the application itself, and by monitoring the amplitude data in real time, we chose two game related problems to demonstrated the applicability of the technique: Computing the perceived direction of a sound: a closed indoor environment with two rooms and a 2010 Brazilian Symposium on Computer Games and Digital Entertainment 978-0-7695-4359-8/10 $26.00 © 2010 IEEE DOI 10.1109/SBGAMES.2010.29 211 2010 Brazilian Symposium on Games and Digital Entertainment 978-0-7695-4359-8/10 $26.00 © 2010 IEEE DOI 10.1109/SBGAMES.2010.29 211

Upload: eider-carlos

Post on 10-May-2017

244 views

Category:

Documents


0 download

TRANSCRIPT

Sound Wave Propagation Applied in Games

Marcelo Zamith, Erick Passos, Diego Brandao, Anselmo Montenegro,Esteban Clua, Mauricio Kischinhevsky, Regina C.P. Leal-Toledo

Computation InstituteFederal Fluminense University

Niteroi, Brazil{mzamith, epassos, dbrandao, anselmo,

esteban, kisch, leal}@ic.uff.br

Abstract—Many games and other interactive virtual envi-ronments are known for their focus in rendering naturalphenomena, such as accurate visuals and physics, in the mostbelievable manner. Several advances in the aforementionedfields took place during the last decade but, unfortunately, thiseffort has not been reflected in libraries for spatial audio. Theselibraries traditionally do not accurately simulate sound wavepropagation through the virtual environment, never taking intoconsideration the speed of sound, reflection and absorbency byscene geometry, phenomena whose simulation could be used torender many interesting effects in real time. In this paper, wepropose the use of a sound wave propagation simulation basedon the finite difference method, running on the GPU, that canbe used to compute how a sound pulse spreads through a virtualenvironment. In the prototypes implemented, the simulationdata is interactively used to determine the perceived directionof a sound source in a closed building, and rendering a mimicof a shock-wave in an open scene.

Keywords-sound wave propagation; finite difference method;GPU;

I. INTRODUCTION

Many electronic games, specially those that are classifiedas simulation-games, rely on the modeling of natural phe-nomena in order to immerse the player into a suspension ofdisbelief state. However, simulating sound wave propagationhas not been considered a priority, partially due to itscomputational complexity. It is true that positional audiolibraries are a valuable effort in this field, but the focus of theindustry, and also of many academic previous and currentresearch, has always been on providing for more realisticgraphics and, to some extent, rigid-body physics.

Although positional audio libraries are now a commodity,current implementations focus only on calculating intensityand pan, based on the relative position and orientation ofthe sound source and the virtual listener. These librariesdo not consider important issues, such as the time soundtakes to travel over the environment (i.e. air) or reflectionand absorbency of the objects present at the scene. Takingscene geometry into account could greatly increase theimmersion experience, because it affects the way sound

travels through the virtual environment, possibly changingthe perceived direction from which the listener hears thegenerated sound. For instance, a stealth game, such as theMetal Gear franchise [1], could use such simulation to adjustthe perceived source position of the original sound.

Besides the aforementioned example, there are many otherinteresting applications of more accurate methods for soundwave propagation simulation in games. Possible uses in-clude, but are not restricted to: mimicking an earthquakepropagation on volume geometry, possibly generating forcevectors for the physics engine; providing animation datafor particle-based effects, such as a shock-wave; and manyothers.

Despite the obvious benefits, simulation methods for suchphenomena are computationally intensive, and running themin real-time, concurrently with all other expensive tasks, hasnot been a viable option. However, current GPU technologyhas the computing power to run an implementation of asimulation like this in real-time, without compromising theoverall performance, i.e., the GPU works as mathematicscoprocessor. Considering the fact that GPUs are faster thanCPU, the proposed work does not aim at showing the speedup between the technology.

In this paper, we describe how we implemented and opti-mized a sound wave propagation kernel in CUDA, based ona Finite Difference Method, and used it to simulate how asound pulse, such as a gunshot or an explosion, propagatesthrough a complex scene geometry. The related works areanalyzed in Section 2, the method and details of the GPUimplementation are described in Section 3. The basic data-structures are lattices to represent the velocity field and thesound wave amplitude of the environment.

This simulation kernel was developed to be completelyindependent of the application itself, and by monitoring theamplitude data in real time, we chose two game relatedproblems to demonstrated the applicability of the technique:

• Computing the perceived direction of a sound:a closed indoor environment with two rooms and a

2010 Brazilian Symposium on Computer Games and Digital Entertainment

978-0-7695-4359-8/10 $26.00 © 2010 IEEE

DOI 10.1109/SBGAMES.2010.29

211

2010 Brazilian Symposium on Games and Digital Entertainment

978-0-7695-4359-8/10 $26.00 © 2010 IEEE

DOI 10.1109/SBGAMES.2010.29

211

Eider
Highlight
Eider
Highlight
Eider
Highlight
Eider
Highlight
Eider
Highlight
Eider
Highlight
Eider
Highlight
Eider
Highlight
Eider
Highlight
Eider
Highlight

corridor connecting them. In this example. we use thesimulation data to compute the perceived direction ofa sound, testing different positions for the source andlistener. The result can be used to adjust the locationof the sound source in the positional audio library, orusing this orientation as input data to a NPC AI. Theresults from this example are analyzed in Section 4.

• Mimicking a shock-wave: an outdoor scene with somebuildings, where we render a shock-wave effect froman explosion, taking into account reflection by thescene geometry. Section 5 shows more details of thisapplication and discusses other uses of this mimickingapproach.

The performance results we obtained are very encouraging,and show that our implementation is suitable for real time,even when running in low cost hardware. We also highlightthe fact that no known previous research or game was foundshowing an implementation or proposing neither the use ofaccurate sound wave propagation simulation nor the methodsand approach presented in this paper for real-time effects ingames. Finally, the concludes are presented in Section 6 aswell as some future work are discussed.

II. RELATED WORK

Applying sound wave propagation simulation for gamesis mainly classified into one of the two categories, im-plementing a real physical sound wave propagation, usingany suitable numeric method; and the second technique ismaking use of ray-casting techniques for sound purposes.Previous works based on numeric methods are in generaltoo computationally expensive for real-time use. At the sametime, approaches based on other techniques, such as ray-casting, do not accurately represent the physics of sound.

Many related works based on heavy numerical simulationhave been developed for running on GPUs recently, but mostof them are not designed for real-time. Highlights in the setof problems that have been solved with the help of GPUsinclude Protein Structure Prediction [2], Solution of LinearEquation Systems [3], Options Pricing [4], Flow Simulation[5], Wave Propagation [6], [7] and others. These works tryto simulate real physics phenomena through the use of moreor less accurate numeric methods. Although using the faststream processors of GPUs, none of these works is designedfor real-time.

In [8], the authors modeled a particle system through voxelsto represent of a blast wave impact on surrounding objects.The approach of this work adopts a fracture algorithmcapable of accounting for the damage of multiple explosions.At another relevant work [9], an analysis of a sound wavepropagation was proposed and developed, based on the com-putation of acoustic energy, also highlighting the possibilities

to map these concepts to radiometry and graphics renderingequations. Although the authors concentrate on ray-basedtechniques, they also consider wave based sound propagationeffects. These works are based on another family of numericmethod other then Finite Difference, and the applicationsand performance results are not comparable to ours.

The work presented at [10] uses a ray-tracing approach anddescribe a technique to model sound propagation accuratelyfor an arbitrary 3D scene by numerically integrating thewave equation. The performance is guaranteed by precom-puting a data-structure, using eigenvalues from a refinedmesh. A domain decomposition approach is done, becauseperforming a modal analysis on the complete scene isusually not feasible. Although the proposed technique hasobserved up to an order of magnitude speedup compared toa standard Finite Difference technique, the processing is notcompletely done in real-time, which makes impossible theuse with variable geometry or locations for the objects. Withour approach, updating the velocity field of the lattice canbe done locally for each moving obstacle.

In [11], an algorithm to synthesize realistic sound effectsin real-time is proposed and applied for interactive simu-lations, such as games and animations. The sound wavesare produced by the user and the proposed modal modelsare driven by contact forces modeled at audio rates, whichare much higher than the graphics frame rate. The contactforces can be computed from simulations as well as customdesigned. Finally, the work also presents the effectivenessof the technique by showing complex realistic simulations.This method is also not based on accurate modeling of theactual phenomenon.

To this date, no previous work was found that used a propersound wave simulation method to compute the perceivedrelative direction of a sound source, one of the proposedapplications of this paper. The use of such physically ac-curate methods is also not common for real-time purposes,specially in interactive applications. Most examples found ingame programming literature are actually based on cullingtechniques, such as Potentially Audible Sets [12]. Webelieve that our prototypes have shown that using suchaccurate simulations are now possible and useful for thiscategory of applications.

III. SOUND WAVE PROPAGATION SIMULATION ON GPU

The wave equation is a second order linear differentialequation which describes the behavior of sound waves overtime, amongst other types of waves, where all of themdescribe a medium perturbation. The acoustic wave fieldis described by P (x, y, z, t) and u(x, y, z, t), where P isthe pressure field in the medium and u is the particle’sdisplacement. The relation between pressure and particle’s

212212

Eider
Highlight
Eider
Highlight
Eider
Highlight

displacement is given by P (x, y, z, t) = −k∇u(x, y, z, t)with k representing the volumetric compression module. Oneof the hypotheses of the model considered here is that thepressure field is constant along the z-axis, which implies thatthe partial derivative with respect to z is zero. Thus, the (2-D) wave equation with a constant volumetric compressionis given by:

∂2P

∂t2= c2(x, y)

[∂2P

∂x2+

∂2P

∂y2

]+ f(x, y, t) (1)

where, P = P (x, y, t), x and y are Cartesian coordinates,t is time, c is the velocity of the acoustic wave in themedium (for instance, 300m/s in the air) and f(x, y, t) isthe source term (e.g., an explosion, a shotgun, etc).

The analytical solution for the problem described in Eq. 1shall be costly or impracticable when the propagation occursin a non-homogeneous medium. Approximation techniquesare usually employed to deal with this issue. The mostcommon family of approximation techniques is that of FiniteDifference Methods (FDM), whose implementation is easierthan, for example, that for the Finite Element Method. Thus,since efficiency is a key issue herein, the FDM was chosenfor our simulation kernel.

A. Simulating sound wave propagation with FDM

Finite Difference Methods (FDM) represent the discretiza-tion of an evolutionary differential equation on a continuousregion by choosing a finite set of representative points.In order to choose coefficients to weigh the importanceof neighboring cells in the discrete description of thecontinuous problem at each point, as well as the numberof neighboring points, Taylor series expansions in spaceand time variables are computed. Coefficients are chosenin order to provide a previously specified local truncationerror. The result is a difference formula that is applicableto every point of the discretization inside the space-timedomain. Such formula relates values of the unknowns onneighboring points, in space and time. Thus, the formularelates successive time steps, in order to account for theevolutionary nature of the problem.

In FDM, when one value, at some time instant, is computedthrough some average of the already available values atits neighboring points, the method is said to be explicit.When the calculation of the value requires the simultaneouscalculation of the values at its neighboring points, themethod is said to be implicit. Thus, implicit methods areoften more expensive than explicit ones because they requirethe solution of a linear or non-linear systems of equationsat each time step. For this reason, an explicit method tosimulate acoustic wave propagation was chosen in this work.

A central-difference approximation can be derived fromTaylor series [13], and a second order approximation forspace and time, assuming h = ∆x = ∆y and t = n∆t,Eq.(1) can be written as:

Pn+1(i,j) = 2Pn

(i,j) − Pn−1(i,j) + A×[

Pn(i−1,j) + Pn

(i+1,j) − 4Pn(i,j) + Pn

(i,j−1) + Pn(i,j+1)

](2)

where, A =(

c(x,y)∆th

)2

and n = 1, ... represents slice time.

In the classical approach, changes in the velocity field c(x, y)reflect fluctuations of the medium. This gives rise to bothreflection and diffraction of waves. Another noticeable fea-ture of this scheme, is how open scenes can be represented,that is, non-finite domains. When employing a computationalmodel, the computational domain size and the associatednumber of variables must be kept as low as possible. Inorder to restrict the computational domain, and thus keepingmemory requirements at a minimum, while preserving arealistic description of the phenomena, artificial boundariesare introduced. This artificial chopping of the domain usuallygives rise to wave reflection at the borders of domain.

Aiming to simulate semi-infinite domains, this work con-siders the boundary conditions proposed by [14]. Suchconditions are determined by decomposing the one dimen-sional scalar wave equation, generating the product of twoterms, each representing the spread of the wavefront inone direction. Equation 3 represents this condition whenthe wave propagation occurs horizontally to the right. Theboundary conditions for waves moving horizontally to theleft can be obtained analogously [14]. The conditions at thetop and bottom (maximum and minimum vertical values) ofthe model are given by Dirichlet conditions [15].

∂P

∂~n=

1

c

∂P

∂t(3)

B. Details of the chosen method

In this work, the discretized model is given by Eq. 2, wherethe neighborhood used in computing a value at some pointin time instant t + 1 is composed of seven elements, sixfrom the previous time instant (t) and the last one is givenby time instant (t−1). Therefore, the value at a point in timet+ 1 is more influenced by its neighboring previous instant,while the time instant t−1 contributes with only one value.Accuracy is associated with method’s order. In this case thescheme is O(h2,∆t2). This means that the error approacheszero when h and ∆t go to zero. More accurate methodscan be used, but they require more information about theneighborhood. The approach chosen met this works’ goals,

213213

Eider
Highlight

providing enough accuracy while keeping computationalcost low.

The complexity of the method is also defined by the dis-cretization and neighborhood features. Thus, the lower the∆h, the greater is the number of unknows for the matricesinvolved. In the case of a 2D domain, for instance, given adomain of 100× 100m and ∆h = 1m, then matrices of size(number of rows and columns) 101 × 101 are involved inthe solution of linear or non-linear systems. Finally, usingEq. 1, the complexity is O(m × n × 6), where m and nare the Width and Height of the domain (that generates alattice), respectively, and the constant 6 is the number ofneighboring points for each point of the discretization.

The explicit scheme described above is less expensive thanimplicit methods. It is, however, conditionally stable. Thestability of the explicit FDM for second order 2D wavepropagation is given by the CFL (CourantFriedrichsLewy)condition. The CFL condition requires that the domain ofdependence of the PDE must remain within the domain ofdependence of the finite difference scheme for each meshpoint of an explicit finite difference scheme. Thus, the CFLcondition that guarantees the stability in the case of anacoustic wave equation is [13]:

√A =

(c∆t

h

)≤ 1√

s(4)

where s is the dimensionality. In the present case, s = 2.On the other hand, being the CFL condition broken, thesimulation fail and produce wildly incorrect results.

C. GPU Implementation

The Finite Difference Method chosen for our simulationis very well suited for a GPU implementation, since it isstrongly based on data-locality (lattice based velocity andamplitude fields). Besides this, this work also made use ofsome features of the CUDA programming model, such asshared memory, to achieve maximum performance from theunderlying hardware. This section describes some details ofour GPU implementation of the aforementioned FDM.

Current GPU architectures favor arrays as data structures, asthey are able to store 1D, 2D, 3D or n-dimensional versions.In this work, one only needs to use 2D arrays, becauseour simulation was run for matrices, and the data-structuresused consist only of the amplitude field for two timeinstants, and a velocity field to represent the medium. Thesematrices must be previously allocated in the GPU dedicatedmemory, and must not be resized during the simulation. Thecorresponding memory space can be released only when thesimulation ends. For instance, given the domain for a specificexperiment or application, the discretization granularity mustbe defined before invoking the kernel, and all memory must

be allocated and filled for the velocity field. The amplitudefield can be initialized with zeros at the first simulation step.

The developed kernel makes heavy use of shared memoryto help minimize the processing time. Hence, the kernel isdivided in two steps: The first copies the pressure values inthe current time for each discretized point Pn

(i,j) from globalto shared memory; the second one uses the Eq.2 to calculatethe values for the next time step at each point Pn+1

(i,j) . Besides,in accordance to the same equation, only points in the currenttime instant t need to be loaded in shared memory.

The approach used maps the computation of each new valuePn+1

(i,j) to a single thread. Hence, the 2D domain is dividedin blocks (and threads per blocks) observing the constrainsdescribed in [16]. For instance, the maximum number ofblocks that can be allocated is 65, 535, with 512 threads ateach one, given a total of 33, 553, 920 possible points on agrid with our approach.

The kernel configuration chosen uses a 2D block with32 threads in one dimension and 16 threads in the other.Besides, shared memorys size is based on the number ofthreads plus a region called buffer border whose size istwo times the neighborhood size, corresponding to the 2Dstencils size. One should be aware that there is a hardwarelimit in the size of the shared memory per block, 16KB inthe hardware used to run the tests described in this work.

The size of the shared memory is based on the number ofthreads plus one times the neighborhood size, in order toguarantee the optimization of the time access to memory.Therefore, each thread accesses the shared memory aligningits thread’s unique number with shared memory positions,where these positions are neighbors of other threads. Theboundaries considered for the shared memory must gobeyond the number of threads to guarantee that all of themare able to access data from time instant t− 1 from sharedmemory. Thus, the edges threads copy and access datafrom the global memory aligned with the neighboring edgethreads of other blocks.

Each thread copies its data in the current time from theglobal memory to the shared memory. Besides, the threadsat the border of a block also copy data corresponding to thedata of its own neighbors which belong to a neighboringblock. By doing this, the shared memory structure has all thedata necessary to compute new values of the points inside ablock without any additional access to the global memory. Inother words, it guarantees that all threads are able to accessthe memory addresses corresponding to instant t from sharedmemory.

The second part of the kernel computes two differenceequations: the first one, Eq. 2, is used for the wholedomain except for the edges. The second equation is used

214214

for absorbing the wave amplitude at the edges, by usingReynods Boundary condition [14].

The method is explicit in time since it provides decouplingof data, i.e., each value is defined for current (t) and previous(t − 1) time instants. On the other hand, this method isconditionally stable, in that the following condition must betrue in order for the method to converge: c(x, y)× ∆t

∆h ≤1√2

,where v is the wave’s velocity, and ∆t and ∆h are thediscretization intervals in time and space, respectively. Thisstability condition was proposed in an analysis developedby [17]. Within the family of implicit methods, severalschemes are not subjected to any constraint, thus they areunconditionally stable. In other words, any values for ∆tand ∆h can be used. Although implicit methods shall bestability condition free, they require a higher computationalcost, because a linear system must be solved to compute thenew value for each point in time step (t + 1).

Nowadays, the consoles as well as home computers havemulti-core architectures, which are able to process differenttasks simultaneously. In this context, the GPU can be usedsuch mathematics coprocessor combined with a parallelgame loop architecture [18]. Thus, the game tasks suchas AI, load data from the secondary memory and manyothers can be done as long as GPU processes the physicssimulation.

IV. INDOOR EXPERIMENT

Computing the perceived direction vector of a sound isan interesting feature, specially because it can be used toaugment the game mechanics, providing an extra level ofaccuracy for stealth games, such as the Metal Gear [1]and Splinter Cell [19] series. In this genre of games, theplayer often must get through complex buildings withoutbeing noticed by the enemy AI, both by avoiding eye contactand not making noises. Traditionally, checking if the AI canhear a player sound is achieved by a simple volume thresholdtest based on distance.

Other techniques, such as Potentially Audible Sets [12],can be used to increase the realism, but are an adaptationof a culling technique and not a proper simulation of howsound is propagated through a closed environment such as abuilding. Our simulation kernel is based on a proper methodfor computing sound propagation and reflections.

A. Experiment Description

In this indoor scene experiment, whose schematic view isshown in Figure 1, we represent two rooms connected by aside corridor, where the walls are sound-proof (propagationvelocity equals zero), completely reflecting the sound waves.

Room A Room B

Corridor

Figure 1: Blueprint of the indoor environment

Listener 1

Listener 2

Listener 3

Angle = 315ºAngle = 270º

Angle = 225º

Figure 2: Listeners

We chose to have one sound source and two listeners at eachtest setup. The sound source is a position in the lattice wherewe generate a sound pulse at the beginning of the simulation.The two listeners are positioned at different locations ateach test setup. Either source or listeners locations couldbe dynamically updated based on data extracted from agame engine. In our experiments, however, we chose fixedlocations for the simplicity of implementation.

Each listener is represented by four connected cells of thelattice, which can be computed based on its actual positionon the visual scene. To determine the relative direction fromwhich this listener perceives the sound coming, once thesound pulse is started we monitor the amplitude value of allfour cells at each time-step of the simulation. Whenever theamplitude passes a threshold level in one or two of thesefour cells, it is possible to classify the perceived directionof the sound source from eight (8) possible angles. Figure2 shows the listener representation and some examples ofthe possibly computed angles.

We ran the tests with three different setups for the relativepositions of the source and listener, as shown in Figure 3.After running some initial experiments, we realized that ouralgorithm was suitable even for low-end video cards, so wedecided to run all tests reported in this paper in a consumerMacbook White, based on an Intel Core 2 duo and aNVidia 9400GM, a GPU with only 32 stream processors and256MB of shared DDR3 memory. The parameters used for

215215

Setup 1 Setup 2 Setup 3

Sound Source Listeners

1

2 2

1 1

2

Figure 3: Test setup for experiment 1

indoor experiments are: ∆h = 0.25 meters , ∆t = 0.0033seconds, domain of 64 × 32 points, representing a floor of8× 4 meters. In Table I, the column (Exp.) identifies theexperiment number, the column (S. P.) represents the sourceposition, (P. L. 1) and (P. L. 2) are the position of listener1 and 2, respectively, while (A. L. 1)and (A. L. 2) show theperceived hearing angles for each listener, as computed bythe simulation.

Exp. S. P. P. L. 1 A. L. 1 P. L. 2 A. L. 21 (4, 4) (31,27) 0 (48,4) 1352 (32,31) (16,4) 45 (48,4) 1353 (63, 31) (16,4) 45 (48,4) 135

Table I: Indoor experiments

B. Result Analysis

We will first describe the results in terms of the datacomputed for the perceived direction angles. Figure 4 showsa sequence of screenshots taken from the debug visualizationof one of the test instances. One can see how the sound-wave propagates through the closed environment, finallyreaching the listener. In the final screenshot, a cone showsthe computed direction vector of the sound source.

Our simulation kernel is deterministic, so there was no needto perform more than one execution instance for each testsetup. However, we ran and monitored several instances ofthe experiment, with different hardware, in order to obtainsome performance data. The results showed that event forthe low end card used (NVidia 9400GM) the time needed tocompute each step was less than 1ms, not impacting overallperformance.

V. OUTDOOR EXPERIMENT

With the outdoor experiment, we wanted to mimic how ashock-wave from an explosion travels through an environ-ment with large obstacles, such as a city block with tallbuildings. The resulting amplitude field was used to render

Listener 1

Listener 2

Figure 4: Indoor experiment

the propagation of a shock-wave-like effect at each frame-step. While not exactly simulating the physical phenomenon,a sound wave propagation is an acceptable approximation forrendering a visual effect for gaming purposes.

The outdoor environment was represented by a lattice withlarger cells, and using Reynolds boundary condition [14] tosimulate domain continuity. The buildings were representedby zeroing the velocity of the cells that intercepted the visualmodels at the ground level. We included both perpendicularand diagonal buildings, as illustrated in Figure 5, to showthat the chosen granularity of the lattice was enough toachieve a good visual result. The kernel parameters forthis experiment are: ∆h = 1.0 meter, ∆t = 0.0033seconds, domain of 128 × 128 points, representing a blockof 128× 128 meters.

We chose to run this experiment both with and withoutrepresenting the buildings in the velocity field. We did this toshow how the simulated wave would propagate if it did nottake scene geometry into consideration. Figure 6 shows therendered effect with the buildings geometry influencing thepropagation, while Figure 7 shows how the same simulationis rendered by ignoring the walls.

216216

Explosion location

Building A

Building B Building C

Figure 5: Open environment representation

As the indoor experiment, the performance results are sim-ilar, since we used data-structures of almost identical sizes.

VI. CONCLUSION

In this paper we have shown how a wave propagationsimulation can be used to augment both the mechanicsand the set of visual effects available to a game designer,specially in games where better physical accuracy is aconcern. We described our simulation kernel, based on aFinite Difference Method, its implementation for a CUDA-based GPU, and demonstrated its applicability with two real-time experiments.

In our indoor experiment, a simple algorithm was used,in conjunction with the simulation kernel, to compute anapproximation of the perceived direction of a sound source.This technique can be used to augment traditional positionalaudio libraries, providing for a better suspension of disbeliefto the player, and/or more accurate input for the enemy AIin stealth games.

Our outdoor experiment has shown how a simple mimic ofa shock-wave, possibly originated by an explosion, prop-agating through a set of buildings compares to the sameeffect done without considering the reflection of the wavesby the buildings. We ran both experiments with a consumergrade GPU, and the results obtained show that our techniqueis indeed suitable for real-time, without compromising theperformance of the underling application.

While developing these applications, many other possibil-ities emerged, such as simulating an earthquake, to show

Figure 6: Outdoor - Building with reflective walls

217217

Figure 7: Outdoor - Building without reflective walls

the visual shock-wave and also computing vertical forcevectors to the rigid-body physics engine. Developing a moreaccurate mimic of this effect is our current aim, possiblycoupled with a 3D version of the simulation kernel, whichwill provide for much more complete amplitude data andpropagation.

A weakness of our the chosen simulation kernel is that itconserves energy, so that there is no attenuation of the soundwaves, resulting in a high entropy state, specially during thetests with our indoor experiment. We solved this by zeroingthe amplitude of the whole field once the perceived directionvector was computed for both listeners. On the outdoorexperiment, the boundaries simulated the continuation ofthe domain, absorbing energy and thus diminishing thisundesired side-effect. To better solve this issue, we planto apply an attenuation factor in future versions of thesimulated equation.

We consider that our goals where achieved with our currentimplementation, as we could systematically reproduce thetests in different hardware and experiment setups, alwaysgetting the expected results.

ACKNOWLEDGEMENTS

The authors gratefully acknowledge CNPq, CAPES andFAPERJ for the financial support of this work.

REFERENCES

[1] H. Kojima, “Metal gear solid series website,”http://www.konami.jp/kojima pro/english/index.html,accessed in: 07-19-2010.

[2] W. B. Langdon and W.Banzhaf, “A simd interpreter forgenetic programming on gpu graphics cards,” in LectureNotes in Computer Science: Genetic Programming. SpringerBerlin-Heidelberg, 2008, pp. 73–85.

[3] J. Bolz, I. Farmer, E. Grinspun, and P. Schrooder, “Sparsematrix solvers on the gpu: conjugate gradients and multigrid,”in ACM Transactions on Graphics: Proceedings of ACMSIGGRAPH, 2003, pp. 917–924.

[4] L. A. Abbas-Turki and B. Lapeyre, “American options pricingon multi-core graphic cards,” International Conference onBusiness Intelligence and Financial Engineering, vol. 0, pp.307–311, 2009.

[5] T. Rozen, K. Boryczko, and W. Alda, “A gpu-based methodfor approximate real-time fluid flow simulation,” MachineGraphics and Vision International Journal, vol. 17, no. 3,pp. 267–278, 2008.

218218

[6] A. Balevic, L. Rockstroh, A. Tausendfreund, S. Patzelt,G. Goch, and S. Simon, “Accelerating simulations of lightscattering based on finite-difference time-domain method withgeneral purpose gpus,” Computational Science and Engineer-ing, IEEE International Conference on, vol. 0, pp. 327–334,2008.

[7] D. Michea and D.Komatitsch, “Accelerating a three-dimensional finite-difference wave propagation code usinggpu graphics cards,” Geophysical Journal International, vol.182, pp. 389–402, 2010.

[8] O. Mazarak, C. Martins, and J. Amanatides, “Animatingexploding objects,” in In Proceedings of Graphics Interface,211-218, Ed. Morgan Kaufmann Publishers Inc, 1999.

[9] N. Rober, U. Kaminski, and M. Masuch, “Ray acoustics usingcomputer graphics technology,” Proc. of the 10th Int. Confer-ence on Digital Audio Effects, pp. DAFx–01–08, september2007.

[10] R. Nikunj, G. Nico, and M. C. L., “Accelerated wave-basedacoustics simulation,” in SPM ’08: Proceedings of the 2008ACM symposium on Solid and physical modeling, vol. 91-102.ACM, 2008.

[11] K. van den Doel, P. G. Kry, and D. K. Pai, “Foleyautomatic:physically-based sound effects for interactive simulation andanimation,” in SIGGRAPH ’01: Proceedings of the 28thannual conference on Computer graphics and interactivetechniques. New York, NY, USA: ACM, 2001, pp. 537–544.

[12] M. Dickheiser, C++ For Game Programmers. Rockland,MA, USA: Charles River Media, Inc., 2006.

[13] A. Mitchell, Computational Methods in Partial DifferentialEquations. John Wiley and Sons, 1969.

[14] A. Reynolds, “Boundary condition for the numerical solutionof wave propagation problems,” Geophysics, vol. 43, no. 1,pp. 1099–1110, 1978.

[15] G. Golub and J. Ortega, Scientific Computing and DifferentialEquations: an Introduction to Numerical Methods, 1st ed.Academic Press, 1991.

[16] NVIDIA, NVDIA - CUDA Programming Guide, NVIDIA,2010.

[17] L. R. Lines, R. Slawinski, and R. P. Bording, “A recipefor stability of finite-difference wave-equation computation,”Geophysics, vol. 64, pp. 967–969, 1999.

[18] M. P. M. Zamith, E. W. G. Clua, A. Conci, A. Montenegro,R. C. P. Leal-Toledo, P. A. Pagliosa, L. Valente, and B. Feij,“A game loop architecture for the gpu used as a mathcoprocessor in real-time applications,” Comput. Entertain.,vol. 6, no. 3, pp. 1–19, 2008.

[19] Ubisoft, “Splinter cell video game website,”http://splintercell.uk.ubi.com/conviction/, accessed in:07-19-2010.

219219