Viewing Pipeline
Viewing Pipeline
- Modeling Coordinates: Objects are created by their own coordinates.
- World Coordinates: The objects are placed in the same world coordinate.
- Viewing Coordinates: Objects are now expressed relative to camera.
- Normalized Coordinates: Everything visible to the camera is mapped to unit cube for easy clipping.
- Device Coordinates: Normalized coordinate (unit-cube) is mapped to the device coordinate.
- Rasterization: 2D primitives turns into pixels.
WC to VC (Viewing Transformation)
If the position and orientation of camera are given, everything is done.
where is camera's rotation matrix and is camera's position.
But usually we only use a look-at direction or a reference position in the scene.
This can reduce number of parameters so we don't have to send the whole rotation matrix.
can be any vector other than one parellel to , usually chosen as (0,1,0).
VC to NC
Projection Transformation
We want to project all object positions onto view plane (or projection plane).
Projection only applies to x, y coordinates, while z (depth) values are kept.
Projecting from 3D to 2D all at once is not a good idea!
Depth information will be lost, and computing objects that are far distant is inefficient.
Instead of rendering every object, we introduce view frustrum.
Only objects that are inside view frustrum will be rendered, so we have to only care about a finit viewing volume.
Normalizing Transformation
After projection, view frustrum becomes a cuboid.
Normalizing transform maps a cuboid to unit cube (a.k.a. canonical view volume).
- It makes clippling easier because you can just discard objects outside the cube.
- It makes manufacturing easier because all manufacturers can assume the normalized coordinates are given as input.
To normalize view frustrum, move the center to the origin, and scale height, width, and depth to 2.
If the coordinates are given as , (left, right, top, bottom, near, far) normalizing transformation is:
Taxonomy of Geometric Projections
We have multiple choices for .
- Perspective projection
- One-point perspective (Single-point perspective)
- Two-point perspective
- Three-point perspective
- Parallel projection
- Orthographic projection
- Multiview projection
- Axonometric projection
- Trimetric projection
- Dimetric projection
- Isometric projection
- Oblique projection
- Cavalier projection
- Cabinet projection
- Orthographic projection
Perspective Projection
- Objects look smaller as they get further away
- Parallel lines (that are not parallel to a view plane) converge at the vanishing point on the horizon
- Number of vanishing point can be 1, 2, or 3. (a.k.a. One-point, Two-point, Three-point)
Pinhole Camera Model
A pinhole camera creates an image by controlling only the light that passes through a pinhole.
Unlike pinhole camera, the view plane in our camera model is located in front of the pinhole. (We don't need to make upside down image!)
Pinhole camera model maps coordinate into
Look carefully! and our projection plane is -d!
This mapping is not linear, but it can be represented by a matrix using homogeneous coordinate representation!
If we assume that the projection plane is the same as the near plane, full perspective matrix looks like this:
Parallel Projection
- Objects are projected along the specific direction
- Object's size does not change in the direction parallel to the view plane
- You can think as the center of proection (pinhole) is at infinity
Multiview Projection
- Preserves relative size
- The direction of projection is parallel to a principle axis of objects
- The projection plane is perpendicular to the direction of projection
Axonometric Projection
- Can display more than one face of an object
- The direction of projection isn't parallel to a principle axis of objects
- But the projection plane is still perpendicular to the direction of projection
Oblique Projection
- The projection plane is aligned with one face of the object
- But the direction of projection isn't perpendicular to the projection plane
- Typically we choose 30° or 45°
Let the direction of projection is , and the view plane is .
- Cavalier projection:
- Cabinet projection:
NC to DC (Screen Transformation)
Now we need to transform unit cube into W x H image (screen).
OpenGL has lower-left origin, while Vulkan and Direct3D has upper-left origin with flipped y-aixs.
Trackball
A trackball translates 2D mouse movements into 3D rotations.
This is done by projecting the position of the mouse on to an imaginary sphere behind the viewport.
To implement this, the camera rotates around an axis perpendicular to the mouse movement.
But... We don't actually use arccos.
- arccos doesn't know direction
- arccos isn't used in computing because of stability (absolute value of input might be over 1)
Solution: use sin and cos values!
- Use atan2:
- atan2's input is not limited, and it has better numerical stability - e.g. can avoid division by zero
- Construct rotation matrix directly from sin and cos values