Intro to Graphics 20 - Shadows & Reflections

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
well thank you all for joining another lecture for introduction to computer graphics uh we're going to continue talking about ray tracing today we're going to talk about a bunch of interesting stuff related to ray tracing but we're going to start with shadows right um so what what what what are shadows so let's say that i have an object like it's a sphere um are they shadows here are the no shadows what do you think is there any shadows here um maybe i mean you could say that maybe the back side of this sphere is in shadow maybe maybe not okay so how about this this is an obvious shadow right so so what happened here all of a sudden you look at the sphere and you can tell that there's something underneath the sphere right something underneath this sphere but i'm not showing you that there's actually a plane here you can actually tell that there's a plane but what is it really what is what is this black thing that we call shadow anyway and this is important to i mean this this is sort of obvious but you know it's important to understand this because that's yeah that's going to be how we're going how we're going to compute shadows right so what is what is shadow the shadow is you can say the absence of light right but it's the absence of light in the presence of light so there's got to be some light to for us to have some shadow no light if there's no light there's going to be no shadows right shadows appear because there's lights and a part of our scene receives the light and some part of our scene does not receive this light and that's why we have shadows so it's all a part of this light we gotta have a light source so by by looking at the shadow you could tell that there was a plane and you could pretty much tell where this light was supposed to be right it gives us this this clue of where this light is supposed to be uh i also like that probably the highlight on the sphere is giving you a hint about where this light source is supposed to be uh but but the point here is that shadows are very very important and very very important to um to compute relatively relatively accurately because it gives us some idea about the how where things are in our scene and how they're oriented together like for example if i just for example if i just remove this shadow if i just remove this shadow look at this what happened here now look at this sphere does it look like it's on this plane not quite right it just doesn't really belong there anymore so shadows are very very very important to get right there are certain things in computer graphics that may not be very important but shadows they are actually important we need to get them right um so we said shadows are related to the light source and we're going to have shadows where the light doesn't move so what does that mean so um let's pick a point in the scene let's pick a point on this planet over here that i picked their point um is this point in shadow well if the light can see that point or if i can see that point from if i can see the light source from this point then the point is not going to be in shadow right so what i'm trying to say is that if there is not nothing between this point and the light source if this line segment is not occluded by anything then this this point is not going to be in shadow right but if i pick another point where this point will not be visible from the light source such that if i draw a line segment from this point to the light source it's going to be going through an object that means that point is not visible to the light source because there's some other object in between here that's blocking the light right so the light cannot see that point or this point cannot see the light or the light from the light source does not is not reaching this point that's why it's a shadow that's a very very simple idea i'm pretty sure you're all uh i'm familiar with the concept of shadow so i'm not going to spend too much time on it but by by doing this test by checking if there's anything between the light source and the point we can tell whether or not that point is inside a shadow one out and that's exactly what we're going to do using ray tracing with shadows uh it's going to be ray j's shadows all right the idea is very very simple and retracing will allow us to do that very easily so let's say that i'm rendering the scene i have this camera all right i put this camera here i could whatever i could put it anywhere let's say that i'm rendering the scene with ray tracing so i'm sending an array from my camera that's going to be my primary right all right and then the primary ray let's say that it went all the way and hit that point that we were looking at previously so to check whether or not that point is in shadow all i need to do is to generate another ray and trace it so i generate another ray starting from that point and i'm going to trace it until all the way until it reaches the light source so if that ray reaches the light source without intersecting with any other object in the scene that means the point is not in shadow but if it intersects with any of any object in this case it's intersecting with a sphere that means that it is in shadow very very simple right and and so this kind of ray we're going to call this a shadow ray right it's a special kind of ray it's used for checking whether or not we're in shadow now i'm going to talk more about shadow rings and other types of rays and how they how they differ but i will talk about it later on so let's say this this special kind of ray is a shadow ray right so simple enough conceptually very simple right i mean this is what today is going to be all about really we're gonna last time we talked about the math of retracing this time we're mostly going to talk about how we use that math to do things with it so computing shadows is just one of them very very simple i'm pretty sure you all can implement it i mean if you can't implement gray tracing if you can generate an array and trace it you can you can trace the shadow ray right it's not that difficult at all if you are able to trace rates in the scene so if you just do this and implement this properly you would expect to get a nice shadow like this right but what you would actually get would look like this oh wait what what happened here what what what is what is what is happening uh we're we wanted to get this we're getting this what is this do you see these their little streaks here sort of like i'm not supposed to have any shadows here but i'm getting these shadow streaks right i'm not i'm not getting this i'm getting what is happening something strange is happening right yeah if you just it's a bug it's not quite a bug this is what happens if you just blindly implement shadow mapping without quite thinking about it too much uh let's let's see what's going on here let's let's let's let's see what's going on all right i'm going to show you the side view so what happened here is that i traced my brain from my camera i found this hit point and then i decided to trace a shadow ray towards my light source and i traced it all the way to the the light and then i'll i'll decide whether or not that this ray hit something and if i'm in shadow right so all i'm checking is that if this shadow rays ray hits anything at all so starting from this point on this surface starting from this point on this surface i'm tracing my ray until it reaches the light source and check if it hits anything at all here's the thing i'm going to zoom in here right just let's zoom in to this area let's zoom inside all right let's zoom in but you know what let's zoom in some more let's zoom in somewhere oh wait what happened what just happened this point is not on my surface like what what is why why is it not on my surface it was supposed to be on my surface i just zoomed in what happened here why isn't it here why isn't it on the surface lack of precision that's right yes rounding error yes so i have whatever floating point representation i use i am going to have a limited number of bits that means maybe i want to represent this exact point on the surface but i cannot represent any position exactly using finite number of bits right i'm going to pick the closest point that can be represented using my floating point representation whatever it is that i'm using well typically i'm going to be using 32-bit floating point values using ieee floating point format but it doesn't matter what you use you're gonna have a limited number of bits so you won't be able to represent a point exactly you're just gonna pick the closest point to it there is that there is that but not just that not just that there is also all sorts of computations you've performed to compute this this point on on this surface and those computations you've you probably use some floating point representations for those those computations too so while computing the position of this point with every one of your computations every time you're doing some multiplication addition or whatever you're losing some precision possibly right when when you have multiple computations one after another after another after another all these small tiny little errors you make they might accumulate and as they accumulate you might be off of this surface a little bit more than what your floating point rounding error would would get you so there's yeah floating point round and error here because of the the precision that you're using but there's also other factors because you you had limited precision with all of your math operations right and all these errors you made accumulated and you're not exactly on the surface anymore you're sort of a little off of that surface so this point might be about the surface in which case it's fine if it's above the surface i don't have a problem but if it is below the surface that's when i'm going to have a problem right because that's when when i'm tracing this ray when i'm tracing this ray what am i going to do if i trace this ray starting from this point i am going to find an intersection right over here yeah so i'm checking if there's anything between this point and the light source the answer is yes there's there's the surface but i am on that surface i don't care about this surface so what do i do one thing i could do is that i could just ignore the surface right i could say oh you know what i'm on the surface i don't care i'm just going to ignore the surface well this might be possible to do in some cases but not always depends on what kind of surface this is so if this is a sphere that maybe it's okay but if it is any type of concave surface it might be it might be shadowing itself right so i can just ignore this surface and and say oh it's not going to cast any shadows when i'm sending tracing a shadow ray from this surface because surface itself might surface might shadow itself and this might be something that i actually want to get depending on how i define this surface so just simply throwing it away is is not a solution that will work in every case in some cases it will work but in not in all cases also it's a little clumsy because every time i'm tracing a shadow array i kind of need to figure out oh where did i start this ray and where was i which surface was i on and there are a few other edge cases where this might give give you a little bit of trouble uh so yeah that would work in some cases but not in all cases so you know we're gonna ignore everything behind the rake right we don't we don't care about that part so we're going to start counting from this point on but we don't have to start exactly at this point we can start a little further out and we can ignore intersections that are too close to this point so basically what we're going to do is that we're going to ignore intersections that are too close to this origin of the ray and we're going to start counting intersections from a different point let's say like over here somewhere a point that is going to be outside of of of display um but some epsilon if you will right and this is what we call bias so we're gonna add some bias to our ray tracing and we're not gonna look at intersections that that are happening in between here and the way to do that the way to implement is actually very very easy so you can think about oh i'm going to take this ray and just move it just a little bit and you know add more floating point operations on top no you don't have to go go there though this is actually super easy to implement super super easy to implement all you got to do is to have some bias value typically this sort of valid bias values are exposed to the end user because it's going to be scene dependent because of our floating point representation the floating point representation we're using the bias we will need will depend on the scale of the scene so depending on how large the numbers we're using for representing all these positions if everything is in small scale the bias should be small everything is lower if everything is large the bias should be large because our error is going to be large if we're dealing with larger numbers so this is going to be sort of scene dependent depends on the scale of the scene uh we're going to pick some some bias value and and here's how we're going to use it it's going to be super easy so you know where we're uh tracing this this ray and let's say we found a hit we found hit at some t value for the ray remember the t value for the ray ray equation any position is p plus t times d being the right direction right we found some t value we found a hit at some t value all right so normally what we do is that if that t value is smaller than zero we will ignore it right that means it's behind the ray or maybe i should say smaller than or equal to zero we'll we'll ignore it instead of doing this test which we already do which we already do we're going to be doing this test with some delta right some some value in this case this delta is a a small positive value that's going to be our bias right so we're going to ignore this bit now it is important that this should not be too large because obviously if it's too large i'm going to ignore some shadows that actually do exist right i'm gonna start seeing wrong things here i'm gonna be ignoring some shadows that i should be counting all i want to do is to move this just enough so that all of my points that fall inside the surface because of numerical imprecision is going to be outside of the surface when i'm when i'm tracing right effectively outside of the surface so it should be a small value it's it's important that it's small but it will be c independent uh but it shouldn't be very large you know often times there's going to be a wide range of possible values this is not going to be very sensitive if this is not too large and it is not too small it's going to work out so you just need to pick a value that that would be okay not not a very sensitive value but you need to have some bias right and if you add this bias then things are going to work out and we're going to have these this nice looking shadow and it's going to be everything's going to be fine right now we don't have these funny streaks anywhere that these points are not shadowing themselves that was the problem we're having before all right so i talked about this in the context of ray tracing i'm saying we generate a primary rate here we find a hit point and then we trace the shadow array but rachel's shadows is not specific to rendering using ray tracing at all like you need to have some retracing capability so that you can compute the ray ray's shadows but your primary arrays they don't have to be computed your primary visibility does not have to be computed using ray tracing right so i could be using rasterization to generate the image it's just that when i have when i'm looking at a point i'm just going to be tracing a shadow array to find the hit point for my camera visibility i don't have to use ray tracing but for computer shadows i am using range racing that's why i'm calling this ringtone shadows alright so uh what if i can't do raytracing what if i'm rendering on the gpu using rasterization and my gpu let's say does not have retracing capability we have a lot of gpus out there on the market that do not have ray tracing capability what do we do then is there anything we can do now we talked about how important shadows are right and without shadows we don't get the proper orientation between all the objects so we need to get we need to somehow figure out a way to compute shadows so even though our topic for today is ray tracing and i've already explained you how to do retrace shadows we're pretty much done about with this topic but um i would like to tell you a very very popular alternative technique to raytrace shadows so how can i compute shadows without raytracing so here's the problem again i'm rendering using rasterization remember rasterization with randomization the problem is i'm getting my scene data one triangle at a time so i have this one triangle i'm going to project that triangle i'm going to draw it on the screen all right so tell me for any fragment shader for this triangle and for any point on this triangle is it in shadow i i don't know i don't even know if there are any other triangles in the scene right so rasterization does not help me at all like with drain tracing actually strings array but without retracing rasterization is not helping me oh guess what there was another triangle and and the triangle was there okay now is this triangle in shadow i don't know i have really no way of knowing actually no way of using rasterization directly to do this but we've been rendering with rasterization for decades and we've been computing shadows how on earth are we doing this here's how so there's a very very popular technique very probably more popular than race race shadows this is possibly the most commonly used technique for computing shadows in computer graphics that is shadow mapping a very very simple idea and that's that's reason why i want i wanted to just briefly talk about this so that you guys you know that this exists and that you have some idea about how it works right so here's what we do with racialization without having the capability of reintroducing here's what i do i'm going to take this this light source and what i'm going to do is i'm going to figure out where i have shadow in the scene now we talked about this if the light source can see a point can see a point directly then that point is not in shadow if the light source cannot see that point then it is going to be in shadow right so i just need to figure out whether or not my light source can't see that point that's the idea so to do that i am going to put a camera instead of my light source and i'm going to render an image i'm going to render an image from my light source right let's say i rendered an image from my light source camera and it looked like something like this right so when i'm rendering from this camera all i need to do is that when i check is at this point is this marked point in shadow i need to find where it corresponds to on this light image and if the light can see that point that means it's not a shadow if the light cannot see that point that means that means it is in shadow well to decide that i don't need to have a colored image like this for my live view what i need is only and only the depth map so the depth map will tell me for each one of the points on this image the depth map will tell me how far that point is from the light source right so with shadow mapping it starts with rendering a depth map or what we call a shadow map from from the view of each light source so each light source will have its own shadow map and then i'm going to use that shadow map to compute my shadows when i'm finally rendering from my camera view alright so it's like a two pass algorithm i first generate this depth map by rendering an image from the device perspective and then i am actually rendering my main image the one that i actually want to render and when i'm doing this for any point that i'm interested in i check where that point lies on the on cameras view and i figure out the depth value here and i check the depth value to the distance from this point to the light source so if there's something that is closer the depth value here is going to be closer in that case i'm going to say oh no i can't see this value it is it isn't shadow otherwise i'll say okay i can see that point so it's not going to be each other so uh shadow maps are gonna have a whole bunch of issues um one issue is that i need to render the shadow maps before i can render my main image right so it's going to be a two pass algorithm if i have multiple light sources then for each light source i'm going to be rendering a separate image it's going to be a little bit of an issue you know i also need to have i need to have the light right field of view for this light source it's a spotlight and it's okay it's a point light illuminating in all directions that's going to be a little bit tricky but not too tricky can be handled this is going to be a raster image so its resolution is important right if it's not high resolution enough then my shadows that i'll be computing they're going to be like jaggedy i'm going to see pixelated shadows here because my shadow map does not have enough resolution so there's going to be all sorts of issues like this but in the end you can think of a shadow map as pre-computed shadows and generating a shadow map it's not doing any shading right it's just computing the depth map generating a shadow map is actually very fast and it's pre-computed and at any point when i'm checking the shadow it's just a look up right i'm just look up look up the value in the shadow map and that's it so this is very fast to compute i'm generation map generation is fast and then computation shadow computation using shadow maps is very fast too so this is a very very efficient very very fast algorithm and that's one of the reasons why shadow mapping is still used a lot today even in offline rendering we sometimes prefer using shadow mapping because it's uh it would be a lot of cases not in every case but in a lot of cases it's going to be significantly faster than ray trace shadows even today this is probably the most popular i'm going to say popular in a sense that it's it's used more often the most popular method for computing shadows but you know raytrace channels are catching up because our computers are fast enough and raytrace shadows have fewer issues there they generate nicer and crisper shadow edges and stuff so people prefer using greater shadows also shadow mapping is only going to work for spotlights and point lights and directional lights with all other light sources more realistic light sources like area lights mesh lights and things like that we won't be able to use shadow mapping but there are ways to use ray tracing to compute shadows from area lights and stuff we're going to talk about this just briefly next time uh so raytrace shadows is actually a more general concept that can be applied to a whole bunch of light sources and that that's why it's becoming that's another reason why rachel's channels are increasing in popularity i i think i still think shadow mapping is uh probably the most common way of computing shadows today but ray trace channels are catching up for for good reason a question here so if a light source in the scene is moving then do we need to render new shadow maps yes so yeah if the light source is moving you need to reconcile your shadow map also if anything in your scene is moving you need to recompute your shadow map right i mean maybe light source is the same the camera is staying the same the plane is things but the sphere is moving i need to recompute my shadow map right so i can't rely on my previous shadow map but if everything is constant if nothing is moving except for my main camera then i can render my channel at one time and just use it like it's a static scene the only thing that moves is the camera this main camera then i don't have to recompute my shadow map so this is shadow maps i just had to talk about this because you know this is how you normally complete shadows but if we have raytracing capability we can just use raytrace shadows it's a lot easier it's a lot simpler it has fewer issues and that's exactly what we're going to be doing for our next project so when we're computing shadows we're going to be computing those shadows using ray tracing all right let's move on we're doing ringtone shadows and we'll do that right simple enough rachel's shoulders are a lot easier we're done we're done with shadows no more shadows let's talk about reflections that's the another thing we could do with ray tracing that makes rage racing really fun all right that's another nice thing that we will be able to do with ray tracing so what are reflections you might must have seen reflections before right so you know what they are but what are they really i mean yeah reflections this is like mirror and i'm seeing things but what what are they remember when we talked about the diffuse component and specular component of a material i told you that the specular component was the reflection of the light source remember that like we're shading the surface and the the specular specular highlight that we see i told you that it's the reflection of the light source right so and it's true it is a reflection of the light source and when we talk about reflections though we're talking about the reflections of other objects not the just the light source but but other objects right so wait what does that really mean let's put it in this context in the context of the rendering equation remember this equation this scary looking information if you haven't seen it before but if you've seen it before it probably makes sense to you now we talked about this so this was an integral over all possible directions and lights coming from all directions and we multiply it by the the cosine term and the b idf and basically this right light is coming from possibly from all directions and we're just doing an integral over all directions and we're figuring out how much light is reflected in this direction that we're interested in right so this was the rendering equation and of course in our practical implementation the lights yeah it can come from all directions but it was only coming from the light sources right so that's what we were interested in but in reality now here's the thing that i'm probably going to repeat a few times in reality light does not just come from the light sources yeah light can come from other things too i mean if light only came from light sources we would only be seeing the light sources we wouldn't be seeing anything else would we right i mean what does this camera do or what are our eyes doing they're seeing lights right so if the light is only coming from the light sources i cannot see anything else about the light sources obviously light is coming from other things like the reflected light off of the surface of this point that is lights right and this is light as much as whatever is coming from the light source is light so light that is reflected off of surfaces like this can be used for eliminating other objects this whole concept of objects reflecting lights and eliminating other objects this whole concept is what we call global elimination it's a very very important part of generating realistic images this this rendering equation accounts for that so the random equation is not just about light coming directly from these light sources but it's also about light coming from other objects that are not light sources but they're reflecting light right so they're receiving light from the light sources and they're reflecting it and that reflected light is being reflected off of other surfaces and then reflect the other surfaces and then that can also illuminate so like diet can bounce around in the scene many many times and and now we can see it but at this point that's not quite what we're interested in i just wanted to clarify this point that light is coming from everything and eliminating this point and we are in general interested in the reflected light off of this point that includes everything like all the light coming from all objects light sources non-light sources everything over the same sphere we're normally interested in all this to generate a realistic looking image but what we're specifically interested in right now is a very very small component of that what we're specifically interested in is light coming from this perfect reflection direction we're going to look at we're going to assume that this surface is like a perfect mirror now that's very smooth mirror and we're interested in these merit reflections so it's not it's not going to be as complicated as this whole story that i'm telling you because we're going to be looking at a small part of this and we're going to talk about this general story a little bit later so don't worry about that we're getting there all right so what we're interested in these um these reflections right these nice looking reflections um off of this this planet surface well actually what we're interested in is uh we're interested in these specular reflections right nice specular reflections i told you specular reflections were the reflections of the light sources right so these are going to be the specular reflections of other objects specular reflections of other objects actually i'm going to put one more adjective here it's going to be perfect specular reflections perfect specular reflections of objects not light sources perfect specular reflections of objects so that's what i mean when i say reflections so what do i mean by perfect like what would happen if these were imperfect reflections if these were imperfect reflections they could look like this they could be blurred a little bit right for most surfaces if the surf is not perfectly smooth if there's some roughness to it the reflections off of that surface is going to get blurred a little bit that's that's what happens for a lot of real materials but that's not what we're talking about because computing this is a bit more difficult we're talking about a very very special case in that special case i am going to be interested in these perfect specular reflections meaning this is going to be a perfectly smooth surface all right that's what i'm interested in and let's see how we do that using raytracer so um here's my setup i have my camera i'm looking at a point i have this point this is my view direction omega omega o and l o is that the light coming from this point towards my camera that's what i want to compute and when i do regular shading what do i do i look at where the light is coming from this light is coming from this direction right i figure out how much light is coming and i do my shading i figure out the reflected light and i'm done so this is the this is the equation right so the outgoing light here is the sum of all light sources and for each light source i figure out how much light is coming multiply by cosine term and then multiply by our surface behind the f that this is our surface material property okay all good this is what we've been doing okay so what if what if this is the kind of surface that has sort of mirror-like reflections what happens then then i will be seeing other objects on on the on the surface right on the surface i will be seeing other objects too so but what do i see to be able to figure out what i see i can just trace another ray that is i can trace the reflection right so a reflection is going to be the reflection of my view direction so this view direction i need to reflect that vector and i need to find the reflected view direction that's where my reflection is going to come from my perfect reflection is going to come from and that vector of course has the same angle with the surface normal as my new direction right and the way we compute this is remember how we did this we talked about computing reflections of this light direction right when we were talking about the whole material model we talked about how to reflect this this uh my direction vector it's it's going to be the same thing i'm not gonna go into the details of that but if you're wondering where this equation came from check out that discussion about how we complete the the reflections of the incoming light direction when we were talking about the foam material model this this simple equation the simple vector equation will give us this this reflection direction all right so what do i do uh what i need to know is how much light is coming from this direction so i'm gonna say uh for my simplified uh shading model light is coming from my light sources it's also coming from this perfect perfect reflection direction so i just need to know how much light is coming from my perfect reflection direction i call it here lr right so what do i do with it well this is very much like a light source right very much like a light source so i need to do some i need to treat it as very much like a light source and i can just use it like this but it's a little bit tricky because i am only looking at perfect reflections so that means i'm going to make some assumptions about my brdf here for the purposes of handling these reflections so if these are perfect reflections they're not going to have any diffuse components that are going to only have specular components and that specular component will only work in the perfect deflection direction so my my specular exponent if you think about this as a foam material the specular exponent is going to be infinity so it all simplifies down to something very very simple when you're dealing with perfect reflections it becomes this so incoming lights from the reflection direction just multiply by some material property all right some material constant material material reflection coefficient this is going to be kr and that would be it right so that's typically how we handle angular reflections and this kr now it's all hidden here specular reflections of objects the chaos this this can our property most software will allow you to set this however you like but a reasonable thing to do for kr would be the specular reflection coefficient as this value so if i'm using a blend material model or a full material model uh let's say in blue material model we have diffuse reflection coefficient we call it kd a specular reflection coefficient we called it ks and we had a specular exponent n so in this case you can think of this as what we're treating we're assuming that k d is zero or black and k r is going to be the same value as k s the specular reflection coefficient and this reflection coefficient is still the specular reflection is done about specular reflections so that should probably be the same value right it's a reasonable thing to do and because we assume that the specular exponent is infinity this this cosine for i in terms of disappear we're left with this so this kr if it's not given to you it's a reasonable thing to use the specular reflection coefficient as just reflection coefficient for other objects because it is still specular reflections right just specular reflections of objects not the light source but i'm going to talk a little bit more about this when we're sort of generalizing this this whole concept to more types of reflections that are not necessarily going to be perfect but for now we're talking about perfect reflections so it simplifies down to something like this okay that's that's very good and all but i didn't tell you how to compute this oh yeah this is going to be given to you as your material property as the specular reflection coefficient what is this when where does this come from here is here's how we compute this this guy what we're going to do is i'm i generated this reflection ray i am going to compute this whatever this value is by tracing the reflection ray and i'm going to trace that reflection ray and hopefully it will hit some point in my scene over here right it's going to hit some point and presumably that point is on some surface with some surface normal right so what i need to do is to find the reflected light off of this point that's what i need to do so how do i do this i do shading at this point right so i'm going to do exactly the same shading that i was doing before so in this case my view direction is going to be this right this is my view direction now and this this reflected light the reflected light in this view direction is going to be equal to this this coming uh coming the reflection light over here the incoming reflection light right so i just need to compute this that means i just need to do the same shading that i did but on this point this side so that's exactly what i'm going to be doing i'm going to be computing on this point so how do i do that i look at the light sources and i figure out how much light is coming to that point and i do my shading by looking at all the light sources it's the same equation as before it's just that you know this is at this point right so this material is that material see i'm done that's it so that's how i compute reflections i start from here i generate the reflection direction i trace that ray i do shading over here and then from that shading i get the the light coming from here and this whole thing becomes this value over here i just add it to my my reflection over here i'm done i'm done i'm done if i don't have any reflections on this surface what if i have like mirror-like reflections on this surface now what do i do then oh very easy i'm just gonna do the same thing over here i'm just gonna generate the reflection direction here and i'm gonna trace that ray right and figure out what that hits and i'm gonna do the same combination of you know if it hits a point i'm going to do the same shading computation at that point i'm going to figure out the light that's coming and then i'm going to multiply by the reflection coefficient of this surface and then i'm going to use all that for for this so so i may have to do this i may have to do this a few times because you know that this reflection ray can can bounce around this blue reflection ray can find another hit point and that and other hit point can be another on another surface that has these perfect reflections so it can reflect again and again and again and again and again actually you know what you can even go to infinity so this is not going to be very good right if it is not good if you haven't realized it by now it's pretty bad for a lot of computation so i need to limit this so i can't just let my race bounce around to infinity because my rendering will never stop them so i'm going to limit this i'm going to put a maximum limit and if i reach my maximum limit then i'm going to say you know what at that shaping point i reach my maximum bounds max maximum rate bounces reflection bounces i'm going to say yeah no more reflection rays with that we're going to ignore the reflections there because we're here to stop at some point so that's how we're going to handle this right so not too difficult actually here the only difficulty is compared to just computing shadow rays is you know i generated a reflection rate this time using this equation and i traced that reflection array and i had to do another shading here and this is sort of like a recursive process so i need to do shading and other shading and other shading another shading implementing all this using some recursive functions is fairly straightforward unfortunately though when we're doing project six that's going to be our main tracing project uh for which we're gonna have to implement some sort of reflections as like a recursive function right so i'm trying to shade this point i generate this reflection array oh it finds this point now i'm gonna shake this and after i'm done with chaining this then i can compute complete shading this point so normally it's the easiest thing to do is to implement it using some recursive functionals but for our project 6 with webgl we won't be able to do this with recursive function calls simply because webgl doesn't support recursive functions but no worries you must have seen this in other cs courses before that you can take any recursive function and convert it into a loop and that's that's what i've done for you so the code that i've given you for project six actually includes a form look that's outside of shading that sort of handles the reflection component outside of the shading just you know you basically add this piece after you do the shading for for this part right so this part is sort of removed from the shading computation because we couldn't do recursive calls right so just the implementation detail about the upcoming project all right so we were talking about bounces my first balance was from this point and when i compute the next reflection is going to be my second bounce and my at this point if this ray hits another point maybe i'll have another bounce there another bounce there and at some point i'm gonna have to stop sorry there's gonna be a limit let me show you what it does in a lot of cases after a certain number of bounces it's not gonna be that important for example if you look at this scene i have some spheres and very nice reflections on these spheres right you see the reflections you don't see the reflections you can't see reflections because my balance limit was zero so i couldn't do any reflections here so you know by changing these points i reach my bounce limit of zero so this year's got no reflection so if i let them have one bounce of reflection just one balance of reflection i will be able to see reflections of the sphere so now i'm seeing the reflections of the spheres on these spheres very good but these reflected spheres don't have any reflections on them right because my bounce limit is one so if i increase my bounce limit to two i am going to start seeing reflections on these reflected spheres right so i'm starting to see reflections on these reflected spheres but i don't see reflections on the reflections of the reflected spheres so if i add another bounce i'm going to start seeing those right bounce limits three you see like relatively fewer pixels are being impacted by this choice and if i add another reflections another level of reflections uh some pixels changed can you see a few pixels are changing here well more than a few actually but it's kind of becoming harder to see from four i can go up to five do you see any difference well if you're paying attention uh on this red sphere uh reflections on this breast view you can see some differences but it's very very hard to tell right so as you as you bounce them it goes higher and higher you're going to have fewer and fewer pixels that will actually need that many bounce so at some point you could say that oh it's okay to be inaccurate for a couple of pixels here most of my image is done so i'm just going to limit it to something next project will have this feature as well because without it our rendering may not ever converge so you kind of need to have a limit right and also no worries webgl will sort of require you to to limit your loops and this is how we're going to limit our loops all right so this is the whole conversation about uh reflections so today we talked about shadows and reflections but uh and another thing that we can do with ray tracing fairly easily is refractions reflections are not very different than deflections the only difference is the direction of the ray that i'm that i'm tracing if i have reflections off of this surface that i'm shading that means that this is like a semi-transparent surface right so this is like light is going through the surface i can actually see through the surface this is the the surface of my material so there's an object underneath this this plane and there's sort of like air about this plane so if there's an object underneath this plane it's probably going to have a different refraction index that means this light that goes in here is going to reflect right so i need to compute that refraction direction so i compute that reflection direction whatever that is and then i trace that ray and figure out what it is and find out how much light is refracted and this is how i can add up your fractures so um competing this is a little bit more just a little bit more complicated um not too hard actually but it involves the index of refractions for the two mediums here like the air and the object i'll skip the details of that we actually talked about this um quite a bit extensively in the the ray tracing course we do all sorts of things about ray tracing and realistic rendering and all that and in the end we have a teapot rendering competition in which you can showcase the kinds of interesting things you could do with your ray tracers an example is here this is an image rendered by jacob hydel who won the the last default rendering competition and here he's showcasing a refractive triangulated the utah teapot using diamond as the index of refraction and this is actually spectral render so you can see some color variations in these refractions which is what happens in in reality this was actually just one frame from from a very nice video that that he rendered but the the point that i'm trying to make here is that you know computing refractions are not too difficult than computing reflections basically the same concept you just trace array in a different direction okay all right there's a few more details but you know still the concept is is very very similar all right so i'll i'll leave the discussion of refraction here for the time being all right so we talked about reflections reflections and shadows in the context of ray tracing and i want to conclude today's lecture by talking about different ray types now that we've seen all these different different rays i just want to emphasize the differences between these different types of phrases so what are the types of rays that we have when i say ray types well we have primary rays if we're doing the primary visibility for my cameras we have primary rays generated from our cameras and we set any rate that i generate elsewhere i'm going to call it a secondary ray so primary rays are the rays coming from camera or coming from our eye like whatever for the for the primary visibility all other rays that i'm generating are going to be secondary raised so setting the rays could be used for computing reflections and refractions i can call them reflection and diffraction ladies or they could be shadow race these two types of rays reflector refraction rays and shadow rays they are fairly different types of rays so these reflection refraction rays sometimes we call them like regular rays normal rays these are not very different than my primary ladies the only difference is where they originate if they originate from the camera i'm going to call them primary rays if they originate at another point i'm going to call them secondary rays but there are going to be normal types of grains and these shadow rays are going to be somewhat different and here's why with these reflection refraction rates when i generate the reflection rate i am going to trace that away all the way to infinity i'm going to trace that ray all the way to infinity that means i'm going to trace until i find the hit point with something and if i don't find any hits then it's fine if the rate goes out of my scene then i'm not going to find any hits then it's fine but i am not going to stop until i go out of my scene that's why i'm calling it straight straight infinity but with shadow rays it's not quite like that with shadow rays the question is is there anything between this point and the light source so i'm going to start from that point and i'm going to trace all the way to the light source and that's where i'm going to stop because i don't care if there's any other hit beyond the light source right after i reach the light source i don't need it anymore so it's going to be different in the sense that i'm going to stop when i reach the light source any hits beyond the light source i don't care i am not going to look at it that that's that's one difference the other difference is that with reflection reflections that surveys i would like to find the closest hit point right so i generate the array i'm tracing it i'm going to find the first hit of that way i don't care if there are any other objects behind it right all i care is the very first hit when i find a hit i need to make sure that it is the first hit it is the first object that the ray intersects moving along in that direction and that that's that's going to be important so if i'm not sure that i found a hit but if i'm not sure that it is the closest it is the first hit then i need to continue looking at other hits if there's any potential that i might be able to find closer hits then i need to check that now let me repeat this let me repeat this because this might be a bug that some of you run into when you're implementing project six when i'm tracing reflection rates or primary rates i need to make sure that the hit that i found is the closest it's the first one along the ray if i'm not sure i need to continue checking all possible other intersections with other objects because maybe i'll find a closer hit right it's very important that i find the closest one because that's the one that i'm going to be shading right but over here with shadow race i don't care i found a hit there exists any objects between this point and the light source i don't care that the kit that i found is the closest one or not because i don't i don't care i was just checking if there's anything between the point and the light source if there's anything at all i'm done right i don't need to find the closest one i just need to check if there's one at all right so this actually simplifies things quite a bit when i find a hit i can say okay i'm done i found hit i'm done i don't need to check anymore right that's going to be a little different because i'm not going to do anything else with that point but with reflection refraction rays i am going to need the heat information i i'm going to need to know what point in the scene i hit like what was that object what's the material on that object what's the surface normal what's the percentage coordinates i need all these hit information because i am going to shade that point to compute the reflection and refraction right i'm going to shade that point so i need a lot of information about what that hit was what did i hit why did i hit it what kind of object was it i need to know that but with shadow race i don't care i don't need to know anything about that point i just all i need to know that it existed that there exists a point and i'm done i don't need anything else so because of that most race racers will have a separate routine for handling shadow raids because you can handle shadow rays much more efficiently than of the other types of rays with shadow rays if you have a full look going through all of your objects you can return as soon as you found a hit and you don't need to return anything you can just say yeah i found hits true or false i'm done but with these kind of reflection reflection types of rays i need to find the closest one i need to make sure that i'm finding the closest one and i need to record the hidden information and i need to return the hidden information as well right so these are going to be tracing these are going to be a bit more expensive uh so shadow rays in general are much cheaper types of race the other regular rays we use for reflections refractions and also primary rays there are going to be relatively more expensive rays for this upcoming project i'm going to leave this part completely up to you you can have a separate routine for handling your shadow race or you can handle them within the same range rehearsal routine that you have which is going to be a bit more expensive than you need to but it will be okay so you can you can do either one uh whichever one you prefer but i just wanted to make it clear here at this point that shuttle race can be cheaper and you can optimize your implementation by handling shadow runes separately potentially right so that's all i plan to talk about for today uh this is where i'm going to stop thank you all for sticking around till the end and i'll see you all next time thank you
Info
Channel: Cem Yuksel
Views: 1,388
Rating: undefined out of 5
Keywords:
Id: l_iVdRbA_4s
Channel Id: undefined
Length: 63min 38sec (3818 seconds)
Published: Sat Nov 06 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.