COS 426: Computer Graphics Spring 2013
|
|
|
General | Syllabus | Assignments | Final Project
Assignment 4: Particle Systems
Due Tuesday, April 30, 11:59 PM
Overview
In this assignment, you will implement a basic particle system. The
program will read in a scene file with particle commands and then
draw particles as they move over time in an interactive viewer.
At its simplest, your program will be able to spawn particles, apply
forces such as gravity and drag to them, and bounce them off of
scene geometry. Once you have the basic system in place, you have a broad
selection of options to improve your system. You can choose to focus
on the rendering or the physics of the particles. Improved rendering
will allow for more convincing simulation of phenomena such as smoke,
fire, and sparks. Improved physics will allow simulation of rope and
cloth, or even flocks of birds or schools of fish.
Getting Started
You should use the following skeleton code (cos426_assignment4.zip) as a starting point for
your assignment. After you have renamed the cos426_assignment4
directory to
[your NetID]_cos426_assignment4
, the
first thing to do is compile the program.
This will create
particleview
(or particleview.exe
).
particleview
is like rayview
, but also calls functions
from particle.cpp
for simulation and drawing of particle systems.
The skeleton code is able to read scene files (like in assignment 3)
augmented to support particle systems. Specifically, the scene
file format now supports five new commands:
particle
, particle_source
, particle_sink
,
particle_spring
, and particle_gravity
.
We provide several scenes with particles in the input
subdirectory of the zip file that you can use to test your program along with
a set of examples.
However, you should definitely create your
own files for testing, demonstration, and artistic purposes.
How the Program Works
When particleview
is executed, it reads a scene file and
spawns a window.
% particleview in.scn
As in meshview
and rayview
,
particleview
allows interactive viewing of the scene with
the mouse and keyboard. Dragging with the left, middle, and right
mouse buttons down rotates, scales, and translates the scene,
respectively. Hitting keyboard keys toggle display of particles (P),
particle springs (R), particle source and sinks (S),
faces (F), edges (E), node bounding boxes (B), lights (L), and the
camera (C). Hitting the SPACE key prints the current
camera parameters (in a format that can be included in another .scn
file), Q quits, and F1 saves a screenshot in an image (in
"imageN.jpg", for N=1,2,etc. increasing each time an image is dumped
in the same session). Some of these commands are also available via a
menu that pops up when the right mouse button is pressed. Of course,
you are welcome to modify the source code in particleview.cpp in any way
you want to produce new displays, but please keep the
semantics of the existing user interface, and please provide
documentation of new features with your writeup.
In the skeleton code, the scene is drawn, but the particle system is not
implemented. Your job is to fill in the code in
particle.cpp
to generate, update, and render particles at
each time step of the simulation. For every refresh of the window in
particleview.cpp
, the DrawParticles
function
is called. It reads the current time (in seconds since the start of
the program) and calls three functions that you must implement (in
particle.cpp
): UpdateParticles
,
GenerateParticles
, and RenderParticles
.
UpdateParticles
should update the position (and possibly
other parameters) of every particle at the current time.
GenerateParticles
should create new particles for every
particle source. RenderParticles
should use OpenGL
commands to draw every particle on the screen. Shells are provided
for these three functions in particle.cpp
, but you must
fill in the details.
What You Have to Do
The assignment is worth 10 points. The following is a list of features that you may implement
(listed roughly from easiest to hardest within each group). The number in front of the feature
corresponds to how many points the feature is worth. The features in bold face are required.
The other ones are optional.
- First step:
- (1) Euler integration. Augment the UpdateParticles function
to update the position of every particle according to its current
velocity and vector forces, taking into account gravity and drag,
using the simple forward Euler integration technique.
- Particle sources:
- (1) Sphere particle sources. Modify the
GenerateParticles function to create particles emanating from the
surface of sphere-shaped particle sources. To generate positions on a sphere
distributed uniformly with respect to surface area, you can use the strategy
outlined here.
- (2) Mesh particle sources. Augment the GenerateParticles function
to create particles emanating from the
surface of mesh particle sources.
- (1) Other particle sources. Modify the
GenerateParticles function to create particles emanating from the
surface of sources in the shape of circles, boxes, lines, cylinders,
cones, etc. One point per source type will be awarded, up to a maximum of 2.
- Particle sinks:
- (1) Sphere particle sinks. Augment the UpdateParticles
function to apply a force that attracts all particles towards the
surfaces of sphere-shaped particle sinks and deletes them when
particles hit the surface.
- (1) Other particle sinks. Augment the UpdateParticles
function to apply a force that attracts all particles towards the
closest point on the surface of sinks in the shape of
circles, boxes, lines, cylinders, cones, meshes, etc.
Particles are deleted when they hit the surface.
- Particle simulation:
- (1) Particle lifetimes. Augment the UpdateParticles
function to delete particles when their lifetimes expire.
- (2) Adaptive step sizes. Improve the accuracy of your
simulation by implementing the adaptive step size technique. You
should be able to implement this technique without changing the global
time step by taking multiple substeps for every particle during each
time step. Demonstate the difference in accuracy on at least one scene.
- (1) Midpoint integration. Experiment with the tradeoffs in
speed versus accuracy in your simulation by implementing the midpoint integration technique.
Demonstate the trade-offs on at least one scene.
- (1) Fourth-order Runge-Kutta integration. Experiment with the tradeoffs in
speed versus accuracy in your simulation
by implementing the fourth-order Runge-Kutta integration technique.
Demonstate the trade-offs on at least one scene.
- Particle interaction:
- (2) Particle-scene collisions. Handle collisions between
moving particles and stationary surfaces represented by shapes in the
scene file. For each particle, in each time step, you should
determine whether the particle traveling along its current trajectory
will collide with shapes in the scene within the given time step, and
if so where and when. When a particle collides with a surface, the
surface exerts a force upon the particle in the direction of the
surface normal causing point-shaped particles to bounce off.
If the elasticity of the
particle equals 1.0, it will go in the specular direction, for smaller
values, the vector component of the velocity which is parallel to the
normal is scaled by the elasticity, the tangential component is unchanged.
You should apply that force to update the
particle velocity (ignore the effect of the particle on the scene) and
then continue to simulate the particle until the end of the time step
(a single particle may collide with a sequence of many scene elements
in the same time step). Required shapes are the sphere, box, and mesh.
Additional shapes are optional and worth 1 point each.
- (1) Particle attraction. Augment your simulation to
allow particles to apply simple attraction forces on one
another. The direction of the force should be along the vector between
the particles, and the magnitude should following Newton's law of gravity
(i.e., F=G(m_1*m_2)/r^2, where r is the distance between particles).
- (2) Springs. Augment your simulation to handle springs
between particles -- i.e., particles conected by a spring exert
a force on one another according to Hooke's Law. To get credit,
you must demonstrate this feature on a string of particles
connected by springs. Fix the first particle in space, and
determine the position of the remaining particles by their spring
connections. To get an additional two points, you can create a
2D mesh of springs representing an elastic cloth and simulate
its motion under non-trivial forces (e.g., collisions with shapes
in the scene).
- (3) Flocking. Implement a system similar to Boids. Make sure that your
boids try to avoid geometry in the scene; you can accomplish this by
allowing them to look a bit ahead of themselves by shooting a
ray. Combined with rendering particles as animated geometry, you can
make a reasonably convincing simulation of a flock of birds or a
school of fish.
- Scene animation:
- (1) Animated camera. Augment
particleview.cpp
to move
the camera automatically along the trajectory of the first particle in
the scene file. Set the camera towards vector along the particle
velocity vector and the up vector to best align with the direction of
maximum curvature of the particle's path.
- (1) Animated obstacles: Make a scene with a hierarchy of
transformations (using
begin
and end
commands or by
creating nodes in your program) and then animate the scene by changing
transformations as a function of time. You can use this feature to
create simple rotating parts like a spinning wheel, flapping wing,
ceiling fan, etc. You get an additional point if particles collide
correctly with the animated scene elements.
- (2) Animated particles: Augment the scene description and parser
to create a scene in which the shape associated with a particle is
animated (i.e., the shape is changing over time).
- Particle rendering:
- (1) Trails. Modify your particle rendering so that each particle
leaves a trail behind it as it moves. You will have to remember
previous positions for each particle and use GL_POINTS or
GL_LINE_STRIP to achieve this effect. Try storing only the last K
positions and fading out the color towards the end of the trail.
- (1) Dynamic materials. Scale the material properties of every
particle based on its velocity and/or lifetime.
- (1) Responsive materials. Change the material properties of every
particle based on its proximity to static shapes in the scene.
- (2) Animated materials. Augment the scene description and parser
to associate multiple materials with every particle and then cycle
through them at regular time slices over the lifetime of the particle.
Combining this feature with textures, you should be able to get a
reasonable approximation of fire.
- (2) Textured sprites. Replace the code in RenderParticles to render a small
square polygon centered at every particle position oriented towards
the viewer and apply a texture (included as the last field of the
material) when rendering the polygon. You should be able to use this
feature to generate interesting visual effects like snow flakes
and smoke (with partially transparent textures).
- Interactive control:
- (1) Source control. Allow the user to click with the mouse
to select a particle source. Then, when a particle source is selected
and the simulation is running, keyboard commands should allow the user
to increase/decrease the rate of generated particles ("R" increases by
10% and "r" decreases by 10%). You could also support keyboard commands to
increase/decrease the speed (e.g., "S" increases by 10% and "s" decreases by
10%), mass ("M" increases by 10% and "m" decreases by 10%), etc. for debugging
purposes.
- (1) Sink control. Allow the user to click with the mouse to select a
particle sink. Then, when a particle sink is selected and the simulation
is running, keyboard commands should allow the user to increase/decrease the force
associated with the sink ("I" increases by 10% and "i" decreases by 10%).
- (2) Source and sink dragging. Allow the user to move particle
sources and sinks by selecting them and dragging with the mouse.
- (2) Rope or cloth manipulation. If implementing rope or cloth,
allow the user to pick a point on the rope or cloth and drag it
around. To get credit for this option, your simulation must be
stable for rapid user motions.
By implementing all the required features, you get 7 points.
There are many ways to get more points:
- implementing the optional features listed above;
- (1) submitting one or more gifs for the art contest,
- (1) winning the art contest,
- (1) answering a nontrivial question on Piazza. Paste the question and answer into your writeup if you do this.
Full credit is 10 points, and scores past 10 will incur diminishing
returns as in previous assignments.
You should provide a working program with
short gifs to demonstrate that your program works.
What to Submit
Following the general guidelines from previous assignments, please submit a single .zip
file named [your NetID]_cos426_assignment4.zip
containing:
[your NetID]_cos426_assignment4/
writeup.html
input/
(all the input data for the examples in your writeup)
output/
(complete with all the examples in your writeup)
art/
(all submissions to the art contest)
src/
(the complete, but cleaned modified source code)
For this assignment, you do not need to submit a Makefile to reproduce your output gifs. Please note any changes or additions you make to the behavior of particleview in your writeup.
The Dropbox link to submit the assignment is
here.