• No results found

Vattensimulaton på Multi-touch-skärmar

N/A
N/A
Protected

Academic year: 2021

Share "Vattensimulaton på Multi-touch-skärmar"

Copied!
21
0
0

Loading.... (view fulltext now)

Full text

(1)

BACHELOR'S THESIS

Water Simulation on Multi-Touch Screens

Simon Andersson

2014

Bachelor of Science in Engineering Technology

Computer Game Programming

Luleå University of Technology Institutionen för system- och rymdteknik

(2)

Water Simulator for Multi-touch Screens

Abstract

Water is an incredibly important part of our everyday life. You find it everywhere, from lakes and open oceans, to even your own body. About three quarters of the earth is covered by water, so there is no surprise that it’s anything but unusual to encounter water in games, as well. However, as water by nature is extremely complex, ways to implement a simulation of water in a realistic yet achievable manner is constantly researched.

Nuiteq is a company with roots in Skellefteå, Sweden. They are developing one of the leading competitors in the multi-touch software markets, the Snowflake Suite. The purpose of this paper is to cover a feasible method for simulating a water surface implemented as an application for the Snowflake Suite. This is done by creating a grid representing small patches of water particles and performing operations on those instead of on each individual particle.

(3)

Water Simulator for Multi-touch Screens

Table of Contents

1 Introduction ……….1

1.1 Background ………1

1.2 Water Surface Simulation ………1

1.3 Social, Ethical and Environmental Considerations ………2

2 Implementation ………4 2.1 Water Simulation ………4 2.1.1 Height Field ……….4 2.1.2 Damping forces ……….5 2.1.3 Applying forces ………5 2.1.4 Calculating normals ……….6 2.2 Graphics ………7 2.2.1 Reflections ………..7 2.2.2 Refractions ……….………8 2.2.3 Fresnel ……….10 3 Results ………11 3.1 Testing ……….12 4 Conclusion ………14 4.1 Restrictions ………14 4.2 Future work ……….15 4.3 Acknowledgements ………16 5 References ………17

(4)
(5)

Water Simulator for Multi-touch Screens

1

1 Introduction

1.1 Background

Water is an important aspect that is improving the realism of computer and video games. All across both the gaming as well as the film industry, we can see water continuously being used in all different kinds of environments [7]. We can find anything ranging from large lakes and oceans, to smaller ponds, to tiny cups of water [2].

We can tell that water is, and will be used in large amounts. This is however easier said than done. Water consists of millions, even billions of small particles, moving around, each affecting each other in a multitude of different ways. Water is extremely complex, and as such, simulating it will not be any different.

Today’s modern hardware is nowhere near being able to accurately simulate large bodies of water in a physically correct way in real time. However, there are numerous different methods made for producing visually acceptable results, which we will be using to our advantage. There are a lot of different ways to achieve this, but this paper is going to focus on a method called water surface simulation [5].

1.2 Water Surface Simulation

Water surface simulation is a method for simulating bodies of water. Instead of simulating every single part of the entire body, it focuses on one part of the water; the surface. In most cases, water will be displayed as part of a larger body in a lake, pool, or an ocean. Only when the camera is placed underwater, or when the water is placed inside a transparent container, or is poured, a solution more complex than water surface simulation is required. In

(6)

Water Simulator for Multi-touch Screens

2

all other cases, the only thing that actually needs to be rendered is the surface, and anything that can be seen through it.

In order to simulate the water surface, this method makes use of a height field that simulates small patches of water spread across the entire surface. Instead of simulating every single particle, it utilizes a grid that is acting as small collections of water particles, performing the calculations on each individual grid cell. Using this method, a behaviour very similar to that of water will be achieved [2].

In order to avoid unnecessary complexity, the water will be assumed to be incompressible. That is, the water will not decrease in volume when exposed to external forces. The volume will remain constant throughout the entire simulation [1].

The algorithm described in this paper has mostly been inspired by the methods that Miklós [2] and Naetterlund [5] have developed.

1.3 Social, Ethical and Environmental Considerations

The application has been designed in a very simplistic manner, in order for the user to not experience any confusion while using it. There should be no need to navigate through a series of different menus in order to reach the actual simulation. Therefore, as soon you start the application, you will be brought to the water. This way, everything is quite self-explanatory. Since there are no advanced layouts or UI, the application should be able to be used by anyone who is able to partake in the visual aspect of water.

