Replace "sampler_MainLightShadowmapTexture" by "sampler_LinearClampCompare" line 24 in the .HLSL file. This has to deal with the newer URP system and the 2022+ Unity versions which are not stable enough yet.
Hi, im having trouble with the texture not loading for some reason. Im using urp and Unity 2022.3.50f. When I try to apply it to a gameobject it becomes purple (missing texture)
You didn't use DistanceAtten right? or did I miss something. Also, suggestions for adding normal maps to this? Just WorldNormal and BlendNormals node or something?
I didn't use DistanceAtten indeed About the normal map, you should add a texture for the normal map, then multiply the output of the texture sample 2D node with the normal vector, and use the result instead of just the normal vector for the dot product with the light Hope that makes sense
Hello PixTrick, as mentioned before, I really appreciate the work you're doing here for us game devs. I wanted to note that the shadow sampling portion of the code does not render properly in orthographic view. I'm not sure why but I am looking into it 😅
I'm not sure why, but adding the following to the top of the hlsl file resolved the issue. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE #pragma multi_compile _ _SHADOWS_SOFT #pragma multi_compile _ _ADDITIONAL_LIGHTS #pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
Thanks a lot for these kind words 😄 I admit that I never tried the shader in orthographic view ... And I have honestly no idea why that happened Anyways thanks for reporting the issue and fixing it !
Hello. Big thanks for your tutorial. But my material, for some reason, doesn't render any self-cast shadows as it was shown on 3:50 of your video. I even tried to apply your shader from your github on my model but it still has no self-shadows. Do you happen to know what the problem might be?
hey, i love your work on this toon shader shadow, just one issue im having with this, when i try applying a texture image for the ShadowTexture2D or even MainTexture, the textures dont apply. any suggestions on how to fix that ? thanks
Hey, thanks :D Perhaps you're using a texture format not supported ? Or maybe it's because of the shadow color and/or the shadow pattern color ? Let me know if you find a solution
Hey ! Thanks ! Yes it's my bad actually, I should do an updated version of this tutorial since it's quite old now. It's due to the order in the operations, I posted a fix last week on the GitHub repository if you want to take a look !
I'm confused as to why I'm getting this error. Shader error in 'Shader Graphs/Master': 'MainLight_float': output parameter 'Direction' not completely initialized at Texture/CustomLighting.hlsl(4) (on d3d11) Using Unity 2022.3.20f1
Hey, I love the look of the shader but I'm having a problem. I'm using Unity 2021.3.30f1 and have just downloaded your shadergraph off of github. The ShadowTexture is just overlaying on top of the object and not working with the shadow at all. Could this be a problem with using a later version of Unity 2021.3 or is there something I might be doing wrong?
@@pixtrick I have tried that, yes. I just set the version to 2021.3.16f1 too to make sure that wasn't the issue and it still looks so wrong to me, if there's a way I could send you a picture of the issue, it might help?
Hey, I'm using unity version 2022.3.27, I've used your shadergraph from github, however the material is not working and is just a pink output. Do you know what im doing wrong?
Hey thank you so much!!! this is great! I am sorry but i am just starting with shaders so I have a question that i am sure that is pretty dumb, in this moment 3:45 you had a preview on the multiply node that was pitch black, then you explain something and when you went back to the shader to continue with custom shadows the preview was half black and half white.. why is that? I don´t really know why this shader isn´t working when i try to put it in my shader, so i thought maybe this was a part that i missed..
I only had to set the main color to white and play with the shadowStep property.. thank you! new question.. can i make this into a subgraph and insert it in any shader?
Glad you found a solution alone, but yeah, you have to play with the variables to make that work Regarding the subgraph, you can 100 % do it yeah, but I don't really know how it could go. So test it, you'll see by yourself ;)
For some reason the shadow of my character on the ground when I apply the shader to ground moves. It doesn't stay in one place when I move the camera. Also I noticed that Distance Atten was left empty. What am I supposed to put there.
How does it move ? Do you mean the shadow translates ? Does its shape change ? About Distance Atten, you are not supposed to put anything there to follow the tutorial, but feel free to play with it if you're curious ;)
This custom shadow's work on the floor and ever other mash I have on the Sean ? The reason I asked it's because if that is and If the transparentcy work with this I will able make shadow's for glass and other similar stuff. For example if have glass bottle I will able to make White showdow and experiment with paternt in the order to look like better. Shame on the beer bottle 🍾 I will make green transparent shadow and I will look so much better seen if I add normal shadow on those object looks pretty bad.
This shader works only for opaque rendering, it does not handle the transparency unfortunately ... It would be something to dig in if I would remake this shader
@@pixtrick i know that but if is possible to make the shadow to have lighter color's and add objects that only have shadow I'm probably able to make the system i wand to make.
It didn't work for me... I have this error: Shader error in 'Master': 'MainLight_float': output parameter 'Direction' not completely initialized at Assets/Shaders/PixTrickCustomShadows-main/CustomShadowsTutorial/CustomLighting.hlsl(4) (on d3d11)
Thanks for the report ! I just fixed the issue on the files. If you want to fix it yourself, you have to make sure you use the right .HLSL file in the shader graph custom function node. Also try to unselect then reselect it, it worked for me. If none of that works, just try to create another material from the shader graph.
Hey, um, me again. So is there a way to make the shadows a bit smoother? Currently the shadows are either 100% or 0%, which means they either don't exist on this plain of reality or show up with in full might. Can you limit these shadows to some lesser values like 0% - 20% - 40% - 60% - 80% - 100%? And possibly make different "levels" of shadows use different textures? Also, is there a way to make the shadows custom-tiled for different objects? The tiling is global and on some small objects the shadow textures look too small, and no bigger ones they look too big. Like, for example, you could (if you can, I certainly can't) make a screen-space shader to render black voids as the texture on the SCREEN (instead of rendering on the object itself). Tell me what you think. Thanks :)
Hey ! Glad to see you're still here after all the trouble of today x) About the lesser values of the shadows, you can already do this. The more the color you're using for the shadow or for the shadow pattern goes to the white, the more it will appear clear and transparent. Regarding the idea of multiple layers of shadows, I already thought about this and I will surely implement it in another version of the shader ;) Finally for the tiling did you try creating multiple materials from the shader ? You would be able to set the tiling, the textures and the colors independently for different objects. Hope that helps !
@@pixtrick I aswell would love to see how you can implemented multiple layers of shadowing. I'm currently struggling with adding clouds to my stylized game because they cast a shadow just as dark as the rest of the scene, and unfortunately URP doesn't natively support translucent shadows, so a way to change the cast shadow strength on specific objects would be amazing! also just want to say I appreciate the tutorial!
You're right ! I guess if the uvs are set correctly beforehand, this would solve the issue, otherwise I admit that I don't know how to fix it. Any suggestion ?
@@pixtrick Unfortunately no, not really. Depending on what one wants stylistically you can get away with using screen or world coordinates or some variation of object coordinates but it all breaks down eventually in one way or another. I have struggled for years by now in various projects with getting some stable coordinates which don't look like they are moving underneath the object :-/.
Hi ! Really appreciate your work ! I think I managed to follow all the steps but there's only one little thing I'm struggling with at the end : the shadow texture appears nicely on shaded areas but is also slightly visible on lit areas.. Does anyone managed to deal with something similar? (I'll continue tweaking things and hopefully I'll find out, but would really appreciate some help ! =D )
Hey, thanks for your comment ! This is basically due to how the effect is made in shader graph, so I'm afraid there's no real solution for that. The only thing I found was to increase the intensity of the base color to 1, but that's so ugly in my opinion ... I'll try to make another video about a cleaner approach to get this effect, stay tuned !
@@pixtrick I will ! Thanks a lot for taking time answering. That's what I was thinking after a lot of tweaking. At least it gives me an opportUnity to be a little bit more at ease with shadergraphe basics. For now, i've just put asside the idea of having hatch texture based shadows. However, with only the simple shadows, the effect stays pretty convincing to me. Thanks again for the good work!
For some reason after I named the Custom Function "MainLight" I get an Error stating: "Shader error in 'hidden/preview/MainLightCustomFunction_94860ece00ec4de4adf7551c22378a3b': Invalid conditional expression. at Assets/CustomLighting.hlsl(5)". The fifth line is just the start of a curly bracket, so it could be an error in the code, but I'm not a good programmer, so I dunno :/
Honestly i don't know how to solve this issue. It appears that i uploaded a new version of the custom lighting file that has a lot of issues ... My bad, i rolled it back so now i think you won't have any other errors.
@@pixtrick It still doesn't work. The error message: "Shader error in 'hidden/preview/MainLightfloatCustomFunction_00ac698ad5524200b248991708ff249a': Invalid conditional expression. at Assets/CustomLighting 1.hlsl(5)"
Ok, I fixed it myself. Instead of: #if SHADERGRAPH_PREVIEW It has to be: #if defined(SHADERGRAPH_PREVIEW) I think lol. That's what a google search told me to do and now it works (eg. I don't get errors, woo hoo)
@@DasioreqDev what a relief 😭 A strange issue, though. Maybe due to your Unity version ? I'll soon make a discord server so that we can discuss that kind of issues... Thanks for the report !
thank you for the video but tbh it was not was I was looking for. Using a complicated custom function is IMO always a bad choice bc tutorials are best when self contained. also you did not explain 80% of the steps (what is step function doing etc.) I don't intend to be toxic but when your goal is to make tutorial then explain please more
You're 100% right. When I made this video, my goal was more about trying to understand the concepts instead of actually teaching things. I apologize for that. Now, I really want to go deeper in the explanations and I'm currently working towards that. I will probably share a video about a more elegant way to do this, using shaders only and not the shader graph. Anyways, I'm aware I'm not a professional, but I swear I really try to improve ;)
@@pixtrick I'm sorry too tbh I get your video now! For the last 5 days I've been trying hard to understand SRP and Shader Graph, and most of the videos were too superficial to understand, and it was really frustrating because I couldn't even get the simplest things to work (like Sobel Convolution). For example, I didn't know how to use a custom HLSL function in Shader Graph, etc. I still don't know how to place your passes using C# with seems super boiler code heavy etc. After watching countless online tutorials, blog posts, etc... I finally feel a little more proficient. Udemy with holistic3D in particular has helped me. Your video is fine, but also not for total beginners like I was, who know how to program shaders and the math, but nothing about how to do it in SRP or HDRP The custom function you use is a standard procedure, but it doesn't work in HDRP, which is what I used! I didn't find that out until later, so I was pissed about the non-standalone part. Also not your fault. So I feel bad, you did your best to teach some concepts for free, but spending hours on it and not understanding why something doesn't work really bugged me.. My only suggestion would be that when you make a video, please don't leave anything out (like checking a bool on etc), so make it exactly like this video, but maybe explain more intermediate steps (like what exactly is shadow attentuation etc). Cheers!
I appreciate the time and effort you put in your comment ! But yeah, learning these things is super complex because of the amount of "tutorials" (mine included ngl) that do not cover the basics. I'm really trying to do so in my more recent videos, but this one is one of my firsts, so yeah, mistakes were made, sorry for that. Thanks for your honesty by the way, it motivates me a lot to make better content :D
great shader but would you know how to use this for unity 2022.2.13??
Replace "sampler_MainLightShadowmapTexture" by "sampler_LinearClampCompare" line 24 in the .HLSL file. This has to deal with the newer URP system and the 2022+ Unity versions which are not stable enough yet.
@@pixtrick Didn't help :(
@@Nightmareinfos can you contact me on discord ? Maybe we can find a solution
Did you find a solution?
I was looking for this!! Thank you sooo much
NEW PIXTRICK VIDEO HONEY WAKE UP
Thanks a lot. You saved me!
Hi, im having trouble with the texture not loading for some reason. Im using urp and Unity 2022.3.50f. When I try to apply it to a gameobject it becomes purple (missing texture)
Hi! Does it turn purple only when you try applying a texture?
You didn't use DistanceAtten right? or did I miss something. Also, suggestions for adding normal maps to this? Just WorldNormal and BlendNormals node or something?
I didn't use DistanceAtten indeed
About the normal map, you should add a texture for the normal map, then multiply the output of the texture sample 2D node with the normal vector, and use the result instead of just the normal vector for the dot product with the light
Hope that makes sense
Hello PixTrick, as mentioned before, I really appreciate the work you're doing here for us game devs. I wanted to note that the shadow sampling portion of the code does not render properly in orthographic view. I'm not sure why but I am looking into it 😅
I'm not sure why, but adding the following to the top of the hlsl file resolved the issue.
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
#pragma multi_compile _ _SHADOWS_SOFT
#pragma multi_compile _ _ADDITIONAL_LIGHTS
#pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
Thanks a lot for these kind words 😄
I admit that I never tried the shader in orthographic view ... And I have honestly no idea why that happened
Anyways thanks for reporting the issue and fixing it !
@Anna Tofa it could yes, but it is pretty unlikely since the default value is 150 meters ...
Hello. Big thanks for your tutorial. But my material, for some reason, doesn't render any self-cast shadows as it was shown on 3:50 of your video. I even tried to apply your shader from your github on my model but it still has no self-shadows. Do you happen to know what the problem might be?
Hello there ! What unity version do you use ?
@@pixtrick22.3.15f1. Also made that line fix you mentioned in the pinned comment
hey, i love your work on this toon shader shadow, just one issue im having with this, when i try applying a texture image for the ShadowTexture2D or even MainTexture, the textures dont apply. any suggestions on how to fix that ? thanks
Hey, thanks :D
Perhaps you're using a texture format not supported ? Or maybe it's because of the shadow color and/or the shadow pattern color ? Let me know if you find a solution
Hello! Reallyyyy cool shader! Do you know why it makes my pattern still show in the whole object and not just the shadows that we create?
Hey ! Thanks ! Yes it's my bad actually, I should do an updated version of this tutorial since it's quite old now. It's due to the order in the operations, I posted a fix last week on the GitHub repository if you want to take a look !
I'm confused as to why I'm getting this error.
Shader error in 'Shader Graphs/Master': 'MainLight_float': output parameter 'Direction' not completely initialized at Texture/CustomLighting.hlsl(4) (on d3d11)
Using Unity 2022.3.20f1
Hey ! You can check the pinned comment, maybe it would solve your problem
@@pixtrick I found the problem I was not using URP T_T Anyways awesome video and I appreciate the response!
@@JeebZ-3D happens x)
Hey, I love the look of the shader but I'm having a problem. I'm using Unity 2021.3.30f1 and have just downloaded your shadergraph off of github. The ShadowTexture is just overlaying on top of the object and not working with the shadow at all. Could this be a problem with using a later version of Unity 2021.3 or is there something I might be doing wrong?
Did you try tweaking the different parameters of the material from the shader graph ?
@@pixtrick I have tried that, yes. I just set the version to 2021.3.16f1 too to make sure that wasn't the issue and it still looks so wrong to me, if there's a way I could send you a picture of the issue, it might help?
@@Hot__d_o_g yes of course ! Please send that on the discord server of the community or to me directly on discord, I'll answer as soon as possible
Hey, I'm using unity version 2022.3.27, I've used your shadergraph from github, however the material is not working and is just a pink output. Do you know what im doing wrong?
Hey ! Have you also imported the .hlsl file that was provided in the files ?
@@pixtrick Yea I did
Can you contact me on discord? It would be easier to understand your issue
Thank you very much, so glad to see this. Sadly I am late to the party. Very cool stuff!
No worries, new parties are coming soon ;)
By the way, i would never have made this video if you didn't ask, so thank you !
For what little it’s worth, I turn everyone I can on to your channel!
That's so kind of you thanks !
Hey thank you so much!!! this is great! I am sorry but i am just starting with shaders so I have a question that i am sure that is pretty dumb, in this moment 3:45 you had a preview on the multiply node that was pitch black, then you explain something and when you went back to the shader to continue with custom shadows the preview was half black and half white.. why is that? I don´t really know why this shader isn´t working when i try to put it in my shader, so i thought maybe this was a part that i missed..
I only had to set the main color to white and play with the shadowStep property.. thank you! new question.. can i make this into a subgraph and insert it in any shader?
Glad you found a solution alone, but yeah, you have to play with the variables to make that work
Regarding the subgraph, you can 100 % do it yeah, but I don't really know how it could go. So test it, you'll see by yourself ;)
I love the style
For some reason the shadow of my character on the ground when I apply the shader to ground moves. It doesn't stay in one place when I move the camera. Also I noticed that Distance Atten was left empty. What am I supposed to put there.
How does it move ? Do you mean the shadow translates ? Does its shape change ?
About Distance Atten, you are not supposed to put anything there to follow the tutorial, but feel free to play with it if you're curious ;)
This custom shadow's work on the floor and ever other mash I have on the Sean ?
The reason I asked it's because if that is and If the transparentcy work with this I will able make shadow's for glass and other similar stuff.
For example if have glass bottle I will able to make White showdow and experiment with paternt in the order to look like better.
Shame on the beer bottle 🍾 I will make green transparent shadow and I will look so much better seen if I add normal shadow on those object looks pretty bad.
This shader works only for opaque rendering, it does not handle the transparency unfortunately ...
It would be something to dig in if I would remake this shader
@@pixtrick i know that but if is possible to make the shadow to have lighter color's
and add objects that only have shadow I'm probably able to make the system i wand to make.
It didn't work for me... I have this error: Shader error in 'Master': 'MainLight_float': output parameter 'Direction' not completely initialized at Assets/Shaders/PixTrickCustomShadows-main/CustomShadowsTutorial/CustomLighting.hlsl(4) (on d3d11)
Thanks for the report ! I just fixed the issue on the files. If you want to fix it yourself, you have to make sure you use the right .HLSL file in the shader graph custom function node. Also try to unselect then reselect it, it worked for me.
If none of that works, just try to create another material from the shader graph.
Hey, um, me again. So is there a way to make the shadows a bit smoother? Currently the shadows are either 100% or 0%, which means they either don't exist on this plain of reality or show up with in full might. Can you limit these shadows to some lesser values like 0% - 20% - 40% - 60% - 80% - 100%? And possibly make different "levels" of shadows use different textures? Also, is there a way to make the shadows custom-tiled for different objects? The tiling is global and on some small objects the shadow textures look too small, and no bigger ones they look too big. Like, for example, you could (if you can, I certainly can't) make a screen-space shader to render black voids as the texture on the SCREEN (instead of rendering on the object itself). Tell me what you think. Thanks :)
Hey ! Glad to see you're still here after all the trouble of today x)
About the lesser values of the shadows, you can already do this. The more the color you're using for the shadow or for the shadow pattern goes to the white, the more it will appear clear and transparent.
Regarding the idea of multiple layers of shadows, I already thought about this and I will surely implement it in another version of the shader ;)
Finally for the tiling did you try creating multiple materials from the shader ? You would be able to set the tiling, the textures and the colors independently for different objects. Hope that helps !
@@pixtrick I aswell would love to see how you can implemented multiple layers of shadowing. I'm currently struggling with adding clouds to my stylized game because they cast a shadow just as dark as the rest of the scene, and unfortunately URP doesn't natively support translucent shadows, so a way to change the cast shadow strength on specific objects would be amazing!
also just want to say I appreciate the tutorial!
@@chalobeats8971 no problems! Since you're not the first one to ask for that, I will make another video/tutorial with every suggestion I received
Beware that the texture might look odd and rotated wrong based on how the uvs of the mesh are layed out.
You're right ! I guess if the uvs are set correctly beforehand, this would solve the issue, otherwise I admit that I don't know how to fix it. Any suggestion ?
@@pixtrick Unfortunately no, not really. Depending on what one wants stylistically you can get away with using screen or world coordinates or some variation of object coordinates but it all breaks down eventually in one way or another. I have struggled for years by now in various projects with getting some stable coordinates which don't look like they are moving underneath the object :-/.
@@fleity well that's what I was afraid of. It's a pity that uvs are so complex to manipulate ...
Hi ! Really appreciate your work !
I think I managed to follow all the steps but there's only one little thing I'm struggling with at the end : the shadow texture appears nicely on shaded areas but is also slightly visible on lit areas..
Does anyone managed to deal with something similar?
(I'll continue tweaking things and hopefully I'll find out, but would really appreciate some help ! =D )
Hey, thanks for your comment !
This is basically due to how the effect is made in shader graph, so I'm afraid there's no real solution for that. The only thing I found was to increase the intensity of the base color to 1, but that's so ugly in my opinion ... I'll try to make another video about a cleaner approach to get this effect, stay tuned !
@@pixtrick I will ! Thanks a lot for taking time answering. That's what I was thinking after a lot of tweaking. At least it gives me an opportUnity to be a little bit more at ease with shadergraphe basics. For now, i've just put asside the idea of having hatch texture based shadows. However, with only the simple shadows, the effect stays pretty convincing to me. Thanks again for the good work!
@@arthurfoucault7358 you're welcome ! Nice pun by the way xD
Please make more shader tutorials!
I will !
For some reason after I named the Custom Function "MainLight" I get an Error stating: "Shader error in 'hidden/preview/MainLightCustomFunction_94860ece00ec4de4adf7551c22378a3b': Invalid conditional expression. at Assets/CustomLighting.hlsl(5)". The fifth line is just the start of a curly bracket, so it could be an error in the code, but I'm not a good programmer, so I dunno :/
Honestly i don't know how to solve this issue. It appears that i uploaded a new version of the custom lighting file that has a lot of issues ... My bad, i rolled it back so now i think you won't have any other errors.
@@pixtrick Thx, I'll check when I finish this Ultrakill level
@@pixtrick It still doesn't work. The error message: "Shader error in 'hidden/preview/MainLightfloatCustomFunction_00ac698ad5524200b248991708ff249a': Invalid conditional expression. at Assets/CustomLighting 1.hlsl(5)"
Ok, I fixed it myself. Instead of:
#if SHADERGRAPH_PREVIEW
It has to be:
#if defined(SHADERGRAPH_PREVIEW)
I think lol. That's what a google search told me to do and now it works (eg. I don't get errors, woo hoo)
@@DasioreqDev what a relief 😭
A strange issue, though. Maybe due to your Unity version ?
I'll soon make a discord server so that we can discuss that kind of issues... Thanks for the report !
Kewl
👍
You have a beautiful voice, try ASMR
I was not expecting that at all 😂
thank you for the video but tbh it was not was I was looking for. Using a complicated custom function is IMO always a bad choice bc tutorials are best when self contained.
also you did not explain 80% of the steps (what is step function doing etc.)
I don't intend to be toxic but when your goal is to make tutorial then explain please more
You're 100% right. When I made this video, my goal was more about trying to understand the concepts instead of actually teaching things. I apologize for that.
Now, I really want to go deeper in the explanations and I'm currently working towards that. I will probably share a video about a more elegant way to do this, using shaders only and not the shader graph.
Anyways, I'm aware I'm not a professional, but I swear I really try to improve ;)
@@pixtrick I'm sorry too tbh I get your video now!
For the last 5 days I've been trying hard to understand SRP and Shader Graph, and most of the videos were too superficial to understand, and it was really frustrating because I couldn't even get the simplest things to work (like Sobel Convolution).
For example, I didn't know how to use a custom HLSL function in Shader Graph, etc.
I still don't know how to place your passes using C# with seems super boiler code heavy etc.
After watching countless online tutorials, blog posts, etc... I finally feel a little more proficient. Udemy with holistic3D in particular has helped me.
Your video is fine, but also not for total beginners like I was, who know how to program shaders and the math, but nothing about how to do it in SRP or HDRP
The custom function you use is a standard procedure, but it doesn't work in HDRP, which is what I used! I didn't find that out until later, so I was pissed about the non-standalone part. Also not your fault.
So I feel bad, you did your best to teach some concepts for free, but spending hours on it and not understanding why something doesn't work really bugged me..
My only suggestion would be that when you make a video, please don't leave anything out (like checking a bool on etc), so make it exactly like this video, but maybe explain more intermediate steps (like what exactly is shadow attentuation etc).
Cheers!
I appreciate the time and effort you put in your comment ! But yeah, learning these things is super complex because of the amount of "tutorials" (mine included ngl) that do not cover the basics. I'm really trying to do so in my more recent videos, but this one is one of my firsts, so yeah, mistakes were made, sorry for that. Thanks for your honesty by the way, it motivates me a lot to make better content :D