Atmosphere shader - Tutorial | Unity URP

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone in this video I will show you how to create an atmosphere shadow in unity urp for this video I have a simple scene which is just one planet and a background the background is just one image in this case this is one texture of a space background if you want to learn more on how to create that I have a dedicated video on the topic this image is used in a six-sided Skybox where every face is just the same image this gives you the idea or should I say the illusion to have a lot of stars in the sky we can also use a panoramic Skybox but in this case you only use the image one time and in the scene only have one object in this case the planet Mars is just a simple sphere like a Unity sphere and I attached a material to it which is just a basic material with one texture on it as the base map there's no normal or height Maps and I change the metallic and the smoothness values to zero to have no reflections so to create this atmosphere shadow I'm gonna simply duplicate my mouse object here I'm going to copy and paste it and I'm going to rename this new object to atmosphere as you can see here we have the exact same material which is not really ideal so I'm going to create a new Shadow here I'm going to right click in the browser create Shadow graph urp and then lead Shadow graph I'm going to rename that atmosphere shadow and before starting on the Shader I'm going to create a material right away when I right click on my Shader create and then material I'm going to rename the material atmosphere mat I'm going to attach this new material which is very basic to my atmosphere object right now we're only see independent Mass but we're not seeing the atmosphere yet so I'm going to hide moss and just focus on the atmosphere object right now if you're going to the shadow graph you can see that we have nothing happening everything is very basic and the main component is a Fresno effect so if you right click and select create node or if you press space you can look for a Fresno effect and the moment you see the first known effect known you can see that this looks like an atmosphere I'm going to attach this fresnor effect node to the emission node so we can see in the Fresno effect node that we have this atmosphere shape and one thing we can already play with is to change the power value here if I increase the power value we can see that this looks more and more like an atmosphere I'm going to save the asset right now and go back into machine to see what it looks like and right now we can see we have a bit of an atmosphere look here and I just noticed that here we have a bit of a refraction and so to remove that because we don't really want reflection on an atmosphere I'm going to change the smoothness value to zero this way if I save I can see that the refraction is gone now consider the power value is the main component to have the look of the atmosphere so I'm going to create a parameter to be able to play around with this value directly into the material this way I don't have to go back to the shadow again so I'm going to add a new parameter I'm going to choose float and I'm going to rename that atmosphere size I'm going to attach the atmosphere size parameter directly into the power of the Fresno effect when I change the default value from 0 to 5. so now if I save my assets and I go directly into the material of the atmosphere I can see that I have an atmosphere exp parameter that I can change directly into the material and I don't have to go back into the Shader every time I want to change this value and one thing we can do to make the atmosphere better is to add a multiply node so I'm going to look for the multiply node and I'm going to connect the output of the Fresno effect into this multiply node and the second value of this multiply node is going to be the atmosphere size again I'm also gonna double click on the link to have a clean Shadow graph by connecting the Fresno effect into a multiply and multiplying that by the atmosphere size I can make the atmosphere of my Shader pop up even more I'm going to connect the result of the multiple version into the emission node and if I save my assets and go back to my scene I can see that my atmosphere looks way better and more intense than before my atmosphere is only white so far and in most planets the atmosphere does not look white so here I need to have a corner so I'm going to create a new parameter and choose color I won't rename that because the name in itself is enough I'm going to click on this color parameter and I'm going to change the mode from default to HDR you don't have to change this to HDR however this allows you to have intensity in the colors which can make your atmosphere look even better I'm going to drag and drop the color parameter and I'm going to create a new multiply node I will then get the result from the previous multiply node into this new multiply node and I will also connect the color to it right now we can see that everything is black and this is because by default my corner is black so I'm going to change the default color to something else like something a bit red for example and we can see in the preview here that the color of the atmosphere is different now I can save the asset again and if I look into my material or if I'll enjoyed into my scene I can see that I have two parameters the atmosphere size from before and also the color and I can change the color directly into the material and I can also change the intensity of the corner to make it broader if I want to in this case I'm gonna have a slightly higher intensity like something like two now that we have a color in the atmosphere there's one more issue our atmosphere Shadow is still great in the middle fixing this is very easy by default the surface type of a shadow is opaque but in this case I want something transparent so I can hide what I don't want to see so if I change the surface type from opaque to transparent then I'll be able to control the transparency of my shadow I also need to change the blending mode from alpha to additive now if I go back to my scene I can see that the shadow is now transparent and I can see the stars to the Shader however I still see this great corner here and this is because the base color of the Shadow is gray and if I change that I can see in the preview that changing in the base color is going to change the color in the middle of the Shader in this case I want something black so the transparency can hide everything and now if I go back to the scene after saving my asset I can see that everything in the middle is transparent because we still have the atmosphere on the outside of the Shadow if I turn on back the object for Mars we can see that we have an atmosphere around Mars now something good to do is to move the atmosphere object under Mars so you want the atmosphere to have mass as a parent so this way you can change the size of your mass object or whatever Planet you have however you want and this will also change the size of the atmosphere now we have a nice atmosphere Shader but we can see one issue here if I uncheck the atmosphere object I can focus on the plant mask by itself and I can see that some of the planet is lit and some of the planet is not lit this is because my direction light is only hitting one side of the planet and the other side is hidden however this is not the case for the atmosphere object if I move my directional light around I can see that this is going to change with the lighting is sitting on my object but this has no effect on the atmosphere so we can go back to our shadow and look for a specific node the main light Direction this node can only be used in urp because it gets the direction on light this does not work in hdrp so wherever the light is sitting the node gets the direction of the light and gets the coordinates of whatever his lit and whatever is not lit then I'm gonna get a DOT product node and I'm gonna get the dot product of the main light Direction and of a normal vector if I do that we can see that the preview is showing us a half lead half back object and I'm going to claim this value here between 0 and 1. if you don't claim the value you can have some weird artifacts happening and the shadow is going to look very odd so for example this is what it looks like if you don't claim the value so now I'm going to get another multiply node and I'm gonna get the result of this operation and I'm going to multiply that with what we did before we can see from the preview that whatever is lit here will show the Shader and whatever is not lit where the light is not hitting then this will be hidden so I can connect that back into the emission node of The Shadow and if I go back to my scene I can see that this is kind of working but not as expected we can see that whatever is not lit will show the Shader and whatever is lit will not show the Shader and this is kind of a problem here because we want to have the opposite of that we want to have the dark part not showing the Shader and the lead part to show the atmosphere shadow and to fix this problem there's one simple solution here you need to go back into the Shader and right after the dot product you need to multiply the result of the dot product with -1 this will give you the inverse of what we did before and you can connect the result of this operation back into the clamp node as you can see here we have reverse what's happening and the shadow is going to be working fine now and if I go back to Asin I can see that whatever is lit by the Light will show the atmosphere and whatever is not lit whatever is dark will not show the atmosphere Shader so this is it for this video and I will see you in the next one
Info
Channel: Morrigan
Views: 2,019
Rating: undefined out of 5
Keywords: unity, atmosphere, shader, shader graph, unity shader, 3d, game, tutorial
Id: Vkj0lgRPzbg
Channel Id: undefined
Length: 11min 56sec (716 seconds)
Published: Wed Jun 21 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.