hi my name's Eric Haynes and I'm an engineer at Nvidia and we're going to do a series of lectures about ray tracing the first one is the basics of ray tracing let's get going the thing I like to do it in any of these lectures is give a little quote at the beginning and this is from David Kirk who's a fellow at Nvidia says there's an old joke that goes ray tracing is the technology of the future and it always will be well the future is now here as of least 2018 that a single Nvidia
card turing card can now do real-time ray tracing let's start with the basics what's a ray well array is defined by just two things it has an origin some point in space XYZ and a direction and Ray casting is the idea of taking that array and shooting it out in that direction and finding what gets hit and this is not in a rendering algorithm it's just a basic tool in the toolbox you can use it however you want you could be using it for checking radiation or doing all kinds of other things we use it
for rendering so ray casting is just shooting a ray out and seeing where it hits something you can also use ray casting between two points so you may say well I've got a point a point B and I should array and I want to see if anything's in between this could be used for for example if I want to see if there's a shadow if here we had the points like a and B there's a light and a surface that you can shoot that ray and if anything gets in the way then you know that
point B is in shadow ray casting is a way that you can actually make an image so if you think of a screen like a screen door and you think of each little square on that screen door that you're looking through think of that that's your pixel so you want to know what's at that pixel and what the ray hits so the ray shoots through that pixel and goes out into the environment and hits a bunch of things and whatever's closest is what you're gonna see through that pixel and then you can shoot Ray's towards
the light for example and see if you have hit or missed anything in between and if you've hit something then the object so you know your point of intersection is in shadow otherwise it's lit and this is actually the first use of ray tracing in a computational form is for by this person Apple back in 1968 he traced raised towards lights to get shadow and his output device was a pen plotter a pen that draws on a big sheet of paper so ray-tracing really takes off back in 1980 with this seminal paper by Turner Whitted
it covers a lot of interesting basic things that we still do nowadays like anti-aliasing and bounding volume harkey's which I'll talk about in a minute but basically he has this intuition or this idea of how can I get reflections and refractions and shadows and how can I do this and in kind of a recursive way that's the big breakthrough so let's show how that works here we're shooting array from the eye again and it hits a piece of glass so this glass is nice and shiny so it's reflective and it's also refractive so we might
first shoot a shadow ray and the Ray goes towards the light okay good that's illuminated but we also do this thing which is to spawn off two more rays when in the reflection direction going down below and one in a refraction direction going through the glass so we can follow both of these rays I'll ignore the one going off the screen the reflection direction one the refraction one then we shoot another shadow ray and see if again the effect of the light and then again we spawn more rays we can shoot a reflection if there's
an internal reflection ray that's going upwards and again we'll kind of ignore how further it bounces and shoots off more Ray's so we'll just follow the refraction one that's going off to the right so that one going off to the right hits that box and again we can shoot a shadow ray and that one actually is blocked so we know that the box is in shadow so with that we now take all those contributions all those intersection points the two and the glass and the one on the box and we kind of add them all
up and we get a color at the eye we could have a color for the pixel so that's what it's style ray tracing it's really good for things like sharp shadows and reflections and refractions the advantage of this kind of rendering algorithm is that you can basically do it from the eye you know that you are hitting a mirror surface and that goes to the light and you basically get a very few number of rays that you need to cast versus if you had sort of shuttle the rays from the light and had them bounce
around and almost all those rays are not going to actually get to the eye so the next breakthrough as far as ray tracing goes is these cook stochastic or sometimes called distribution rate racing in 1984 the idea here is that instead of shooting just a single reflection ray for example you might have a glassy surface something with kind of a sheen and you shoot out sort of a burst of rays instead you can also get cool effects like motion blur and the idea here is just that instead of shooting one reflection ray you're shooting a
bunch or instead of shooting one shadow ray you're shooting a bunch to try to get a soft shadow with stochastic ray tracing you shoot a ray out it hits the box and then you shoot one raid at the area light so our Sun now is a little bit larger to give it some actual area just like the real Sun and we pick some arbitrary point on that Sun this one made it all the way to the light and here's two more Ray's one hit one missed so now we know at this point that two-thirds of
our rays are hitting the area light and so we can say well okay the shadows you know somewhat soft two-thirds illuminated but we can shoot more and more and more rays and get a better answer so this is stochastic ray tracing and the idea here is like I say just shooting a burst erase it's more expensive you have to shoot more Ray's and the more rays you shoot the better the answer you get but that's you know it's it's often worth the cost so in 1986 was sort of the next theoretical leap which is kochiya
style diffuse inner reflection and this is a paper a classic paper which we'll go to in a further lecture in a later lecture called the rendering equation and basically his idea is well you know what if we say the sky's the limit we're just going to shoot rays out from the eye and we're going to have each ray hit something and we don't necessarily know which way it's going to reflect if it's a mirror we know sure it'll reflect in the mirror direction but say it's something like unglazed pottery or some other thing like cement
or something you then don't really know which way the lights coming from well you know the lights coming from all kinds of different directions so what you do is you shoot more Ray's in different directions but with path tracing you shoot just one ray in one direction and follow it along a path so let's let's show you what that looks like so here's path tracing where we've stopped one ray through you know through our pixel and it's in one particular location in the pixel it hits this box and we shoot a secondary ray in some
direction and it goes off to the sky say we shoot another ray that one happens to hit a light so that's actually going to be a fairly important contribution that's sort of a lot of direct illumination from the Sun and notice that we've also put the pixel sample in a slightly different location within the pixel this allows you to get sort of anti-aliasing kind of for free because you by moving the samples around within the pixel you're basically sampling the whole box the whole pixel box instead of just the center of the pixel and so
we go we continue here here's a path where we hit the ground and then it hit that cylinder and that it shot off down you know to the ground somewhere else and so on you keep shooting these Ray's and you get more and more paths and once you have all the paths then all meaning you're tired of shooting Ray's you basically then add up all those contributions you basically have figured out where the lights coming from for a bunch of different directions a bunch of different paths and you add them up and get a color
so in the film industry for example you'll often see scenes where they'll use a thousand rays 3000 Ray's per pixel and so those take a little while to compute the point is is that by doing this you will eventually get the right answer you you know it's sort of reversing the whole process of getting light percolating through the system and but doing it just from the eye and you will eventually get the right answer so that's path tracing and what makes retracing great is the fact that it can be that simple it's just you're shooting
array and bouncing it around along different paths and here's a ray tracer in fact that's on the back of a business card this is from Paul heck birds business card when he was at Pixar in the 80s and it actually is a ray tracer it will actually make a little ray trace scene with I think it's shooting against a bunch of spheres so it's a very compact simple kind of algorithm you have this simple tool array and using those Ray's in various great ways you can basically get beautiful results like this where you're getting soft
shadows and lovely reflections and that's it for this lesson I wanted to point out some further resources that you'll see on the webpage links to places where you can find books and there's also going to be a link for ray tracing gems which is the book that I helped go edit so thanks and I'll catch you at the next lecture [Music]