compsci.373 tutorial 7 - auckland · the assignment skeleton code your assignment is almost up! the...

23
Compsci.373 Tutorial 7 COMPUTER GRAPHICS III 1

Upload: others

Post on 24-Jan-2021

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Compsci.373 Tutorial 7 - Auckland · The Assignment skeleton code Your assignment is almost up! The resources of the programming assignment will consist of two parts: 1. A skeleton

Compsci.373 Tutorial 7COMPUTER GRAPHICS I I I

1

Page 2: Compsci.373 Tutorial 7 - Auckland · The Assignment skeleton code Your assignment is almost up! The resources of the programming assignment will consist of two parts: 1. A skeleton

Today’s outlineA look at the Assignment skeleton code

The rasterization process

A few exercises

2

Page 3: Compsci.373 Tutorial 7 - Auckland · The Assignment skeleton code Your assignment is almost up! The resources of the programming assignment will consist of two parts: 1. A skeleton

The Assignment skeleton codeYour assignment is almost up!

The resources of the programming assignment will consist of two parts:

1. A skeleton project for you to complete (if you choose to)

2. A document detailing the skeleton project, and what steps you need to take to complete it.

3

Page 4: Compsci.373 Tutorial 7 - Auckland · The Assignment skeleton code Your assignment is almost up! The resources of the programming assignment will consist of two parts: 1. A skeleton

The Assignment skeleton codeBecause the assignment is assessed entirely online, this limits the complexity of the questions we can ask you there. That means that you will have to put more effort in to complete the skeleton, but there are plenty of reasons to do it:

◦ You’ll be able to complete the online assignments by just pasting your code.

◦ You’ll gain a much better understanding of Ray Casting for the exam.

◦ You’ll have a working Ray Casting engine!

4

Page 5: Compsci.373 Tutorial 7 - Auckland · The Assignment skeleton code Your assignment is almost up! The resources of the programming assignment will consist of two parts: 1. A skeleton

Lets look at the skeleton code

5

Page 6: Compsci.373 Tutorial 7 - Auckland · The Assignment skeleton code Your assignment is almost up! The resources of the programming assignment will consist of two parts: 1. A skeleton

A quick recap on Ray CastingRecall the Ray Casting procedure:

1. Define our rays

2. Normalize our rays

3. Find the step sizes for our rays

4. Step the rays into the world until they hit something

6

Page 7: Compsci.373 Tutorial 7 - Auckland · The Assignment skeleton code Your assignment is almost up! The resources of the programming assignment will consist of two parts: 1. A skeleton

A quick recap on Ray CastingOnce the rays are all hitting something in the world, we have all that we need to begin the rendering process.

7

What we have What we want

Page 8: Compsci.373 Tutorial 7 - Auckland · The Assignment skeleton code Your assignment is almost up! The resources of the programming assignment will consist of two parts: 1. A skeleton

The rasterization processWe want to draw a vertical column of pixels for each ray, where the height of the column depends on how far the corresponding ray needed to travel.

The relationship between the height of the pixel column we want to draw, and the length of the corresponding ray is inversely proportional. That means that the further the ray had to go, the smaller our pixel column.

8

Page 9: Compsci.373 Tutorial 7 - Auckland · The Assignment skeleton code Your assignment is almost up! The resources of the programming assignment will consist of two parts: 1. A skeleton

The rasterization processWe need to define this relationship, but first, it helps to take another view of the problem.

This is the view of one ray from the side.

9

Our camera

A ray

Ceiling

Floor

Wall segment in worldWall segment projected on viewplane.

Vertical stripof the viewplane

Page 10: Compsci.373 Tutorial 7 - Auckland · The Assignment skeleton code Your assignment is almost up! The resources of the programming assignment will consist of two parts: 1. A skeleton

The rasterization processWe need to define this relationship, but first, it helps to take another view of the problem.

This is the view of one ray from the side.

10

Our camera

A ray

Ceiling

Floor

Wall segment in worldWall segment projected on viewplane.

Vertical stripof the viewplane

Page 11: Compsci.373 Tutorial 7 - Auckland · The Assignment skeleton code Your assignment is almost up! The resources of the programming assignment will consist of two parts: 1. A skeleton

The rasterization processWe need to define this relationship, but first, it helps to take another view of the problem.

This is the view of one ray from the side.

11

Our camera

A ray

Ceiling

Floor

Wall segment in worldWall segment projected on viewplane.

Vertical stripof the viewplane

Page 12: Compsci.373 Tutorial 7 - Auckland · The Assignment skeleton code Your assignment is almost up! The resources of the programming assignment will consist of two parts: 1. A skeleton

The rasterization processNotice how the strip on the viewplane gets larger the closer the wall is? How are the sizes related?

12

Our camera

A ray

Ceiling

Floor