(7)

Water Simulator for Multi-touch Screens

(8)

Water Simulator for Multi-touch Screens

4

2 Implementation

The water will be implemented using a method which simplifies the entire body as simply the water’s surface, and breaks it apart into a grid of smaller patches of water particles.

2.1 Water Simulation

2.1.1 Height Field

The water surface can be divided up into an arbitrary amount of cells distributed across a two-dimensional space. Each of these cells contains the average height and velocity of the water that is currently located within the cell. Every update step, the grid cells are compared with their neighbouring cells (figure 1a) in order to determine and apply the acceleration of each cell (1).

i i i i i i (1)

Figure 1.a, 1.b. Higher levelled neighbours will spread to the lower cells.

(9)

Water Simulator for Multi-touch Screens

5

i i (2)

There is of course restrictions to this algorithm. The grid is contained within its own borders. When comparing one of the grid cells on the border of the grid with its neighbours, the algorithm will attempt to read outside of the grid. A way to deal with this special case is required. In this simulation, simply clamping the values within the borders of the grid is sufficient for achieving a realistic result.

2.1.2 Damping forces

Friction is an important part of the physical simulation. With no friction, the waves would be able to continue travelling across the surface during the entire simulation. This is obviously not correct, as waves die out after travelling some distance. To simulate this, a damping force is applied to each velocity after it has been calculated (3).

i i (3)

2.1.3 Applying forces

As stated earlier, since the water is assumed to be incompressible, pushing an object into the water will not make the water that occupied that space disappear. It will instead be pushed away from it’s initial position, to the neighbouring water cells. This will cause the water level around the object to rise, ultimately creating waves around the point where the change in water level occurred. In order to satisfy the simulation equation, a force is applied to the water cell where an object has touched the water. That force will then be split up into several opposing forces which will be distributed to each neighbouring cell (figure 2). Letting the updating algorithm take care of the rest from here on will create the wave effect that is strived for.

(10)

Water Simulator for Multi-touch Screens

6

Figure 2. A force is applied to a water cell. Opposing forces will be applied to it’’s neighbours.

2.1.4 Calculating normals

As the shape of the water surface is constantly changing, so will the normals. The normals will be a very important factor while deciding what will be seen during the render step, so they will need to be recalculated each frame.

(11)

Water Simulator for Multi-touch Screens

7

2.2 Graphics

There are two major components that contribute to the realism of the water surface. Those components are the reflections and the refraction [3].

2.2.1 Reflections

There are two different types of reflections. Local reflections are the reflections of objects in the near vicinity of the water surface. If this is assumed to be part of a game, then those objects would be the game characters, environment objects and nearby landscape. The other type of reflection is the global reflections. These include the sky, distant landscape and sunlight, among others.

Considering the nature of the project, no external game objects will be present. Therefore, local reflections can be ignored, allowing full focus on the global reflections.

Cube maps are a great way to achieve global reflections. They are boxes of textures that usually are placed with their centers at the camera in order to create a constant world around the viewer. The sky and distant landscape can be created as part of a so called skybox which will be used by the water shaders in order to create the reflections. It is possible to include the sun in the skybox as well, but this simulation is instead using a light source for lighting up the water, as it is easier to control, than to control the position of the light on the texture.

(12)

Water Simulator for Multi-touch Screens

8

Figure 3. The view vector E is reflected at the water surface and reflected by normal N, resulting in reflect vector R.

At each point on the water, a reflection value will be calculated. By letting the view vector - the direction the camera is looking at the water - be reflected by the water normal (figure 3), a point on the skybox can be fetched. This point will be reflected on the water.

2.2.2 Refractions

Some light will not be reflected at the water surface. Some of it will pass through the surface and be refracted. This will make objects and surfaces underwater look bent, and displaced (figure 4).

(13)

Water Simulator for Multi-touch Screens

9

Figure 4. A wave gets refracted when entering a medium with a different index of refraction, according to Snell’s law.

According to Snell’s law ( ), when a light wave passes from one medium to another with different indices of refraction n1 and n2, the wave will change direction. The ratio of the sines

