Awesome skybox shader graph in Unity #unity3d #tutorial #unitytutorials

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hello everyone, welcome back to the channel. In today's video we will create skybox using shader graph. I am using Unity version 2022.2 but it will work on any Unity LTS versions. I have created a project in urp and while you set up yours, let me roll the intro. Okay so we can set any unlit  material as our skybox. So let's create a shader graph and pay attention here we go built-in, then unlit shader graph. Let's call it, Skybox shader graph and double click to open it. Skybox will typically has  different colors over the y-axis or vertically top to bottom. So let's create a position node. We want World position so  let's keep the space at world and now we need to normalize it so let's take the output and  feed it into normalized node. It will convert our position vectors  length or magnitude to 1 unit. I want value between 1 and -1 so I normalized it. Okay we need y-axis so let's create a split node. Feed this output here and this G will be our Y. So let's take that and preview it. As you can see in the preview we  have positive value at the top and while bottom only shows  black it has negative values so very top is exactly 1 the center is zero and the very bottom will be -1. and everything is in between. Okay let's deal with the sky part first so let me take this Y and hook it into the clamp node And clamp the value between 0 and 1. So the bottom half no longer  contains any negative values. Then we want to control this gradient blend so feed its output into the power node. What power node does is, it just darkens the value that are  less than one as we increase the power. Let me give you a quick example, that we have a value of 1 with the power of 2 so 1 raised to 2 equals 1, but the value of 0.5 raised to 2 will be 0.25 So it darkens the value as we increase the power. Okay so I hear you ask why we clamped the values? Let me show you what happens if we directly feed this Y into our power node and it breaks. Basically any negative value is not working. In practice any negative base without brackets with the power of positive value p will give a negative value but somehow it returns NaN error also known as not a number. This is the reason it is displaying pink color. Maybe it's a bug. If you know why it is happening tell me in the comments. Now we want to control this blend from the inspector so let's create a float property call it ZenithBlend and give a default of something like 1 and as you saw problem with negative values, let's keep the mode slider and keep the minimum to near zero so 0.01 and the maximum will depend on the preference so let's try 50. Let's drag that in and feed it to the power node here now we need a color for our sky so let's create another property, color this time. Call it SkyColor. Give default value of your liking drag that in and multiply it with our power output just like that. Time to do the same for the ground. Now we need bottom part, this bottom part. So let's take the Y and clamp it minimum value this time will be -1 and max will be zero So we have a top part with zero all the way to the center and then we have negative values in the bottom. However we need to convert those negative values into positive values otherwise it will break in the power node and we cannot actually tint or multiply it with the ground color as well So to convert them we will use negate node. Which will basically multiplies  values we pass in with -1 so let's grab the output and feed it into negate now we have the ground part. We will follow the same for the blend and color as we did with the sky so let's create another float property. I will duplicate this ZenithBlend and call it NadirBlend drag that in take this and feed it into power and this one as well and then let's create another property for color. Let's duplicate the color, call it GroundColor give a default value drag this one in and multiply with the power output. We can just add these two, let me just add but as you can see we would get this black horizon part so let's deal with that. Now we don't really need this preview anymore so delete it and we will add this clamp output with the negate so we have this black horizon now we cannot multiply any color with the black or the value of zero because it will just return black. So let's invert this, keep in mind here we have values between 0 and 1. So to invert them, we have a handy little node called One minus node which will just do 1 minus whatever value we pass for example if we pass one so 1 minus 1 equals zero so white to black and if we pass 0 then 1 minus 0 equals 1 so black to white and you get the idea right. So let's feed it into one minus now we also want to control the blend of the horizon so, you guessed it let's duplicate one of the blend property call it HorizonBlend drag that in grab this output, feed it into another Power node. And this one here and give a default value of something like 30. So we can see the effect and the same thing for color so let's duplicate one of the color call it HorizonColor let's drag this one in and multiply with our power there we go only thing that remains is, we need to add all these multiply outputs so let's just do that. We can add in any order it doesn't matter so let me just add this multiply with our horizon and add this one with our ground and feed this into our Master node's base color. And save our graph. Head back into the project window let's create a material call it Skybox and go to our lighting Window's environment tab so window rendering and Lighting so in lighting go to environments Tab and then in this Skybox material slot feed our Skybox let's go so yeah there we have it we can adjust this from the inspector And yeah, we have our custom skybox I would typically say that's it for this video but this time there is more to come so stay tuned for that. If you find the video helpful consider like, share and subscribe. If you have any questions post them in the comments and that's it from me and I will see you guys in the next one.
Info
Channel: Digvijaysinh Gohil
Views: 5,391
Rating: undefined out of 5
Keywords: Unity3D, Unity engine, Shader, Material, Skybox, Procedural, Shader graph, Tutorial, How to
Id: WIdVRU2tI5U
Channel Id: undefined
Length: 11min 33sec (693 seconds)
Published: Sat Apr 01 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.