Download presentation
Presentation is loading. Please wait.
1
Ray Tracing Geometry CSE 681
2
Camera Setup Need to establish viewing geometry from camera’s point of view And make a ‘virtual’ array of pixels in front of the camera Rays will go through pixel centers Need view direction, angle of view, and which way is up CSE 681
3
Camera Setup v n w u “up” vector View direction
‘u’ can be formed as cross product of view vector and up vector Use info about camera to construct 3D camera coordinate system CSE 681
4
Camera Setup =? Tan(q/2) = yres*pixelHeight/2D
Side view of camera Given theta (either half angle or full angle of view can be specified), D Compute extent of virtual frame buffer Then using pixel resolution, computer pixel height and width Tan(q/2) = yres*pixelHeight/2D pixelHeight = 2*Tan(qy/2) *D/yres =D pixelWidth = 2*Tan(qx/2) *D/xres CSE 681
5
Screen Placement How do images differ if the resolution doesn’t change? Q: if same pixel resolution, what’s different about the images generated when using different distances for virtual frame buffer? A: nothing So use D = 1 to simplify computations CSE 681
6
Pixel Calculation Tan(q/2) = yres*pixelHeight/2D
pixelHeight = 2*Tan(qy/2) *D/yres pixelWidth = 2*Tan(qx/2) *D/xres Pixel AspectRatio = pixelWidth/pixelHeight Aspect ratio is width to height ratio Coordinate (in u,v,n space) of upper left corner of screen = ? CSE 681
7
Pixel Calculation Coordinate (in u,v,n space) of upper left corner of screen = ? v u w Tan(q/2) = yres*pixelHeight/2 pixelHeight = 2*Tan(qy/2) /yres pixelWidth = 2*Tan(qx/2) /xres Using camera coordinate system vectors, form location of upper left corner of screen in world space Assume virtual screen is one unit away (D=1) in w direction Eye + w - (xres/2)*PixelWidth*u + (yres/2)*PixelHeight *v CSE 681
8
Pixel Calculation Coordinate (in u,v,n space) of upper left pixel center = ? Then back off half a pixel width and height to compute pixel center Eye + w - (xres/2)*PixelWidth*u + (yres/2)*PixelHeight *v + (pixelWidth/2)*u - (pixelHeight/2)*v CSE 681
9
Interate through pixel Centers
scanlineStart = Eye + w - (xres/2)*PixelWidth*u + (yres/2)*PixelHeight *v + (pixelWidth/2)*u - (pixelHeight/2)*v Update by pixel width and pixel height to go to adjacent pixel on scanline and next scanline, respectively There will pixelCenter += pixelWidth * u scanlineStart -= pixelHeight * v CSE 681
10
Pixel loops ScenlineStart = [from previous slide] For each scanline {
pixelCenter = scanlineStart For each pixel across { form ray from camera through pixel …. pixelCenter += pixelWidth*u } scanlineStart -= pixelHeight*v Update by pixel width and pixel height to go to adjacent pixel on scanline and next scanline, respectively There will CSE 681
11
Process Objects 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 } Color pixel according to intersection information Keep closest intersection Need intersection function for each object type processed Later, we’ll build ‘intersection structure’ CSE 681
12
After all objects are tested
If (distancemin > infinityThreshold) { pixelColor = background color else pixelColor = color of object at distancemin along ray d ray object eye CSE 681
13
Ray-Sphere Intersection - geometric
Knowns C, r Eye Ray t= |C-eye| k d+k = (C-eye) · Ray s t2= (k+d) 2 + s2 d r C r2 = k2+ s2 If s > r, then no intersection If s == r, then ray just grazes intersection eye t d = (k+d) - k CSE 681
14
Ray-Sphere Intersection - algebraic
x2 + y2 + z2 = r2 P(u) = eye + u*Ray Substitute definition of p into first equation: (eye.x+ u *ray.x) 2 + (eye.y+ u *ray.y)2 + (eye.z+ u *ray.z) 2 = r2 Analytic equation of sphere and parametric form for ray Use quadratic equation to solve for u If term inside radical is <0, no intersection If term == 0, ray just grazes sphere Expand squared terms and collect terms based on powers of u: A* u 2 + B* u + C = 0 CSE 681
15
Determine Color Use z-component of normalized normal vector FOR LAB #1
Clamp to [ ] objectColor*Nz ray What’s the normal at a point on the sphere? Simple illumination example Just use z coordinate for normalized normal vector, clamped from below to 0.3, eye CSE 681
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.