• No results found

Visualization of smoke using particle systems

N/A
N/A
Protected

Academic year: 2022

Share "Visualization of smoke using particle systems"

Copied!
31
0
0

Loading.... (view fulltext now)

Full text

(1)

Visualization of smoke using particle systems

VERONICA GINMAN & KIM MALMROS

Bachelor’s essay at CSC Supervisor: Petter Ögren Examiner: Mårten Björkman

(2)
(3)

Abstract

Visualization is used everywhere in today’s society, from big screen pictures and video games to commercials and artistic images. The desire to be able to create realistic looking and behaving phenomena has long existed and to- day’s technology allows us to come close to realistic results.

Particle systems is a technique that has long been used to create many visualisations for all of these purposes. In this paper we will describe this simple method of creating realis- tic visualizations. We will look at the results of the simplest of particle systems and compare them to those of the more

(4)

Referat

Visualisering används idag inom många områden så som filmer, datorspel, reklam och även för konstnärliga bilder.

Viljan att kunna skapa fenomen som ser verklighetstrogna ut och som beter sig på ett realistiskt sätt, har länge fun- nits. Idag har teknologin kommit så pass långt att det nu går att skapa visualiseringar som kommer riktigt nära verk- ligheten. Partikelsystem är en teknik som länge har använts för att skapa visualiseringar inom alla dessa områden. I den här rapporten kommer vi beskriva denna enkla metod som används för att skapa verklighetstrogna visualiseringar. Vi kommer att analysera resultaten av ett enkelt partikelsy- stem och jämföra dessa med resultat från mer avancerade partikelsystem.

(5)

Statement of collaboration

Veronica: Research, programming, all sections of report, proof reading.

(6)

Contents

1 Introduction 1

1.1 Problem statement . . . 1

2 Background 3 2.1 History . . . 3

2.2 Real-time vs. pre-rendering . . . 3

2.3 Smoke visualization . . . 4

2.4 Related work . . . 4

2.4.1 Particle systems and fluid dynamics . . . 4

2.4.2 Particle systems and NURBS surfaces . . . 6

3 Approach 9 3.1 The particle . . . 9

3.2 The particle system . . . 10

3.3 The main class . . . 10

4 Results 11 5 Conclusions 15 5.1 Improvements . . . 15

Bibliography 17 Appendices 18 Appendix A . . . 18

PVector.hpp . . . 18

PVector.cpp . . . 18

Particle.hpp . . . 19

Particle.cpp . . . 19

ParticleSystem.hpp . . . 21

ParticleSystem.cpp . . . 22

System.cpp . . . 23

(7)

Chapter 1

Introduction

Particle systems is a technique used to model objects that are difficult to model with classical surface-based modelling. Objects that are dynamic, change over time or that are fuzzy, fluid or in other ways non-static may be modelled in a more realistic way using particle systems. Particle systems creates a volume of particles with individual properties rather than a surface with a texture. With this approach it is possible to change each individual particle’s appearance over time and in this way creating visualizations that in a realistic way show fire, smoke, water, explosions and with some alterations even hair and fur. This technique has many useful applications and one of these is in special effects. Whether it is big explosions, dust, fires or large crowds of people, special effects are essential in many films, animated or motion capture. Films featuring massive explosions and destroyed buildings may want to have these effects simulated rather than having to do them for real. In this report we will be focusing on the modelling of smoke using particle systems. Smoke is in nature made up of small smoke particles that move independently from each other, however, since the particles will have mostly the same forces acting on them they will behave similarly.

1.1 Problem statement

The goal is to create realistic looking and behaving smoke using a particle system.

(8)
(9)

Chapter 2

Background

2.1 History

Particle systems have been used to model many different kinds of flock behaviours from birds and fish to water, fire and smoke and with some alterations even hair, cloth and fur. In essence particle systems are best applied to phenomena that can be seen as a volume of tiny objects that interact mainly with their neighbours.