Wall segment in worldWall segment projected on viewplane.

Vertical stripof the viewplane

Page 13: Compsci.373 Tutorial 7 - Auckland · The Assignment skeleton code Your assignment is almost up! The resources of the programming assignment will consist of two parts: 1. A skeleton

The rasterization processThe following triangle is formed from the distance to the viewplane and the height of the drawn pixel column, and the distance to the wall and the height of the wall.

13

Wall segment in world

Wall segment projected on viewplane.

Distance to wall in world

Distance to viewplane

Page 14: Compsci.373 Tutorial 7 - Auckland · The Assignment skeleton code Your assignment is almost up! The resources of the programming assignment will consist of two parts: 1. A skeleton

The rasterization processThe following triangle is formed from the distance to the viewplane and the height of the drawn pixel column, and the distance to the wall and the height of the wall.

14

Wall segment in world

Wall segment projected on viewplane.

Distance to wall in world

Distance to viewplane

Page 15: Compsci.373 Tutorial 7 - Auckland · The Assignment skeleton code Your assignment is almost up! The resources of the programming assignment will consist of two parts: 1. A skeleton

The rasterization processThis is great, because we can leverage the properties of similar triangles to form a relationship between the wall sizes. We essentially have two triangles which are different scales of each other:

Because these are scaled versions of the same triangle, they both have the same ratio between the length of the far side of the triangle, and the length of the triangle.

15

Wall segment in world

Distance to wall in world

Wall segment projected on viewplane.

Distance to viewplane

Page 16: Compsci.373 Tutorial 7 - Auckland · The Assignment skeleton code Your assignment is almost up! The resources of the programming assignment will consist of two parts: 1. A skeleton

The rasterization processThis gives us the relationship:

Which rearranges to:

Giving us:

16

Projected wall height

Distance to viewplane=

Actual wall height

Distance to wall in world

Projected wall height =Actual wall height

Distance to wall in world∗ Distance to viewplane

Projected wall height = 𝑣𝑑s

𝑹

Page 17: Compsci.373 Tutorial 7 - Auckland · The Assignment skeleton code Your assignment is almost up! The resources of the programming assignment will consist of two parts: 1. A skeleton

The rasterization processNow that we have that relationship, we can draw one column per ray:

17

Page 18: Compsci.373 Tutorial 7 - Auckland · The Assignment skeleton code Your assignment is almost up! The resources of the programming assignment will consist of two parts: 1. A skeleton

The rasterization processHold on, that looks distorted!

18

What we have What we want

Page 19: Compsci.373 Tutorial 7 - Auckland · The Assignment skeleton code Your assignment is almost up! The resources of the programming assignment will consist of two parts: 1. A skeleton

The rasterization processHold on, that looks distorted!

19

What we have so far What we want

Page 20: Compsci.373 Tutorial 7 - Auckland · The Assignment skeleton code Your assignment is almost up! The resources of the programming assignment will consist of two parts: 1. A skeleton

The rasterization processTo calculate the correct distance, we simply take the orthogonal vector projection of our ray onto our viewplane vector and finally subtract this vector from our ray for our undistorted ray vector, which we will call 𝑹𝑢. Using projection, this gives us:

20

CRay projected onto viewplane vector

𝑹𝑢 𝑹𝑢 = 𝑹 − 𝑽𝑹 ∙ 𝑽

𝑽 ∙ 𝑽Or 𝑹𝑢 = 𝑹 − 𝑽(𝑹 ∙ 𝑽)

(because 𝑽 is normalized)

Page 21: Compsci.373 Tutorial 7 - Auckland · The Assignment skeleton code Your assignment is almost up! The resources of the programming assignment will consist of two parts: 1. A skeleton

ExercisesAssume the following full Ray Casting environment:

21

C T0,1d ˆ

5dv

T1,0v ˆ4sv

S = 10

T14,17c

Page 22: Compsci.373 Tutorial 7 - Auckland · The Assignment skeleton code Your assignment is almost up! The resources of the programming assignment will consist of two parts: 1. A skeleton

Exercises1. What is the normalized direction of the 2nd ray (n = 1)?

2. What is the initial vertical step vector, 𝑽𝐼?

3. What is the initial horizontal step vector, 𝑯𝐼?

4. What is the main vertical step vector, 𝑽𝑺?

5. What is the main horizontal step vector, 𝑯𝑺?

6. What will the 2nd ray be when it has been stepped to the 3rd vertical intersection?

7. What will the 2nd ray be when it has been stepped to the 3rd horizontal intersection?

8. What is the undistorted length of these two rays?

22

Page 23: Compsci.373 Tutorial 7 - Auckland · The Assignment skeleton code Your assignment is almost up! The resources of the programming assignment will consist of two parts: 1. A skeleton

That’s all for today!

23