Procedural Texture Generation and Particle System

This program uses time-varying 3D procedural texture mapping techniques to simulate smoke and fire, with sparks simulated by a particle system. Smoke and fire textures are created by using perlin noise and filtering techniques, while the particle system was created using basic physics and the animating capabilities of openGL.

Procedural Texture Generation
and Particle Sys
tem


uses time-varying 3D procedural texture mapping techniques to simulate smoke and fire

Running the program:
The program was made using visual studio.net
You need to include in your linker input the following libraries:
odbc32.lib
odbccp32.lib
opengl32.lib
glu32.lib
glut32.lib
glaux.lib

The project is currently setup to compile light.cpp, which is the final composite program.
You can compile the other parts of the program, but setting it so that only one .cpp file complies, as opposed to the others. To compile properly, there needs to be a folder named data in the directory of the project, which contains your particle bmp. To obtain the same results of the gifs, complie and run image.cpp to view texture generation, checker.cpp to view the particle system, and light.cpp to view the composite.
All of the sources code can be found here, as well as the exe’s for each version. It is recommend though
that you download the entire folder, then run the exe’s.

Also note that by pressing, h when focus is on the opengl window, a help menu will popup and tell you which keys you can press to effect the program variables.
In final.exe the variables for the program are:
+/- for all variables
T/t animation timestep
S/s particle timestep
F/f particle birthrate
W/w Vertical Wind Speed
G/g gravity –keep in mind that since I’ve defined gravity to be negative, if you want things to go down faster use capital G
P/p Procedural Texture sharpness
C/c Cover, which is related to the turbulence of the texture, less c means less turbulence, more C more turbulence

The wind is defined only in the vertical direction, so it goes along with the direction of the generated smoke and fire.

Program Methods:
The noise 3d dimensional perlin noise. See http://freespace.virgin.net/hugo.elias/models/m_perlin.htm for more information.

The program works like in these steps:

3d Texture System:
Create a 32×32 map. Set the values of the map to be randomly generated 3d perlin noise. The noise function is the same one from the perlin noise site but extended to 3 dimensions. Then apply liner interpolation to that noise map to smooth out the noise. Next using a method that is better explained here, use 4 octaves of noise scaled up to progressive levels
32×32, 64×64,128×128,256×256, to create the final 256×256 noise map. Next apply, an exponential filter to the map to give it the appearance of clouds / smoke.

The filter is of the form:
function CloudExpCurve ( v )
c = v CloudCover
if c < 0 then c = 0
CloudDensity
= 255 – (( CloudSharpness c ) * 255 )
return CloudDensity end function

Once we have our map256 filled with the cloud noise, the makeCheckImage function is used to actually generate the texture by applying the appropriate rgb and noise values to an GLubyte array. makeCheckImage returns the fire-type noise, and makeCheckImageSmoke returns creates
smoke type noise. It is essentially the same function to generate the noise maps, but you apply different rgb values depending on what look you’re going for.

Next we use our 2 textures now, smoke and fire, and place them in the scene. . The smoke is mapped behind the fireball object to appear as though it is rising from it, due to blending problems however, it appears more so behind the fireball then mixed with it. Due to my unfamiliarity with opengl I was not able to properly blend the two before the project deadline. Also since my graphics card does not support 3d texture, the textures are displayed as slices. Meant to be rendered from back to front to create the illusion of depth. The fireball is a special sphere, made using its own drawSphere function, the texture is meant to map onto it one slice per depth of the sphere.

The particle system:
Particles are defined as:
typedef struct
{

//position of it
float x;
float y;
float z;
float mass; //not really relevant consider each has 1 mass problem solved šŸ™‚

//velocity
float xveloc;
float yveloc;
float zveloc;

//used for force accumulator
float xforces;
float yforces;
float zforces;

bool alive;
//how much has the particle faded
float fade;
//how much time do we let it live
float life;

}particle;

We initialized all of the particles in the system to be alive, start at x,y,z position of 0,0,0, and have random velocities. When the drawParticles function is called here we load the texture for the particles, increase the position of each alive particle based on its velocity taking into account the forces of gravity, the vertical wind force, as well as the drag effect, as well as decreasing their life by the random fade value each particle gets when generated. This life value is used to calculate each particle’s alpha value so that over time as their life fades so do they do. Though the particle system works well on its own, because of the computational complexity of generating noise and applying it, it appears as though opengl can not display the particles fast enough to keep up because it is busy processing the noise functionality. Also do to my newness with opengl I had problems blending all 3 systems, noise generation, noise application, and the particle system. In the final result you get white particles as opposed to red and they tend to bleed into the smoke.

Putting it all together:
Since this is a time varying animation using opengl, the way the screen updates is in terms of the glutTimerFunc and glutPostRedisplay.
Thus, the 2 main functions of the program are init and display.

init:
Call SetNoise on 32×32 map1 — this calls the noise function on 32×32 map
call finishNoise —this applies linear interpolation as well as using the octave method to generate the 256×256 noise map
Perform sst
Call setNoise on map2
call finishNoise on map2
makeCheckImage — makes fire texture
makeCheckImageSmoke — makes smoke texture
call initParticles() to initialize the particle system

display:

drawParticles() — draws our particles as well as updating their information

using blending method described here to interpolate between consecutive frames of noise
bind the texture for fire
display fireball
bind texture for smoke
display smoke

Repeat display adi nfitum

The Source code fot the project can be seen here:
checker/
or downloaded directly at
checker.rar

Now for the movie clips:

Example of consecutive texture animation from image.cpp:
image.gif


Example of fire texture generation:
fire.gif


Example of particle system in action from checker.cpp:
particle.gif

fixed

 

 

 

 

 

 

 

 

 

 

 


Example of fireball and smoke composite from light.cpp:

ball.gif

Finally — composite of all 3 systems in place from light.cpp
final.gif

All executeable files can be found at:
checker/exs/
and final.exe and particles.exe found at
checker/

Though to get particles.exe and final.exe working, you need to have the particle.bmp in the appropriate folder. So it is probably best to just download the entire checker folder and work from there.
To get a better overview try out each .exe file and press h to see what you can do.

Citations:
Base code of window and pixel manipulating via glutbye arrays taken from image.c from the opengl redbook
RGB manipulation, i.e. turning the noise red and yellow based on Scott Arthur’s ideas about rgb values
Also see from red book: image.c, envphong.c, checker.c, and light.c. Pieces of code inspired from / borrowed from each.

Also see http://freespace.virgin.net/hugo.elias/models/m_perlin.htm , especially the section on clouds as most code was based on their ideas regarding perlin noise

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: