Unity Shader Graph Basics (Part 6 - Lighting Basics)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in part six of this series we're going to talk about lighting lighting is one of the core aspects of your game's Graphics that help to make a scene feel more realistic and a lot of the work is done inside the Shader whether you're aiming for photo realism or a stylized look lighting is key so let's Enlighten ourselves about some of the times of lighting we might see in our scenes I'll assume you have some basic knowledge about vectors first up we have to fuse light surfaces in real life are rarely perfectly smooth and appear uneven when you zoom right in when Light reaches a point on the surface it gets reflected in all directions so the intensity of the light that reaches your eye doesn't depend on the angle you're viewing from the only thing that matters is the angle between the Surface normal and the light source anything above 90° results in no illumination next we have specular light which causes shiny highlights on some parts of the surface perfectly smooth objects reflect the majority of incoming light rays in the same direction when this happens the amount of Illumination on the surface definitely depends on the position of the viewer this is why the specular highlight on a sphere appears to move around when the camera moves around now let's talk about ambient light this one is easy and it's been here the whole time it's a base level of Light app cled to the entire scene which you'll see even if there are no light sources in the scene this can be used to Loosely approximate indirect light balances sort of like how an indoor room can be illuminated by a window the light sources in a scene include actual light objects who manually Place such as directional or Point lights and Environmental Lighting such as indirect light bounces from other objects or from the Sky Box however setting up lights is a bit outside the scope of this tutorial because I want to focus on how lighting Works within the Shader on that note let's right click in the project View and go to create Shader graph urp lit Shader graph and name it lighting example when we open this graph we'll see far more things in the output stack than we used to unity's LIT Shader uses what's called physically based rendering or PBR which essentially means we tell Unity about the physical properties of object what its base or albo color is how rough the surface is whether it's metallic or non- metallic and from this information Unity automatically figures out how much diffuse and specular light should appear on the object we don't need to worry about the lighting calculations ourselves for this tutorial I'm going to use a grass texture from ambient CG it's the same one from part two of this series however what I didn't mention is that ambient CG normally gives you not only a texture for the base color which is what this is but also textures for its roughness ambient occlusion displacement and normals those are all times I'll cover in a moment let's go through each of the graph outputs in order the base color output represents the albo color of the object this works exactly the same as it does in an unlit graph and you'll be familiar with this from part two let's add a base texture property of type texture 2D then connect that property to a sample texture 2D node and output the result to the base color craft output simple however let's also deal with the displacement texture we got from ambient CG this is a grayscale texture representing how far each bit of the surface should pop out so we also call it a height map black pixels are the low areas and white pixels are the areas we can pass this to our Shader with a texture 2D property called height map texture this height map isn't actually going to change the shape of the object geometry though instead we'll use a node called parallx mapping which uses our height map and some fiddly map to modify the UVS we use for the base texture it's easier to see what's happening on this brick texture which is also from ambient CG than on the graphs on the graph I used the parallx mapping output as the UV input for the base texture sample next up we have the normal texture the normal map feels similar to the displacement map but it is distinct the displacement map was pretending that some pixels have moved away from the surface whereas the normal map changes the angle of each pixel it's like saying this pixel doesn't face the same way as the physical object geometry it should face a bit left Unity modifies its internal lighting calculation accordingly using both normal and displacement Maps like this can yield nice results in Shader Ru I'll add a texture 2D called normal texture and then connect it to a sample texture 2D node we should use the displace 2vs from earlier also we should change the type option to normal because Unity samples regular textures and normal textures slightly differently we can connect the output to the normal graph output next we have the metallic graph out put if you go to graph settings then you'll see that Lit graphs actually have two workflow options metallic and specular with metallic we control specular Reflections by just saying whether the object is a metal or not using a slider between zero and one with specular you have direct control over the color of the specular highlight but it's essentially your personal choice which of these you pick I'll stick with metallic since we don't have a texture for this I'm going to use a float property called metallic and wire it up directly to the metallic output but you can definitely include texture and Sample it for the metallic if you have access to one next we have the smoothness graph output annoyingly ambient CG doesn't give us a smoothness map it gives us a roughness map which is the opposite concept on a roughness map black represents perfect smoothness and white represents a totally rough surface Unity expects white to represent perfect smoothness but it's not a problem we can correct the discrepancy inside the Shader let's add a new texture 2D property called roughness texture and wire it up to a sample texture 2D node just like we've done with all the other textures this time however I'm going to take the red output because this is a grayscale texture we can pick any of the RGB outputs to get the roughness and I'm going to pass it into a one minus node which will invert the values we can then pass the result into the smoothness output let's move on to the emission output ambient CG didn't Supply a texture for this one either but essentially the base color output is influenced by Shadow if we place our object in a dark room then the color of the object gets dimmer emissive color on the other hand does not dim no matter where the object is it will stay lit I'll add another color property called emissive color and this time I will set it mode to HDR this allows us to use high intensity colors beyond the normal range and as we will see when used in the emission output we can create glowing materials I'll wire the emissive color directly to the emission graph output but as I mentioned with the metallic output sometimes you might have access to an emission texture at this point it's worth noting that you need a bloom postprocessing filter to see any glowing a fresh urp project will automatically include one in your scene but if it's missing you can create a new postprocessing volume via game oret volume Global volume then create a new volume profile save it wherever you want and select add override postprocessing blue you might have to change the intensity setting to one and you should see your glue the final lit output is ambient occlusion we've talked about objects that have imperfections on their surface but sometimes those imperfections are a bit more pronounced like holes or hard edges on the surface in the real world light has a harder time getting into those gaps so they appear darker and we can approximate this effect using an ambient elusion texture it describes how much each part of the surface is uded hidden basically from the ambient scene light if in the grass texture the uded parts of the surface would be the lowest down Blades of grass hidden by the others values of zero mean that the object is totally occluded and one means it's totally visible I'll add a texture 2D property called ambient occlusion track it onto the graph sample it with a texture 2D node and connect any of the red green or blue outputs to the ambient occlusion graph output and with that we have essentially recreated the functionality of unity's default lit Shader the one you see whenever you create a primitive match there's a surprising amount that goes into a Shader like this this part is getting a bit long so in part seven I will cover a few use cases related to the lit Shader until next time have fun making shaders
Info
Channel: Daniel Ilett
Views: 4,714
Rating: undefined out of 5
Keywords: unity, shader, tutorial, shader graph, unity shader graph, texture, shader tutorial, vfx tutorial, lit shader, physically based rendering, pbr, specular lighting, diffuse lighting, phong lighting, phong shading, lit graph, unlit shader, unlit graph, cc0, cc0textures, ambientCG, smoothness, normal mapping, ambient occlusion, emissive lighting, glow shader, urp, universal render pipeline
Id: Tjo6mUhqui8
Channel Id: undefined
Length: 9min 50sec (590 seconds)
Published: Tue Mar 19 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.