Main content

### Course: Precalculus (Eureka Math/EngageNY) > Unit 2

Lesson 7: Topic E: First-person video games—projection matrices- How one-point linear perspective works
- Linear perspective interactive
- 1. Ray tracing intuition
- 2D rendering intuition
- 2. Parametric form of a ray
- Parametric ray intuition
- 3. Calculate intersection point
- Solve for t
- 4. Using the line equation
- Ray intersection with line
- 5. 3D ray tracing part 1
- Ray intersection with plane

© 2024 Khan AcademyTerms of usePrivacy PolicyCookie Notice

# 1. Ray tracing intuition

First, let's look at ray tracing in 2D using a simple example. In 2D, an image line is formed from the camera location and the viewing direction. When a pixel's color is being determined, a ray is built from the camera, through a point on the image line, and off into the scene. Let's look at the algebra of intersecting a ray with a line segment!

## Want to join the conversation?

- at1:40why is line C never ending even if Susan said it is a line segment(9 votes)
- Just because the end of the ray
**C**is not visible in this example does not mean it never ends. In practice, the ray used for tracing does have a maximum length. Look up*clipping planes*.(5 votes)

- I was doing the practice for 2nd rendering intuition and I did the first question correctly and hit the check box. It wouldn't let me move onto the next question. Any tips on how to fix this?(2 votes)
- How the camera view direction determines the image plane or the image line? I thought they were perpendicular to each other. But it seems not.(0 votes)
- Aren't pixels: red, green and blue?(0 votes)
- Hi there!

I'm really excited to get into ray tracing, but I have one question.

So, when we send a ray through the Image Plane into*the unknown*, we check for intersections between objects (triangles probably).

Then, we need to find the color of that point. We send off some rays in the direction of the light source, reflected direction, refracted direction, ect.

But all that does is*effect*the color of the object, that doesn't actually tell us what color the object is.

So great, we got some cool things going on, we have some reflected light, but how do we know that the color is?

In real life, object absorb lights of certain wavelength, meaning they absorb some of the light, and reflect the others.

What do we do in ray tracing? Do we just*set*each point to a color, and then when our ray intersects with that point, we send off some rays to reflect on it to effect it, and then calculate the final color (that was shaded by adjacent lights & colors)?

This was a bit of a mouthful, but I hope I can get a nice answer.

Thanks! :-)(0 votes)- Once you have your hit point, you need three more things:

a) the color of the texture on that object (could just be a solid color)

b) the shade of that point (calculated with normals and light sources)

c) whatever other additions you have (calculated by reflecting and recursing back through the trace function(0 votes)

## Video transcript

(introductory sound) We saw in the previous lesson that to write a ray tracer, you need a mathematical way to answer a bunch of questions. Where does a ray intersect a scene object? Does a shadow ray reach the light source before it intersects another object? How does the surface reflect light? How far away is the light source? Finally, where is the camera? In the remainder of this lesson, we're going to focus on the first sub-problem, that of ray object intersection. We're going to start our study by first looking at the simpler problem of how to do ray object intersection in two dimensions. What does ray tracing look like in two dimensions? Let's start with our three-dimensional situation and take a cross-section through this white plane that contains the camera and the viewing direction. Notice too that the white plane intersects the image plane on the line, which we'll call the image line. That means if we draw just what's in the white plane, we get a picture like this. To make the problem even easier, we'll try first intersecting with the simplest object possible, the line segment. Here's our scene: Just a line segment connecting two points, A and B. To render the scene, just as in three dimensions, we need to pick a location for our camera. Call the camera point, C. Next, we pick a viewing direction, shown here in red. In three dimensions, the camera location and viewing direction defines an image plane. but in two dimensions, it gives us an image line. That's the line in which our image will be formed. Now, let's pick a point, P, on the image line to denote the pixel we want to determine the color of. Recall that the ray tracer builds a ray from C through P off into the scene. We need a mathematical way to compute intersection points. Like this one, called 'I'. To develop the math, we first introduce a coordinate system. The math we need comes from looking at the Algebra of intersecting a ray with a line segment. We've introduced quite a few ideas in this video. So, use the next exercise to make sure you're comfortable with two-dimensional ray tracing.