Intro to Graphics 15 - Shading

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
well thank you all for joining another um lecture point to thank you computer graphics so i'll um jump in and start talking about today's topic and today's topic is going to be big surprise shading yeah we're gonna talk about shading so what is shading those of you have done some computer graphics stuff before have some idea maybe but when you think about shading shading when i ask people like what is shading like but when you're talking about like pencil shading like something like this this is shading this is literally shading so you know different types of shading with pencil right so what we're going to do in computer graphics is actually going to be very similar to this it's going to be a very similar concept but of course we're not going to be doing with pencil we're going to be doing it on 3d models it's going to be all about computing color and color variation on 3d surfaces not necessarily 3d surfaces but yeah that's where we're going to start so shading in computer graphics if i have this lovely teapot what a lovely teapot isn't it it's a little too dark for my taste so let's put some color on this i'm not digging this black so much let's make it red how about that kind of fits the overall theme here right red red teapot great great looking teapot isn't it no no not not so much it's a little flat don't you think it doesn't look like a 3d teapot to me it's pretty flat because it's the same red everywhere i would expect to see something more like this right with some color variations some parts are darker parts are brighter and then this finally looks 3d and that's very very important that's what we're trying to do in computer graphics right so um what's going on here this whole thing is about light right and this whole thing is about lighting so a lot of the conversations that we're going to have regarding shading is going to be actually about lighting and how to compute light reflectance off of surfaces because based on that light reflectance we're going to have some parts of the object that's going to be dark and some parts of the object is going to be bright so you may or may not have paid attention to how things look like in the real world and what parts of objects are darker what kind of parts of objects are brighter but you all have a very good intuition about how light works even if you haven't ever thought about this you have a very good institution and you can tell by looking at this is that probably there's light above right even if you don't think about this too much you can tell by looking at this image you can infer the 3d shape of this object because your your brain is sort of wired to understand this lighting and just from this lighting and from this this uh let's call it shading you can actually tell the 3d structure so getting this lighting and light reflectance of the objects right is very very important so we're going to talk about some basics of that whole procedure today as a part of our discussion on shading so let's do that but let's not start with with teapot right away let's start with something a little bit simpler a flat plane how about that now again this flat plane looks dark because i don't have light yet so if i just put a light on top of this where i'll finally see its color yeah it was it was red but we couldn't see that it was great because because there was no lights so when we have light we can see that it's red now this light is coming from now i just put a light figure here just to show you that there is light above here but don't think about this as like an actual light source or anything it's just some light is coming from above that's what i'm trying to say here right and so let's let's say that this is my light direction my light direction is towards up and i'm going to represent my light direction with this omega symbol here omega is going to tell me where the light is coming from in this case light is coming from above right so if i take this plane and i rotate it what's going to happen if i rotate it a little bit oh it's getting a little bit darker you see it's getting a little bit larger my light direction is still up but my i rotated my plane i'm going to rotate it some more some more such that it's almost in the same plane as my light direction it's almost black now it's not quite black it's still reddish but it's almost black if i rotate it a little bit further ah now the light is sort of on the back side now it's completely pitch black right and i can rotate it a little further yeah see it's completely black on this side because light is coming from the other side of the surface from from this side there's no light coming in so it's black on this side so if i rotate it back and still black if i rotate some more and now i'm starting to get sunlight on the surface and i'm rotating all the way back now i'm fully getting some some light on the surface and i'm getting its full color so let's let's see what's going on here and why this is happening so we can actually quantify exactly what's happening here uh so for that i'm going to do a different view so let's look at it from from from from this cross-section view and for that i'm going to look at a beam of light coming from this light source right a beam of light it's just coming and and hitting this surface so in this case this this beam of light is eliminating a portion of my my surface here like this portion that this this light beam fell on this surface and it eliminated this portion right and in this case in this specific case my light direction omega is the same as my surface normal so my surface normal is perfectly aligned with the light direction right so you can say that the light direction is perpendicular to to this plane all right everything's good all right so what i'm going to do here is that i'm going to take this plane i'm going to start rotating it i'm going to rotate it this way now let me rotate it just a little bit uh you see now the surface normal is not aligned with my light direction it just moved a little bit let me rotate it some more so you can actually see the difference you know what i'm going to rotate even more all right over here there's quite a bit of difference here's what happened this light beam that eliminated this this small area on the surface now it's spread to a larger area on the surface the same light beam but now it's spread over a larger area on that surface right and it all depends on it's all based on the angle between this this light direction and the surface normal that's that that let's call it theta theta is the angle between the light direction and the surface normal right so let's let's investigate what's going on here for that i'm going to move this side you know what i'm going to zoom in a little bit so we have more space to work with just going to you know zoom in it's just tell the same white beam so before i rotated this plane before i rotated this plane it was it was flat like this right and let's say the length that's in this 2d cross section the length that my light beam covered let's call it unit 1 so that my light beam was eliminating some some length that was let's say call it one unit all right after i rotated it now it's spread over a larger area let's give it something let's call it s now now that i've rotated it it's spread over an area that's um as long as s so if the light per unit area here the light illumination light per unit area in this case was let's say out if it was l after i rotate it now it's spread over a larger area by s so after i rotate it it's going to be l over s right so this was l over 1 which was l now it's going to be l over s because it's spread over a larger area so that's why when i rotate it i will expect this to look darker now because it's receiving less light per area does that make sense because s is greater than one obviously now but how much greater than one can we exactly say how much it is based on this this angle theta over here because that's that's going to determine everything right so if that angle is theta that angle is theta uh this angle is going to be pi over 2 minus theta right because uh light direction was perpendicular to the plane so this has to be pi over 2 minus theta and this is pi with 2 minus theta this remaining angle here must be theta because my surface normal is perpendicular to the plane right all right so based on this can i form a relationship between you know that that tells me what s might be uh yeah that's going to be cosine theta so what is cosine theta cosine theta is going to be like this is a right triangle right so it's going to be this length which is 1 over the hypotenuse that's going to be 1 over s all good and if cosine theta is 1 over s and i want to get this quantity that quantity becomes l cosine theta right so from this i can see that the amount of light i receive on the surface scales based on cosine theta so that's going to determine the amount of light per unit area that i'm going to get on the surface this cosine theta and we call this cosine theta the geometry term and that's going to show up in our shading equations uh and and much later too and this geometry term is going to determine how much light i'm receiving per area on the surface of my material that's why it's very very important and it's purely based on the geometry geometric relationship between the the light direction and the orientation of the surface all right that's why we call it the geometry term it has nothing to do with what kind of surface i'm like what what's the color of the surface i i don't care that's not what i'm talking about it's just about what percentage of the like how much the light is scaled based on the geometric orientation so this is the geometry term all right and i'm going to repeat this again this cosine theta is the geometry term it's gonna be it's gonna come up many times i'm gonna when i say geometry term i would like you to understand that i'm talking about this cosine theta okay all good all right let's move on let's get back to 3d again so here's our plane and in this case the light direction and the surface normal is aligned now instead of rotating this plane this time i'm just going to move the light source i'm going to get the light from it different directions that more of the light sort of see it got darker did you see that did you see that so it was brighter over here and it got darker how long is it all right and it all depends on this angle between the surface normal and the light direction now i said this was red how did i do that well i had to you know specify that i said that my material this material on this surface was red so let's give it some name let's say kd for reasons why that that will be a little more clear later on i'm going to call this kd for now uh and this was red and you see it's not the same shade of red now this is a little bit darker it's a little bit darker because light is coming from an angle so what i see here is more like kd times cosine theta kd times the geometry term all right so to be able to figure out this color that i'm supposed to see on the surface i need to compute this cosine theta now presumably i know the light direction i should know the light direction and i should know the surface normal so and this this kd must be given to me and i should be able to compute this cosine theta k b times cosine theta and that would be very easy can you compute the angle cosine of the angle between two vectors very very easy especially if these are these are unit vectors yes exactly that's going to be the dot product so the dot product of n and w the order does not matter because this dot product this is going to give us cosine theta cosine of the angle between them and this is a very very important identity we're going to be using that a lot this is this is very very important now this only works because both of them both of these are unit vectors right they have to be unit vectors if they're not unit vectors then dot product is going to be scaled by the length of the vectors so yeah they're supposed to be in vectors such that we get cosine theta now i can do this right so if my surface color is red then i just multiply it by the geometry term and i get the the proper shading color of the surface that i'm supposed to see all right but what if i'm using a texture on this surface what do i do then uh things are getting a little bit complicated i just don't i don't have just one color i have a ranger colors based on the texture right now in that case the texture is going to be my color all right so my color is going to come from this texture so my kd is not red my kidney is whatever the texture is whatever the texture value is at that point on the surface all right so i'm just going to sample the texture on the point that i'm trying to shade and i'm going to multiply that color by this by the geometry term uh another thing that i haven't considered here is the intensity of this light right i mean the light intensity is going to have some some some value like if the light is kind of not very strong it's it's things are going to look dark obviously right if i have a very strong light then things are going to start to look really really bright so yeah there's this geometry term yes but things also depend on this light intensity term right and it's not just the light it's not just a magnitude of intensity light can't have light sources can have colors right if the splice was tinted in some way i'm going to see that tint on the surface as well right i mean you've all seen this if you have colored light source on a material you're going to see that color on the material right so the color that i'm going to be seeing on the pixel the pixel color is going to depend on all of these terms the the lights this is the color term light intensity including its color multiplied by the geometry term multiplied by my surface color right and this this type of material is what we call a laboration material or diffuse material so this d came from diffuse this is so this is the diffuse coefficient that's why i'm calling it kd and this is a color value but it can come from a texture and this is the the color or intensity of my light source and this is the geometry term and if you multi when you multiply them all together i'm going to get the the final pixel color that i'm supposed to see all right so when we're doing shading with a liberation diffuse material this is going to be the equation that we will be using and we're going to get different variations of the surface color based on this equation it's going to be purely based on the geometry term and of course material property and the light source so here is an example flam version material on our lovely teapot in this case i'm using a more reasonable texture on the teapot so now we have a wooden teapot right so this is what a laboratory material would look like looks fine but i have you know parts that are darker parts that are brighter actually uh the lighting here is a little bit complicated so if you're if you're trying to see where the light is coming from if you if you can't this is understandable because um for eliminating this i'm using multiple light sources not just one light is coming from in multiple places but there's still you can still see some color variation here like so the bottom over here is a little bit darker and over down here is a little bit darker so you you still have some enough information to tell what this shape looks like now the thing about this material is that it's a little dull so it's like a a wooden teapot that's not polished right it's it's kind of rough it's not a very smooth and shiny surface because it was if it was a smooth and shiny surface it will look more like this now this one looks shiny right rotate both of them you'll see that you know that this one this one is shiny this one is kind of dull now this one the one above is just diffuse only it's a lamborghini material it only has diffuse type of reflections on the surface so light reflects diffusely as we call it so the other one has what we call specular reflections on that and these specular inflections is what gives this gives it this this shiny look to it all right and so that's that's very important to to to do let's uh let's see how we can get shiny objects and uh shiny materials now these specular reflections you can think of these specular reflections as the reflections of our light source so if i move this light source from certain angles i might start seeing the reflections of the light source and that's exactly what these specular reflections are so if i move this a little further you'll see that the uh these reflections are going to be somewhere else these specular reflections are going to be somewhere else and and they will move as i move my object or as i move the light source so you will just sort of dance around on the object so unlike the diffuse diffuse component diffuse reflections that are sort of attached to the surface right so that was the surface color it was a either we put a brick texture or we put a wood texture they were attached to the surface but these specular reflections are not sort of they don't look like they're attached to the surface they sort of move around as i move the light source right they're almost moving with the light source all right so if you look at this these these teapots uh you see that specular reflections on this teapot are sort of moving around right i mean they're kind of like staying exactly where they are and the tea party is rotating that's what it looks like but on the teapot they are moving because the the teapot is rotating right so they're not they're not attached to the teapot that's that's what they look like and there's a good reason for it because where you see the specular reflections depend on where you're looking at it from so your view direction becomes very very important right so let's see how we can handle specular reflections again starting with a plane like this but i'm going to look at it from side view so of course we have our light source light is coming from somewhere and this is my light direction but this time i'm also going to consider the viewing direction so i'm going to put my camera somewhere and i'm going to look at that viewing direction let's call it v d is going to be my vector for the for representing the viewing direction all right now there are various ways of computing these specular reflections there are various material models with with different types of computing these specular reflections so we're going to start with one of the simplest materials and one of the first materials used in computer graphics that's going to be the the phone reflection model the foam specular bubble foam specular reflections now this foam specular reflection model will use the reflection of my light direction so i'm going to take this vector and i'm going to reflect this vector off of this plane in the perfect reflection direction and i'm going to call that direction r so r is the perfect reflection of my light direction so if this angle is theta which it is we call that beta this angle over here is also going to be theta right because it's reflected that's how reflection works now from specular model we'll look at the difference between this perfect reflection direction and my view direction now we said specular reflections are reflections of the light source right so if i'm looking at this from the direction r i should be able to see that light source right it's going to be like perfect but if i'm a little off it's not going to be i'm not going to see it as much it's going to be maybe i'm not going to see it at all if this is a perfectly perfectly flat object but if this and it's perfectly smooth but if it has some roughness to it and some little bit of roughness to it this reflection is going to be blurred a little bit so i should still be able to see some reflection from this v direction as well right so this foam specular reflection model is going to look at the angle between this perfect reflection direction and the viewing direction and let's call that angle phi right and it's going to look at the cosine of that angle because cosine is easily computed to some power alpha all right some some exponents alpha and i'm going to pick that exponent how i pick that exponent will determine how rough the surface is if it is perfectly smooth then i need to pick a very very large alpha i'll we'll see some examples if not i'm going to pick a smaller alpha value and how do i compute this cosine cosine phi again dot product right it's going to be the dot product of v and r both are unit vectors again so their dot product will give me the cosine of the angle between them so this point specular reflection model will be based on this term the angle the cosine of the angle between these two directions and of course i'm going to have some term telling me how shiny the surface is uh so let's call it ks this is like the specular specular coefficient of my material and so these two things a ks and this alpha exponent they are going to be my material properties so they're going to define the the kind of material that i'm using for this play for this object okay and of course of course of course i need to multiply this by the intensity of the light source right kind of makes sense just like we did for the the diffuse reflection so multiply the light source intensity by my specular coefficient and then the cosine of the angle between these two directions to the power alpha that's going to give my phone specular reflection term all right so that's how the the foam model works and if i put this on a material if i combine combine this whole thing the foam material model is going to look like this so this is the the one that you should recognize this is the liberation model that we talked about earlier the diffuse model and this is the phone specular component so this material model has a diffuse component and the specular components so the material has diffuse reflections along with specular reflections right so just like the teapot that we looked at it still has the diffuse wood texture on it also has some shiny reflections that are coming from the specular component right now chaos is a colored value so that will tell me how much specular reflections i'm going to have if this if ks is black that is 0 0 0 that means i i won't have this term the the material will look completely liberation if chaos is some colored value like it's typically going to be white or some shade of gray that's typically what it is in most materials so it's not going to be tinted it can be tinted in some materials but oftentimes it's going to be just a just some some gray value so it's going to tell me the the the magnitude of the the specular reflections now this term is going to determine the shape of these specular reflections and i'm going to show you some examples of that in a little bit based on this i can tell how wide the specular reflections are on the surface so that's that's going to control the shape of the specular and this is going to control the magnitude the of the specular reflections all right so you see both diffuse and specular terms are multiplied by the light intensity here so i can just take that by intensity out of out here this looks a little more reasonable right okay now is this something that's bothering you when you look at this equation anything bothering you because something should be bothering you something should be bothering you so here's the thing this cosine phi term i said that's the phone model phone came up with it and and we've been using it as the phone model it's okay right this is where it came from where did this guy come from remember this this is what the geometry term yes it's the geometry term and it depends on the geometry of the the surface and the light source right and it depends on what percentage of the light is received per unit area on the surface so it doesn't depend on the material property or anything right so why is this not impacting my specular term it kind of should right i mean shouldn't it it kind of determines how much light i'm receiving on the surface so it should it should look more like this right i mean this should be the light and i should multiply this specular term with that but no we don't do that we don't do that and there's a reason because in the following material model there's actually a hidden one over cosine term here all right so that's why we're not doing this and if you omit this if you omit this cosine theta then the phone model becomes the modified form material model if you don't include that and use this equation that kind of makes sense you'll get the modified foam material model but foam material model is going to have this one over cosine theta here now uh doesn't if this looks like a hack to you yeah kind of it is a hack because back when phone came up with this idea and wrote his material model he didn't really write it in this form so and we added it later when we realized that oh the what phone was doing here in the diffuse store was actually the geometry term that that terminology came to the computer graphics community much later on so yeah i mean this is a newer form of writing the foam material model but this is this actually makes perfect sense there's a there's a very good reason why you would have this one over cosine theta which i'm not going to explain because just explaining that it's going to take a very long time for the time being just take my word for it that this actually makes sense that you're you are having a one over cosine theta here and that's how you would get more i'm going to say reasonable looking specular reflections that way i don't want to say realistic because this is not a physically based model this is like a more like a perceptual model you look at it then you say oh most objects kind of look like this so let me use this term and that's what phone did back in 1970 something and it was good it still works to some extent so that's the fun model so this is the hidden cosine so if you if you google this you're not going to find this form of the equation you're going to find this form of the equation because for historical reasons this is what phone wrote but i want you to understand that this is the geometry term okay this is not the diffuser no this is this is not specific to diffuse all right this is the geometry term this tells me how much light is coming to that surface all right actually actually this is not even complete uh because this cosine theta can be negative right i mean if the light is coming from behind the surface this cosine theta is going to be negative which is going to be bad i don't want that i mean what is negative elimination anyway makes no sense so i don't want the negative point so i'm going to actually write it in this word right so so when i write in cosine theta i'm just it's it's shorthand form of of this but this is actually what i mean if the light is coming from behind no i don't i don't want that light i don't want the negative light alright so this has to go yeah this needs to be positive or zero right actually same goes for this guy i don't want this to be negative either because that would make no sense so let me get rid of that too yeah this has to be positive i don't want that to be negative as well actually you know what if the light is coming from behind i don't want any specular because that would make no sense like it's coming from behind the surface and how would i get specular terms so you know let's take this out over here and divide by cosine theta so this is actually implementation wise this this looks more like it okay so if your cosine theta is negative then you should say okay there's no illumination throw it away shading is black nothing but if it is greater than zero then you don't have to multiply and then divide by the same number of course so you can just uh you know omit this this piece and omit multiplication by this as well when you're implementing something like this right but you know this is the idea and and remember this cosine theta term is just the dot product between the surface normal and the light direction and similarly the cosine phi is the dot product of the perfect reflection direction and the direction so the only thing i haven't told you about how to compute this is how to compute this r presumably all the others will be given to you but not r so let's see how we can compute r is not actually fairly easy i can start with taking that like direction omega and just inverting it if i invert it it's going to be this guy over here right and then i'm gonna i'm gonna see i'm gonna go in the surface normal direction from here to there and for that i will use the projection of omega on the surface normal and what is this that the length of this the length of this is going to be well if this is one because it's a unit vector its length is one this is going to be cosine theta right that this length is going to be cosine theta so it's going to be omega dot n and it's in n direction so i can write it as omega dot n in n direction surface normal direction all right so i can put one of that over here that will get me to this this point on the surface and i can add another one that will get me to the perfect reflection direction so if you combine it all the perfect reflection direction can be computed by two times this guy minus omega right so two times omega n times n minus omega that's going to give my perfect reflection direction and we're gonna we're gonna do stuff like this later on so it's a i i think it was it's it's good that we talked about this at least once all right now i'm going to show you now we talked about all the math stuff all the math stuff is gone i can show you some examples of what forming material model will look like now for these examples i'm going to start with a very unreasonable example so here is here's the unreasonable parameters my diffuse color is perfectly red my specular color is perfectly white and my exponent is one so exponent one does not make much sense you did you see this uh really reflective kind of shiny thing it's a little weird so let's uh i'm going to keep the color values the same even though these are not great i mean if i'm getting this much specular reflections from a realistic surface this color should be darker but i don't want to keep it dark i want to keep it sort of bright so that's why i pick these values so these aren't going to be very realistic but you know it will give you an idea about at least what this exponent does so let me crank up this exponent to two you see that specular reflections became a little narrower right and if i crank it up some more to five it's gonna get smaller to ten even smaller to twenty even smaller fifty you have a smaller 100 right uh 200 you're getting small you get the idea right 500 to the power 500 it's not a very unreasonable parameter to use for this actually about a thousand you know what 10 000 right so if your surface is really really smooth really really smooth this would be a very reasonable parameter to set for it and actually a on a perfect mirror this would be infinity so 10 000 is a lot smaller than infinity i would say by how much infinitely smaller than infinity alright so going back to math this is our four material model now this is just one material model two and after the four material model jim blend came up with a his own material model so it's a little bit different it's a little bit different in the way that the specular component is computed so the blend material model will not look at the perfect inflection direction it's going to look at something else it's going to look at what we call this half angle h at that half angle is the angle between this light direction and the view direction so it's half half angle is going to be the direction between these two directions so the angle between omega and h is going to be equal to the angle between h and v right so it's going to be the half angle so how do i compute this half angle it's actually very easy i just add these two vectors v and omega and normalize it just add these two vectors normalize it that's going to give you a unit vector in the direction of h and so this is how h is defined so h is a unit vector exactly between uh omega and v the like direction in the v direction so the blind material model is going to use the same equation but it's going to define this phi differently phi is going to be the angle between the surface normal and the half angle and that's going to be our blend material and of course i can compute cosine phi by taking the product of these two vectors right so and that h is going to be cosine phi so this puts this now um the foam material makes immediate sense you'll look at the perfect reflection direction and you're around the perfect reflection direction this one does not make immediate sense so let me try to show you a little bit of an intuition of what's happening here so if you compare the blind and phone models so phone model is looking at this angle over here right and the blinn model is looking at this angle over here so if i move my camera if i take my camera and move it towards the perfect reflection direction this angle is going to disappear right it's going to go to zero and so will the other angle so if my view direction is exactly along the perfect reflection direction then my surface normal and the half vector they're going to be completely aligned as well so the angle between them is also going to be zero but if i pull away from it in this 2d cross section the defy angle that's the blind model uses is going to be exactly half or the fire angle of the form model uses right it's going to be exactly half of it but that's not the case in 3d so this is only the case when surface normal incoming light direction and the view direction they're all are on the same plane and they don't have to be on the same plane they can be on different planes in 3d if they're on different planes then there's this relationship between these two five definitions is not going to hold uh they're going to be different so what what blind does what blend specular model does is that it changes the shape of the specular lobe it's going to take a different shape now than the foam material so let's see a couple of examples to see what that will look like now here's the phone model and over there is the blend model as you can see the phone has a larger specular load but it's also sort of like elongated based on the surface direction right and this is more circular so blend would give you a more circular shape than phone and blend argue i believe a lot of people agree that this is a more realistic looking specular reflection shape that's more representative of what light actually does so if i crank up this exponents both of them will get smaller again they're looking at different angles so actually like the same you're not you're you're not gonna get so if you wanna get similar looking specular reflection size with blended foam you should use different alpha values but i'm using the same alpha value for these these two just so that you can see how they differ this is going to have this sort of elongated shape and this is again having the circular shape and you can even see it if i crank it up to a thousand over here ten thousand i'm not sure that you can see but actually there's a little bit of difference right okay so this is the blinn model and the phone model and they all look very similar there's there's one thing that's a little bit um a little bit of a problem for both of them though and now we get light we get shading only the part of the surface that is facing towards the light source this other part of the surface is this back side of the sphere here i'm getting know what what i mean is i'm getting literally no light no shading is pitch black and it's not just this point at the back anything on the second half of this is going to be pitch black like the one hemisphere is getting some light and the other hemisphere is getting absolutely no light so it's going to be completely pitch black so yeah in this case it's not that bad but what if my background was black now my sphere sort of disappeared i don't even know the backside exists there right i can't even see it at all i don't even see the the shape of my model anymore so this is a little bit of a problem because that's not quite what happens in reality in reality there's always light coming from all directions in some ways now we're going to talk about that and we're going to talk about how to compute that but computing that is actually very expensive very very hard back in the 70s it was really really expensive even today it's very expensive back in 70s it was like well we can't even think about doing that so they came up with this very simple idea it's still used today the idea is having some ambient light just have some some light around coming from all directions this ambient light term uh and that ambient light turns it's gonna add some light to everywhere and if you add sunlight to everywhere you're gonna start seeing something on the surface right now if i add some ambient light i can see that oh this was a sphere it's not completely lost in the blackness of my background it's actually visible now so it solves that problem so things are not sort of unrealistically dark like pitch black dark and i can control how much ambient light i want in my scene and i if i put it inside my bling phone material model i'm going to have the you know the diffuse term i'm going to have the specular term and i'm going to have this ambient term here now in this case i have this ambient color of my material as a parameter just multiply by the ambient light so this i a is different than this i this i was my light source ia is just some some ambient light defined independently all right and this this is my ambient coefficient of my material now this looks a little funny all right i think you guys understand where this ambient light is coming from it's actually not coming from anywhere realistic it's just coming from a necessity that i want to have some lights everywhere right i don't want anything to be pitch black because that was that's not very realistic so it's a very very crude approximation of light being in coming from all directions in more realistic scenes but where this ambient material term is coming from this is this is a little strange to have an ambient material color like what i mean you can understand like this is the color of the surface diffuse color is the color of the surface this is the reflections of the light source all right the specular reflections i mean i can understand what these are this is like if i have a a wood texture that's going to be this this wood texture right and if this is going to be just how shiny that is on the surface and this is going to be the shape of that shininess how smooth the surface is but what is this it doesn't make any sense to have an ambient color term here for my material so most of the time even though it's a material term i'm going to say that my ambient color is going to be the same as my diffuse color most of the time the typical thing to do is to say that they're the same they don't have to be a lot of software will allow you to specify this this color independently just to give artists a little more control so if you see this don't be surprised it's actually exposed to the end users but you can actually control it but most of the time what makes sense here would be to use the diffuse color as your ambient color right so if it's not given to you you you would use a diffuse color okay and that's exactly what we're going to do in the in the project all right so this is shading using blend and phong model now when people talk about the bling foam model they sometimes called blind model bling phone model they're talking about the blind model um say blind slash material model because it's the same equation the only difference is how i define this this angle phi that's the only difference between these two material models okay that's all i had in mind about computer shading in our remainder of our time i would like to briefly talk about how to how to handle light sources in computer graphics there are various ways of handling light sources in computer graphics so i'm just going to briefly talk about this i'm not going to go into a lot of detail uh over here this is this can be a very very extensive topic on its own but i i don't think it's it's too fundamental it's important that we get the basics and so i'm just gonna cover the basics here there are various different light types that we can define we we use in computer graphics here's some some illustrations of different lights on the sphere and what they look like on the sphere and on the walls and on the ground with shadows and everything the the simplest one that you can think of and the one that we're going to be using in our upcoming project is the directional light the directional light is the example is far at the end over there the directional light is going to have just a very simple it's going to have a light intensity and direction so it's light coming from saturn direction whatever that is that's going to be that's going to be the directional light source very very simple it's actually a pretty decent approximation of a light source like the sun so sun is far far away so for all intensive purposes you can assume that sunlight is coming from just one direction right you set the direction for your scene it's always coming from the same direction yeah there's a little bit of a variance depending on where you are at any point that's going to be slightly different because you know sun is not coming from the same direction everywhere on earth at the same time right but since our scenes often times are much smaller than the earth's surface itself it's it's a good approximation and it's okay so directional lights are actually used fairly often and they're often used for as a replacement for a light source like the sun the other one is going to be um points or spot light source a point light source is just a point that emits light it's one of the simplest light forms used in computer graphics because of its simplicity exactly point wise are used a lot they're very very popular even today not the most realistic light sources because they're just a point and a point does not have a size of anything so i mean realistic objects have sizes points don't have a size so yeah uh so it doesn't they're not very realistic but they are a good replacement for small light sources if you have a small light bulb somewhere so what does small mean small in the context of your scene right one i don't know i'm rendering a giant hole and there's some light source up on the ceiling maybe it could be a point light because it's very small as compared to the rest of my scene so i might as well just approximate it as a point light and that would be fine right so point lights are used a lot the other variant of that is spotlight spotlight is a point light that doesn't just um unlike point lies that eliminates all directions just emit light in all directions spotlights will emit light in certain directions only so there's going to be a spot angle and the spotlight will eliminate this illumination only along that direction so as you can see over here the point light example is eliminating the wall really nicely because it's eliminating all directions but in this case the spotlight it's very much like a point light with a spot angle around it it's not directly eliminating the wall sort of eliminating the wall but not not everywhere right it's eliminating only a part of the wall that that is contained in that in that spot direction right so that's a that's a spotlight of course it will come with additional properties so a point lights is going to have intensity and position so if you want to know the light direction you're going to have to compute it so there's this point a in my scene in 3d and i want to know where the light is coming from from what direction i am just going to have to compute the vector from this point towards the the light position and that's going to be my light direction right so for any point in the scene i'm going to have to compute the light direction if i'm using point light sources if i'm using a directional light source i already know my light direction it's a parameter of my light source so it's it's already given to me but for point lights i need to compute it same goes for spotlights uh in addition to being a point lights i need to check whether that direction is inside this this spot angle if it's outside that spot angle i'm going to say okay no light is coming if it is inside then i'm going to say some light is coming so those are the simpler light sources we have in computer graphics the other more realistic light sources the more modern light sources that we use more more often in especially for offline high quality rendering and also some in high quality real time rendering is going to be aerial light sources now these are more realistic because these aerialized sources will be a much better representation of objects that have some size think about area light sources as like surfaces objects in reality are volumetric but we represent the in computer graphics as surfaces right same goes for light sources light sources have their own volumes right there sizes and masses but we represent them as their surface areas so when we say aerial light source don't say like it's a flag it doesn't have to be flat it can be flat like a rectangle light source or a disk light source or it can be a sphere or it can be some arbitrary polygonal mesh i can say teapot my teapot is a light source it can be a light source and you can use it as a light source and that'll be perfectly fine but now how do you compute the light direction from an area light source uh and that's gonna be a little tricky right because okay for directional light source it was already given for point light source i could just compute the direction for an area light source i don't have just one direction now now i have like a range of directions that correspond to that area and so that's going to be a bit tricky so computing aerialized sources working with aerial light sources is going to be computationally a lot more expensive for some specific cases there are ways to sort of compute it relatively efficiently but but but in general computing lighting from aerial light sources it's going to be a bit more tricky and also doing shading with area light source is going to be tricky right because with with shading i need to know the incoming light direction but if my light direction is a range of directions like how do i do blind shading now that's not it's not going to be that easy right i kind of need to look at an integral over a surface or something yeah that's literally what we're going to have to do that's that's literally how it works and there are different ways of computing that integral we're going to talk about a part of it later on so but for now just know that you know these are more realistic light sources are light sources and they do exist and they're very very helpful and they're going to be a lot more expensive to compute the final type of light source that i'm going to talk about that's not given as an example down here is going to be a skylight or an environment light imagine imagine that you're in a sunny day there's sunlight of course sunlight is the dominant light source and maybe i can approximate it as a directional light like this but there's also light coming from around me uh from the atmosphere and that type of light can be represented using what we call an a skylight or an embodiment light so that's going to be the light coming from all directions it's not coming from specific objects per se like this mesh light it's coming from directions that are far far away going all the way to infinity and they're coming from from all directions they may be the same amount so i can say i can have a skylight with a constant color value in that case i i'm basically saying i have this constant light coming from all directions all directions that you can think of i have the same light coming that's going to be a constant skylight but oftentimes i'm going to use some function to determine the amount of light coming from all directions so given that direction i'm going to compute that the amount of light coming from that direction i can have some procedural function for that or i can just use a texture i can just use a textured image and that image tells me how much light is coming from all directions like imagine like a giant sphere encapsulating my entire scene that seems that sphere's radius is infinity quite literally infinity and my scene is centered on that infinite sphere and i have a texture on that infinite sphere that will tell me how much light is coming from all directions so that's going to be a skylight or an environment light and i can use that environment light also as the background so my camera is looking in some direction whatever i see as the environment light could be the background of my camera image and this brings us to the concept of image based lighting so i can take an image i can actually even take an image of an actual scene and i can use this as an environment image i can form like a 360 environment image of a scene and i can use that for doing lighting they use that a lot for special effects with live action actually so in a sense they would take the light measurement coming from all directions so when you put a virtual object in that scene it can be eliminated by the same elimination environment that exists in that city and that's the the concept there is the image-based lighting so here are some here's an example of image-based lighting using a sphere using three spheres with three different materials on them so as you can see we have some very nice reflections of the light source reflections of the light source that's the environment light that's basically the environment image and we're getting some super nice shadows underneath that down there and fairly you if you look at this white sphere uh you see that some some color variations color sort of changes it's very subtle but these kind of subtle differences is what actually sells this image and what makes it look realistic when when you look at something like this so image based lighting is a very very powerful tool for generating realistic images of course there is a lot more that gets that has to get into generating an image like this you need to have realistic material models i'm not sure what material models these use but if they're not blend phone i'm i'm not going to be surprised so the image based lighting is just one component of getting this realistic looking image there's going to be other components there as well so but talking about lighting i talked about image based lighting as well but most of the time what we're going to be concerned with is going to be just point lights and directional light sources in this course all right because those are simpler light sources all right so that's um what i plan to cover for today just one thing that i realize i haven't specifically told you what happens if you have multiple light sources in scene let's say i have two light sources and i'm going to do blind shading how am i going to do that i have light source a i have light source b which one am i going to use am i going to use both of them and if i'm going to use both of them well i should probably use both of them how am i going to combine them am i going to take the average light intensity or am i going to take the average direction so something like blended light source no that's not how light works light is additive all right so you compute the reflections from one light source that includes diffuse reflections and specular reflections and then you compute reflections of the other second light source and you add them on top of it if you have a third light source you add that one too in your fourth light source you add that one too just like we added the the ambient light source right we added the ambient light on top of the diffuse and specular just like that for any lights you're gonna have the diffuse and specular components and you will add them on top of the other light sources right so it is it is additive keep that in mind when you're dealing with multiple light sources but luckily in the upcoming project we're going to be dealing with a single light source so that's going to be a little bit easier not a lot easier just a little bit easier all right so i'll end it here then thank you all for sticking around till the end your slice bag thank you i'm happy that you like them i'll have more coming next time all right thank you all i'll i'll see you all next time
Info
Channel: Cem Yuksel
Views: 1,619
Rating: undefined out of 5
Keywords:
Id: Xg6KEmhqHCY
Channel Id: undefined
Length: 62min 58sec (3778 seconds)
Published: Fri May 28 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.