Camera Placement for Ray Tracing Lecture #3 Tuesday 0/4/4 st Review Camera Placement! The following slides review last Thursday s Lecture on world to camera transforms.! To see shift to raytracing context, it is key to have all the basics of camera parameterization at one s fingertips.! In particular! Placement! Orientation 0/4/4 Ross Beveridge & Bruce Draper, CS 40 CSU 203 2
Watch for VPR vs. PRP issues!! This talk originally was designed with the VRP being the center of the image plane! In this run through, it will be modified to assume the VRP and PRP are the same.! But be aware when figures may not fully indicate the distinction. 0/4/4 Ross Beveridge & Bruce Draper, CS 40 CSU 203 3 Camera Coordinate System Formally, the view reference coordinate system! VRP is the center of the image plane (shown)! PRP is the focal point (not shown)! Image u is red! Image v is green! VUP is yellow! Camera z is blue VRP 0/4/4 Ross Beveridge & Bruce Draper, CS 40 CSU 203 Slide 4
View Reference Point! Where is the camera to be placed?! At the view reference point in world coords. 0/4/4 Ross Beveridge & Bruce Draper, CS 40 CSU 203 Slide 5 How is this done?! Placing the camera is a simple translation. vrp x 0 0 vrp x VRP = vrp y T = 0 0 vrp y vrp z 0 0 vrp z 0 0 0! What about orientation? 0/4/4 Ross Beveridge & Bruce Draper, CS 40 CSU 203 Slide 6
Need to Orient the Camera! Where is the camera pointing.! Define which way is up. Color coded axes: red for x, green for y, blue for z. 0/4/4 Ross Beveridge & Bruce Draper, CS 40 CSU 203 Slide 7 Point the Z-Axis away.! Somewhat counter intuitive at first.! Standard convention is camera looks down the negative z-axis. 0/4/4 Ross Beveridge & Bruce Draper, CS 40 CSU 203 Slide 8
Recap, Where Are We?! Translate the camera, negative vrp.! Specify a pointing direction.! Defined by a vector. L x n x L x L = L y L z n = n y n z = L x 2 + L y 2 + L z 2 L y L z! This is a beginning for a rotation matrix.! L called the View Plane Normal (VPN). 0/4/4 Ross Beveridge & Bruce Draper, CS 40 CSU 203 Slide 9 Transformation So Far CAMERA X AND Y AXIS We need to define unit length basis vectors for these other directions. x c y c z c =??? 0??? 0 n x n y n z 0 0 0 0 0 0 vrp x 0 0 vrp y 0 0 vrp z 0 0 0 x m y m z m CAMERA Z AXIS Recognize that this projects translated model points onto a basis vector defining the camera z axis! 0/4/4 Ross Beveridge & Bruce Draper, CS 40 CSU 203 Slide 0
How Do You Hold a Camera Consider life in a world with Gravity. Gravity means there is an up. Good photographers keep their cameras level. Which of these looks right to you.!!!! up 0/4/4 Ross Beveridge & Bruce Draper, CS 40 CSU 203 Slide VPN & UP Define Horizontal! The horizontal, u, axis is perpendicular to! a plane defined by the VPN and VUP. n= VPN VPN u= VUP n VUP n v = n u 0/4/4 Ross Beveridge & Bruce Draper, CS 40 CSU 203 Slide 2
Put it All Together! Translate then Rotate. x c y c z c = u x u y u z 0 v x v y v z 0 n x n y n z 0 0 0 0 0 0 vrp x 0 0 vrp y 0 0 vrp z 0 0 0 x m y m z m 0/4/4 Ross Beveridge & Bruce Draper, CS 40 CSU 203 Slide 3 Alternate - LookAt Point 0/4/4 Ross Beveridge & Bruce Draper, CS 40 CSU 203 Slide 4
VRP, LookAt & VUP Form! The View Plane Normal is! VPN = VRP - LookAt! Often easier to work out in your head.! Look at the Bear!! Thus, locate a camera by specifying:! VRP (View Referene Point)! LookAt (Point in the world to lookat)! VUP (Vector indicating whats up) 0/4/4 Ross Beveridge & Bruce Draper, CS 40 CSU 203 Slide 5 Internal camera parameters! VRP, VPN & VUP are external! Often called external camera parameters.! Position/orientation camera relative to scene.! Internal parameters are camera properties.! Focal length! Field-of-view! Combination determine geometry.! Points in scene to points on image plane. 0/4/4 Ross Beveridge & Bruce Draper, CS 40 CSU 203 Slide 6
2 nd Now for Ray Tracing! Camera Specification is the Same.! How it is used changes fundamentally.! The goal is not to shift world points to 3D camera coordinates.! The goal is to enumerate rays associated with camera pixels in world coordinates. 0/4/4 Ross Beveridge & Bruce Draper, CS 40 CSU 203 7 Part : Position & the PRP! Specify the PRP, i.e. focal point, in world coordinates. PRP = x PRP y PRP z PRP! Begin thinking about where individual pixels lie in the world, start at the PRP P α, β = PRP +? Warning: We are not using the VRP. For ray tracing, it is more convenient to specify the position of the PRP in the world. 0/4/4 Bruce Draper & J. Ross Beveridge 202 8
Part 2: Center on Image Plane! Recall we typically specify focal length in terms of the distance from the PRP to the near clipping plane.! So, move an amount d (the near distance) in the direction opposite to the VPN. ( ) +? P α,β = PRP + d VPN! This is the center of the image plane P 0,0 = PRP dvpn 0/4/4 Bruce Draper & J. Ross Beveridge 202 9 Part 3: Moving on Image Plane! Here alpha and beta are being used to accentuate their role in specifying image plane location in the range - to. They are not yet integer pixel indices.! If only we knew what 3D world direction to move in order to move along the horizontal axis of the image plane! Wait we do know that. (next slide) 0/4/4 Bruce Draper & J. Ross Beveridge 202 20
Recall Earlier Rotation Matrix x c y c z c = u x u y u z 0 v x v y v z 0 n x n y n z 0 0 0 0 0 0 vrp x 0 0 vrp y 0 0 vrp z 0 0 0 x m y m z m These are exactly the vectors we need to move in the world in the horizontal and vertical image plane directions. U = u x u y V = u z v x v y v z 0/4/4 Ross Beveridge & Bruce Draper, CS 40 CSU 203 2 Part 3: Move to Pixel Location! Once we get to the image center (in 3D)! Now, move an amount alpha in the horizontal camera direction,! and an amount beta in the vertical camera direction. P α,β = PRP dvpn +αu + βv Realize we ve just worked out the exact position of a pixel in the 3D world for a camera whose position and orientation are specified using the PRP, VPN and VUP formulation. 0/4/4 Bruce Draper & J. Ross Beveridge 202 22
Part 4: A Ray for a Pixel! May seem a bit like a step backwards,! Ray direction is defined by the vector going from the PRP to the Pixel (we must change symbols here because U is already used.) W α,β = P α,β PRP = PRP dvpn +αu + βv PRP = dvpn +αu + βv 0/4/4 Bruce Draper & J. Ross Beveridge 202 23 A Point & a Direction = Ray! As before, loop through pixels (i,j) and create rays at equivalent locations (α,β) on the - to bounded image plane.! Ray is pair: R = ( PRP, Wˆ ) α,β! As before, call trace using this ray and returned the depth and color for the first object intersected by that ray. 0/4/4 Ross Beveridge & Bruce Draper, CS 40 CSU 203 24
Now the Pseudo Code! Cast rays from PRP for (int i = 0; i <=255; i++) {! for (int j = 0; j <=255; j++) {! alpha = (2.0 / 255.0)*i.0;! beta = (2.0 / 255.0)*j.0;! w_x = (-d*vpn_x) + alpha * u_x + beta * v_x;! w_y = (-d*vpn_y) + alpha * u_y + beta * v_y;! w_z = (-d*vpn_z) + alpha * u_z + beta * v_z;! // Note ray_cast must normalize vector w! ray_trace(prp_x, prp_y, prp_z, w_x, w_y, w_z);! }! }! 0/4/4 Ross Beveridge & Bruce Draper, CS 40 CSU 203 25 Now Different Pseudo Code! Variant - Cast rays from Pixel for (int i = 0; i <=255; i++) {! for (int j = 0; j <=255; j++) {! alpha = (2.0 / 255.0)*i.0;! beta = (2.0 / 255.0)*j.0;! w_x = (-d*vpn_x) + alpha * u_x + beta * v_x;! w_y = (-d*vpn_y) + alpha * u_y + beta * v_y;! w_z = (-d*vpn_z) + alpha * u_z + beta * v_z;! p_x = prp_x + w_x;! p_y = prp_y + w_y;! p_z = prp_z + w_z;! // Note ray_cast must normalize vector w! ray_trace(p_x, p_y, p_z, w_x, w_y, w_z);! }! }! 0/4/4 Ross Beveridge & Bruce Draper, CS 40 CSU 203 26
Loose Ends!! When are intermediate terms calculated?! Fill in based upon explanation of U and V.! Why no vector data structures?! Use of matrix packages is encouraged.! What gets returned by ray_trace! Return illumination/color-value.! Ray Tracing is Recursive, so! Control recursion depth. 0/4/4 Ross Beveridge & Bruce Draper, CS 40 CSU 203 27