Making a Zelda-style Cel Shading Effect in Unity Shader Graph

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 ก.ย. 2024

ความคิดเห็น • 109

  • @danielilett
    @danielilett  3 ปีที่แล้ว +15

    Here I'll post clarifications and additions to the video! I mentioned we're using the Phong lighting model throughout the video, but we're actually using a modification of the original Phong model called Blinn-Phong. The Phong model uses r⋅v for the specular component (where r is a reflection of light direction, l, in n), whereas Blinn-Phong changes that to n⋅h, which I use in the video.

    • @Ma-kusu
      @Ma-kusu ปีที่แล้ว

      Great tutorial but for some reason my unity keeps saying this error message when I try and do the code you did at 3:34 : Shader error in ":Parse error : syntax error unexpected TVAL_ID at line 5

    • @hunabku9615
      @hunabku9615 3 หลายเดือนก่อน

      @@Ma-kusu Don't modify the 0.0f to 0f or 1.0f to 1f, juste copy past like in the github

  • @jarred7721
    @jarred7721 3 ปีที่แล้ว +22

    Another great shader video! The way you break it down into sections is great too, really helps to understand what's going on and how the shader achieves its effect.

    • @danielilett
      @danielilett  3 ปีที่แล้ว +6

      Thanks! Lately I've been trying to add sections more because I also find them helpful when watching or reading a tutorial. Some of my much older videos are shorter but they're also just a big block of information!

  • @LocalContentShow
    @LocalContentShow 3 ปีที่แล้ว +9

    I think I need to come back to this when I understand more about how Unity coding works but I like how you explained the different types of lighting at the beginning

    • @danielilett
      @danielilett  3 ปีที่แล้ว +4

      Thanks! I have a feeling that making a few videos based on theory like that might be something that's useful for people, so it's something I'll consider focusing on!

  • @ThisOldBlog
    @ThisOldBlog 2 ปีที่แล้ว +19

    Hi, this video was a massive help.
    Tip for others: Step and SmoothStep actually run and output per channel (RGB) so you can introduce unintentional artifacting at the edge of your colour changes if using using non-perfect-white lights (1,1,1) in your scene.
    To get cleaner edges: before doing your Diffuse SmoothStep, Subtract two of your colour channels (Green Y, Blue Z), so you effectively perform the SmoothStep on a single channel (Red X). Then you have several techniques to add the Green and Blue back in, for example a Combine with all channels fed the Red value.
    Note if you are going hard into diffierent coloured lights but want to use the above, you may want to re-add tints from the light colour back in directly.
    Update: Having considered the problem further, combining your RGB to a single balanced brightness channel and doing the Step on that would be more effective than basing just off Red.

    • @damiankuaga1115
      @damiankuaga1115 ปีที่แล้ว +1

      Can you show it on your shader graph?? I'm new in to shader's 😅

  • @kristianthaler6525
    @kristianthaler6525 ปีที่แล้ว +1

    Taking my time over several days to slowly digest this information, and it's a real goldmine. I've subscribed; teach me more sensei.

  • @infinityvy
    @infinityvy 2 ปีที่แล้ว +3

    yo this was amazing. you got me to finally learn shaders after procrastinating about it for almost a year now.

    • @danielilett
      @danielilett  2 ปีที่แล้ว +3

      Happy to hear that! Hope you enjoy your shader journey, I personally got hooked once I finally gave it a go and haven't stopped since!

  • @TheBirdSolution
    @TheBirdSolution 2 ปีที่แล้ว +1

    The immense satisfaction I feel when I'm having to explain to a dev how we as a publisher want a game stylised and I can pull out the WELL I KNOW A GUY card

  • @silashughesmusic
    @silashughesmusic ปีที่แล้ว +4

    Hello! If anyone is struggling with shadows not applying to objects with the cel shader material, all you have to do is go to the shader graph, and correct the material from Unlit to Lit, and you could also drag the overall output to the emission AND base color :)
    Hope that helped

    • @chalobeats8971
      @chalobeats8971 ปีที่แล้ว

      seems a little weird to use a lit shader after doing all this work to get the light sources from the scene 😅

    • @emor67
      @emor67 ปีที่แล้ว

      I agree it is a little wierd solution but now my shader looks cooler than before. Thanks btw

  • @bigtimecool9635
    @bigtimecool9635 ปีที่แล้ว +2

    Thank you so much for making this! This was such an informative video 10/10

  • @rinsofia8225
    @rinsofia8225 ปีที่แล้ว +2

    Great tutorial ! Helps a lot

  • @yeahnope620
    @yeahnope620 ปีที่แล้ว +3

    I feel like in order to be able to design shaders of this complexity on your own, you need to be an actual professional or otherwise be nearly fulltime occupied with this. For everyone else, you can only replicate this sort of stuff by following videos such as this one lol. Thanks for the upload.

    • @danielilett
      @danielilett  ปีที่แล้ว +3

      I very much felt the same way when I started out with shaders, but I'm thankful tools like Shader Graph have made things a bit more approachable. I spent a lot of time at the start following tutorials until bits of it here and there started clicking, but they did eventually all click and I hope they do for you too!

    • @yeahnope620
      @yeahnope620 ปีที่แล้ว +1

      @@danielilett Hey thanks man, appreciate that. Much love 🙏

  • @gnosnaz
    @gnosnaz 11 หลายเดือนก่อน +2

    Great information here, but moves so fast that it's difficult to follow along if you're trying to learn through re-creating in real time. A lot of stressful pausing, rewinding, oop it went too fast, rewind again, etc.

  • @mohammedgamersc9572
    @mohammedgamersc9572 3 ปีที่แล้ว +6

    i am hyped

  • @MaxIme555
    @MaxIme555 2 ปีที่แล้ว +1

    Very deserved Like and sub, great info thank you so much, you saved me from buying a cell shader from the asset store! In addition I got to understand how it works too

  • @evmoFPV
    @evmoFPV 2 ปีที่แล้ว +4

    When I try to make the GetAdditionalLights subgraph I get the error "Undeclared Identifier GetAdditionalLights_half at line 184" . I've followed your instructions exactly. Going through the code it seems I named all the variables correctly so I'm not sure what's going on here.
    EDIT: I fixed it. Name of the node had a typo.

  • @calaverah7889
    @calaverah7889 3 ปีที่แล้ว +2

    I'm pretty sure Breath of the Wild only uses one light source (I'm 100% sure WW does because of a certain effect it uses). But I'm wondering how it would be possible to define this shader with one source at a time and be able to switch between legal sources depending on distance/priority. So if you are near a lamp that you want to light up your character, it would take the over the main shading (passing on its own lit/shadow profile) and if you were near no other source the environmental directional light would take over. (I remember in WW you could see two torches near Link and it would jump between the two depending on distance.) Obviously this kind of effect would require good light placement so that two sources are never battling each other similar to two planes on top of one another clipping to infinity.
    Edit: I'm new to shader math so if this is obvious just ignore lol.

  • @qcortex07
    @qcortex07 ปีที่แล้ว +1

    Does this work in built-in RP? I tried it, and everything works just fine until the very end. When I try to set the base color to the sum of the light sources, I get the magenta checkers of death in the preview and in the material.

  • @Predulus
    @Predulus 2 ปีที่แล้ว +4

    @Daniel Ilett Sir, might you be persuaded to expand this to include received shadows? Edit: Hmm now I'm a bit confused, because the Lighting.hlsl file does seem to include some shadow stuff. The thing is, when I move my mesh into the shadow of a building, it is still fully lit by the directional light 😒

    • @JakeP78
      @JakeP78 2 ปีที่แล้ว +1

      I was able to add received shadows by changing the graph from Unlit to Lit, and then sending the output to the emission instead of the base color. It worked quite nicely 😁

  • @emor67
    @emor67 ปีที่แล้ว

    What a wonderfull tutorial

  • @leenpaws9680
    @leenpaws9680 2 ปีที่แล้ว

    Learned a Lot. Thanks for the Video

  • @lokemansson7508
    @lokemansson7508 2 ปีที่แล้ว +1

    WTF THIS IS SPACE SCIENCE!!!!

  • @ij20man35
    @ij20man35 ปีที่แล้ว +1

    What additional name spaces do you use for your script? Do you use "using Unity.Mathematics" for example? Thanks for reading.

  • @hollowstreak9553
    @hollowstreak9553 ปีที่แล้ว +1

    I've seen solutions to add shadows to this but whenever I use a point light the objects no longer have shadows. Do you have a better method to add shadows to this shader?

  • @lavaa7392
    @lavaa7392 2 ปีที่แล้ว +7

    This tutorial slaps. However, when I connect everything up, unity hits me with a "Shader error in 'Master': 'MainLight_float': output parameter 'Direction' not completely initialized at Assets/Graphics/Lighting.hlsl(1) (on d3d11)"

    • @OceaneAL
      @OceaneAL ปีที่แล้ว

      Did somebody solve that problem ?

    • @crouchyyy
      @crouchyyy ปีที่แล้ว

      Yea any solution on this? I have the same problem

    • @Comfortably-Dumb
      @Comfortably-Dumb ปีที่แล้ว

      I, too, have been hit with this problem

    • @Comfortably-Dumb
      @Comfortably-Dumb ปีที่แล้ว

      Turns out I just needed to switch to a URP project and the error went away for me!

  • @kooky74
    @kooky74 2 หลายเดือนก่อน +1

    Hello. I did more or less the same things with HLSL in my custom VR engine. I'm asking, why not doing the whole in HLSL? And is it efficient? BTW thanks for your video. I didn't think we could do so complicated with shader graphs

    • @danielilett
      @danielilett  2 หลายเดือนก่อน +1

      Doing this yourself directly in HLSL is almost certainly more efficient, but also a lot more complicated for a beginner (especially when you factor in depth passes, shadow passes etc, which Shader Graph does for you). The fact that Shader Graph lacks good support for custom lighting (even in later versions, you can get the main light direction and that's it) is restrictive, so this is an imperfect solution shown in the video, but yes it's nice that we can at least use a bit of HLSL code in graphs like this. It opens up a lot of complex possibilities!

    • @kooky74
      @kooky74 2 หลายเดือนก่อน

      Thx for the answer. After 20 years of low level custom engine programming, I'm new to Unity and allways be surprised how doing complex stuffs can now be easy for a non expert with these tools ;)

  • @nikarand6246
    @nikarand6246 2 ปีที่แล้ว

    thanks daniel very cool

  • @DonDisainer
    @DonDisainer 3 ปีที่แล้ว

    what a great way to explain :D thnx a lot!

  • @quentin6687
    @quentin6687 2 ปีที่แล้ว +1

    Thnaks for the tutorial ! I really like the final result of the Shder, But How can I receive shadow from other object with this shader ?

    • @thatonekid702
      @thatonekid702 ปีที่แล้ว

      switch from Unlit to Lit in the shader graph properties

  • @vacantly
    @vacantly ปีที่แล้ว +1

    awesome tutorial, but was wondering, the cel shading article on your site seems to be missing? tried going there to find it manually but couldn't. would be great to have that written version if it's possible.

    • @danielilett
      @danielilett  ปีที่แล้ว

      Hey, I actually do have a version of this on my website - I just made it before I started making TH-cam tutorials! This version was also an "introduction to Shader Graph" tutorial and it's a bit outdated since it uses Unity 2019.3, but it's there: danielilett.com/2020-03-21-tut5-1-urp-cel-shading/

    • @vacantly
      @vacantly ปีที่แล้ว

      @@danielilett ohh awesome for some reason the link in the description didn't work but this does! thanks so much!!

    • @danielilett
      @danielilett  ปีที่แล้ว

      I had no idea it was the wrong link, thanks for letting me know!

  • @digitalconsciousness
    @digitalconsciousness 2 ปีที่แล้ว +1

    Daniel, thanks for the video. I got it working perfectly. One question though: When it comes to things like link's blue shirt, how would the white line details be done? This setup doesn't seem like it's designed to work with textures, so I am assuming models would be split up into separate objects for each object that needs to be its own color. Is this correct? I would need to have all those white lines on the blue shirt be separate models so they can have a version of this shader applied to them, yes? That is my understanding of how this works. Great video!

    • @zekerton7262
      @zekerton7262 ปีที่แล้ว

      Skip to 12:30 to see how to use a texture. It's really easy.

  • @Kenji_195
    @Kenji_195 ปีที่แล้ว

    During 10:26, you start explaining these two sub-graphs for any additional light in the scene, as at that point it only works for the main light source (most likely the sun), and you've mentioned how there is nothing to handle loops in the shader graphs
    So your easy/quick solution was simply to copy the "main section" of each subgraph and paste it for multiple additional lights, my question in this comment is: Do we paste that section as many lights as there is in the scene?
    Idk, maybe for example let's say some hallway with a bunch of firelamps, let's say 30, 15 for each side, do we have to copy and paste that section for BOTH subgraphs 29 times (29 because it's minus the original)?
    And you shortly after say "It's up to 8", so there is no way to handle too many lights in this style?
    It's just out of curiosity, if I'm ever using this I doubt I'd have more lights sources other than the sun anyways

    • @mn-cb1ry
      @mn-cb1ry ปีที่แล้ว

      copy/paste it 8 times, unity will pick the 8 closest lights for you. you can adjust the max number in the render pipeline asset

  • @parriedswoosh
    @parriedswoosh 2 ปีที่แล้ว +2

    Anyone else having trouble with TransformWorldToShadowCoord(WorldPos); and GetMainLight(shadowCoord);

  •  3 ปีที่แล้ว +2

    Impressive work, do you think a similar effect can be achieved on UE4 using this as a guideline?

  • @animationsbelike
    @animationsbelike 2 ปีที่แล้ว

    Great Tutorial! :D

  • @MajorminorGaming
    @MajorminorGaming 2 ปีที่แล้ว +2

    This sort of shader is something I've been looking to make on my own for a while!
    I do seem to be having trouble casting shadows onto objects that use shader though. Is there any way I would be able to fix that?

  • @softwet525
    @softwet525 2 ปีที่แล้ว +1

    is it possible to add transparency to this shader? And if so, how would one go about doing it?

  • @timothepaul_
    @timothepaul_ 3 ปีที่แล้ว +1

    Hi, I just completed the tutorial, which is great ! Do you have any idea not to make the model look shinny ? I understood the settings for the specular, but it always have that shinny look that I think doesn't look great with skin or fur for example. If you have any idea to "fix" that, I would greatly appreciate it

  • @sh3rbert
    @sh3rbert 2 ปีที่แล้ว +1

    So far the previews seem to broken and I don't think I messed up, hopefully it works in application
    Edit: Figured it out make sure to set values to the properties (me stupid)

  • @NutBuster99
    @NutBuster99 3 ปีที่แล้ว +1

    I manually followed this great tutorial and made the lighting.hlsl exactly as shown but alas I could not get it to run on HDRP :(

    • @danielilett
      @danielilett  3 ปีที่แล้ว +1

      I think you might need to make the shader in a different way for HDRP unfortunately. I don't really use HDRP myself, but I believe it treats lighting quite differently to URP so unfortunately the custom lighting code isn't transferrable between the two. From what I've read online, it looks like the easiest way to do something similar in HDRP is to use an Unlit material and manually send over the position/orientation of each of your lights to the shader through scripts (although I could be wrong).

  • @shariarpapaon5305
    @shariarpapaon5305 9 หลายเดือนก่อน

    how did you pass in the int (index) as input through shader graph, there doesn't seem to be an int type.

  • @atomichoppo637
    @atomichoppo637 10 หลายเดือนก่อน

    Hi guys, maybe one of you can help. I always get the error: Shader error in 'Master': undeclared identifier 'AdditionalLight_half' at line 189 (on d3d11) the same for MainLight
    I have checked the correct names of the hlsl files and the parameters but I haven't solved it yet.

  • @SteadyPaceVince
    @SteadyPaceVince 2 ปีที่แล้ว

    This is an awesome video

  • @djcoll123
    @djcoll123 ปีที่แล้ว

    Nice looking Genshin Impact shader without Outlines but is not Breath of the Wild it have to mutch Frensel/White/Shimmer Edges but it still looks nice thought

  • @luistorres6850
    @luistorres6850 2 ปีที่แล้ว

    Amazing tutorial! One of the best in the subject.
    How would applying this effect to the 2D renderer work? I'm trying to replicate the effect used in laigter software, had lots of trouble getting the light information in shader graph. Ended using shader lab, add some okish results. Would you recommend using shader graph? Is it possible even? If so the code snippet works?
    (Sorry for asking so many questions, but there's not a lot of info in the subject out there :( )

  • @smetar3169
    @smetar3169 2 ปีที่แล้ว

    why does the function have to be called :void MainLight_float? and not MainLight
    ??

  • @emilhdov3350
    @emilhdov3350 10 หลายเดือนก่อน

    Hi Daniel, some textures don't work correctly. How can I solve that?

  • @downstream0114
    @downstream0114 2 ปีที่แล้ว

    So is there a way of doing self shadowing for non convex objects? I tried using a lit graph, it works to some degree, but picks up other lighting too.

  • @ij20man35
    @ij20man35 ปีที่แล้ว

    Hi, thanks for the super helpful video. I am experience one issue though. The line #ifdef SHADERGRAPH_PREVIEW is giving me this error "Preprocessor directive expected". Any help would be appreciated, thanks for reading. I'll be trouble shooting it using the Unity manual on this area.

  • @semle346
    @semle346 2 ปีที่แล้ว +1

    the additional lights break everything for me, whole screen full of artifacts

  • @michaelcross8392
    @michaelcross8392 2 ปีที่แล้ว

    Did anyone else end up with a weird error? Undeclared Identifier "unity_multiply_float" in master. some weird stuff.

  • @martyboi5609
    @martyboi5609 2 ปีที่แล้ว

    I downloaded your project and imported your shaders and materials to my project... but everthing shows up as pink

  • @inkofthedragon
    @inkofthedragon 2 ปีที่แล้ว

    As soon as I change the shader to "Shader Graphs/CelShadingTextures" , the model disappears.

  • @nicko3151
    @nicko3151 3 ปีที่แล้ว

    Does anyone know how to add normals+diffuse for this? Dunno if it's easy or not, I am a newbie.

  • @ObrineArts
    @ObrineArts 3 ปีที่แล้ว +3

    "AdditiionalLight_float" cannot convert output parameter from "float3" to "float" when creating the addiitional light function, i've set it up the exact same way as main light no idea why i'm getting this error, any iideas?

    • @tatl64
      @tatl64 2 ปีที่แล้ว

      You need to change the name to "AdditionalLight". It has to be the same name as the void method. If iets different it will not work. I made the same mistake. I forgot to change the name "MainLight" to "AdditionalLight" in the GetAddiotionalLight parameter above the source.

    • @paloma8423
      @paloma8423 2 ปีที่แล้ว

      I ran into this error too, even though I've checked that the "name" parameter has the exact same text as the void method. did you find a way to solve it?
      Edit: I'd forgotten to add the index input lol

    • @asokaella
      @asokaella 2 ปีที่แล้ว +1

      @@paloma8423 Thank fucking god you updated with the solution i thought I was going crazy not being able to type a name properly for like 5 min.

  • @theluadog5857
    @theluadog5857 2 ปีที่แล้ว

    Hello! How would I add a black outline to the material?

  • @Cassie-dj5lc
    @Cassie-dj5lc 3 หลายเดือนก่อน

    couldn't get specular light with Unity 2021

    • @Cassie-dj5lc
      @Cassie-dj5lc 3 หลายเดือนก่อน

      ah you got to reduce diffuse

  • @mrslake7096
    @mrslake7096 2 ปีที่แล้ว +1

    I think shader graph now has builtin nodes for MainLight and for Additional Lights and Additional Lighting

  • @LinkstaRuViews
    @LinkstaRuViews 3 ปีที่แล้ว +1

    You create file AdditionalLight.hlsl?

    • @danielilett
      @danielilett  3 ปีที่แล้ว +1

      You can put the code for the additional lights inside the same file as the code for the main light. I stick them all in a file called Lighting.hlsl. If you go to the GitHub link in the description, then you can download the file from there directly!

  • @dertobbe1176
    @dertobbe1176 2 หลายเดือนก่อน

    "direction not comoletly initialized"

  • @thatinusitatus
    @thatinusitatus ปีที่แล้ว

    how do you apply the shader to an material?

    • @danielilett
      @danielilett  ปีที่แล้ว

      I don't know how much experience you have with Unity so I'll just give the most complete answer I can:
      There are a few ways to do it in Unity. Either you can right-click a shader in the Project View and select Create -> Material from the menu, or select a Material that's already been created and then use the Shader drop-down at the top of the Inspector to change the shader - you can use the search bar, or find it manually. Shader graphs by default are under a "Shader graphs" folder.
      Then, to apply the material to an object, drag the material onto the object in the Scene View, or select the object and change the material on its Renderer component using the little circle icon next to the Material field. You might need to expand the Materials field first by clicking it. Hope all that helps!

  • @stephenschuster3555
    @stephenschuster3555 2 ปีที่แล้ว

    Hey, which graph do I use? PBR graph?

  • @momiko934
    @momiko934 ปีที่แล้ว

    Wow im the 2k likes!

  • @jwhatcha6052
    @jwhatcha6052 2 ปีที่แล้ว

    uuuugh why does everything i do with shaders never work

    • @zazo5525
      @zazo5525 2 ปีที่แล้ว

      I think I can help you. Is your shader just pink? What's wrong?

    • @jwhatcha6052
      @jwhatcha6052 2 ปีที่แล้ว

      @@zazo5525 i dont remember i just scrapped it and move to a new tutorial if i do remember ill come back with a reply, but thank you for taking the time to lend a hand!

    • @zazo5525
      @zazo5525 2 ปีที่แล้ว +1

      @@jwhatcha6052 Oh it’s no worries :) I was just asking because I just realized that you have to switch the render mode thing to URP in project settings. Took me like four hours searching through forums to find that out lol. Anyways good luck!!!

  • @hydroweapon
    @hydroweapon 2 ปีที่แล้ว +5

    I'm amazed anyone can follow this - he keeps jumping all over the place

  • @indiegamesonly6617
    @indiegamesonly6617 2 ปีที่แล้ว

    sorry i dont work at NASA so i guess i cant understand this

  • @Nyx_z_
    @Nyx_z_ 2 ปีที่แล้ว

    How to add shadows from other objects?

  • @jujda7
    @jujda7 2 หลายเดือนก่อน

    theres no way that in blender you can do this with 3 nodes but unity has the most conveluted way possible. what the fuck is this

  • @LinkstaRuViews
    @LinkstaRuViews 3 ปีที่แล้ว +2

    undeclared identifier 'GetAdditionalLightsCount' 🤷‍♂️