






|
|
Computer Graphics
CAP 4730
|
Fall 2000
Tuesday/Thursday 9:30am
103 Love Building
Dr. David C. Banks
|
|
| |
|
|
Office hours 11:00-12:30 Tuesday and Thursday.
Prerequisites: COP 4530 (Data structures);
COP 3330 (Object-Oriented Programming);
MAD 3107 (Math in Computing) or MAD 2104 (Discrete Math).
|
|
|
|
|
Quiz solution
|
|
|
|
Programming Homework
 |
Drawing pixels. Animation. |
|
|
 |
Weight functions. |
|
|
 |
Line segments. |
|
|
 |
Light. |
|
|
 |
Ray casting. Postscript |
|
|
|
|
Creating a spherical emittance distribution
Each team computes z = sqrt(1-x2-y2)
on a unit grid. The grid is projected onto cardboard. Using paper
with gray levels from 0.0 to 1.0, each team cuts a pixel with color
z and attaches it to location (x,y). Each member of the faster
team received a souvenir sphere (a ping-pong ball).
|
|
|
|
Students
|
|
|
|
Computer graphics is the reason you have learned how to
program. Computer graphics is why you want a fast machine.
Computer graphics is the microscope, the telescope,
the x-ray glasses that let you examine all sorts of objects
that are fabricated digitally. Computer graphics gives
you your own TV station.
This course is concerned with algorithms for creating
2D images of objects in 3-dimensional space.
To make objects that look real, we simulate the way light
is emitted from sources and then reflects off surfaces. Representing
the shape and reflectance of an object is called
modeling. Sampling the shape according to a 2D sampling
pattern (dictated by pixels) is called rasterizing.
Sampling the view directions is called ray-casting.
Computational scattering evaluates the flow of light.
In general, graphics algorithms are characterized by
their outer loop. An object-order renderer loops
over the geometry in 3D. An image-order renderer loops
over the rays through a viewpoint. The rest is details.
|
|
|
|
How they do graphics at other places
Pixar
Stanford
Caltech
UNC Chapel Hill
Georgia Tech
Carnegie Mellon
|
|
|
|
The Visualization Lab is located in the 4th floor of the
Dirac Science Library. It is available for your use weekdays
between 8am and 5pm. When using the facility you
are a guest of the
School of Computational
Science and Information Technology. Do not bring food
or drinks into the lab.
|
|
|
Although this course is about how to do computer
graphics the right way, there is always room
for experimentation with really bad, but fun,
code.
Here's a graphics program
I wrote to show that 4 lines
(there's also a 3-line
version, but it doesn't compile on every platform)
of C-code
can transform,
illuminate, and z-buffer a torus.
Save this code as as torus.c,
then type (in a UNIX shell) cc torus.c -o torus -lm.
Run it in an 80-character window.
char G[]="^<VL8CO! ",C[80][80],*P,k,j;double sin(),cos(),c,x,z,L,M,N,i,I=.01;
main(){for(;i<629;){N=sin(i*I);c=cos(i*I);M=sin(i);L=cos(i+=I);x=c+3;z=3*M*x+
60-N;if(z>*(P=&C[k=z+5*N][j=40+x*L*9])){*P=z;c*=L+M-N/c;P[-3200]=G[k=c<0?0:
c*5];}}for(P=*C;P<=C[40];)putchar((P++-*C)%80?*P+32:10);}
Unfortunately, it did not win the
Obfuscated C
Contest.
|
|
|
|
Here is a small (but slow) triangle renderer I wrote
as part of a challenge problem for my computer graphics class
in fall 1997. It reads data from stdin, performs linear
interpolation and depth-buffering, then writes
a .ppm file to stdout. It uses barycentric coordinates.
The shortest student-written program that obeyed the
contest rules was 100 lines, by Wendong Wang. The
shortest student-written program that only cheated a little
was 60 lines by
Hench Qian
(check out the links at the bottom of his page).
I got mine down to 26 lines, no cheating; 11 lines
jamming lots of statements per line.
Chris Weigle helped me torture it down further to 6 lines.
float V[18],D,b[6];int i,j,k,x=100,I,C;char S[60016];main(){for(C=x*x;read(0,V,
72);)for(j=0;j++<C;){for(I=1,i=18;i;I&=(b[i/6]/=D)>=0)for(i-=6,D=b[i/6]=0,k=3;k+
9;k-=6)D+=k/3*(V[9-k]-*V)*(V[10+k]-V[1]),b[i/6]+=k/3*((V[(i+9-k)%18]-j%x)*(V[(i+
9+k)%18+1]-j/x));if((D=*b*V[2]+b[1]*V[8]+b[2]*V[14])>S[3*C+j]&I)for(i=3;i--;S[3*
C+j]=D)S[j*3+i+15]=*b*V[i+3]+b[1]*V[9+i]+b[2]*V[15+i];}sprintf(S,"P6 %d %d 255 "
,x,x);write(1,S,3*C+15);}
When given a list
of triangles as input it rendered the image at the
upper right.
|
|
|
|
For a minimal ray tracer, see Paul Heckbert's
example.
|
|
|
|
|