Particle systems are said to have been used in video games as early as in the 1960’s[3] to simulate explosions using 2D pixel clouds. In the early 1980’s however, William T. Reeves used particle systems to model fire engulfing a planet in the film Star Trek II: Wrath of Khan[5], the result of this can be seen in 2.1. Reeves is considered to be the inventor of particle systems and he produced a paper on in it 1983 explaining how it was done[5]. Reeves continued to develop this idea further and has since contributed more to the area of particle systems. Development has continued and today most game engines, such as the popular Unreal engine[1], contains a particle system.

2.2 Real-time vs. pre-rendering

The technique of using particle systems is used frequently within the visualization field. However, using particle systems when rendering in real-time, such as with many computer games, differs from that of pre-rendering as is the case when used in films. Rendering in real-time will require more of the users computer and therefore particle systems used in games with real-time rendering may not include as many particles as when used with pre-rendering. The number of particles, as well as the number of vertices each polygon that makes up these particles has, can greatly affect performance and appearance. Since real-time rendering in general is much more complicated, computer graphics used in games can not keep up with that of the special effects seen in films. In films, especially those featuring real people, special effects are often required to be flawless so that the viewer can not tell the difference from the real footage and the computer animated visualizations. According to Lutz

(10)

CHAPTER 2. BACKGROUND

Figure 2.1. Planet being engulfed by fire in the film Wrath of Khan[5].

Latta[3] real-time implementations of particle systems could handle up to 10 000 particles in 2004 however Latta propose a full GPU implementation that can handle up to 1 million particles[3].

2.3 Smoke visualization

Visualization of smoke could be described differently depending on the source of the smoke. Smoke emerging from a burning building or a bonfire will behave in a way similar to that of clouds or fog because of the large quantities of smoke being created, example in image 2.3. Smoke coming from an explosion or a collapsing building will behave in way that can be described as a huge powerful cloud rapidly expanding from the source of explosion and then changing into the appearance of fog, example in image 2.2. Furthermore, smoke coming from a cigarette or a candle will slowly rise, following the flow of air only, and because of the small amounts of smoke created it can appear more translucent and fine. Example of incense smoke in image 2.4 and a realistic visualization of small scale smoke as seen in image 2.5 based on the work of Park et al.[4] described more in section 2.4.2. This small scale smoke is also probably the most difficult to visualize due to the fact that it requires a great touch of realism achieved by the use of air flow simulation, more on this in section 2.4.1.

2.4 Related work

2.4.1 Particle systems and fluid dynamics

Smoke particles behaviour are similar to that of light gases. The smoke particles are light and small and when emitted from a still source such as a candle will have

4

(11)

2.4. RELATED WORK

Figure 2.2. Large scale smoke from explosion, Photo by Charles Levy, Title Atomic bombing of Nagasaki on August 9

no velocity. What causes the behaviour of the particles are mainly the surrounding forces. Unlike birds or fish smoke particles will have no affect on their own movement but are solely dependent on outside forces pushing and pulling them in different directions. Smoke is in general drawn upwards due to the particles light weight not being heavily affected by gravity and also because smoke tend to be warm and warm air rises. Because the light weight of the particles they will follow the air stream and thus rise upwards. Smoke, like fluids, will also follow surfaces when interacting with objects. To model such behaviour computational fluid dynamics are often used. Commonly used equations for solving CFD are the Navier-Stokes and Euler equations. Both equations describe how velocities and mass change and assuming viscosity to be zero removing heat conduction[2] from the Navier-Stokes gives the Euler equation. Stam et al.[6] applied the equation into an implementation that gives stable solutions meaning that even for small time steps the simulation will not give absurd results.

(12)

CHAPTER 2. BACKGROUND

Figure 2.3. Smoke from a bonfire, Photo by Tomas Sienicki, 2005. Smoke from bonfire.

2.4.2 Particle systems and NURBS surfaces