of the angle of incidence and refraction will be equal to the inverted ratio of the indices of refraction (figure 4).

2

2

(4)

A refraction map must be set up in order to calculate the refractions. In the case of objects seen through the water, a separate render pass is required in order to determine what can be seen. This would be rendered to a texture which in turn will be used as the refraction map. In this case, since there won’t be anything moving beyond the water surface, a simple texture with, for example, the pool floor will be sufficient. If the view of the water surface was from an angle, special cases dealing with this would be required, however this is not the case right now. Each point on the refraction map will now be displaced.

(14)

Water Simulator for Multi-touch Screens

10

2.2.3 Fresnel

Now, both the reflection and refraction has been calculated. What’s remaining is to determine whether the incident ray is reflected or refracted. Generally, the rays will partially be reflected and partially be refracted, both at the same time. Depending on the normals where the ray hits the water, a specific mix of the two will combine to determine what is seen. So, a way to calculate the reflection/refraction ratio is needed. This is done using the Fresnel equations (5, 6).

(5)

(6)

The final color of the water surface will be a mixture of the reflection and refraction (7), where if fresnel is high, the reflection will be more prominent, while on the other hand, if

fresnel is low, the refraction will.

(15)

Water Simulator for Multi-touch Screens

11

3 Results

By the end of the project, the water simulation had been completed in due time, with visually pleasing results. The application runs on both regular computers, as well as on the multi-touch screens Nuiteq uses for their own applications.

The final result is an application that visualizes a water surface on a multi-touch screen, provided by Nuiteq. The application allows the user to interact with the water surface, just like one would be able to do with a real surface. You can touch the screen in order to apply pressure to the water surface, which will simulate the rippling effect that occurs when

something hits a water body (figure 5). Any arbitrary number of touches is supported by the application, allowing for a great amount of surface movement to demonstrate the capabilities and accuracy of the simulation. The only thing limiting the amount of touch inputs is the hardware limitations. Since the water algorithm is designed to be running at a constant speed, input count contributes nothing to the frame rate. The only thing that will affect the rate is the grid resolution, as well as the beforementioned hardware limitations.

The water is rendered in a pool-like environment, viewed from above. Besides the actual water, there are three major external features included in the scene. One of these is the pool floor, presented as a texture that is placed below the surface, then refracted by the surface normals. There is also the sky texture, as well as the main light source of the scene, which will be reflected on the water surface.

(16)

Water Simulator for Multi-touch Screens

12

Figure 5. Ripples are generated on the water surface, the refraction is clearly visible.

All of these components can easily be altered using Snowflake’s customization tool. Values like different water behaviours, such as spreading speed and wave amplitudes, as well as different textures can be altered in various ways. The diversity of the different settings allows the application to simulate a broad range of varying results. With the correct settings, any kind of different fluid can be reproduced.

3.1 Testing

The application has been tested continuously during the entire course of the project. From the state when the water was nothing but data hidden in the algorithm in the code, to when the water was represented as tiny squares with a specific color depending on its height, to the

(17)

Water Simulator for Multi-touch Screens

13

final result with fully shaded water effects, multiple tests have been performed every single day. Different things have been successful, and some have been shown to be very wrong. The most prominent thing that has become apparent from the testing have been that if you set the values of the width of each water cell and the speed the waves travel at greatly apart, such that if you divide one value with the other, the result will be much larger or much smaller than 1, the simulation will produce effects nowhere near the behaviour that water should produce (figure 6).

(18)

Water Simulator for Multi-touch Screens

14

4 Conclusion

My initial schedule turned out to be misplanned, as some parts near the end of the project took more time than earlier expected. However, as I managed to finish the main parts of the project quicker than planned, I had more than enough time to deal with these problems. In the end, I had just the amount of time to do the things I had planned to do.

The most difficult part of the project was actually not the water simulation itself. The actual algorithm was in itself not too advanced, making it not too hard to implement. The only thing that was hard to do on that part was tweaking the values to make the water look realistic. The hardest part of the project was actually the visualization of the simulated water. Getting that right took a lot of time, and a lot of abstract black and white patterns.

I am quite pleased with the way the project finally turned out. There are a few minor restrictions which I will describe in further depth in a moment, but otherwise, everything met any kind of expectations that I initially had.

4.1 Restrictions

