Coordinate Systems

A coordinate system is needed for measuring objects' positions

It allows us to describe any location by a set of numbers - 2 numbers when working in 2 dimensions, 3 numbers for 3 dimensions.

A coordinate system has an origin (a reference point) and coordinate axes

In 2D we have an X axis and a Y axis. In 3D, we add a Z axis.

The axes are perpendicular - they are independent






Coordinate Systems

Some coordinate systems:






Vectors

A vector is a direction and magnitude (length). Vectors are used to represent many different things - for example, object motion or relative locations of objects. In 3D, vectors are used extensively in lighting.






Vectors

We normally describe a vector as a pair of (X, Y) values (in 2 dimensions), or a triplet of (X, Y, Z) values (in 3 dimensions) - (vx, vy, vz) represents a vector that points vx units in the direction of the X axis, vy units in the direction of the Y axis, and vz units in the direction of the Z axis.

e.g., (2, 0, 0) is a vector pointing in the direction of the X axis, 2 units long. (1, 1, 0) is a vector pointing at a 45 degree angle between the X and Y axes, 1.414 units long.

The magnitude of a vector (x,y,z) is its Euclidean length - the square root of vx2 + vy2 + vz2.






Vector Addition

Two vectors can be combined by adding their corresponding components together.
i.e. (vx, vy, vz) + (wx, wy, wz) is (vx+wx, vy+wy, vz+wz ).

Or, written more expansively:

The result is a vector that is equivalent to sticking the vector W onto the end of vector V, and creating a new vector from the beginning of V to the end of W.






Vector/Scalar Multiplication

A vector can be multiplied by a single number (a "scalar") to change its length without changing its direction.






Dot Product

The dot product of two vectors is an operation defined as:

The result is a single number, which is equal to the product of the lengths of the two vectors and the cosine of the angle between them.

It can tell us how much two vectors point in the same direction - it is maximum when they point in exactly the same direction, and it's 0 when they're at right angles.






Programming With Vectors

Creating a vector class allows one to work with vectors more simply.

Vector operations just require a single statement, rather than a loop or separate statements for X, Y, & Z components.

    a = Vector3(1, 2, 3)
    b = Vector3(0, -1, 0)
    c = a + 2 * b
    d = a.Dot(b)





Photorealism






Perception






Color

Colors in the physical world can be any wavelength, or combination of wavelengths, of light


ColorWavelength
Violet 420 nm
Blue 470 nm
Green 530 nm
Yellow 580 nm
Orange 620 nm
Red 700 nm





The Eye

Rods & cones absorb light, send signal to brain






Color Perception

Any visible wavelength is perceived the same as some combination of 3 basic colors
(roughly blue, green, and red)






RGB Color

RGB = Red , Green , Blue
Each component (R, G, or B), ranges from a minimum (no intensity) to a maximum (full intensity), typically 0.0 to 1.0.






Color on the Computer

glClearColor(r,g,b,a)

Your browser does not support the canvas element.
r: 1.0
g: 1.0
b: 0.0





Color on the Computer

glColor3f(1.0, 0.5, 0.0)

Computer numbers have a finite resolution - how many distinct values can be represented

24 bit color = 8 bits red + 8 bits green + 8 bits blue
(a.k.a. 8 bits per component)
8 bits = 256 possible values

32 bit color usually means 8 bits red + 8 bits green + 8 bits blue + 8 bits alpha
16 bit color can be 5 bits red + 6 bits green + 5 bits blue


HDRI: High Dynamic Range Imaging - uses 16 or 32 bits per component






RGB display


LCD monitor closeup

older CRT monitor





RGB Photography


Prokudin-Gorskii, ca. 1910





RGB Photography






CIE XYZ Color

Based on tests of human perception.
Very roughly: Color = luminance + chromaticity




CMY Color

CMY = Cyan , Magenta , Yellow
    C = 1.0 - R
    M = 1.0 - G
    Y = 1.0 - B

CMYK = Cyan , Magenta , Yellow , Black






HSV Color

HSV = Hue , Saturation , Value






HSV to RGB

[h in range 0...360, s & v in range 0...1]
h /= 60.0
frac = h-int(h)
if h < 1:
    r,g,b = v, v-v*(s-s*frac), v-v*s
elif h < 2:
    r,g,b = v-v*s*frac, v, v-v*s
elif h < 3:
    r,g,b = v-v*s, v, v-v*(s-s*frac)
elif h < 4:
    r,g,b = v-v*s, v-v*s*frac, v
elif h < 5:
    r,g,b = v-v*(s-s*frac), v-v*s, v
else:
    r,g,b = v, v-v*s, v-v*s*frac





Color Gamuts






Luminance

The "brightness" of a color.

Formula, used in NTSC television standard, based on human perception:

    0.30 * R + 0.59 * G + 0.11 * B






Real-world Luminance

Background Luminance
Moonless overcast night sky 0.00003 cd/m^2
Moonlit clear night sky 0.03
Twighlight sky 3
Overcast day sky 300
Day sky with sunlit clouds 30,000


Rods & cones adapt to average level of illumination

Rods most sensitive at low levels (scotopic vision)

Cones more sensitive at higher levels (photopic vision)



Creative Commons License
This document is by Dave Pape, and is released under a Creative Commons License.