Park et al. [4]present an interesting way to visualize small scale smoke such as smoke coming from candles, incense and cigarettes. Particles are used to create streaklines from which they create NURBS surfaces. Opacity maps are then calculated using the density of the smoke and its surface contours characteristics and then applied to the surfaces. As can be seen in 2.5 their approach create very realistic looking smoke that captures the behavioural characteristics of small scale smoke and at a low computational cost.

6

(13)

2.4. RELATED WORK

Figure 2.4. Small scale smoke from incense,

Source:http://en.wikipedia.org/wiki/Image:Incenselonghua.jpg

Figure 2.5. Result and work approach from Park et al. [4]

(14)
(15)

Chapter 3

Approach

Our implementation for creating realistic looking smoke is done in C++ and with the use of OpenGL. It consists of two parts and a main function to tie them together.

The parts are the particle and the particle system. The main function is in a third part called system, in this function there is a infinite while-loop. Each iteration of this loop will be referred to as a cycle in the rest of the report.

3.1 The particle

The particle class is the class that contains all the information for the individual particle. Each particle has colour, size, shape, lifespan, location, acceleration and velocity associated with it. All of these parameters can be tweaked to improve the appearance and behaviour of the particles. Colour is described by RGBA values which, by using a blend function in OpenGL, means that our particles can become transparent. RGBA values are red, green and blue values with the A representing the alpha value. The alpha value ranges from 0, which is completely transparent or invisible, to 1 which is completely opaque. The colour parameter is currently set to go from opaque, to completely transparent. This is done by letting the alpha value of each particle depend on the lifespan which means that the particle becomes more transparent with each cycle. The lifespan of the particles are initiated at a pre-set value and then decreased slightly each cycle. The lifespan represents how long a particle will live and when it reaches zero the particle is marked as dead.

To make the colour appear more realistic it will appear less translucent if several particles are drawn on top of each other. To make one single particle’s colour depend on other crossing particles OpenGL provides a useful blending mechanism that we used which allows the colour from each object in the same location to be added to the final drawing colour.

All the particles are drawn from a starting position which we call the point of emission or the emitter. Each particle receive a randomized emission point by the particle system that is dependent on the emitter given to each particle system as a parameter when a new system is initialized.

(16)

CHAPTER 3. APPROACH

To make the particles move the location is updated each cycle. The movement is randomized to make the particles behave more realistic than if they were to move in straight lines. The particles will move upwards in general but can fluctuate slightly downwards.

The shape of the particles are circular OpenGL polygons with 10 vertices each.

3.2 The particle system

The particle system class is the class where new particles are added to a system.

The particle system takes one parameter, a vector, that is the emission point for the particle system. The particle system is a collection of many particles and contains a vector to keep track of them. A particle can be added to the vector using the addParticle function. A new particle is added every cycle in our system, to create a continuous flow of particles. Each particle’s run function is called from the system, when a particle is dead it is removed from the vector of particles and its run function will not be called. If the particle vector is empty the system is dead.

3.3 The main class

The main class contains all the information and code necessary for drawing. It is from the main class that everything runs and where the particle system is initiated.

In each cycle of the while loop a new particle is added to the system and the particle systems run function is called. Then everything is drawn using OpenGL.

If the particle system is dead, the while-loop is broken.

10

(17)

Chapter 4

Results

The images below show the output visualizations from our particle system with different values for the particle size and the number of particles emitted each cycle.

The simulation was originally done as grey particles on white background but we later did the same simulations as light particles on black background because that seemed to be the convention. All screenshots were taken after the first emitted particles had died so that particles of all ages are represented in the visualizations.

(18)

CHAPTER 4. RESULTS

Figure 4.1. Results from our implementation. 1. Size 0.02 emitted particles per cycle 1 2. Size 0.01 emitted particles per cycle 4 3. Size 0.1 emitted particles per cycle 1 4. Size 0.05 emitted particles per cycle 1 5. Size 0.05 emitted particles per cycle 2 6. Size 0.02 emitted particles per cycle 2 7. Size 0.005 emitted particles per cycle 10.

Figure 4.2. Results when using dark particles on white background

12

(19)

Figure 4.3. Cropped image of 4 in 4.1

Figure 4.4. Cropped image of 2.3

(20)
(21)

Chapter 5

Conclusions

The visual result of our implemented system can not be considered realistically looking or behaving. However, the first thing people would relate our visualization to would probably be smoke coming from a fire. In visualization the appearance of an object and how it is perceived by the viewer is the most important thing. Realistic accuracy is less important but may of course help in creating visualizations that should appear realistic. Looking at 4.3 the texture appear quite realistic compared to 4.4, which is a real photo of smoke.

Comparing our different outputs with each other, the result of having large particles images 3, 4, 5 in 4.1 can appear more realistic while zoomed in in terms of texture as seen in 4.4. The small particles look too scattered though this might be improved by adding more particles. However, visualizing 10 particles per cycle, such as in 7 in 4.1, and with each particle having a lifespan of 3 000 cycles, results in rendering 30 000 particles which is more work than preferred on an ordinary PC.

In addition, each particle was made up of 10 vertices making it 300 000 vertices in total, lowering the amount of vertices could have a positive effect on performance.

5.1 Improvements

Possible improvements would be to apply fluid dynamics so that individual particles interact with each other. Stam [6] outlines a computationally inexpensive method of applying fluid dynamics to simulate smoke which a particle system can be built on top of which would improve the realism.

The shape and colour of the particles can also be improved. While smoke par- ticles do not come in a particular shape in the real world, randomizing between a few irregular shapes might improve appearance. This might be especially good for those particles that are outside the main collection of particles. By applying dif- ferent textures to the particles we might also make the appearance more realistic.

Using a texture that itself has a fuzzy edge and a fading colour towards the edges could soften the look making edges of particles less apparent.

Offloading some of the operations on the GPU could lead to performance im-

(22)

CHAPTER 5. CONCLUSIONS

provements when the number of particles become larger. Since the particles in our current implementation are independent of each other it should be possible to improve performance by parallelizing their position and transparency updating.

16

(23)

Bibliography

[1] Particle system reference. http://udn.epicgames.com/ThreeParticleSystemReference.html.

[2] John D. Anderson. Computational Fluid Dynamics, The Basics With Applica- tions. Mcgraw-Hill Higher Education, 1995.

[3] Lutz Latta. Building a million-particle system. http://www.gamasutra.com/

view/feature/130535/building_a_millionparticle_system.php?page=1, July 2004.

[4] Jinho Park, Yeongho Seol, Frederic Cordier, and Junyong Noh. A smoke visu- alization model for capturing surface-like features. 00(0), 2010.

[5] William T. Reeves. Particle systems a technique for modeling a class of fuzzy objects. 17(3), July 1983.

[6] Jos Stam. Real-time fluid dynamics for games. http://www.dgp.toronto.edu/

people/stam/reality/Research/pdf/GDC03.pdf.

(24)

BIBLIOGRAPHY

Appendix A

PVector.hpp

#ifndef _PVector

#define _PVector class PVector { public:

double x;

double y;

double z;

PVector();

PVector(double x_, double y_, double z_);

void add(const PVector & v);

PVector operator=(const PVector & other);

};

#endif

PVector.cpp

#include "PVector.hpp"

PVector::PVector(){

x = 0;

y = 0;

z = 0;

};

PVector::PVector(double x_, double y_, double z_){

x = x_;

y = y_;

z = z_;

};

void PVector::add(const PVector & v){

x = x + v.x;

y = y + v.y;

z = z + v.z;

};

PVector PVector::operator=(const PVector & other){

x = other.x;

y = other.y;

z = other.z;

return *this;

18

(25)

APPENDIX A

};

Particle.hpp

#ifndef _Particle

#define _Particle

#include "PVector.hpp"

class Particle{

private:

PVector location;

PVector velocity;

PVector acceleration;

float lifespan;

public:

static const double size;

static const double _pi;

static const double angle[10];

static const double _cos[10];

static const double _sin[10];

Particle();

Particle(PVector l);

void run();

void update();

void display();

bool isDead();

double random(double upper, double lower);

};

#endif Particle.cpp

#include<stdio.h>

#include<iostream>

#include<stdlib.h>

#include<X11/Xlib.h>

#include<GL/glx.h>

#include<GL/glu.h>

#include<cmath>

#include "Particle.hpp"

extern GLuint smokeTexture;

(26)

BIBLIOGRAPHY

const double Particle::size = 0.02;

const double Particle::_pi = 3.141592;

const double Particle::angle[10] ={2*_pi*1/10., 2*_pi*2/10., 2*_pi*3/10.,

2*_pi*4/10., 2*_pi*5/10., 2*_pi*6/10., 2*_pi*7/10., 2*_pi*8/10., 2*_pi*9/10., 2*_pi};

const double Particle::_cos[10] = {size*cos(angle[0]), size*cos(angle[1]), size*cos(angle[2]), size*cos(angle[3]), size*cos(angle[4]), size*cos(angle[5]), size*cos(angle[6]),

size*cos(angle[7]), size*cos(angle[8]), size*cos(angle[9])};

const double Particle::_sin[10] = {size*sin(angle[0]), size*sin(angle[1]), size*sin(angle[2]), size*sin(angle[3]),

size*sin(angle[4]), size*sin(angle[5]), size*sin(angle[6]), size*sin(angle[7]), size*sin(angle[8]), size*sin(angle[9])};

Particle::Particle(){}

Particle::Particle(PVector l){

location = l;

velocity = PVector(0.0,0.001,0);

lifespan = 255;

}

void Particle::run(){

update();

display();

}

double Particle::random(double upper, double lower){

double range = (upper-lower);

double random_double = lower+(range*((double)rand())/(RAND_MAX));

return random_double;

}

void Particle::update() {

double x_acc = 0.000034*random(-1,1);

double y_acc = 0.00001*random(-1,1);

double z_acc = 0.0;//0.0001*random();

acceleration = PVector(x_acc,y_acc,z_acc);

velocity.add(acceleration);

location.add(velocity);

lifespan -= 0.2;

}

void Particle::display() {

20

(27)

APPENDIX A

double inty = 1.2 - lifespan/255.;

glColor4f(0.9,0.9,0.9,inty);//, inty, inty);

//float delta_theta = 0.01;

//double _pi = 3.141592;

//glBindTexture(GL_TEXTURE_2D, smokeTexture);

glBegin( GL_POLYGON ); // OR GL_LINE_LOOP for(std::size_t i = 0; i<10;++i)

{

glVertex3f(location.x + _cos[i], location.y + _sin[i], 0.);

} glEnd();

glFlush();

}

bool Particle::isDead(){

if(lifespan < 0.0) { return true;

}else{

return false;

} }

ParticleSystem.hpp

#ifndef _ParticleSystem

#define _ParticleSystem

#include<vector>

#include"PVector.hpp"

#include "Particle.hpp"

class ParticleSystem{

private:

std::vector<Particle> particles;

PVector emitter;

public:

ParticleSystem(){};

ParticleSystem(PVector l);

void addParticle();

PVector random();

void run();

bool isEmpty();

(28)

BIBLIOGRAPHY

};

#endif

ParticleSystem.cpp

#include "ParticleSystem.hpp"

#include<iostream>

#include<cmath>

#include<stdlib.h>

ParticleSystem::ParticleSystem(PVector l){

emitter = l;

}

void ParticleSystem::addParticle() {

PVector tmp = random();

tmp.add(emitter);

Particle p(tmp);

particles.push_back(p);

}

void ParticleSystem::run(){

std::vector<Particle>::iterator it;

for(it = particles.begin(); it < particles.end();){

if(!(*it).isDead()){

(*it).run();

++it;

} else{

it = particles.erase(it);

} } }

PVector ParticleSystem::random() {

double lower = -0.02;

double upper = 0.02;

double range = upper-lower;

double rand_x = lower+(range*((double)rand())/(RAND_MAX));

double rand_y = lower+(range*((double)rand())/(RAND_MAX));

22

(29)

APPENDIX A

return PVector(rand_x,rand_y,0);

}

bool ParticleSystem::isEmpty(){

if(particles.size() == 0) return true;

else

return false;

}

System.cpp

#include<stdio.h>

#include<iostream>

#include<stdlib.h>

#include<X11/Xlib.h>

#include<GL/glx.h>

#include<GL/glu.h>

#include<png.h>

#include "Particle.hpp"

#include "PVector.hpp"

#include "ParticleSystem.hpp"

Display *dpy;

Window root;

GLint att[] = { GLX_RGBA, GLX_DEPTH_SIZE, 24, GLX_DOUBLEBUFFER, None };

XVisualInfo *vi;

Colormap cmap;

XSetWindowAttributes swa;

Window win;

GLXContext glc;

XWindowAttributes gwa;

XEvent xev;

int main(int argc, char *argv[]) { PVector emission_location(0,0,0);

ParticleSystem ps(emission_location);

dpy = XOpenDisplay(NULL);

if(dpy == NULL) {

printf("\n\tcannot connect to X server\n\n");

exit(0);

(30)

BIBLIOGRAPHY

}

root = DefaultRootWindow(dpy);

vi = glXChooseVisual(dpy, 0, att);

if(vi == NULL) {

printf("\n\tno appropriate visual found\n\n");

exit(0);

} else {

printf("\n\tvisual %p selected\n", (void *)vi->visualid);

}

cmap = XCreateColormap(dpy, root, vi->visual, AllocNone);

swa.colormap = cmap;

win = XCreateWindow(dpy, root, 0, 0, 600, 600, 0, vi->depth, InputOutput, vi->visual, CWColormap | CWEventMask, &swa);

XMapWindow(dpy, win);

XStoreName(dpy, win, "Smoke");

glc = glXCreateContext(dpy, vi, NULL, GL_TRUE);

glXMakeCurrent(dpy, win, glc);

glEnable(GL_BLEND);

glDisable(GL_DEPTH_TEST);

glBlendFunc (GL_SRC_ALPHA,GL_SRC_ALPHA);

XGetWindowAttributes(dpy, win, &gwa);

glViewport(0, 0, gwa.width, gwa.height);

glClearColor(1.0, 1.0, 1.0, 1.0);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

while(1) {

ps.addParticle();

glClearColor(1.0, 1.0, 1.0, 1.0);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

ps.run();

glXSwapBuffers(dpy, win);

if(ps.isEmpty()) break;

24

(31)

APPENDIX A

} /* this closes while(1) { */

} /* this is the } which closes int main(int argc, char *argv[]) { */

References

Related documents

Identity value - the perceived difference of cost and benefit related to identity The third and least important value, of the chosen three, using car sharing services

These categories are: (1) articles in which value terms appear as a part of the research process; (2) articles in which value (and value-related concepts) are used in a

13 Revolutionising spruce breeding 14 Heureka – balancing forest objectives 16 Restoring forests little by little 20 Wood is good for the climate 21 Mapping the ultrastructure of

The disciplinary context of the study is in the field of knowledge management, a domain that is part of library and information science (LIS), information technology (IT)

I have therefore chosen the Järvafältet area in northern Stockholm to study the role of green spaces in a European capital city that within the next decades faces

Keywords: Brand values, brand equity, consumers’ interpretation of brand values, consumer behaviour, brand management, engagement, brand sensitivity, brand knowledge, brand

This study arises from pedagogical discussion about learning potential with computer games – more precisely, that one game genre called open-ended (sandbox) games can make players

This study arises from pedagogical discussion about learning potential with computer games – more precisely, that one game genre called open-ended (sandbox) games can make players