Nov 25: Perspective as linear transform, clipping, Object3D and Geometry
We showed in class that the perspective operations
z' ← 1 / (1 - z/fl)
x' ← x * z'
y' ← y * z'
are actually just the following linear transformation, followed by a projection from (x,y,z,w) down to (x/w,y/z,z/w):
1 | 0 | 0 | 0
|
---|
0 | 1 | 0 | 0
|
---|
0 | 0 | 0 | 1
|
---|
0 | 0 | -1/fl | 1
|
---|
We also discussed, at a high level, the fact that when the z value of a vertex gets very near to fl,
and eventually moves to behind the camera plane z=fl,
the projected vertex position can blow up, which is not useful.
In order to avoid this, modern GPUs contain triangle z-clipping logic,
which clips triangles to just in front of the camera plane.
This clipping can result in a triangle turning into a quadrangle.
In this case, the resulting shape may be sent through the GPU
as two separate triangles.
We also talked about how you can describe any geometric
shape as a list of vertices and a corresponding list of faces.
Each vertex contains (x,y,z) location plus some extra information that
we may need, such as surface normal at that vertex.
Each face is a triangle, which is stored as an array of indices,
where each index is just the index of some vertex in the vertices array.
When viewed from the outside, the vertices of a face
should form a counterclockwise loop.
One thing that's tricky about all this is that we need to
distinguish between
a vertex on a curved surface, where surface normal varies
continuously, and the vertices across an
edge, when there is a discontinuity of surface normals.
The way we do this is by using a single vertex for a curved surface,
which is shared between adjacent faces,
but using different vertices across an edge.
So, for example, as we go around the curve of a cylinder,
we can share vertices across successive faces.
But across the edge between the tube of the cylinder and the top or bottom of the cylinder,
we should use different vertices.
A cube is a very simple complete example of a shape that can described by vertices and faces.
Because a cube has edges separating its six faces,
we don't share vertices across those six faces.
Instead, each face has its own distinct vertices.
So a cube should have 24 vertices: three vertices at each of its eight corners.
var vertices = [
[-1,-1,-1], [ 1,-1,-1], [-1, 1,-1], [ 1, 1,-1], [-1,-1, 1], [ 1,-1, 1], [-1, 1, 1], [ 1, 1, 1],
[-1,-1,-1], [ 1,-1,-1], [-1, 1,-1], [ 1, 1,-1], [-1,-1, 1], [ 1,-1, 1], [-1, 1, 1], [ 1, 1, 1],
[-1,-1,-1], [ 1,-1,-1], [-1, 1,-1], [ 1, 1,-1], [-1,-1, 1], [ 1,-1, 1], [-1, 1, 1], [ 1, 1, 1],
];
Geometrically, the above vertices are arranged as follows:
2-------3
/| /|
6-------7 |
| | | |
| 0-----|-1
|/ |/
4-------5
If we were storing four sided faces, we could then describe the six sides as follows:
var faces = [
[ 0, 4, 6, 2], // negative x face
[ 1, 3, 7, 5], // positive x face
[ 8, 9, 13, 12], // negative y face
[10, 14, 15, 11], // positive y face
[16, 18, 19, 17], // negative z face
[20, 21, 23, 22], // positive z face
But to make things easier to send to the GPU, we make all faces triangles.
So each face of a cube would actually be stored as two triangles:
var faces = [
[ 0, 4, 6 ], [ 6, 2, 0], // [ 0, 4, 6, 2]
[ 1, 3, 7 ], [ 7, 5, 1], // [ 1, 3, 7, 5]
[ 8, 9, 13 ], [ 13, 12, 8], // [ 8, 9, 13, 12]
[ 10, 14, 15 ], [ 15, 11, 10], // [10, 14, 15, 11]
[ 16, 18, 19 ], [ 19, 17, 16], // [16, 18, 19, 17]
[ 20, 21, 23 ], [ 23, 22, 20], // [20, 21, 23, 22]
];
For Thursday, December 4,
your assignment is to figure out how to describe various 3D shapes
as a list of vertices and a list of triangular faces.
Shapes you should do this for are: cylinder, sphere, cube (which I already showed you how to do, above), octahedron, torus.
You can try other shapes as well if you are feeling ambitious.
For example, can you make a shape that looks like a house?
An animal?
A tree?
3D letters?
Remember, your triangles all need to be oriented counterclockwise, when viewed from the outside of the shape.
Try making an interesting animated scene using your vertices/faces shapes.
Dec 02: Principles of character animation
We created a simple humanoind jointed stick figure that is animated entirely by length constraints and simple forces.
We also looked at
this example of a procedurally animated walking character.
To run it, you need to add trusted site http://mrl.nyu.edu
to your Java preferences.
On a Mac, you can do that as follows:
Click on the Apple menu and open the System Preferences panel;
Click on Java;
Click on the Security tab;
Click on Edit Site List;
Add http://mrl.nyu.edu
to the list
Dec 04: Face numbering, introduction to WebGL and three.js
In class we went through the code to create faces for a parametric mesh.
Then we went through an example of low level code for sending vertices down to WebGL.
I will upload that code to this page soon.
Then we showed how to do the same thing using the high level three.js library,
which does most of the work for you.y
You can find three.js in the chalktalk library that I provided for you earlier this semester.
I need to hand in the grades for this class by Wednesday December 24 before noon,
so think in terms of a final project that you can complete by noon
of Tuesday December 23 (since I'll need time to grade everyone).
It's ok for two people to do a final project together,
but remember that such a project will need to be more ambitious in scope.
Your assignment for Thursday, Dec 11 is
to finish up anything you may still have
unfinished from the assignments to date
This is also a good time to make any improvements
or extra enhancements that you were
meaning to make, but didn't get around to.
Dec 09: Discussion of final projects and advanced topics
In this class students discussed their
final project ideas, and then
we had a wide ranging and general discussion
about various advanced topics.
Dec 11: Ray tracing to general second order surfaces
In this lecture we went over the math for transforming second order surfaces for purposes of ray tracing.
Here is a review of what we did,
which also includes a little extra section at the end that shows you how to transform
the surface normal (so you can do lighting and shading on your transformed surface).
Also, as requested in class, here is an excellent textbook
for those who are interested in more advanced reading on
the subject of computer graphics:
Computer Graphics, Principles and Practice, third edition
Dec 16: Ray tracing to general second order surfaces
Dec 16: Extra class begins at 10am
CLASS ON TUESDAY DECEMBER 16 BEGINS AT 10AM!