Download presentation

Presentation is loading. Please wait.

Published byMaurice Ryan Modified about 1 year ago

1
Ray Tracing Part I References /rtrace0.htm A. Watt & M. Watt. Advanced Animation & Rendering Techniques. D. Hearn & M. Pauline Baker. Computer Graphics (C version). Chapter 3 (Coordinate Spaces)

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 backwards from the eye to the light source. – Then we guarantee we're only computing photons that actually matter to us.

4
Overview, cont. Step1: Create a "virtual view screen" Place it some distance in front of viewer Assumption: our (pygame) window is w x h pixels Step2: Ray-tracing Create a ray: o Origin = the 3d position (on the virtual view screen) which is a counter- part to the pygame pixel (i, j) o Direction = direction from virtual viewer to the ray's origin. Determine the closest object that is hit by the ray. CaseI: Nothing is hit => set pixel (i,j) to a background color Case II: Something is hit => set pixel (i,j) to the [shaded] color of that point on the object. Repeat for each pixel, where 0 <= i <= w-1 and 0 <= j <= h – 1.

5
Virtual View Screen The 3d position (for the counterpart to a 2d pixel) is influenced by: o The viewer (camera) position. o What the camera is looking at (center-of- interest). o How the camera is rolled around that axis. o The close-ness / far-ness of the camera to the plane o The width / height of the surface in pygame. Think of the virtual view screen as a grid of 3d points, one for each pygame pixel.

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) Later (after matrices), we'll see how to convert points / vectors in local global coordinates.

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 to you like world C.S.

10
Camera Space interest worldY worldZ cameraPos cameraY cameraZ cameraUp Note: NOT generally 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 ◦ View Angle Comparisons

13
view screen near viewScreenWidth viewAngle/2 viewScreenHeight What are viewScreenWidth and viewScreenHeight? They are in world coordinates 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 a pygame pixel (i, j) The position is determined by: – Camera position – Camera axes – Near distance – 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

17
View Screen shape Pygame window View Screen 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 with direction = –cameraZ (Orthogonal) – Send each ray out away from the camera (Perspective).

22
Orthogonal

23
Perspective

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google