Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ray Tracing Part I Sources: * raytrace/rtrace0.htm * A. Watt & M. Watt. Advanced Animation & Rendering.

Similar presentations


Presentation on theme: "Ray Tracing Part I Sources: * raytrace/rtrace0.htm * A. Watt & M. Watt. Advanced Animation & Rendering."— Presentation transcript:

1 Ray Tracing Part I Sources: * http://www.siggraph.org/education/materials/HyperGraph/ raytrace/rtrace0.htm * A. Watt & M. Watt. Advanced Animation & Rendering Techniques. * D. Hearn & M. Pauline Baker. Computer Graphics (C version).

2 Overview "Sort of" physically-based way of rendering Consider how you view things: Light comes from light source Bounces off objects Eventually hits your eye

3 Overview, cont. Impractical! – Millions (Billions, Trillions) of "photons" – Most don't hit our eye. It has been done: – Usually on a limited scale Observation: – Why not trace photons from the eye to the light source.

4 Overview, cont. Create a "virtual view screen" Place it some distance in front of viewer Shoot ray through view screen until hits something (if anything) That determines color at one location Repeat until whole screen covered

5 Virtual View Screen Two “worlds” which we want to connect I. A pygame surface (made up of w x h pixels) II. A virtual view screen: Also made up of pixels (one for each in pygame) Each is a 3d point. The location of each depends on: The camera’s position. What it’s looking at (center-of-interest). How it’s rolled around that axis. The close-ness / far-ness of the viewer to that plane The width / height of the surface in pygame. So…think of the view screen as a grid of points.

6 Virtual "World" Pygame "World" virtual screen

7 Coordinate Spaces (Ch. 3) So far we’ve been using the world coordinate space. – Do we need anything else? – Sometimes. It’s more convenient to express some quantities in a local coordinate space. – Move forward. – Rotate yourself counter-clockwise. – Is object X in front of us?

8 Coordinate Spaces, cont. These local coordinate spaces are nested within the global coordinate space. – We can convert between the two. – We need to know where the nested coordinate space is in terms of the world space. A local origin (a Vector3 – a point – in terms of world space) A set of 3 axes (each a Vector3 – a vector – in terms of world space)

9 Camera Space We'll define camera space: – origin is (virtual) camera position. – axes are perpendicular and define a Right-handed coordinate system (since our world does) – Imagine yourself where the camera is (and oriented with the camera) – camera C.S. should look like world C.S.

10 Camera Space interest worldY worldZ cameraPos cameraY cameraZ cameraUp Note: NOT the same as cameraUp – but we use it to calculate cameraY CameraX comes out of the page. It’s perpendicular to the plane defined by cameraZ and cameraUp. CameraY is perpendicular to the plane defined by cameraZ and cameraX.

11 Camera Space

12 (Virtual) View screen ~100 ◦ ~60 ◦ ~40 ◦

13 view screen near viewScreenWidth viewAngle/2 viewScreenHeight What are viewScreenWidth and viewScreenHeight? They involve pixelWidth and pixelHeight, but those are in the pygame world We need a virtual (3d) world distance.

14 View Screen What we'll need to calculate: – viewScreenWidth and viewScreenHeight in world units – The 3D position of the pygame pixel (i, j) The position is determined by: – Camera position – Camera axes – new – viewAngle – pixelWidth, pixelHeight

15 More on viewAngle A side view of the view screen… viewScreenHeight/2 viewAngle/2 near We need to calculate viewScreenHeight from viewAngle/2 and near. How? Hint: Use one of the trig formula’s from the right and the right-triangle (in red) Trig Identities Sin(θ)=Opp/Hyp Cos(θ)=Adj/Hyp Tan(θ)=Opp/Adj

16 View Screen "shape" We want the "shape" of the view screen to have the same "shape" as the pygame window. – If they didn't we'd get "stretching" artifacts – The scales will, however, be different – viewScreenHeight is determined by: near, viewAngle/2 – viewScreenWidth should be proportional to: viewScreenHeight the "shape" of the pygame window

17 View Screen shape Pygame window View Screen 200 1.3 100 300 0.9 2.7 400 200 1.5 0.75 The aspectRatio, which is width/height is the same in both

18 Calculating Pixel Position (in 3d), cont. vH/2 vW/2 vH/2 Let’s say we want to calculate the 3D position of the pygame pixel (0,0). Remember, the camera and view screen might not always be oriented as they are in this drawing. But…the view screen will always be in the same local coordinate space (camera space). How do we get there? 1. Start at the camera ( a position). 2. Go near units (a scalar) in the direction (a vector) opposite to cameraZ. 3. Go vH/2 units (a scalar) in the direction (a vector) of cameraY. 4. Go vW/2 units (a scalar) in the direction (a vector) opposite to cameraX. cameraX cameraY cameraZ

19 Calculating Pixel Position (in 3D), cont. Your job: figure out the vector math to do steps 1-4 on the previous slide! We can calculate other points on the view screen with a small difference: – For points on the right half, we go in the same direction as cameraX. – For points on the lower half, we go in the opposite direction as cameraY. – For points in the middle…

20 Calculating Pixel Position (in 3D), cont. For points in the middle (e.g. 2,3)… vH/2 vW/2 vH/2 ΔXΔX ΔYΔY 1. Calculate ΔX and ΔY, the horizontal and vertical (respectively) distance between neighboring pixels. Hint: for ΔX, it involves vW and the width of the pygame surface. 2. Start at the pixel (0,0 in pygame). 3. Calculate a vector (ix * ΔX) * cameraX (ix in this case is 2) 4. Calculate a vector –(iy * ΔY) * cameraY. (iy in this case is 3) 5. Steps 3 & 4 show us the vector offsets needed to get from the “view screen origin” to the point we were after!

21 Projections All rays will start at (i.e. have their origin at) a virtual pixel position on the view screen. The direction of the ray will drastically alter the image we get. We have two choices: – Send all rays out parallel to –cameraZ (Orthogonal) – Send each ray out away from the camera (Perspective).

22 Orthogonal

23 Perspective


Download ppt "Ray Tracing Part I Sources: * raytrace/rtrace0.htm * A. Watt & M. Watt. Advanced Animation & Rendering."

Similar presentations


Ads by Google