<p>A <em>ray</em> is just a semi-infinite line, and <em>casting</em> the ray finds intersections between the ray and an object in the scene. It doesn't just tell you the position in space that the ray intersected the object: it also tells you the texture co-ordinates of that point on the object, the surface normal and tangent, and (depending on the algorithm you use) filter widths.</p>

<p>So in a ray-tracer, there are different kinds of rays. <em>Primary rays</em> and reflection and refraction rays use their intersection to run a shader and compute a fragment colour. They also fire <em>shadow rays</em> at lights, which don't compute a colour but just tell you whether any object is shadowing the light.</p>

<p>So rays are about finding the objects which are in the scene, and shading those objects to make an image. They're also about finding the reflections and refractions on shiny objects. They are used to draw shadows. They're also used for more advanced effects like ambient occlusion and photon tracing.</p>

<p>This is one of the main conceptual advantages of ray-tracing over scanline rasterisation: instead of having to use different techniques for computing reflections, shadows, and all those other effects, the same core ray-cast algorithm can be used recursively to compute the whole image.</p>

CC BY-SA 3.0
2017-03-14T15:08:38.553Z
2017-03-14T15:08:38.553Z
Dan Hulme
<p>I'd like to leave a longish comment with pictures on the drawing aspect. Raytracing is not limited to computer graphics you can and often do see see artists manually raytrace to figure out intersections of shapes on paper with a ruler or even freehand by elbow twisting*.</p>

<p>It is also useful for many physical sciences like mechanical engineering and surveying. Or anywhere where you can use geometry to solve your problem.</p>

<p>While @DanHulme correctly surmises that the mathematical definition of a ray is just a line with a starting point and no ending point (goes to infinity). This is not really what people do, instead it's defined that way to be rigorous. In general it's just a line that goes far enough for the job, and we aren't really interested in the other end but rather how the line interacts with something. Infinity is just a safe way of saying it will in fact interact if possible. Mathematicians are very particular about stuff like that.</p>

<p><a href="https://i.sstatic.net/WwdR3.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/WwdR3.jpg" alt="enter image description here"></a></p>

<p><strong>Image 1</strong>: An example of manually tracing shadows of objects with ruler and pen for an as of yet unfinished answer on the subject <a href="https://graphicdesign.stackexchange.com/a/86754/18306">here</a>. Mainly here because I had spent yesterday evening doing the rays.</p>

<p>So you see you would use rays whenever you try to find a geometric intersection between two geometric primitives. It's not only useful for shadows, it's for anything where you can intersect two things, with a starting point somewhere. So tracing can be used to find the shape of 2 intersecting surfaces, manually drawing perspective images, volumetric problems, rendering implicit surfaces like metaballs solving mathematical functions numerically etc etc. </p>

<p>* The definition of what now is called a ray was first described by Euclid's Elements about 300 bc. Which predates computers by a safe(ish) margin.</p>

CC BY-SA 3.0
2017-03-17T14:06:30.177Z
2017-04-24T10:17:59.363Z
2017-04-24T10:17:59.363Z
joojaa
<p>Keeping in mind the definition of wave-front:</p>

<p><a href="https://i.sstatic.net/Upuwr.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Upuwr.gif" alt="enter image description here"></a></p>

<p>Now quoting from <a href="http://www.springer.com/gp/book/9789401065207" rel="nofollow noreferrer">Image Acquisition</a> book:</p>

<p>"A <strong>ray</strong> of light is a straight line connecting the wavefront normals in a series of radiative wavefronts. Connecting together the like-angle normals of the wavefronts emanating from a source defines a ray of light from that source. A collection of rays emanating from a <em>point</em> is referred to as a <strong>pencil</strong> of light, while a group of pencils emanating from a <em>finite-area patch</em> is called a <strong>beam</strong> of light."</p>

CC BY-SA 3.0
2017-03-17T15:28:38.707Z
2017-03-17T15:28:38.707Z
ali
<p>I'm learning Ray Tracing using <a href="https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-837-computer-graphics-fall-2012/assignments/MIT6_837F12_assn4.pdf" rel="nofollow noreferrer">this MIT tutorial</a>.</p>

<p>I've heard Ray Tracing only in the context of lighting. I.e. I understand that ray casting is used to light an object that has been already drawn. However, I've also seen ray casting in the context of just drawing the picture (not lighting). So which one are rays about?</p>

<p>What's the concept of "ray" really?</p>

