We have taken our 3D objects,
specified its vertices relative to an origin in a coordinate reference frame.
What happens to a triangle?
To turn it from this representation that we've got,
the vertices, the faces, into pixels on the screen.
We've got faces,
we can now transform them, by applying a transformation at every
vertex so we can turn them and scale them and move them around.
But how does that now fit into the bigger picture?
How do we go from the local space of our 3D object in which its vertices are defined,
into a 2D representation on a screen.
Well there are several stages and they're all different transformations that we apply
The first one is from the local object space of our representation,
into world space. So we pick an origin for the world which I suppose we'll say
is the middle of the table, and we then apply a transformation
which re-specifies all of the vertices of our 3D object in local space,
in terms of the world origin.
So what we're basically doing is saying, "Well we want our pyramid to be at
+1 in x or -1 in x, -1 in z, 2 in y".
We can also then rotate it and scale it if we like. And we can do that
with several objects and move them all to different places and each will have a
different transformation which places it in the world, it moves it from its
local space to world space and that is called a world space transformation.
What we can also do, because we can combine transformations together,
is specify one object in terms of another. So that we can nest these different
transformations so that..
We might want to stick this pyramid to that one and so it has a--.
First, it has a transformation that moves it from its own local space, to the space of this
pyramid, which then moves to the world space wherever we want to place
it in the world and so we can nest things that way.
All we need to know, really, is where each vertex is in the world.
We need to know its world space position. All of the vertices then need to be re-specified
from world space, in terms of the space of the viewpoint.
If the viewpoint is here, say - This is our little camera and it's looking out on the world.
As we turn the camera this way,
what we actually do, is apply a transformation to everything in the
world which swings it over this way.
So the camera really never moves. All we're doing is applying a transformation
that appears to move everything relative to the camera. We're re-specifying all
of our objects in terms of the local space of the camera. And this is
view space or eye space, if you like. So it's really just another
transformation. All we're doing is moving from world space into view space.
We're re-specifying one coordinate frame of reference in terms of another.
So just like we moved from object space: the local space of the pyramid
to world space where it was positioned in our world.
We're now moving from world space into view space, which is again just another
transformation and we can actually just combine those transformations and have a
world view transformation which combines both of them into one.
And so, all we need to do is apply that operation - every vertex on every single shape.
We then need to project down from 3D space into 2D space
which again, is just another transformation. Everything is just another transformation.
A projective transformation is a little bit different to the others because
whereas before we were just applying translations and scales and rotations to
move objects from one space to the next, to the next.
Now what we have to do is have a special transformation which removes all the
depth information from the scene, squashes of all these vertices down onto a
2D plane and also because we might want to have the perspective effect
whereby objects in the distance seem smaller,
we need to collapse, and scale them down based on their distance and so on and so forth.
And now all of that is encoded in the projective transformation
So yes, so what we've done? We've taken our local representation, moved it
into world space, constructed the scene out of our pyramids and then
moved all of those relative to the eye.
So we know exactly what's in front of us, what's going to be seen.
And then we collapse all of those down in two dimensions.
So what happens to a triangle, to turn it from this representation that we've got:
the vertices, the faces, into pixels on the screen?
Well let's just draw some pixels out, not very many pixels - the resolution a bit low.
So let's just take a random triangle and draw it on there.
Let's draw it in purple.
So here's our representation, now it's been squashed
down into two dimensions and what we now have to do to turn it into pixels,
is go through every pixel here, and decide whether or not it's inside the triangle.
Now I've not drawn very many pixels up here, so it's not going to look very good.
But we can say that this one is pretty much inside the triangle.
This one is pretty much inside the triangle, and for argument's sake I'll go
with this one and this one, and these two as well. And so now what we've done is
taken that simple geometric representation and discretized it.
We've turned it into a representation that
no longer has any information about said vertices and faces.
It just says, "This pixel is inside of this triangle."
When we collapse down from 3D to 2D,
some of the vertices are going to lie outside our field of view.
And in that case, we need to clip them.
What we have to actually do is generate another two vertices here
Because we don't know what's happening to this; because it's not part of our representation anymore.
Because we have clipped it to the viewports as it's called.
The problem is, now as you can see: We no longer got a triangle
So, well we just use our old trick of turning an odd polygon
into a triangle representation, into two triangles.
And then the process of deciding which pixels and triangle proceeds.
But for these two new triangles, that now fit perfectly inside our viewpoint.
And that's called clipping.
And then the next step beyond that
is just coloring in the pixels, and deciding exactly how to shade them and light them.
We'd like to thank audible.com for their support of this Computerphile video.
And if you'd like to download one of their huge range of books, go to audible.com/Computerphile.
And you can download one for free.
I'd like to recommend one today:
My favorite computer-related book and one of the first books
that made me think, "Hang on, computers could be cool."
And that's Neuromancer by William Gibson.
So get on to audible.com/Computerphile, download your free book, and thanks again
to audible.com for supporting this Computerphile video.