During the planning of the project, I had considered adding caustics, which is an envelope of the refracted rays, as an extra visual effect. Though I knew that this was no simple task, as caustics is an area of research of it’s own. Thus I decided to consider it an extra feature, in case I would have time to look into it at the end of the project. I actually ended up having the time to try it out, and implemented a simple caustics prototype. However, I eventually decided to remove it, as the only thing it contributed to was adding more confusion to the already good-looking water effects.

The most prominent restriction will become apparent when playing around with the

(19)

Water Simulator for Multi-touch Screens

15

settings, and will sometimes generate weird effects instead of the desired results (figure 6). This is of course not a big deal, since the algorithm won’t be broken unless you’re trying to break it.

4.2 Future work

One of the most important things that should be implemented into the simulator would be support for submerged objects. Right now, there will not exist any external objects on the scene. This is no wonder, as the simulation is nothing else, besides the actual water surface. It works well this way, but you will not only want to keep the water in such a small

environment, as it will have very few usages. The goal will most certainly be to implement this into a game environment, thus external objects will be introduced.

(20)

Water Simulator for Multi-touch Screens

16

Once the water has been added to a more vivid environment, there will be a great need for more realistic effects, besides ripples on the surface. Splashes, bubbles and breaking waves are all examples of important parts of water that this simulation will benefit from. These can all be implemented through the help of particles [6] [7]. Adding a particle generator to the simulation would be quite straight forward.

4.3 Acknowledgements

I would like to thank Nuiteq, Harry van der Veen and all the other guys working there for letting me do my bachelor thesis at their office. I also want to thank them for lending me the equipment necessary to perform my work. I want to thank Johan Österberg for providing feedback and technical support during the entire course of the pro ect, and finally, I’d like to thank Patrik Holmlund for reading and sending feedback on my report.

(21)

Water Simulator for Multi-touch Screens

17

5 References

[ ] James O’Brien and Jessica Hodgins, Dynamic Simulation of Splashing Fluids, 1994.

https://smartech.gatech.edu/bitstream/handle/1853/3599/94-32.pdf

[2] Bálint Miklós, Real-time Fluid Simulation Using Height Fields, 2004.

http://www.balintmiklos.com/layered_water.pdf

[3] Claes Johansson, Real-time Water Rendering, 2004.

http://fileadmin.cs.lth.se/graphics/theses/projects/projgrid/projgrid-lq.pdf

[4] Robert Bridson et al, Curl Noise for Procedural Fluid Flow, 2007.

https://www.cct.lsu.edu/~fharhad/ganbatte/siggraph2007/CD2/content/papers/046-bridson.pdf

[5] Morgan Naetterlund, Water Surface Rendering, 2008.

http://www8.cs.umu.se/education/examina/Rapporter/MorganNaetterlund.pdf

[6] Cem Yuksel et al, Real-time Water Waves with Wave Particles, 2010.

http://www.cemyuksel.com/research/waveparticles/cem_yuksel_dissertation.pdf

[7] Matthias Mueller, Real-time Simulation of Large Bodies of Water with Small Scale Details, 2010. http://www.matthiasmueller.info/publications/hffluid.pdf

References

Related documents

Figure 4.4 indicates size distribution of activated sludge flocs and the effect of sonication on breakage of particles in secondary effluent.. This figure shows that there is

Är MapGuide en programvara som kan vara något för kommunen att använda i sin distribution av geografiska data.. Det är en billig lösning som kan relativt

The objective of achieving a good water status for water bodies in 2015 is elaborated in the Order in Council that will establish the environmental quality standards for

This study has shown that slow sand filters without an appropriate sand height or required sand grain size doesn’t purify the raw water to a suitable drinking standard according to an

Degree Project in Architecture, Second Level 30 credits. 8

Thin metal films with low resistivity may have a ratio exceeding one at 0 K if the TE modes give a significant contribution at sepa- rations where retardation effects on the TM

Detta behöver dock inte ses som fysiskt våld utan kan till exempel ske genom avskräckning eller ett tvingade att ge efter eller acceptera annan stats vilja

Faktorerna som ses som viktiga för arbetstagarnas arbetsmotivation är inte direkt relaterade till distansarbetet, men de förutsättningar som Företaget har skapat har trots detta