<p>E.g. in that tutorial one draws the picture like:</p>

<pre><code>image.SetPixel( x, y, pixelColor );
</code></pre>

<p>where <code>pixelColor</code> has been acquired from the Ray Caster. But I read this to mean that <code>pixelColor</code> already has lighting information.</p>

<raytracing><lighting><ray>
What's the concept of "Ray" really?
mavavilj
# What's the concept of "Ray" really?

(Asked by: username_0 on 2017-03-14)

I'm learning Ray Tracing using [this MIT tutorial](https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-837-computer-graphics-fall-2012/assignments/MIT6_837F12_assn4.pdf).

I've heard Ray Tracing only in the context of lighting. I.e. I understand that ray casting is used to light an object that has been already drawn. However, I've also seen ray casting in the context of just drawing the picture (not lighting). So which one are rays about?

What's the concept of "ray" really?

E.g. in that tutorial one draws the picture like:

```
image.SetPixel( x, y, pixelColor );

```

where `pixelColor` has been acquired from the Ray Caster. But I read this to mean that `pixelColor` already has lighting information.

**Tags:** raytracing, lighting, ray


---

## 3 answers

### Answer by username_1 on 2017-03-14. Score: 6

A *ray* is just a semi-infinite line, and *casting* the ray finds intersections between the ray and an object in the scene. It doesn't just tell you the position in space that the ray intersected the object: it also tells you the texture co-ordinates of that point on the object, the surface normal and tangent, and (depending on the algorithm you use) filter widths.

So in a ray-tracer, there are different kinds of rays. *Primary rays* and reflection and refraction rays use their intersection to run a shader and compute a fragment colour. They also fire *shadow rays* at lights, which don't compute a colour but just tell you whether any object is shadowing the light.

So rays are about finding the objects which are in the scene, and shading those objects to make an image. They're also about finding the reflections and refractions on shiny objects. They are used to draw shadows. They're also used for more advanced effects like ambient occlusion and photon tracing.

This is one of the main conceptual advantages of ray-tracing over scanline rasterisation: instead of having to use different techniques for computing reflections, shadows, and all those other effects, the same core ray-cast algorithm can be used recursively to compute the whole image.


---

### Answer by username_2 on 2017-03-17. Score: 2

I'd like to leave a longish comment with pictures on the drawing aspect. Raytracing is not limited to computer graphics you can and often do see see artists manually raytrace to figure out intersections of shapes on paper with a ruler or even freehand by elbow twisting\*.

It is also useful for many physical sciences like mechanical engineering and surveying. Or anywhere where you can use geometry to solve your problem.

While @username_1 correctly surmises that the mathematical definition of a ray is just a line with a starting point and no ending point (goes to infinity). This is not really what people do, instead it's defined that way to be rigorous. In general it's just a line that goes far enough for the job, and we aren't really interested in the other end but rather how the line interacts with something. Infinity is just a safe way of saying it will in fact interact if possible. Mathematicians are very particular about stuff like that.

[![enter image description here](https://i.sstatic.net/WwdR3.jpg)](https://i.sstatic.net/WwdR3.jpg)

**Image 1**: An example of manually tracing shadows of objects with ruler and pen for an as of yet unfinished answer on the subject [here](https://graphicdesign.stackexchange.com/a/86754/18306). Mainly here because I had spent yesterday evening doing the rays.

So you see you would use rays whenever you try to find a geometric intersection between two geometric primitives. It's not only useful for shadows, it's for anything where you can intersect two things, with a starting point somewhere. So tracing can be used to find the shape of 2 intersecting surfaces, manually drawing perspective images, volumetric problems, rendering implicit surfaces like metaballs solving mathematical functions numerically etc etc.

\* The definition of what now is called a ray was first described by Euclid's Elements about 300 bc. Which predates computers by a safe(ish) margin.


---

### Answer by username_3 on 2017-03-17. Score: 0

Keeping in mind the definition of wave-front:

[![enter image description here](https://i.sstatic.net/Upuwr.gif)](https://i.sstatic.net/Upuwr.gif)

Now quoting from [Image Acquisition](http://www.springer.com/gp/book/9789401065207) book:

"A **ray** of light is a straight line connecting the wavefront normals in a series of radiative wavefronts. Connecting together the like-angle normals of the wavefronts emanating from a source defines a ray of light from that source. A collection of rays emanating from a *point* is referred to as a **pencil** of light, while a group of pencils emanating from a *finite-area patch* is called a **beam** of light."


---

