What Are Shaders?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone and welcome back this is the happy cat here and today's video is sponsored by Skillshare and we're gonna take a look at the absolute basics of shaders what they are and how they work this topic can get confusing pretty quickly so we're gonna stick to very basic examples in this video with some more advanced further reading in the description below and in further videos so let's get started a shader is a set of instructions to the GPU which are executed all at once for every pixel on the screen so you might give a shader a pixel at a certain position and it returns a new color for that pixel for example a shader could say for all pixels look at their RGB value their color and add 50 to the blue value for all pixels so this adds a blue tint to your entire image and we could take that further we can create a gradient by instructing the shader to increase the blue value as the x-coordinate of a pixel increases so that we have less blue on the left and more blue towards the right we could also add some motion over time by using wave functions like sine and cosine - let's say alternate a red and blue tint I think it's important to develop a certain intuition when you're starting to think about how to solve problems with shaders if you notice we're not saying for each frame slowly change from red to blue we're using a deterministic equation we're using a sine function that doesn't care what frame it is that doesn't care what any other pixels output is we just feed in a pixels position and its color and then it outputs a new color for that pixel so to illustrate this let's say we want our shader to create a checker pattern so pixels alternate between black and white we don't say if the previous pixel was black make the next one white instead we might say if the current pixels x value is even and the y value is odd color it black and then alternate depending on the even and odd coordinate some of the pixels because this is completely deterministic and completely blind to what any other pixel on the board is doing now let's say we have something a little more complicated like applying lighting to 3d objects in this case we need to use some equation to calculate what color each pixel should be to apply the highlights this is where we may need some additional information like maybe the normal vector and a lighting vector for the area we're calculating common examples of these equations are the lambertian reflectance model for diffuse lighting or lighting on kind of rough or soft surfaces and there's the Phong reflectance model for specular lighting or more of like shiny surfaces which we can go into more detail in a future video while those are considered more standard models we can do some artistically interesting things with shaders and lighting for example cell shading is a type of shader where it gives a cartoony flat 2d look to 3d models you also hear it called a toon shader it achieves this effect by using a few discrete colors to represent light and shadow rather than having a sort of realistic gradient blend between the lights and darks let's look at this from a technical side conceptually how does cell shading work let's say we're calculating the lighting on Wind Waker links tunic for each pixel we calculate the intensity of the lighting if the intensity is above some number X we may color light green if it's below as we color dark green this is in contrast to a more may be realistic shader where instead of mapping and bucketing different intensities to two or three colors we would find the closest green to the decimal value of the intensity so the shade slowly gets lighter or darker note that this example is kind of simplified but there is a link in the description to a very readable example of this kind of cell shading code another artistically interesting use of cell shading is the game Okami I think Okami is interesting because it uses very little of this dynamic lighting you can see the people and buildings and trees are all very flat there's almost no dynamic shadow it's mainly the shadows and details are painted on the models themselves rather than changing with a light source and this lack of lighting makes them look like flat paper cutouts and it enhances the feeling that the game is a giant painting no matter what angle you're looking at anyway guys hopefully this gave you an idea of what shaders are and how they work we've barely scratched the surface so in future videos we will dive into the code and technical details and I've also left as mentioned further reading and links that I think are super helpful in the description below today's video was sponsored by skill share skill shares an online learning community with more than 17,000 classes in technology business programming even 3d modeling and game design premium membership gives you unlimited access so you can improve your skills and do the work you love taught by real professionals Skillshare believes an accessible learning and unlimited access is less than ten dollars a month and we have a promo code whitey happy why tha PPI e in the description down below so the first 100 people to use the promo code will get their first two months to try it out risk-free now personally I've been using it to fill some gaps I have in my skills I've been using it to brush up on Photoshop and graphic design tools and to learn and refresh myself on how to use programs like Maya to do 3d modeling so hopefully you guys enjoy that and hopefully you're looking forward to more content in the coming months but most importantly have a happy day wherever you are and I'll see you guys soon bye
Info
Channel: TheHappieCat
Views: 147,367
Rating: undefined out of 5
Keywords: shaders, shader, 3D, code, cel-shading, toon shader, cel shader, skillshare, thehappiecat, happiecat, happycat
Id: sXbdF4KjNOc
Channel Id: undefined
Length: 6min 24sec (384 seconds)
Published: Wed Nov 01 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.