Ray Tracing Geometry CSE 681
Camera Setup CSE 681
Camera Setup v n w u “up” vector View direction Can be formed as cross product of view vector and up vector CSE 681
Camera Setup =? Tan(q/2) = yres*pixelHeight/2N pixelHeight = 2*Tan(qy/2) *N/yres =N pixelWidth = 2*Tan(qx/2) *N/xres CSE 681
Screen Placement How do images differ if the resolution doesn’t change? CSE 681
Pixel Calculation Tan(q/2) = yres*pixelHeight/2N pixelHeight = 2*Tan(qy/2) *N/yres pixelWidth = 2*Tan(qx/2) *N/xres Pixel AspectRatio = pixelWidth/pixelHeight Coordinate (in u,v,n space) of upper left corner of screen = ? CSE 681
Pixel Calculation Coordinate (in u,v,n space) of upper left corner of screen = ? Assume virtual screen is one unit away (N=1) in w direction Eye + w - (xres/2)*PixelWidth*u + (yres/2)*PixelHeight *v CSE 681
Pixel Calculation Coordinate (in u,v,n space) of upper left pixel center = ? Eye + w - (xres/2)*PixelWidth*u + (yres/2)*PixelHeight *v + (pixelWidth/2)*u - (pixelHeight/2)*v CSE 681
Interate through pixel Centers scanlineStart = Eye + w - (xres/2)*PixelWidth*u + (yres/2)*PixelHeight *v + (pixelWidth/2)*u - (pixelHeight/2)*v pixelCenter += pixelWidth * u scanlineStart -= pixelHeight * v CSE 681
Organization of Ray Tracer For each pixel { Form ray from eye through pixel distancemin = infinity For each object { If (distance=intersect(ray,object)) { If (distance< distancemin) { closestObject = object distancemin = distance } CSE 681
Organization of Ray Tracer If (distancemin > infinityThreshold) pixelColor = background color else pixelColor = color of object at distancemin along ray d ray object eye CSE 681
Ray-Sphere Intersection - geometric Knowns C, r Eye Ray Ray t = |C-eye| d+k = (C-eye) · Ray k s t2= (d+k) 2 + s2 d r C r2 = k2+ s2 eye t CSE 681
Ray-Sphere Intersection - algebraic x2 + y2 + z2 = r2 p = eye + t*Ray Substitute definition of p into first equation: (eye.x+ t *ray.x) 2 + (eye.y+ t *ray.y)2 + (eye.z+ t *ray.z) 2 = r2 Expand squared terms and collect terms based on powers of d: A* t 2 + B* t + C = 0 CSE 681
Determine Color Use z-component of normalized normal vector FOR LAB #1 Clamp to [0.3..1.0] objectColor*Nz ray What’s the normal at a point on the sphere? eye CSE 681