Notes for March 5-7

 

What we discussed on Tuesday Mar 5:

We sent through the math for ray tracing to a half space, which requires intersecting a ray with a plane:

Given halfspace H = (a,b,c,d) // (we would define this in GLSL as vec4 H)

Given a point p = (x,y,z,1)T // (the superscript means "transpose" since p is a column vector)

There are three cases:

  • p is inside H if H ● p < 0
  • p is on the surface of H if H ● p == 0
  • p is outside H if H ● p > 0

To find the plane of intersection with ray V + t W, where t > 0:

Hx (Vx + tWx) + Hy (Vy + tWy) + Hz (Vz + tWz) + Hw = 0
which is equvalent to:
t Hxyz ● W + Hxyz ● V + Hw = 0
Solving for t we get:
t = -(Hxyz ● V + Hw) / (Hxyz ● W)

We then used that to build up the procedure for ray tracing to shapes that are built by intersecting planes.

  • Find the maximum tIn of all halfspaces that face toward from the ray (ie: Hxyz ● W < 0)
  • Find the minimum tOut of all halfspaces that face toward from the ray (ie: Hxyz ● W > 0)
  • If tIn < tOut then we hit the shape at tIn. If tIn > tOut then we miss the shape.

In particular we looked at the six intersecting half spaces that define a cube:

      (-1, 0, 0,-1 )  // -x - 1 <= 0
      ( 1, 0, 0,-1 )  //  x - 1 <= 0
      ( 0,-1, 0,-1 )  // -y - 1 <= 0
      ( 0, 1, 0,-1 )  //  y - 1 <= 0
      ( 0, 0,-1,-1 )  // -z - 1 <= 0
      ( 0, 0, 1,-1 )  //  y - 1 <= 0

We talked about 4x4 matrices, and our convention for storing them in column major order:

      mat4(0.,1.,2.,3.,  4.,5.,6.,7.,  8.,9.,10.,11.,  12.,13.,14.,15.)
represents:
  0  4  8  12
  1  5  9  13
  2  6  10  14
  3  7  11  15

We talked about 4x4 matrix transformations, and the six most useful basic matrix primitives:
 
Identity
  1  0  0  0
  0  1  0  0
  0  0  1  0
  0  0  0  1
 
Translate
  1  0  0  tx
  0  1  0  ty
  0  0  1  tz
  0  0  0  1
 
Rotate about X
  1  0  0  0
  0  cos θ  -sin θ  0
  0  sin θ  cos θ  0
  0  0  0  1
 
Rotate about Y
  cos θ  0  sin θ  0
  0  1  0  0
  -sin θ  0  cos θ  0
  0  0  0  1
 
Rotate about Z
  cos θ  -sin θ  0  0
  sin θ  cos θ  0  0
  0  0  1  0
  0  0  0  1
 
Scale
  sx  0  0  0
  0  sy  0  0
  0  0  sz  0
  0  0  0  1

What we discussed on Thursday Mar 7:

In class we first showed how to capture mouse movement in the canvas, convert that to shader coordinates (-1 < x,y < +1), and pass that info down to the shader as uniform vec3 uMouse, where uMouse.z is 0.0 while the mouse is up and 1.0 while the mouse is pressed.

We went over the tricky question of how to do a linear transformation of a linear equation.

Let's say that the planar surface of a half space H contains a point P.

Mathematically we would say that H ● P == 0.

If a matrix M transforms all points P to (MP), then we need to transform all half spaces H such that the transformed points are on the planar surfaces of the transformed half spaces.

We need to transform H into: (H M-1), because:

(H M-1) ● (M P) =

H (M-1 ● M) P = // (because matrix multiplication is associative)

H ● P = 0

We showed how to raytrace to a cube (and then an octahedron), and implemented several matrix primitives to transform our shape. The code for all of that is in shader5.zip.

Homework due before class on Thursday March 14:

Create your own shapes defined by intersecting half spaces. Implement all six matrix primitives (we left out translation and rotation about Y).

As with the previous assignment, there are many opportunities here for extra credit, including adding procedural textures to various places, and doing interesting things on the Javascript side before you pass data down to the GPU.


At the end of the lecture we watched Carlitopolis