Interactive Fire Simulator
Sam Hallam
Project Summary
This interactive fire simulator was created for CSCE 450. It started with adapting base code from Assignment 1 from CSCE 450, Lab 13 from CSCE 441, and code from my SPH simulator made for a research course. A user sets up an input text file to pass information such as the path to ffmpeg (for video recording support), the name of the OBJ file, the name of the texture file, and the scale of the model. The simulator then loads this model and allows the user to specify a fire source by clicking on the mesh. The user can play, pause, and reset the simulation, as well as edit simulation parameters such as particle death time, color, and physics constants such as gravity to create an animation. Once a user is satisfied with the end result, they can record the animation directly from the application itself.
Supported Features and Implementations
- Physics-Based Particle System: This simulation generates a fire animation using a (pseudo) physics-based particle simulation. The velocities and positions of the particles are guided by forces such as gravity, wind, and temperature. In this case, the scalar temperature value is a function of a particle's distance from its spawn and used to generate an upwards force vector. In a more accurate simulation, scalar temperature would be calculated differently, and fuel would be another driving force within the simulation. However, this was not included in this model in order to have more time to implement and debug other features related to interactivity.
- Lighting: The particle system representing the fire is used to create attentuated light within the shaders. This is implemented by storing both particle positions and colors as one-dimensional textures and passing them into the shaders. As a result, the light is responsive to any changes the user makes to the simulation. This method also creates a flickering effect reminiscent of actual fire.
- Particle Collisions: Particle collisions are supported through the ray-triangle intersection library by Thomas Möller. To determine whether or not a particle is going to collide with a mesh, a ray is cast using the particle's position as an origin and the vector from its position to its potential new position as the direction. The length of the ray is used as the max distance a triangle can be away from the origin to prevent collisions with triangles that might be on the opposite side of the mesh. Collision response is done with a custom function that accounts for the fricition and elasticity of a particle. Friction and elasticity cannot be controlled by the user and were heurisitcally determined to give the particles a crawling effect.
- Clicking the Mesh: Users select where they want the fire to start on the mesh, which is also implemented through using the ray-triangle intersection library by Thomas Möller. When a user clicks on the screen, the click position is transformed from window to world coordinates. From this data, we can cast a ray based on click position to determine if the mesh was selected and if so, where.
- Recording within the App: The simulation supports users recording from within the application using ffmpeg, a framework used to encode videos. In order to be used, a user specifies the location of ffmpeg on their computer in their provided input file. If the path is provided in the input file, when record is pressed, an array is generated to read pixel data from the frame buffer, and the ffmpeg command is executed. Every render pass, the information provided to the array from the frame buffer is piped to ffmpeg, which uses it as the next frame in the video. When "Stop Recording" is pressed, a 30 FPS .mp4 file is produced.
- GUI: Users can edit simulation parameters using a GUI. This GUI was created using the ImGui library.
Gallery
Credits for Models, Libraries, Etc.
- Ray-Triangle Intersections: This library was used to do determine location of ray-triangle collisions.
- ImGUI: This library was used for creating the GUI.
- ffmpeg: ffmpeg, the executable used to record within the application.
- Animated Animal Pack: The model pack the deer came from.
- Cat: The link to the cat model used.
- OpenGL, GLFW, and GLM: For rendering graphics, handling windows, and handling matrix/vector math, respectively.