For those wanting to make the rim light on the same side that the main light (the directional light in your scene) is facing, remove the negate node in front of the Get Main Light node and it will display the rim light effect on the same side as the light
Just found this tutorial, holy moly that GetMainLightDirection was just what I needed to create a planet atmosphere shader. I tried so many complicated tutorials with scattering and complex calculations... tried a very simple solution with a masked inner and an outer gradient and so far seems to work like a charm.
Thanks for this, it was a great help. What is annoying is that my newer version of Unity does not show the nodes with the same intensity so I thought I was doing something wrong initially, but it works the same in the end. I added a Vector3 and multiplied it in the custom code section with the main light direction to offset the direction a bit so I can adjust and tweak it for aesthetic purposes ;)
Doesnt work for me :C Shader error in 'Shader Graphs/RimLightTest': 'GetMainLightDirection_float': output parameter 'MainLightDirection' not completely initialized at line 284 (on d3d11)
Thank you! I think that would only be possible if you had a normal map for your sprites. In that case, instead of getting the normal vector with a normal node, you would just read the normal map and convert it from tangent space to world space, using a Transform node.
The custom function seems to work... but it has a weird issue like as if it's not getting the right direction... when I'm rotating my directional light it effects it, but the light isn't showing up in the correct directions, do I need to multiply it by the object's transform or smth?
Hi! I would just test that GetMainLight().direction is returning the correct value. Route that custom function directly into main color and check the results. If you point your light directly east, it should color the mesh red, directly up should color it green, etc.
@@NedMakesGames Oh my bad, in my version of unity it seems to reset the output variable type when I set it to the text instead of file and so it got set to float.
Thanks for the video Ned, very concise. Trying to do something piggybacking off of what I learned here but don't know the URP code that well. could something similar to your custom function be used to pull data from a point light? took me too long to realize that point lights aren't accepted as "main lights" haha
Hi! I'm glad it helped you! You can, but it's not quite as easy to do. All other lights are stored in an array, so you have to loop through them to find one hitting your mesh, and loops cannot be natively expressed in the shader graph. Take a look at my custom lighting in the shader graph video. It has a section about it. If you only have one point light, you could use that to return data about it and keep the rest of the graph as is.
Im currently using 2020.1.10f but there isn't an option for a lit shader graph so I attempted this with a PBR graph. Im stuck at the part where you add float properties since the option isnt there, how were you able to get these options in URP?
Hi! Unity made a lot of changes to the shader graph UI between 2020.1 and 2020.2. One was renaming PBR graph to Lit, and Vector1 properties to Float. So yeah, just use Vector1 properties. I made a video about these changes here if you’re interested: th-cam.com/video/QDbWAZzw1dU/w-d-xo.html
Hi! If adjusting the light and rim power values don’t do it, you could try feeding the light term into a smooth step node, to scale the ramp up a bit. Try increasing the minimum edge value.
Hi, thank you! Do you mean color the shadowed area or color cast shadows? They both require that you get light information, like we did in this video. The light structure also has a shadowAttenuation field that tells you if a shadow is falling on that pixel. Might be helpful!
Hi, thank you! By sword particle effect, you mean like a swoosh trailing behind the blade when you swing it? That would be fun, I'll add it to my list!
Hi! Do you mean with sprites? You will need to get normal information somehow, like with a normal map. Then you can use a similar algorithm. This graph won't work with URP's 2D renderer though, since lights are handled much differently.
Ned really woke up and said “I’m going to bless you with knowledge”
If someone wants to copy this:
#ifdef SHADERGRAPH_PREVIEW
MainLightDirection = float3(0.5,0.5,0);
#else
MainLightDirection = GetMainLight().direction;
#endif
Quick Heads up, MainLightDirection is now a standard Shadergraph node in Unity 2022.3 LTS! :)
For those wanting to make the rim light on the same side that the main light (the directional light in your scene) is facing, remove the negate node in front of the Get Main Light node and it will display the rim light effect on the same side as the light
thx
Just found this tutorial, holy moly that GetMainLightDirection was just what I needed to create a planet atmosphere shader. I tried so many complicated tutorials with scattering and complex calculations... tried a very simple solution with a masked inner and an outer gradient and so far seems to work like a charm.
Hi! I'm really glad to hear that! I wish Unity would just add main light nodes to the Shader Graph, but these will do for now.
Thanks for this, it was a great help. What is annoying is that my newer version of Unity does not show the nodes with the same intensity so I thought I was doing something wrong initially, but it works the same in the end. I added a Vector3 and multiplied it in the custom code section with the main light direction to offset the direction a bit so I can adjust and tweak it for aesthetic purposes ;)
That's amazing!
wow so cool! great job!
thanks, helped me figure out a bug i had on my own variant of rim
I'm glad this helped out! Thanks for watching
Hey thanks for the tutorial! is this also possible for 2d projects? because 2d URP lit shader doesn't have an Emission input under fragment.
Wizard doing wizardry things. Classic.
Very useful, thanks for sharing.
Hi nice tutorial! Is this also possible in the build in render pipeline? Unity gives me an error in the custom note :/
Doesnt work for me :C
Shader error in 'Shader Graphs/RimLightTest': 'GetMainLightDirection_float': output parameter 'MainLightDirection' not completely initialized at line 284 (on d3d11)
Hmm, what version of Unity are you using?
That's great, any idea how to make something similar in 2d?
Thank you!
I think that would only be possible if you had a normal map for your sprites. In that case, instead of getting the normal vector with a normal node, you would just read the normal map and convert it from tangent space to world space, using a Transform node.
I love ur videos , they are soo well made ......Can u make a toon shader that can use a normal map ?
Hi! Thank you, and thanks for the suggestion! I hope to return to toon shaders soon, and I’ll keep this in mind
Hey... great tutorial. anyway, GetMainLight isn't available in HDRP. is there any alternative for it?
HDRP has a node "MainLight Direction" or something like that build in, hope it helps
Um in my graph shader, in fragment, i dont see emission. (my unity version is 2020.3.25f)
Hi! Make sure you’re working with a “lit” URP graph, as opposed to “unlit.” You can change modes in the graph inspector.
The custom function seems to work... but it has a weird issue like as if it's not getting the right direction... when I'm rotating my directional light it effects it, but the light isn't showing up in the correct directions, do I need to multiply it by the object's transform or smth?
Hi! I would just test that GetMainLight().direction is returning the correct value. Route that custom function directly into main color and check the results. If you point your light directly east, it should color the mesh red, directly up should color it green, etc.
@@NedMakesGames Oh my bad, in my version of unity it seems to reset the output variable type when I set it to the text instead of file and so it got set to float.
@@hereticstanlyhalo6916 No problem, happens to the best of us!
Thanks for the video Ned, very concise. Trying to do something piggybacking off of what I learned here but don't know the URP code that well. could something similar to your custom function be used to pull data from a point light? took me too long to realize that point lights aren't accepted as "main lights" haha
Hi! I'm glad it helped you!
You can, but it's not quite as easy to do. All other lights are stored in an array, so you have to loop through them to find one hitting your mesh, and loops cannot be natively expressed in the shader graph.
Take a look at my custom lighting in the shader graph video. It has a section about it. If you only have one point light, you could use that to return data about it and keep the rest of the graph as is.
Great stuff yet again! I have like, only 3 channels that get the bell. This being one.
Thank you! That means a lot!
really wish I could have gotten this working in HDRP, good tut though
Hi, thank you! Yeah, unfortunately URP and HDRP handle lights much differently, so any lighting custom function would have to be rewritten for it.
Im currently using 2020.1.10f but there isn't an option for a lit shader graph so I attempted this with a PBR graph. Im stuck at the part where you add float properties since the option isnt there, how were you able to get these options in URP?
Hi! Unity made a lot of changes to the shader graph UI between 2020.1 and 2020.2. One was renaming PBR graph to Lit, and Vector1 properties to Float. So yeah, just use Vector1 properties.
I made a video about these changes here if you’re interested: th-cam.com/video/QDbWAZzw1dU/w-d-xo.html
this is not working correctly
How would I make the edge line thicker?
Hi! If adjusting the light and rim power values don’t do it, you could try feeding the light term into a smooth step node, to scale the ramp up a bit. Try increasing the minimum edge value.
@@NedMakesGames Exactly what I wanted, thank you so much!
Great tutorial!! BTW is there any way to have colorful shadows,?
Hi, thank you!
Do you mean color the shadowed area or color cast shadows? They both require that you get light information, like we did in this video. The light structure also has a shadowAttenuation field that tells you if a shadow is falling on that pixel. Might be helpful!
Can you make a tutorial on sword particle effect or sword slash shader pls.
Also this was very helpful keep at it
Hi, thank you!
By sword particle effect, you mean like a swoosh trailing behind the blade when you swing it? That would be fun, I'll add it to my list!
@@NedMakesGames yep that is what i meant and i canr wair for to watch another amaIng tutorial
How to make a 2D Rim Light?
I want to video😭
Hi! Do you mean with sprites? You will need to get normal information somehow, like with a normal map. Then you can use a similar algorithm.
This graph won't work with URP's 2D renderer though, since lights are handled much differently.