by William Shoaff with lots of help
You might want to read Blinn's article on pixel coordinates now, see [1].
We want to map directly from clip space to device space,
never stopping in normalized device space.
Normalized device space, or simply normalized space is a rectangle that runs from
and
,
where
b is the physical aspect ratio of the display device.
Normalize device space hides from us:
Notice that we are not really much interested in z from now on, except later we may want to do some hidden surface analysis using the z value. But for right now, we can work in a 2 dimensional space. We know how to get from clip space to normalized space; well not really, perhaps. Our clipping algorithms are often executed prior to the homogeneous divide, so we need to
Now we need a map from normalize space to device space.
Given our definition of clip space at
Before proceeding with this though, let's mention that viewports are
most often specified in pixel coordinates, so how does one compute
their normalized range?
Let's pretend the display has resolution
.
For concreteness assume
Nx = 1280 and Ny=1024 so the aspect
ratio of the physical display device is
b = 1024:1280 = 0.80.
Horizontal pixels are numbered from 0 to
Nx-1=1023 and
vertical scan lines are numbered from 0 to
Ny-1=1279.
Let's pick a pixel viewport where it will be easy to verify the arithmetic,
say
by
,
so, intuitively,
x in normalized space runs from -1 to about 0 and y runs
from about 0 to about 1/2 of 0.8.
One way to to look at this is that the normalized range expressed
above should map to the pixel range express here. That is,
We are given the pixels and wish to find the real coordinates in
normalized space.
We know that this maps is a scale and translation, so
in x we have
For our particular example,
Thus, the map from clip space to normalized space, for this example is,
Suppose the display has resolution
.
For concreteness assume
Nx = 1280 and Ny=1024 so the aspect
ratio of the physical display device is
b = 1024:1280 = 0.80.
Horizontal pixels are numbered from 0 to
Nx-1=1023 and
vertical scan lines are numbered from 0 to
Ny-1=1279.
We will define normalized space as the rectangle
The obvious transform is defined by the assignments:
The above map would be correct if pixels, like points, had no dimension, but they do occupy a region of space. If we do not allow for this our graphics images may have visible seams.
It is better to let a pixel coordinate (x, y) denote the center of a unit
square defined by:
Pixels are addressed by integers pairs; when a normalized point,
which is a floating point pair,
is mapped to a pixel we must round to an integer pair.
This is accomplished by adding 0.5 and truncating.
We can build this into the normalized to device map.
A normalized point with x=1 or y=-b will map to a pixel with x=Nx or y=Ny which are outside the range of legitimate pixel addresses. Blinn's solution to this is to cheat! It isn't really; it's a matter of floating point error in trying to map a continuous space to a discrete space. For example, you never test a floating point number for exact equality (do you?).
In the old days, one often chose a tuning parameter to make code
work correctly. He we want to choose a parameter
so that no
point in normalized space gets mapped to Nx or Ny.
Blinn suggests
and the assignment:
In the last few lectures we've seen that the tail of the graphics pipeline is implemented by: