4
$\begingroup$

I'm learning Ray Tracing using this MIT tutorial.

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.

$\endgroup$
6
$\begingroup$

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.

$\endgroup$
2
$\begingroup$

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 @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.

enter image description here

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. 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.

$\endgroup$
0
$\begingroup$

Keeping in mind the definition of wave-front:

enter image description here

Now quoting from Image Acquisition 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."

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.