Toon Shader in Unity Using a Shader Graph with Custom Lighting! ✔️ 2020.3 | Game Dev Tutorial

Поділитися
Вставка
  • Опубліковано 21 жов 2024

КОМЕНТАРІ • 525

  • @hamishpaget1619
    @hamishpaget1619 3 роки тому +75

    For anyone getting an error saying "Invalid conditional expression"
    instead of:
    #if SHADERGRAPH_PREVIEW
    It has to be:
    #if defined(SHADERGRAPH_PREVIEW)

  • @poisonouspurple
    @poisonouspurple 3 роки тому +42

    For everyone who runs into the 'Invalid conditional expression' error, here is the solution:
    simply write
    #if defined(SHADERGRAPH_PREVIEW)
    instead of
    #if SHADERGRAPH_PREVIEW
    Hope this works for you :D

    • @burakhandogan6076
      @burakhandogan6076 3 роки тому +2

      i want to thank you crying

    • @kennyamat
      @kennyamat 3 роки тому +1

      i dont know why but for some reason do I already have shadows without the shadow part. so I don't see the use of that part

    • @poisonouspurple
      @poisonouspurple 3 роки тому +1

      @@kennyamat yeah this video is one year old and Unity updated and added a lot so it will be probably already implemented in some render pipelines or basic shading

  • @CaveHeroesofficial
    @CaveHeroesofficial 4 роки тому +19

    This is by far the best and cleanest tutorial I've ever seen.

  • @kilanlarsen7692
    @kilanlarsen7692 Рік тому +1

    I searched through a fair number of toon shader tutorials but this is the only one I found that properly addressed dynamic lighting from point/spot lights in the scene. Hands down the best shader and I'm extremely grateful for the information - you've earned a sub good sir

    • @NedMakesGames
      @NedMakesGames  Рік тому

      Hi, thank you so much! I hope you enjoy future tutorials.

  • @gamethingstuff
    @gamethingstuff 3 роки тому +6

    Followed another tutorial that massively overcomplicated everything and didn't get the desired result and then I watch this one and it's so simple. Great job man

  • @madifoldstudio8064
    @madifoldstudio8064 3 роки тому +3

    One of the best Toon Shader explanations there are (including the Open Projects one that is a drag).

  • @NedMakesGames
    @NedMakesGames  4 роки тому +4

    Hi everyone! Thank you for all your comments! Also, if you're using a version after Unity 2020.2, please check the top of the video description for fixes!
    I created a follow up video to this which adds spot light shadows and some lighting improvements. Check it out here: ua-cam.com/video/whmPkDp3dqo/v-deo.html

    • @Stinger-rq4gy
      @Stinger-rq4gy 3 роки тому

      So to make a small FPS multiplayer building with toon shading style/cell shaded style I need to apply cell shading style to the walls, and floors of the building, if the walls and floors are not already toon shaded?

    • @NedMakesGames
      @NedMakesGames  3 роки тому +1

      @@Stinger-rq4gy Yeah, you would need to apply the toon material, or a variation of it, to get them toon shaded as well

    • @Stinger-rq4gy
      @Stinger-rq4gy 3 роки тому

      @@NedMakesGames Excellent thanks ill do that, I am studying Unity its very complex. I am building a FPS game called Zombie💀Castle, with a castle with 100 zombie bosses on each 100 floors. I would like the building, guns, zombies to have the toon shading style. Thanks for your help🙋‍♂️🍻

    • @Stinger-rq4gy
      @Stinger-rq4gy 3 роки тому

      @@NedMakesGames This is mt to do list to build my game, I only have 2 people to build this app game. 1. Find a way to make props, walls floors, etc in cell-shaded/toon shading style.
      2. Build a FPS gun in Unity 3D.
      3. Find lots of free props for Zombie Castle💀
      4. Learn how to do enemy A.I.

    • @NedMakesGames
      @NedMakesGames  3 роки тому +1

      @@Stinger-rq4gy Sounds like a good plan! Good luck with your game!

  • @kayohwai
    @kayohwai 3 роки тому +20

    After completing the tutorial, I added a small bit extra onto the graph. Since I didn't want everything toon shaded to be shiny, I threw in an extra bool ("Matte"), and a Branch. If Matte is true, it cuts out the Add for the shine branch. If Matte is false, it feeds through the full branch.

    • @inxendere
      @inxendere Рік тому

      Wait this is really cool how did you set this up exactly? How can the branch cut out the add or not cut it out??

    • @inxendere
      @inxendere Рік тому

      nvm i got it

  • @sam8686
    @sam8686 4 роки тому +1

    Just want to thank you for breaking this down so well. As someone who is learning this stuff, it is really difficult sometimes to understand what people are doing in tutorials and why they might add certain nodes. Your tutorial is incredibly well explained and easy to understand. This level of detail is very much appreciated, keep it up! :)

  • @mochou_p
    @mochou_p Рік тому +6

    In Unity 2021.3.25f1, to get shadows, change the keyword scopes to Global
    (select a keyword in Blackboard > go to Graph Inspector > Node Settings > Scope)
    You should see shadows now, so you can ignore the material inspector debug thingie

  • @bencollom2513
    @bencollom2513 3 роки тому +16

    Since I ran into this issue:
    When creating custom shader - Error: wrong file type, must be .hlsl:
    Your windows directory may not be showing file extensions, and your text file is Lighting.hlsl.txt. In your windows directory, click "View" up at the top, then check "Show file extensions." now you can rename your file to Lighting.hlsl

  • @megalon2d685
    @megalon2d685 3 роки тому +6

    For anyone getting an error about invalid if statement in Lighting.hlsl
    You need to change
    "#if SHADERGRAPH_PREVIEW"
    to
    "#ifdef SHADERGRAPH_PREVIEW"

  • @tbdtandres
    @tbdtandres 3 роки тому +1

    I'm going through all your tutorials and they are SO GOOD, I've learned so much, THANK YOU

  • @cortlandia7618
    @cortlandia7618 3 роки тому

    I've spent the past few hours trying to find a tutorial that works and this one does! Tysm

    • @NedMakesGames
      @NedMakesGames  3 роки тому

      Hi! I'm glad to hear that. Thanks for watching!

  • @chorong7351
    @chorong7351 6 місяців тому +2

    Thank you what a detailed description!
    Here are my edited code for those who have trouble receiving shadow on the object itself:
    void CalculateMainLight_float(float3 WorldPos, out float3 Direction, out float3 Color,
    out half DistanceAtten, out half ShadowAtten)
    {
    #if SHADERGRAPH_PREVIEW
    Direction = float3(0.5,0.5,0);
    Color = 1;
    DistanceAtten = 1;
    ShadowAtten = 1;
    #else
    #if SHADOW_SCREEN
    half4 clipPos = TransformWorldToHClip(WorldPos);
    half4 shadowCoord = ComputeScreenPos(clipPos);
    #else
    half4 shadowCoord = TransformWorldToShadowCoord(WorldPos);
    #endif
    Light mainLight = GetMainLight(0);
    Direction = mainLight.direction;
    Color = mainLight.color;
    DistanceAtten = mainLight.distanceAttenuation;
    #if SHADOWS_SCREEN
    ShadowAtten = SampleScreenSpaceShadowmap(shadowCoord);
    //ShadowAtten = mainLight.shadowAttenuation;
    #else
    ShadowSamplingData shadowSamplingData = GetMainLightShadowSamplingData();
    half shadowStrength = GetMainLightShadowStrength();
    ShadowAtten = SampleShadowmap(shadowCoord, TEXTURE2D_ARGS(_MainLightShadowmapTexture,
    sampler_MainLightShadowmapTexture),
    shadowSamplingData, shadowStrength, false);
    #endif

    #endif
    }

    • @llamas_attack
      @llamas_attack Місяць тому

      Hi! I tried this code and I'm not getting any errors, but I'm also still not receiving shadows -- are there any additional keywords or pipeline asset settings to also be aware of?

  • @mochou_p
    @mochou_p Рік тому +1

    optimization suggestion:
    since here we dont use an actual "color" from the ramp textures (we only take the value), we can combine up to 4 maps into one image file. each will only affect one color channel.
    a texture with transparency can hold pixels as vector4s (RGBA). many games use memory efficiently this way, and just split it into the individual maps in shader graph.

    • @NedMakesGames
      @NedMakesGames  Рік тому +1

      Hi, yes! This can be a good optimization if your ramps are plain grayscale.

  • @jeriswatching
    @jeriswatching 3 роки тому

    Liked and subbed. You saved me where Unity's own tutorial didn't.

    • @NedMakesGames
      @NedMakesGames  3 роки тому

      Thank you! Yeah, their toon shader tutorial just plain doesn't work in newer versions... they don't add the needed keywords to the graph.

  • @durgam_sumerian7815
    @durgam_sumerian7815 3 роки тому

    Wow, didn't know there are such free cool tutorials with rich info & explanation like this one, well, Subscribed.

  • @iOJPF69854
    @iOJPF69854 Рік тому +3

    Hello, I also have a error like Shader error in
    'Master': 'CalculateMainLight_float': output parameter 'Direction' not completely initialized at Assets/Scripts/includes/Lighting.hlsl(4) (on d3d11)
    On the script I can see -- Light mainLight = GetMainLight(0); -- this as a red font color. Do you know how to fix it? Thanks

    • @iOJPF69854
      @iOJPF69854 Рік тому

      Oh, I think I figured out. Go to Graph Inspector in the shader graph and add Universal on the Target Setting.

  • @nicolasL009
    @nicolasL009 3 роки тому +1

    Awesome tutorial man, thanks a lot, keep up the good work!

  • @mochou_p
    @mochou_p Рік тому +3

    for me, only directional light is toon, the additional lights have normal smooth falloff, which is weird since i ramp all of them since they are combined

  • @NathanPrince1
    @NathanPrince1 4 роки тому

    Thank you sir I have been trying to get good looking shadows for a long time in URP and cascades never worked for me. Until I found you lovely vids and the shadow keywords fixed my problem. thanks and you get a like and subscribe for life :)

    • @LexGear
      @LexGear 2 роки тому

      Hey Nathan, it might be because I'm using a much later version of Unity, but I cannot get this shader to recieve shadows at all and I followed this video to a T. Including all the keyword tricks. What version of unity did you use?

  • @FistFlameful
    @FistFlameful 4 роки тому

    Thanks for the tutorial! This was really helpful for learning about custom lighting and shaders!

  • @abhirutmeherishi5738
    @abhirutmeherishi5738 3 роки тому +1

    Wow! Thanks for this.
    Now all thats left is how to create comic like black outline and how to give it a jelly like appearance.

  • @GreenCream
    @GreenCream 3 роки тому

    This is great, but is it supposed to work with differen light colors or just white? You didn't show that in the video and colors don't seem to be working for me (even with just the main light without the ramp).

    • @NedMakesGames
      @NedMakesGames  3 роки тому +1

      Thank you! It should work with different light colors, since that was one of my goals with this shader. Make sure you multiply the light color with the output of the ramp subgraph!

    • @GreenCream
      @GreenCream 3 роки тому

      @@NedMakesGames You're right. My bad! I Messed up one of the inputs as a float instead of a vector3. Thanks again for the fantastic tutorials. Hope to see more! 😊

    • @NedMakesGames
      @NedMakesGames  3 роки тому +1

      @@GreenCream Ah, no problem! That happens to me too frequently...
      Thank you! I'm writing the next tutorial's script as we speak!

  • @VyvyanTheGreat
    @VyvyanTheGreat 3 роки тому +2

    Phenomenal tutorial. Thank you SO much!

  • @BLOXOBIZZAREMK2
    @BLOXOBIZZAREMK2 2 роки тому

    Rater than using a texture sample node and texture, a quicker and easier to hot-edit option is using a gradient node set to fixed with a gradient sample node, when X or Time is the output of the saturated N dot L (or the light direction dot normal) :)

    • @NedMakesGames
      @NedMakesGames  2 роки тому

      This can work great! Just keep in mind you can't edit gradients in the material inspector (as of 2020.3 anyway), so if you plan to do that, stick with textures.

  • @noperiest8320
    @noperiest8320 Рік тому +1

    This is a great tutorial video however I got stuck at implementing for additional lights. If I write the method ' GetAdditionalLightsCount(); ' in hlsl code file and apply it to custom function node in shader graph, the node says GetAdditionalLightsCount is undefined identifier. Wasn't it built in method for hlsl? idk why I can't use it. Could you please help me?

  • @dennisj8149
    @dennisj8149 3 роки тому

    Thank you for sharing your knowledge! Hope you have a great day :)

  • @217tman3
    @217tman3 3 роки тому +1

    This tutorial like a treasure

  • @dianjakap4805
    @dianjakap4805 2 роки тому

    Great job, best shader tutorial ever!

    • @NedMakesGames
      @NedMakesGames  2 роки тому

      Thank you, that means a lot!

    • @dianjakap4805
      @dianjakap4805 Рік тому

      @@NedMakesGames hello, I am back with a question. I am using unity 2021. for shadow, after modified the hlsl, the shadow work without implementing "MAIN_LIGHT_CALCULATE_SHADOWS" key. do I still need to use the key?

    • @NedMakesGames
      @NedMakesGames  Рік тому

      @@dianjakap4805 If it works, no there's no reason to use the keyword. Just make sure your shader both casts and receives shadows, since they're separate concepts when it comes to rendering.

  • @GustavoMondini
    @GustavoMondini 9 місяців тому

    does it work as well for HDRP or is the coding completely different ? I can handle the graph easily, but im a completely noob at shader coding

  • @lesarch
    @lesarch 4 роки тому

    This is an amazing tutorial! Thank you for this!

  • @AdXxRi
    @AdXxRi 4 роки тому +1

    Great video mate! love it

  • @larsmaas07
    @larsmaas07 2 роки тому +1

    Unity 2021.3 works perfect

    • @chetanamali956
      @chetanamali956 7 місяців тому

      hey I'm using unity 2022.3 but it gives me an initialized error for directional light "output parameter 'Direction' not completely initialized at Assets/Includes/Lighting.hlsl(4) (on d3d11)" what should I do?

    • @larsmaas07
      @larsmaas07 7 місяців тому

      i've quit gamedev for like half a year now

  • @ty-xq7bl
    @ty-xq7bl 3 роки тому

    Great guide man thank you so much

  • @hidemat5141
    @hidemat5141 3 роки тому

    Omg. Thank you for this, some toon shader tutorials out there don't tackle the shadows issue, and your shader is so well organized. You made my day :) Just one question though. The shader looks weird in the scene view, is there a way to fix this? Edit: Oh fixed it. I had lights disabled in my scene viewer.

  • @minhhai9281
    @minhhai9281 Рік тому +1

    I'm using Unity 2022.2.21 f1 and a have problem with Add Additional Lights custom node(variable CustomFunction_9d076c439b9d46d794647 4fc35720596 Diffuse 10 Float' used without having been completely initialized at line 180). I need help please

  • @mattlepage1898
    @mattlepage1898 3 роки тому

    Love ur video! Glad I clicked! :)

  • @Kopftier
    @Kopftier 2 роки тому

    great Tutorial, thanks! :D

  • @kostjaaf
    @kostjaaf 4 роки тому +1

    I would Love to see more!

  • @BarcelonaMove
    @BarcelonaMove 4 роки тому +2

    I came for cooper and found gold.

  • @Weenmeen
    @Weenmeen Рік тому

    With the second lighting script that adds shadow I'm getting this error ""MainLight_float": no matching 0 parameter function at line 174"

  • @sealsharp
    @sealsharp 3 роки тому

    Hey Ned! Nice work, Sir! Question: When URP gets deferred rendering, will that work with this shader? ( And your hull outline shader ).

    • @NedMakesGames
      @NedMakesGames  3 роки тому

      Hi, thanks! I doubt it will automatically since lights are handled differently in deferred rendering. I will probably make a video about it when deferred mode is released! Same with the hull outlines.

    • @sealsharp
      @sealsharp 3 роки тому

      @@NedMakesGames Wow, that answer came fast. Looking forward to it. Have a nice weekend, Ned!

  • @danbirman3374
    @danbirman3374 2 роки тому

    This was an awesome tutorial -- I have one issue though which is that shadows don't render for additional lights for me. The shadowAttenuation is always 1 -- is there another keyword that has to be enabled for them to work or possibly some other issue?

    • @NedMakesGames
      @NedMakesGames  2 роки тому +1

      Hi, thank you! I made a follow up tutorial to fix that, which you can find in the video description. Keep in mind point light shadows are only possible in Unity 2021.1 and later, though.

  • @marigo856
    @marigo856 3 роки тому +1

    I'm using 2020.3. I followed the instructions for the shadows precisely and quadruple checked that I did everything exactly but its still not receiving any shadows. I made sure to read the description for the changes needed for 2020.3 and copied the "Final Version for 2020.2" script. There's no misspellings in the keywords for the materials nor shader graph. I made sure to use a directional light. Been scratching my head at this for hours. Any ideas what I'm doing wrong? I can provide more details if needed.

    • @NedMakesGames
      @NedMakesGames  3 роки тому +1

      Hi! Ah, Shadows are really annoying to get right at the moment, there are a lot of places to make mistakes.
      I would make sure that your camera has render shadows turned on and that your URP settings asset has shadow cascades and soft shadows turned on. Make sure your mesh renderers have cast shadows turned on. If a mesh with a standard lit shader receives shaders, you know that part's all set up. Additionally, your ramp or some other part of the graph could be obscuring things. I would try to route the main light shadow attenuation directly into the base color field of the master stack to see if shadows show up that way.

    • @marigo856
      @marigo856 3 роки тому

      @@NedMakesGames I FINALLY got the shadows to work! After two weeks of poking the shader and digging the internet, I found the fix. Turns out, I just needed some extra lines of code (pastebin.com/buzfq0eJ) which I found on this forum (forum.unity.com/threads/shadow-and-distance-attenuation-do-not-work-in-urp-unlit-graph.803025/). I don't understand shader language, so I have no idea how this works, but it works and I can finally sleep well! I hope you might be able to find this helpful too or at least interesting.

  • @Nebraf
    @Nebraf 4 роки тому

    Thank you very much! this was so helpfull!

  • @robosoup2873
    @robosoup2873 2 роки тому

    hey, thanks for the tutorial ned!
    I swear I am having some kind of fundamental issue calculating just the basic specular angle.
    the highlight shows up in roughly the center of a sphere no matter what, and does not react to changing a directional light whatsoever. It also doesn't change in the shader graph previews when I adjust the default light angle supplied in your script.
    Your script is clearly working just fine, because the toon shading adjusts to the light angle as predicted.
    I have gone over each node carefully, they all have the exact same settings as in the video. the problem is somewhere before the saturation of the dot product at 13:04 in the video.
    did unity change something about the view direction node? I'm on 2020.3.34.
    EDIT: it's always when you finally write out your problem that you find the solution! I had to normalize the view direction before using it, as you point out in a newer video :)

    • @NedMakesGames
      @NedMakesGames  2 роки тому +1

      Oh yeah, there's a bug in certain versions of Unity where world space view direction isn't normalized. I should make a note of that in the description. Glad its working now, thanks for watching!

  • @ItsIntelligentDesign
    @ItsIntelligentDesign Рік тому

    Does this shader allow for materials that receive shadows, or just materials that cast shadows? I'm getting issues with my model not "seeing" shadows cast by other objects when using a material with this shader applied

    • @NedMakesGames
      @NedMakesGames  Рік тому

      Yes, you should be able to receive and cast shadows.
      Since I made this video, Unity has made several changes to the way keywords interact with Shader Graph. The method explained in this video may not work depending on the version you're using. Sometimes, just placing all the keyword properties on a sub graph works.
      You can also change your graph to a Lit graph and route everything through Emission (be sure to set base color to pure black). This will work for most uses.

    • @ItsIntelligentDesign
      @ItsIntelligentDesign Рік тому

      @@NedMakesGames Thanks. This comment made me realize my issue was that I had created regular booleans and not keyword booleans

  • @BLOXOBIZZAREMK2
    @BLOXOBIZZAREMK2 2 роки тому

    Btw anyone watching now you can get the light position and other data by making a vector 3 (for position, or a colour for light colour) variable, clicking on it and opening the 'node settings' in the graph inspector, unchecking expose, and changing the reference to specific key words. I cannot remember them off the top of my head but if you google 'get main light position shader graph' you should find them. Will save some time :)

    • @NedMakesGames
      @NedMakesGames  2 роки тому

      Yes, this is a nice trick to get main light data quickly! The variable names are the same ones used in this tutorial.

  • @kostjaaf
    @kostjaaf 4 роки тому

    Very nice Tutorial!

  • @anonymoussloth6687
    @anonymoussloth6687 3 роки тому

    at 12:54 why do we have to normalize the result of view dir + cam dir? since we are taking the dot product, the result would always be between -1 and 1 (and if we saturate, btw 0 to 1). I don't get why, mathematically, this is necessary? I tried to do it without the normalization, the the specular highlight became to big.

    • @NedMakesGames
      @NedMakesGames  3 роки тому +2

      We need the half vector to be a unit length. The dot product scales with the length of each vector, so it’s only -1to 1 if both vectors are unit length!

  • @Auroron
    @Auroron 3 роки тому

    Cant for the life of me get the light colors to work properly, not even the main light. Following the tutorial the point lights give off light but dont give off any color on my object. Fiddling with the graph im able to get point light colors to work (Foregoing the CalculateLightningRamp for the specular for example), but only some colors seems to show? For example blues wont show, any idea why?

    • @NedMakesGames
      @NedMakesGames  3 роки тому

      Hi! I think this might have to do with the way the shader handles light colors. It multiplies the light color with the texture color, so, for example, if the texture is pure red (1, 0, 0) and the light is pure blue (0, 0, 1), the resulting color will be black (0, 0, 0). This is how Unity handles lights normally, but since this toon shader doesn't have ambient lighting, it's extra pronounced. If you don't like this, you could convert each color to HSV and combine them somehow.
      If you change the light colors to white, does everything work as expected? If not, please post an image of your graph along with what version of unity you're using, and I can take a look.

  • @ralfaralf6805
    @ralfaralf6805 3 роки тому +2

    I was wondering for a while why I don't get shadows. Turns out shadows were deactivated in the directional light settings by default for me in Unity 2020.3. I case of someone else is struggling...

    • @NedMakesGames
      @NedMakesGames  3 роки тому +1

      Thanks for letting people know! Glad it’s working now

    • @ralfaralf6805
      @ralfaralf6805 3 роки тому

      @@NedMakesGames Thank you for making such great tutorials. It's working great and I'm having a lot of fun learning about shaders thanks to your tutorials :)

    • @NedMakesGames
      @NedMakesGames  3 роки тому

      @@ralfaralf6805 I’m really glad to hear that! That’s my goal!

    • @jessehenao4555
      @jessehenao4555 3 роки тому

      Thanks a bunch ! I was going nuts hahah

  • @anonymoussloth6687
    @anonymoussloth6687 4 роки тому

    Lol I am new to Unity so I didn't understand a thing in this video XD but it seems like a great video. Do you have any suggestions/resources that are helpful in starting shader graphs?

    • @NedMakesGames
      @NedMakesGames  4 роки тому +2

      This tutorial seems pretty good: www.raywenderlich.com/3744978-shader-graph-in-unity-for-beginners. Unity also has official tutorials here: learn.unity.com/tutorial/introduction-to-shader-graph. Thanks for watching though, I hope these help!

  • @mobartingames2053
    @mobartingames2053 2 роки тому

    Thanks for the tutorial :) One thing, you are speaking with same mono voice tone during all tutorial, it makes hard to follow up. thanks again

    • @NedMakesGames
      @NedMakesGames  2 роки тому

      Hi, I think I improve on that a bit in later tutorials. But thanks for watching!

  • @howarthstudios1217
    @howarthstudios1217 3 роки тому

    Is there anyway I could implement some sort of AO using this? I heard you say at the end about Ambient Lighting
    What sources did you use to learn about all this? Much appreciated thank you!

    • @NedMakesGames
      @NedMakesGames  3 роки тому

      Hi! The easiest way to do AO would be to sample the AO texture and multiply that value with the diffuse and specular attenuation before exiting the CalculateLights graph.
      I listed some sources in the video description! But mostly, I looked at the URP source code. There's not a lot of documentation yet.

  • @WALT_LIVE
    @WALT_LIVE 3 роки тому

    Hey i was wondering why you would use a 2D texture for the color of your materail instead of just using a color property? Great tutorial btw.

    • @NedMakesGames
      @NedMakesGames  3 роки тому

      Hi, thank you! Do you mean the texture around 8:40? That's the main texture, used to add details to your object. You can add a color tint pretty easily though. Just add a color property and multiply it with the ramp output.

  • @shabadava62
    @shabadava62 Рік тому

    no matter what i do, the smoothness dot on the main light source does not change size by editing the smoothness value. Any help?

  • @Hazzanamous
    @Hazzanamous Рік тому +1

    Hi there Ned great tutorial! I am running into an issue at the additional lights section where the "GetAdditionalLightsCount" function doesnt seem to work properly even after copy and pasting your final code. The error I get is "undeclared identifier 'GetAdditionalLightsCount' at line 34" Definitely at a loss for what to do at the moment since even copying the code completely didn't fix the issue. I am running on Unity 2021.2.19f.

    • @NedMakesGames
      @NedMakesGames  Рік тому

      Hi! That is strange, GetAdditionalLightsCount seems to work correctly for me in 2021.2! Can you please make sure that URP is a "target" of your graph? In the graph inspector, it should list it under "Targets."

    • @angelgabrielcaviedesjoya9368
      @angelgabrielcaviedesjoya9368 Рік тому

      @@NedMakesGames I have the same problem and it is shown as a target in the graph inspector

    • @ColtPtrHun
      @ColtPtrHun Рік тому

      I'm getting a similar error on 2022:
      "undeclared identifier 'AddAdditionalLights_half' at line 190".

    • @ColtPtrHun
      @ColtPtrHun Рік тому +3

      For me it can be solved by:
      - Clicking on the custom function node
      - In Graph Inspector/Node Settings change the Precision from "Inherit" To "Single"

    • @izzydev9919
      @izzydev9919 8 місяців тому

      ​@@ColtPtrHun Life saver, much appreciated

  • @mhrohan917
    @mhrohan917 3 роки тому

    Love this Channel For Shader. Thanks @Ned

  • @hibiscusbear
    @hibiscusbear 4 роки тому

    really cool and well done :)

  • @ChasmerPlays
    @ChasmerPlays Рік тому

    Hey, really nice tutorial. I got shadows working but they are so bad. Jagged edges, ugly self-shadowing. How did you manage to make them look so crisp in your project? I tried fiddling with RP asset settings like distance, cascades and so on... But all shadows just look so bad. On things like capsule or sphere my diffuse shadows are completely covered by ugly self-shadowing. Do you know how to get rid of that?

    • @NedMakesGames
      @NedMakesGames  Рік тому

      Hi! Sounds like you need to change the shadow biases. You can edit these on the URP settings asset or the main light in your scene. If adjusting biases doesn't change the look at all, there must be some other cause. I would see if shadow map resolution, soft shadows, or cascades adjust the shadows at all.

  • @IshaiMeresman
    @IshaiMeresman 3 роки тому

    Thanks for the great tutorial!
    Can it be that the shadows part is unnecessary? I get shadows after the diffuse part

    • @NedMakesGames
      @NedMakesGames  3 роки тому +1

      Thank you!
      Shadows seem to work for some people out of the box, so if they do for you, you can skip all that with keywords. Just be sure that both casting and receiving shadows works, because they’re separate concepts when working with shaders.

  • @Likii_Handle
    @Likii_Handle Рік тому

    Hi, I’m using Unity 2022 something and it seems that you cannot access the shadow keywords as you did but after some aimless scrolling I did find them in some sub menu in the material inspector. They were turned on by default however the shadows are still not appearing… All the other requirements for the shadows you mentioned were present too. Do you know what’s the cause for the shadows not showing? Thanks!

    • @NedMakesGames
      @NedMakesGames  Рік тому

      Hi! Unfortunately, I have not been able to try this out in 2022, so I'm not sure what the issue could be. I have heard that some viewers can get it working by copy-pasting the keyword properties to a subgraph or defining the keywords at the top of the HLSL include file, like "#inlcude _MAIN_LIGHT_SHADOWS", ect.

  • @J0ta_Emee
    @J0ta_Emee Рік тому

    Hello, thanks for the video, the shaders turned out exactly how I expected. However, I'm having some troubles and have some questions, I'm new to unity and to programing, so, sorry if any of them are dumb questions. The first one is: how can I use the shaders I made in the new project in other projects that I have ?
    The second one is: when I tried to make the specular lighting, my view direction added with the custom function always turned out with the "add circle" being fully the same color as the custom function circle, no matter what I did, what could be the cause of it ?

    • @NedMakesGames
      @NedMakesGames  Рік тому

      Hi! Sorry for the late reply, I was away for the holidays.
      I'm glad you liked the video!
      1. In Unity, you can export assets into an "asset package" file which you can import into another project. docs.unity3d.com/2018.1/Documentation/Manual/HOWTO-exportpackage.html
      2. The preview nodes usually don't have all lighting data available, so even if they look strange, your shader might still work correctly! Be sure to test it out on an object in the scene.

  • @Bluequaz
    @Bluequaz 3 роки тому

    My objects cast shadows, but do not receive them. Anybody have fixes? the entirety of the shader graph UI is different, so I cant find settings for MultiCompile and Local. Any help appreciated on this. Is this example even supposed to receive shadows?

    • @NedMakesGames
      @NedMakesGames  3 роки тому

      Hi! Yes receving shadows is supported! In 2020.2 and later, Unity changed the UI so that keyword settings are in the inspector window (by default in the top right corner). You might have to switch tabs to see them.

  • @anonymoussloth6687
    @anonymoussloth6687 3 роки тому +1

    When I type the keywords in the debug mode, the ramp strips become very distorted and bad looking (I can see a bit happening in yours as well at 11:27). Why does this happen and is there a way to fix it?

    • @NedMakesGames
      @NedMakesGames  3 роки тому

      Hi! It could be your shadow settings. Go to your URP settings asset and up the shadow resolution. I’d also check the ramp’s texture importer settings. Turn off compression, sRGB, automatic power of 2, and mipmaps.

    • @anonymoussloth6687
      @anonymoussloth6687 3 роки тому

      @@NedMakesGames The shadow res only affects the shadows and not the ramp texture used to get the cell shading effect on the object. This happens right after i put the keywords in the debug mode. Also, for some reason, I am getting shadows without using the keywords (I am using unity 2020.2 and URP 10.2.2) as I mentioned in another comment just now. I just don't get shadows on the object itself (is this because it is unlit)?

    • @NedMakesGames
      @NedMakesGames  3 роки тому

      @@anonymoussloth6687 A small shadow map resolution could affect the apparent ramp, since shadows would be pixelated. Also, the keywords enable shadows on the object, so you do need them in that case. Objects will cast shadows regardless, but only receive shadows with the keywords enabled.

    • @anonymoussloth6687
      @anonymoussloth6687 3 роки тому

      @@NedMakesGames I played around with the settings a bit more and it seems that the URP shadow settings is the culprit. For some reason, if soft shadows is enabled, the ramp outlines on the object are fine, but when it is disabled, they become distorted and pixelated

    • @diamonds8014
      @diamonds8014 2 роки тому +1

      For anyone else reading this in 2022! I'm using unity version 2020.3.21f1, to fix the ragged edges on the toon ramp, go into Universal RP settings and changing the Shadows-> Depth Bias setting or the Shadows -> Normal Bias setting. This fixed the ragged edges for me.

  • @GiraPrimal
    @GiraPrimal 2 роки тому

    Hi!
    I'm trying this tutorial in 2021.2.8f1 and my objects do not receive shadows. It does work in 2020.3 LTS, though.
    I wonder if I'm missing something specific to that version of Unity... or if I simply missed a step. Any ideas?

    • @NedMakesGames
      @NedMakesGames  2 роки тому +1

      Hi! You might try following the steps in this video for shadows, mostly the part about keywords: ua-cam.com/video/GQyCPaThQnA/v-deo.html
      Just place the keywords in a subgraph, and it should work nicely.
      That tutorial makes something similar to this toon shader tutorial, but uses more current techniques. At some point, I plan to recreate this toon shader tutorial using that custom lighting as a base.

    • @GiraPrimal
      @GiraPrimal 2 роки тому

      @@NedMakesGames It works like a charm! Thanks ;)

  • @brennanbugbee
    @brennanbugbee 2 роки тому

    Instead of a texture you can use a gradient node and sample the gradient using the diffuse values

    • @NedMakesGames
      @NedMakesGames  2 роки тому

      That's true! Just note that you can't edit gradients in the material inspector, so all materials will have to use the same gradient. If that's OK, this can be a good trick!

  • @niiiiiiiiiiiiiiiiiiiiiiiiiiick
    @niiiiiiiiiiiiiiiiiiiiiiiiiiick 3 роки тому

    Hi thanks for the great tutorial :) Wondering if there's a reference somewhere I can look at for URP related functions in shader graph - would love to expand this shader so that it is affected by environment lighting, even just the sky / equator / ground colors from the gradient mode would be really cool.

    • @NedMakesGames
      @NedMakesGames  3 роки тому

      Hi! Thanks, I’m glad it helped you out!
      You can see a list of nodes here: docs.unity3d.com/Packages/com.unity.shadergraph@10.4/manual/Node-Library.html
      It’s pretty difficult to get full environmental lighting in an unlit graph, but check out the “Ambient” and “Baked GI” nodes.

  • @ty-xq7bl
    @ty-xq7bl 3 роки тому

    I was wondering if its possible to remove the rounding of shadows and instead opt for heavy artifacts(boxy shadows) instead?
    Which nodes would I need to use in order to
    -Remove the shine in the object and have it completely flat texture?
    -Reduce the automatic rounding of the shadows and keep the artifacts(it looks cool imo but its a very strange request i know)
    Thanks in advance!

    • @NedMakesGames
      @NedMakesGames  3 роки тому +1

      Hi!
      You can remove the shine by setting the specular ramp to black, or just removing the specular ramp nodes.
      If you want blocky shadows, remove the SHADOWS_SMOOTH keyword from your graph and turn off smooth shadows on your URP settings asset. This will probably degrade the toon effect near shadows, but maybe that's what you're looking for!

    • @ty-xq7bl
      @ty-xq7bl 3 роки тому

      @@NedMakesGames Thank you!

  • @jamjam.100
    @jamjam.100 Рік тому

    This toon shader would be perfect with the 3d pixel style, any informative methods onto how to add pixelated style??

    • @NedMakesGames
      @NedMakesGames  Рік тому

      This video looks nice! ua-cam.com/video/R9MoyEOdmeA/v-deo.html

  • @gonzaloburgos6444
    @gonzaloburgos6444 3 роки тому

    Hi Ned, I'm working on Unity 2020.3.0f1
    I'm trying to replicate this tutorial using your "Main and additional lights" scripts.
    When I set up the custom function on the graph inspector I get this bug message instead of the green color of the 4:51-->
    Shader error in 'hidden/preview/CalculateMainLightCustomFunction_c82dff837c5f4d038c71b6ca881cb0c4': Invalid conditional expression. at Assets/Shaders/New-toon-shader/includes/Lighting.hlsl(4)
    Pointing me to the 4th line of the Lightning.hlsl-->
    void CalculateMainLight_float(float3 WorldPos, out float3 Direction, out float3 Color, out half DistanceAtten, out half ShadowAtten) {
    What I'm doing wrong?

    • @NedMakesGames
      @NedMakesGames  3 роки тому

      Hi! Are you using 2020.2 or newer? Try changing “#if” to “#ifdef” Unity changed how one of their keywords worked in 2020.2

  • @Gaffroninja
    @Gaffroninja 4 роки тому

    Hi, I'm having an issue with the specular highlighting.
    Note: I am using 2020.1.6f1, I'm also a bit of a newbie to all this shaders stuff and trying my best to learn how they work :)
    I did exactly as stated in the video up to 13:28, and there has been no change to the shaders appearance. At first, I had skipped out the change to the code to get shadows working as from what I noticed that issue has been resolved in this version of unity. However I ended up implementing that code just in case I needed it for the specular highlights, unfortunately this started throwing up errors;
    e.g. Shader error in 'hidden/preview/Normalize_47D966FC': 'CalculateMainLight_float': no matching 4 parameter function at line 56 (on d3d11)
    This occurs for other nodes in the shader editor.
    Any help would be great! :)

    • @NedMakesGames
      @NedMakesGames  4 роки тому

      Hi! It's hard to tell what's wrong just from that error message. Could you post a screenshot of your Lighting.hlsl, specifically line 56? It seems like some function is being called with 4 arguments when it doesn't support that number.

    • @Gaffroninja
      @Gaffroninja 4 роки тому

      @@NedMakesGames Apologies for that, here is the screenshot. prntscr.com/vgcr4g
      I realised my mistake with the errors that it was a log of errors from whilst I was making changes rather than the current build.
      However, I am still stuck on why the specular highlight isn't showing up. I've followed you on twitter and my DM's are open on there if it's an easier place to talk!

    • @NedMakesGames
      @NedMakesGames  4 роки тому

      @@Gaffroninja Hmm, so you saw highlights before you added in shadows? Your script looks OK. I would double check that your ramp is set up to handle specular highlights. You could also temporarily disconnect the diffuse lighting (in the Toon graph, route the specular ramp output directly to the Unlit master node). That will show you what your specular lighting looks like by itself. Might help you diagnose the issue.
      Feel free to post screenshots of your graphs too. It's easy to get things twisted around

    • @Gaffroninja
      @Gaffroninja 4 роки тому

      @@NedMakesGames My bad again, I find it difficult to be concise and precise over text.
      The shadows have been working fine, but I even had shadows before I added the scripting in to allow shadows to be cast. (I assume that was because of something unity has changed in the version I'm using.)
      The highlights weren't visable before or after I added the scripting for shadows, however I think it would be something to do with my ramp like you said as I haven't touched that (This could easily be a lack of understanding on my part.)
      Here's the screenshots of my current Graphs
      Toon: prntscr.com/vge4xz
      CalculateLights: prntscr.com/vge54e
      CalculateLightingRamp: prntscr.com/vge6fk

    • @NedMakesGames
      @NedMakesGames  4 роки тому

      @@Gaffroninja Oh no problem!
      I think this is my bad! Your graphs are fine actually, you just need to continue past 13:28 in the tutorial. I was trying to show what could happen if you implemented specular lighting without the adjustment I mention at 13:40, but for you, no highlight would actually display yet. I can see how that's confusing. I'm sorry about that!
      So yeah, just continue through the video. You should get highlights by 14:56. If you have any other problems, feel free to post again!

  • @f0xta1l99
    @f0xta1l99 11 місяців тому

    How would you go by adding a custom texture to your toon shader's calculate lighting ramp?

  • @BLOXOBIZZAREMK2
    @BLOXOBIZZAREMK2 2 роки тому

    After finishing the Shadows section, should the meshes now be receiving shadows as well as casting? Mine cast but do not receive

    • @NedMakesGames
      @NedMakesGames  2 роки тому

      Hi! Yes, you should receive shadows. Did you get to the part where you add keywords to the graph and material?

    • @BLOXOBIZZAREMK2
      @BLOXOBIZZAREMK2 2 роки тому

      @@NedMakesGames Yeah, I went through the whole shadows section about 20 times, almost frame-by-frame in the end, but no matter what I do, they do not receive shadows

    • @NedMakesGames
      @NedMakesGames  2 роки тому +1

      @@BLOXOBIZZAREMK2 Oh darn! What version of Unity are you using? This part can be difficult to get working since it's a little "hacky."
      You can try adding the keywords to a subgraph, like in this video: ua-cam.com/video/GQyCPaThQnA/v-deo.html
      It's sometimes more reliable.

    • @BLOXOBIZZAREMK2
      @BLOXOBIZZAREMK2 2 роки тому

      @@NedMakesGames yeah that worked :)

  • @WillzyX07
    @WillzyX07 Рік тому

    It might sound stupid, but how can I apply the shader to my existing objects in the scene? Ideally I would like to apply it to all texture at once instead of one by one...

    • @NedMakesGames
      @NedMakesGames  Рік тому

      Hi! Unfortunately, there's not an easy way to do this. If you set the reference name for your properties to match the names in your shader, they may move over. For instance, the main texture for the default lit shader uses "_MainTex"

  • @sebastiancai221
    @sebastiancai221 3 роки тому

    Hi, Ned, thank you very much for sharing this brilliant tutorial!!!! I learned a lot. But still a problem that bother me a little. I noticed that for this model, it works only when the light source is set as directional light, is there a way that I can also apply point light as the light source and still have such effect?

    • @NedMakesGames
      @NedMakesGames  3 роки тому +1

      Hi! Thank you for watching!
      By the end of the tutorial, additional point and spot lights should light your model (but your model will not receive shadows from them, I add that in the follow up video: ua-cam.com/video/whmPkDp3dqo/v-deo.html )
      If you're talking about the main light, I think Unity only supports directional type for that.
      Sometimes the light ramp can hide light from additional light sources. If you change the light color, it might make things more obvious!

    • @sebastiancai221
      @sebastiancai221 3 роки тому

      @@NedMakesGames thank you very much 😬

    • @sebastiancai221
      @sebastiancai221 3 роки тому

      @@NedMakesGames Hi, Ned. Thank you again. I finally made it with the spot light. But still a small thing i want to ask. If i choose to use a very low pixel texture as the shadow ramp map, the dividing line between two colors becomes blurred, as the same as when i want to apply a low pixel texture to the material (for example to use 8*8 pixel texutre for your rainbow texutre), the material is really blurry. For the image setting i have already set the Filter Mode as Point(no filter) and Compression is None, is there a way to fix it?

    • @NedMakesGames
      @NedMakesGames  3 роки тому

      @@sebastiancai221 No problem! That is strange. With point filtering, you should get crisp lines. Maybe try turning off mipmaps? They're not needed for such small textures anyway.
      Also, if you're passing a sampler to a SampleTexture2D node, make sure they're set to point filtering mode as well.

    • @sebastiancai221
      @sebastiancai221 3 роки тому

      @@NedMakesGames Thank you very much >.< I figured it out, I did add some other notes in the shader graph, after deleting them i have now crisp lines. You're so kind!! I never see anyone else who replies everyone everytime like you 💖

  • @ERBaruin
    @ERBaruin 4 роки тому

    Loved this tutorial!
    I'm testing different toon shaders and Shadows are always a problem. How do you handle shadows cast by other objects?.
    First problem is blocking the directional light and apply shadow accordingly.
    Next issue are objects with the toon shader casting shadows between themselves.
    And for some reason the objects dont block light, they are affected by point lights, but the light is still reaching the ground behind them.
    I hope you make a part 2 :D
    Thank you very much!

    • @NedMakesGames
      @NedMakesGames  4 роки тому +1

      Thank you! Yeah, shadows are always tricky.
      This shader uses URP's (Universal Render Pipeline) shadow code for the main directional light. So that is fully featured.
      Unfortunately, URP does not support point light shadows, so this shader cannot either. If you need them, I would consider using the High Definition Render Pipeline, but I don't know how easily my shader graph will move over to it.
      Spot lights are another issue entirely. URP does support spot light shadows, but they were really buggy for me, so I did not include support for them in this video. Maybe I should look more into it?

    • @ERBaruin
      @ERBaruin 4 роки тому

      @@NedMakesGames I really hope that Unity expand the support for shadows in shadergraph... Thanks! I learned a lot from this tutorial, but I guess we have to wait a little longer :D

  • @aAaAaAaAaAaAaAaAaAaAaAaAaAaAh6
    @aAaAaAaAaAaAaAaAaAaAaAaAaAaAh6 2 роки тому

    Hi, I have a problem in Shadows part, Unity say to me this: Shader error in 'Master': Invalid conditional expression. at Assets/Includes/Lighting.hlsl(5)

    • @NedMakesGames
      @NedMakesGames  2 роки тому

      Hi! Are you using Unity 2020.2 or later? Try changing the "#if SHADER_GRAPH_PREVIEW" at that line to "#ifdef SHADER_GRAPH_PREVIEW". You might also have to do that later on in the file too.

  • @gabrielpereira6930
    @gabrielpereira6930 Рік тому

    How can I make the object cast shadow on another object using this toon shader for unity 2021.3? I tried to follow the video by in the debug mode, there isn't the field to insert the keywords anymore.

    • @NedMakesGames
      @NedMakesGames  Рік тому +1

      Hi! I've had some conflicting reports on this, but you might be OK with just the keyword entries in the subgraph's properties. Also try copy-pasting them to the main Toon graph.
      If that doesn't work, you can change your graph to a Lit graph, and then route the final color into Emission instead of Base Color / Albedo. This last option might have some strange side effects with baked lighting, but I'd try it out and see if it works for your game.

    • @NuggsSauce07
      @NuggsSauce07 7 місяців тому

      @@NedMakesGames just confirming, ran into same bug, copy and pasted "CalculateLights" shader to "Toon" shader and it worked! thanks for the tutorial and still helping w trouble shooting 3 years later, your awesome!!

  • @uicosole
    @uicosole 3 роки тому

    Updated to unity 2020.3, now I'm getting "Invalid conditional expression" at Lighting(5), which is the
    "out half DistanceAtten, out half ShadowAtten)" part of the calculatemainlights function.
    Does it still work, is there something I need to change?

    • @uicosole
      @uicosole 3 роки тому

      oh hold on, saw the description, gonna test that

    • @uicosole
      @uicosole 3 роки тому

      the fourth step fixed it, thanks again for the great tutorial!

    • @NedMakesGames
      @NedMakesGames  3 роки тому

      @@uicosole I’m glad that worked! Thanks for watching!

  • @Montigorable
    @Montigorable 3 роки тому

    Thank you for the tutorial. A bit sad to hear that the shader graph has limitations and some parts of a shader had to be written using code. Do you know if Amplify shader editor has such limitations?

    • @NedMakesGames
      @NedMakesGames  3 роки тому

      Hi! Sorry, I don't have any experience with Amplify

    • @Montigorable
      @Montigorable 3 роки тому

      @@NedMakesGames Ah, okay. Thank you very much for the tutorial!

  • @dhruvbajaj1054
    @dhruvbajaj1054 2 роки тому

    Help. I cant get the object to receive shadows. Im using Unity 2021 LTS, tried it on 2020LTS too

    • @NedMakesGames
      @NedMakesGames  2 роки тому

      Hi! Sometimes it works better if you put the keywords in a subgraph instead of the main graph. Try copy and pasting them there.

  • @holdenthompson1449
    @holdenthompson1449 4 роки тому

    I'm trying to use the calculate light subgraph node in a 2D set up, but it's just not wanted by to work with the unlit sprite graph or the regular unlit graph. What am I missing here? Does this method just not work with 2D lights?

    • @NedMakesGames
      @NedMakesGames  4 роки тому

      I have no experience with 2D lights, but a quick glance tells me they are handled pretty differently. So, unfortunately, I think you're right.

    • @holdenthompson1449
      @holdenthompson1449 4 роки тому

      @@NedMakesGames I guess I could just use 3D lights on the 2D Sprites, but that's not exactly optimized :/

    • @NedMakesGames
      @NedMakesGames  4 роки тому

      @@holdenthompson1449 Yeah, that's probably the easiest thing. You could maybe find out how to adapt the shader to 2D lights by reading through the URP source code, but that is pretty intimidating. I hope you can get it working, whatever you chose to do!

  •  Рік тому

    Great tut! but any ideas on how to add the keywords in 2021.3? the debug option in the material is gone. Now there is one called "valid keywords" which is an array, but it wont let you modify it :/

    • @NedMakesGames
      @NedMakesGames  Рік тому

      Hi! Yeah... Unity has made several changes to the way keywords interact with Shader Graph since I made this video. The method explained in this video may not work depending on the version you're using. Sometimes, just placing all the keyword properties on a sub graph works, ignoring the material steps.
      You can also change your graph to a Lit graph and route everything through Emission (be sure to set base color to pure black). This will work for most uses.

  • @fun2run4
    @fun2run4 3 роки тому +2

    Anyone wondering about how to do rim lighting. I've found the fresnel effect works quite well.

  • @Guy-rv2vl
    @Guy-rv2vl 3 роки тому +1

    Hi Ned,
    I got this awesome shader to work but when I try it in my AR scene (Android) it bugs out and doesn't seem to work. can you think of a solution? I think ShaderGraph might be buggy with XR atm.

    • @NedMakesGames
      @NedMakesGames  3 роки тому

      Oh, that’s a shame! I’m not sure why it would have a problem with AR, but I’ll take a look at in the next few days. Do you mind uploading a screenshot, if possible? Thanks!

    • @Guy-rv2vl
      @Guy-rv2vl 3 роки тому

      ​@@NedMakesGames
      Hi Ned!
      Thank you so much for reply (and quick)
      Here's an image showing the issue:
      ibb.co/frzFPRz
      My shader is on the right, on android it is just stuck, doesn't seem to respond to the nDot light direction etc..
      I added a one or two things to your shader like dithered and dotted specular (using unity's graph only).

    • @NedMakesGames
      @NedMakesGames  3 роки тому

      @@Guy-rv2vl Thanks for the screenshot. That is strange! I had a bit of time to look into this and I couldn’t find any obvious reason this is happening. It’s possible Unity might have fixed a bug in the 2020.2 beta. You could try the shader in that version. Make sure you make of copy of your project so you can revert to your current Unity version, if needed.
      Also, have you tried bypassing the ramp, to see if the bug is in the lighting calculation or the ramp sampling?
      I’ll investigate some more over the week!

    • @Guy-rv2vl
      @Guy-rv2vl 3 роки тому

      @@NedMakesGames I think it had to do with android and the phone performance, on IOS it seems to work fine now that I've tried. So I'll use that for now.
      Thanks a lot & keep up the good work :)

  • @captain_baru
    @captain_baru 3 роки тому

    Once I pick the colorRamp texture for my toonRamp nothing changes. I did the tutorial twice to this point, but I got the same problem again. Does anyone know why?

    • @NedMakesGames
      @NedMakesGames  3 роки тому +1

      Hmm how does your object look? All black, no shading, or smooth shaded? Do you get any errors?

    • @captain_baru
      @captain_baru 3 роки тому

      @@NedMakesGames Thanks for your help! There aren't any errors. Its smooth shaded.

    • @NedMakesGames
      @NedMakesGames  3 роки тому +1

      @@captain_baru no problem! That suggests to me that your graph is bypassing the ramp calculation or your graph is set to lit mode. Check that the graph type is set to unlit in the graph inspector, if you’re using 2020.2 or newer.
      If you want to upload a screenshot of your graph to imgur or whatever I can take a look, too!

  • @whytecold
    @whytecold 3 роки тому

    I am having trouble with the main light, the preview looks good in ShaderGraph, but in the Editor itself the shader is broken, complaining about Direction not being set. I'm not sure what causes this, as it should be directly taken from the MainLight?
    Shader error in 'Master': 'CalculateMainLight_float': output parameter 'Direction' not completely initialized at Assets/Models/Shaders/mainLight.hlsl(4) (on metal)

    • @NedMakesGames
      @NedMakesGames  3 роки тому

      Hi! It seems like you’re not setting the “Direction” output variable in the #else block (which only compiles outside the shader graph previews). Maybe you need to add “Direction = light.direction” ?

    • @whytecold
      @whytecold 3 роки тому

      @@NedMakesGames I‘ll check again for typoes, but I do set direction with light.direction, which is why the error confuses the heck out of me EDIT: I literally copypasted the gitcontent and the error persists. It looks like the GetMainLight function is somehow not working/not returning any results

    • @NedMakesGames
      @NedMakesGames  3 роки тому

      @@whytecold That seems to be happening. Very strange. What version of Unity and URP are you using? Do you have a directional light active in your scene?

    • @whytecold
      @whytecold 3 роки тому

      @@NedMakesGames It was me being stupid. I apparently managed to delete the 'Universal' target for the shader, which broke it. Now I just need to find out why my spot lights only affect the shadowed part of the toon, while multiple directional lights work...

    • @NedMakesGames
      @NedMakesGames  3 роки тому

      @@whytecold Oh no problem, it happens to the best of us. I found that the ramp tends to wipe out spot and point lights unless you increase their intensity more than you normally would. It can be difficult for them to overcome directional lights' intensity.

  • @lucky665
    @lucky665 3 роки тому

    Hey thanks for this tutorial. I have a problem and I do not know what to do. In the first part (until 7:50) it doesn't quite work with the ToonRamp. It only goes to the half of the sphere. So where the light shines directly it is white (that's right), then comes the light gray (that's also right). Then comes only a narrow ring with the dark gray and the rest again with the light gray. So he doesn't go through with the shadow completely. Can anyone help me? Thanks (I'm using 2020.3)

    • @NedMakesGames
      @NedMakesGames  3 роки тому

      Hi! That sounds strange. So the side that should be in total shadow is still receiving some light? Without the ramp texture, does it look OK?
      Maybe try setting your ramp texture to point mode in the texture importer. And make sure that the very edge of your ramp is completely black.
      If you want, you can upload a screenshot of your ToonRamp graph and I can take a look at that too!

    • @gnommen
      @gnommen 2 роки тому

      The Sampler State node needs Wrap to be set to Clamp

  • @adityarahmanda
    @adityarahmanda 3 роки тому

    Help, my prefab is casting shadow if I drag it to the scene, but it doesnt cast shadow when I instantiate it.
    Do anyone know how to solve it?
    Edited : Solved. It cast shadow, but a small shadow. I used a low res shadow and bad lighting angle so it look like it doesnt appear.
    Nice tutorial 👍

  • @bramboeykens6030
    @bramboeykens6030 3 роки тому

    Hi for some reason the additional lights didnt contribute to the the shadow on the model, any ideas what i missed?

    • @NedMakesGames
      @NedMakesGames  3 роки тому

      Hi! I made a follow up video detailing how to add additional light shadows here m.ua-cam.com/video/whmPkDp3dqo/v-deo.html

  • @huntserston3579
    @huntserston3579 4 роки тому +1

    Quick question is it possible to mask the shadows with a texture? I want to do comic book style where they use dots to represent some of the shading

    • @NedMakesGames
      @NedMakesGames  4 роки тому +4

      Yeah this is definitely possible! I want to do a video on it eventually, but the idea is to use the ramp texture to choose a shading texture to overlay on the model. These textures can have a dot pattern to get the classic halftone/comic look.

    • @huntserston3579
      @huntserston3579 4 роки тому

      @@NedMakesGames nice can't wait to see what you do! Also can't wait to see what other rendering and shading vids you do!

    • @LexGear
      @LexGear 2 роки тому

      @@NedMakesGames Has this been done yet?

    • @NedMakesGames
      @NedMakesGames  2 роки тому

      @@LexGear Unfortunately not. It's on my list to do when I return to toon shading, which is high on my list.

    • @LexGear
      @LexGear 2 роки тому

      @@NedMakesGames Litterally the only thing left on my list of "nice to haves". If you ever get around to it, that would be super.

  • @Jon-ux4zi
    @Jon-ux4zi 3 роки тому

    Hello I am getting a frustrating error code inside the shader graph along with two errors in the console. Only one person has commented about this but it is unclear the solution. The error in the shader graph says "Variable ' _CalcualteMainLightCustomFunction_ a bunch of numbers_Direction_1' used without having been completely initialized"
    I have no spelling errors and up until the custom function point everything I have is the same as yours, any help would be much appreciated!

    • @NedMakesGames
      @NedMakesGames  3 роки тому

      Hi! Where are you in the tutorial? The first custom function to get the main light info?
      That error means that the variable "Direction" hasn't been initialized before exiting the custom function. This might be because of an annoying change Unity made in 2020.2. Do you have a line that says "#if SHADERGRAPH_PREVIEW" ? Try changing that to "#ifdef SHADERGRAPH_PREVIEW" . If that doesn't fix it, feel free to upload your script to GitHub Gists or a similar website and I can take a look at it.

    • @Jon-ux4zi
      @Jon-ux4zi 3 роки тому

      @@NedMakesGames Hey thank you for reaching out and helping me. I am on the first custom function. I am deeply sorry because unfortunately I am not experienced with any shader graphs at all. So please hang in there with me but I assume by script you mean the lighting.hlsl file? If so that is here "gist.github.com/jobrogi/fa6a7ddc88f8a4349eeb4f983b0bd4d5" changing the ifdef did not help sadly.

    • @Jon-ux4zi
      @Jon-ux4zi 3 роки тому

      I would just like to come back to this in case anyone is having this issue. I just now figured it out after looking at a comment below mine and double checking. My computer was hiding the extension files and because of that it wasn't showing that it was still a .txt file. Like the comment below mine said you can go to view at the top of your file directory tab and select show file extensions to check if that is happening to you. Also I did find that I did have to change the #if to #ifdef inside the hlsl file. @Ned Makes Games thank you for your help!

  • @sam8686
    @sam8686 4 роки тому +1

    Don't know if this is even possible but if it is how would you go about implementing this shader receiving shadows from other objects as it's unlit and I'm not that great at hlsl

    • @NedMakesGames
      @NedMakesGames  4 роки тому +1

      They should already receive shadows caused by the main light.
      In the custom functions, I hook into URP's shadow code, so even though the shader uses the unlit master node, it has the same shadow code as if it used the PBR master node. Only exception is I couldn't get spot light shadows working, but I plan to look into that more in the future.

    • @sam8686
      @sam8686 4 роки тому

      @@NedMakesGames Thank you!! After a bit of re-going over it all, I realised I had spelt a couple of the keywords wrong and that was causing the problem. Do you have any tips or places to look to learn all of this shader and hlsl stuff because I'm really into it I just am a bit clueless :)

    • @NedMakesGames
      @NedMakesGames  4 роки тому +1

      Glad you got it working! I can recommend a couple other tutorial writers I found really helpful.
      For more shaders and graphs, Check out Minions Art: minionsart.github.io/tutorials/
      For a deep dive into rendering and how the SRP works, there's Cat Like Coding: catlikecoding.com/unity/tutorials/
      Hope that helps!

  • @kostjaaf
    @kostjaaf 3 роки тому

    getting this error on the lightnig.hlsl : variable '_CustomFunction_282e701e532b47ef9548c90b3d66d9e9_Direction_1' used without having been completely initialized
    Compiling Fragment program
    on unity 2020

    • @NedMakesGames
      @NedMakesGames  3 роки тому

      That means the output variable Direction is not always set to a value. It’s hard to tell exactly without seeing your code, but maybe you didn’t set it to zero before the shadergraph preview block?

    • @kostjaaf
      @kostjaaf 3 роки тому

      @@NedMakesGames thanks i got it to work now :)

  • @zhiyuehuang8351
    @zhiyuehuang8351 Рік тому

    Many thanks for the tutorial! I'm using Unity 2021.3.17 and I don't see Shader Keywords in the material debug. Instead I see valid keywords and invalid keywords. However, when I type into the size of valid keywords, the number automatically goes to invalid keywords. Is it a bug or...?

    • @NedMakesGames
      @NedMakesGames  Рік тому

      It seems in newer versions of Unity you don't need to worry about adding the keywords to a material. Try it with the keywords in a subgraph, and if that doesn't work, try to copy-paste them into the main graph.

    • @mochou_p
      @mochou_p Рік тому +1

      for me (2021.3.25f1), changing keyword scopes to global helped

  • @SuSu-nm5tf
    @SuSu-nm5tf 4 роки тому

    Hi ! sorry about asking a basic question but it's really confusing to me so much :S
    I have followed every steps in this video and everything is good til the Specular lighting part
    I tried to check every steps again and again but the specular light just can't show up.
    my unity version is 2019 4.8f1, I wonder this problem might be caused by version ? thanks for your tutorial : )!

    • @NedMakesGames
      @NedMakesGames  4 роки тому

      Hmm I doubt it’s the Unity version. You could try downloading the project from GitHub and comparing it to your project. Maybe you’ll find a bug that snuck in!

    • @samuelmhobbs
      @samuelmhobbs 4 роки тому

      Su JeMin, did you ever get this fixed? I ran into the same problem and haven't figured it out myself.

    • @TheKyle1YT
      @TheKyle1YT 4 роки тому

      @@samuelmhobbs In the same boat, did you find anything?

    • @samuelmhobbs
      @samuelmhobbs 4 роки тому

      ​@@TheKyle1YT I ended up combing through a few other tutorials that were credited from this video and ended up making a very nice toon shader with some adjustments. After reviewing this video again, the speaking isn't in synch with the movements of the shader graph exactly and he's jumping between a few subgraphs. I believe what is happening is that his subgraph outputs to a specular value that is already hooked up in the main shader graph (which is why it pops up without it looking like he hooked it up already). What ultimately needs to happen is described at about 14:30 in the video. You need to calculate the specular value and attach that to the attenuation node of the toon ramp that then gets added to the diffuse and fresnel lighting. Let me know if this helps.

    • @capzyL
      @capzyL 4 роки тому

      @@samuelmhobbs Thank you so much Samuel. I couldnt understand where I went wrong but if i kept going for a bit it all turned out great!