If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

Main content

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?

  • hopper happy style avatar for user Chitraksh Uppal
    at why is line C never ending even if Susan said it is a line segment
    (9 votes)
    Default Khan Academy avatar avatar for user
  • mr pants purple style avatar for user Elise
    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)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user yigu
    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)
    Default Khan Academy avatar avatar for user
  • blobby green style avatar for user SC_NeXy
    Aren't pixels: red, green and blue?
    (0 votes)
    Default Khan Academy avatar avatar for user
  • hopper cool style avatar for user Iron Programming
    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)
    Default Khan Academy avatar avatar for user
    • leaf blue style avatar for user xacer
      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.