Sprite Shadows in Unity - Cast and receive shadows using a SpriteRenderer

Casting shadows from your sprites is as simple as pie. For some reason, Unity hides this by default, but I'm here to abuse the system and show you how to turn it on.
URP Shader link: bit.ly/34c0ttF
Original source: hananon.com/how-to-make-2d-sp...
❤️ Become a Tarobro on Patreon: / tarodev
=========
🔔 SUBSCRIBE: bit.ly/3eqG1Z6
🗨️ DISCORD: / discord
✅ MORE TUTORIALS: / tarodev

Пікірлер: 147

  • @SuperMaajka
    @SuperMaajka2 жыл бұрын

    "If you want to build it yourself here's the blueprint". That line is just music to my ears.

  • @ObviousDev
    @ObviousDev2 жыл бұрын

    Nice one! Love these kind of super compressed tutorials.

  • @hegworks
    @hegworks2 жыл бұрын

    It can't be any more concise. Matt, you the best!

  • @hylidia
    @hylidia2 жыл бұрын

    Thank you so much for this video! I've searched a few hours before finding a tutorial that actually work x')

  • @padrox9789
    @padrox97892 жыл бұрын

    Nice video! I can’t wait for the procedural animation tutorial i’m so teased 🤩🥺

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    Lol it's under construction

  • @m0tholith
    @m0tholith2 жыл бұрын

    Great video, short and simple!

  • @TheFreckelz
    @TheFreckelz Жыл бұрын

    You are a legend for making this video. Almost all the other ones are outdated.

  • @sahilsharma2867
    @sahilsharma28672 жыл бұрын

    This channel sure is good. I watched some previous videos and have just one advice keep it simple ;D

  • @emoneydatruth1
    @emoneydatruth12 жыл бұрын

    Awesome, You are DOPE! Thank you for what you do for the community! Stay free from tyranny!

  • @timilehinafolabi1757
    @timilehinafolabi17572 жыл бұрын

    You are the new BRACKEYS. Thanks a bunch. 😌

  • @diligencehumility6971
    @diligencehumility69712 жыл бұрын

    Discovered your channel recently. This is like a fully featured replacement for Bracky's. Didn't know we still had high quality Unity channels. Subbed

  • @pelayofigaredogarcia6515

    @pelayofigaredogarcia6515

    2 жыл бұрын

    Came to the coment section to state the same, this man is a treasure

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    Thanks boys, appreciate the glowing compliment!

  • @jesusmgw

    @jesusmgw

    2 жыл бұрын

    Replacement and natural progression for us that started at the time. I was a noob in the Brackeys era and their videos were beginner level, now I'm working full-time as a gamedev and most of these videos have the exact intermediate-advanced level that I need.

  • @tyler7268

    @tyler7268

    2 жыл бұрын

    @@jesusmgw This is the perfect way to describe how i feel about his videos.

  • @aniljoshi917
    @aniljoshi9172 жыл бұрын

    Superb ! Shown a lot in a short video

  • @azrhyga
    @azrhyga11 ай бұрын

    Very great!! Thanks for sharing this awesome tip!! It's really appreciated :D

  • @Algyr_
    @Algyr_ Жыл бұрын

    Oh man... what a god, this is huge, thank you

  • @Typtick
    @Typtick2 жыл бұрын

    BEAUTIFUL

  • @preludelight
    @preludelight2 жыл бұрын

    Really love the short, sweet, and right to the point presentation. Keep it up! Off topic: I also love the way your background plane looks there. Is that a normal map giving it the ripples like that?

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    Just a terrain with some noise :)

  • @DanPos
    @DanPos2 жыл бұрын

    Nice and too the point! Weird it's so locked away!

  • @notDiru
    @notDiru2 жыл бұрын

    I love everything you do

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    Oh diru

  • @DexterManning
    @DexterManning2 жыл бұрын

    hmmm this didn't work for me, the sprite just disappears, any idea how to fix it?

  • @angelrankingofthunder
    @angelrankingofthunder2 жыл бұрын

    Best video on the whole channel

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    Lol damn bro

  • @CrabeExtra
    @CrabeExtra Жыл бұрын

    I did everything last night and I didn't get result, until today I saw your video and I realize I didn't set shadow in debug mode, thankssssssssss

  • @PauloHSousa237
    @PauloHSousa2372 жыл бұрын

    Just found your channel, really good content, +1 sub. Thank you.

  • @Rioni
    @Rioni2 жыл бұрын

    Hi! Thanks for this! I don't plan on using this but it's pretty interesting, Could you explain how the shader works? The blueprint is fairly simple and it seems you use lit instead of sprite unlit, I assume you treat the sprite as a quad using a cut out shadow but I'm still not sure. Could you explain the shader a little?

  • @thomasmuller8118
    @thomasmuller81182 ай бұрын

    This actually also works with the UI image component without the need to change anything in Debug mode

  • @tientam779
    @tientam779 Жыл бұрын

    Thanks for the helpful info. Do you know if this would also work for a Spine character rig?

  • @paulorodrigues1603
    @paulorodrigues16039 ай бұрын

    ON THE POINT, THANKS!!

  • @jayhay7620
    @jayhay7620 Жыл бұрын

    thanks for the tutorial, it worked, now is there a way to do this to lots of sprites at once in my scene, say all the sprites contained within a single sprite sheet that have been sliced to individual sprites? or would that be a big performance inpact. thanks. jay

  • @cesarsfalcao
    @cesarsfalcao11 ай бұрын

    Pure gold

  • @Gernata_Dev
    @Gernata_Dev2 жыл бұрын

    NOiCE !!

  • @svendpai
    @svendpai2 жыл бұрын

    quick and easy

  • @laurentcharles7179
    @laurentcharles7179 Жыл бұрын

    For people who might not be able to cast shadows, check URP asset > Lighting > Main Light & Additional Lights > Cast Shadows.

  • @ArchV
    @ArchV2 жыл бұрын

    Hmm I did this kind of a back-assward way; I used a quad, and made a material out of the sprite, then it could receive lighting and shadows. Extra steps though, your way is better ;)

  • @GemTappX
    @GemTappX Жыл бұрын

    Best Video on the topic! But how do you do it in 2D? No one online is explaining that well.

  • @datablob
    @datablob2 жыл бұрын

    Badabing, Badaboom!

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    You got it blobby boi

  • @Elxnicorojas
    @Elxnicorojas2 жыл бұрын

    You need to set the "Alpha Clip" to true in the shader's Graph Settings to make this work.

  • @xisu8167

    @xisu8167

    Жыл бұрын

    hi nicholas, could you describe where this alphac lip button is in unity? Thanks!

  • @Elxnicorojas

    @Elxnicorojas

    Жыл бұрын

    @@xisu8167 Well, if you open your shader with shadergraph just like the video does at 0:20, you'll see the graph inspector window at the top right corner. There are two tabs: Node Settings and Graph Settings. You go to Graph Settings, expand the "Universal" arrow and check if your Material is set to Lit like the video... if it is, then you should enable the "Alpha Clipping" setting. However, if your material is set to Sprite Lit there's no need to check anything, I think in that case Alpha Clipping is enabled by default. If the material is anything else then I don't know what's going on, but if you are following the video you should set it to "Lit". I was using Unity 2021.2.14f1 tho... Don't really know if your version works this way.

  • @thesilentwisp
    @thesilentwisp2 жыл бұрын

    Omg badabingbadaboom thank you

  • @Betruet
    @Betruet2 жыл бұрын

    Sweet

  • @pnvgordinho
    @pnvgordinho11 ай бұрын

    Barabin barabum, thank you.

  • @user-dc1pg5lh9j
    @user-dc1pg5lh9j5 ай бұрын

    Thank you Tardev :) , Question, Can it be used for match 3 games for particles to have shadows ? if so , how is the performance course

  • @AyItsKevin
    @AyItsKevin2 жыл бұрын

    Haunting background music 🤣

  • @Grimace_ShakeBRTY
    @Grimace_ShakeBRTY2 жыл бұрын

    Nice Twice👌

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    x2 nice?

  • @joedynamiteTV
    @joedynamiteTV Жыл бұрын

    I'm not super well versed in using shader graph yet but is there a way to modify this to include a rotation of the sprite (billboarding) but not the shadow? I'm trying to use this as well as pieces of your isometric game tutorial to make an isometric 3D world inhabited by 2D sprites. If I rotate the sprite renderer so that it displays properly in the isometric scene, the shadow is out of alignment since it is cast from the rotated sprite. It's only off slightly but still noticeable if you look closely.

  • @hellfirestudios-em3wu

    @hellfirestudios-em3wu

    18 күн бұрын

    Sorry this is late but I'm doing something similar. I did it by having a shadow caster object that is aligned to the camera which keeps the actual sprite invisible but casts the shadow, then you have the actual sprite that is visible not cast the shadow. Then you use a little code to keep the offset so everything is lined up correctly depending on the animation.

  • @raghunandan2671
    @raghunandan2671 Жыл бұрын

    Hey Loved the video. I have all the settings working but the sprites are not casting shadows. So confused right now :/

  • @openrealms
    @openrealms5 ай бұрын

    Thank you for the awesome video and shader! :) I got a weird bug adding this to a gameobject in my scene, where the sprite was all black. Where I went wrong: I was updating the x and y scale of the gameobject but not the z scale (because its 2D? who needs a 3rd dimension? You would think!) Hope this helps someone who might run into the same issue in the future

  • @TheDeadlyCherry
    @TheDeadlyCherry Жыл бұрын

    I only get purple texture when using URP, is there a fix for this? Edit: I am a fool who didn't install URP correctly. Great tutorial as always!

  • @kappi_
    @kappi_2 жыл бұрын

    Does this write to the depth buffer so things are automatically sorted by distance? Is there a way to do that in shader graph with sprite renderers?

  • @hansml03
    @hansml03 Жыл бұрын

    Hi thank you but is there a way to rotate the shadow a bit for sprites in isometric view

  • @djblast101
    @djblast1012 жыл бұрын

    Lol the ending 😂

  • @gxplorers
    @gxplorers Жыл бұрын

    Awesome video! Amm I have a problem I dont know how to solve, I have a Paper Mario Style character that flips when it turns, and when the character/sprite flips it is completelly Dark, is there a way to fix this? :c thank you!

  • @jayocaine2946

    @jayocaine2946

    Жыл бұрын

    Turn Cull Off

  • @heeo7848

    @heeo7848

    Жыл бұрын

    Damn I've been looking into this issue for a long time too. Here is a KZread video that might serve as a solution. After the video, make the following additional settings: 'Normal Vector - Space' and the 'Graph Inspector - Fragment Normal Space' to "World," the problem should be resolved. I hope this helps. kzread.info/dash/bejne/aWpo1ctmcdXJebg.html

  • @M-TALHA
    @M-TALHA Жыл бұрын

    hi , i was looking for this , but can you tell if this worked with URP

  • @WeirdGoat
    @WeirdGoat Жыл бұрын

    Great video, works like a charm! But I have one question, how to add normal map in this way? Thanks

  • @quarterpaul5712

    @quarterpaul5712

    9 ай бұрын

    Add a second Texture2D property to the shader called Normal. Connect this property to a Sample Texture 2D node that goes directly into the Normal output.

  • @WeirdGoat

    @WeirdGoat

    9 ай бұрын

    @@quarterpaul5712 Thanks dude!

  • @niuage
    @niuage Жыл бұрын

    I think this doesnt work in Unity 2022 and possibly 2021 something? It says that the main tex has scale/offset set and is incompatible with the sprite renderer. It works in the editor, but as soon as I save, it breaks (sprite disappears in my case)

  • @vic137
    @vic137 Жыл бұрын

    will this work with URP? Sorry I'm new and I'm really having a hard time with lighting

  • @spacekusa
    @spacekusa Жыл бұрын

    It doesnt allow me to place it in material slot.

  • @NowKnownMAWO
    @NowKnownMAWO2 жыл бұрын

    very awesome little tutorial like always, smooth editing, nice graphics and ... what the f*** was that weird looking creature at the end xD?

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    Just a little discord meme 😜 come join

  • @yong6160
    @yong61602 жыл бұрын

    Good! Is there a tutorial to make 2D sprite drop shadow in 2D world?

  • @jakenirmal5441

    @jakenirmal5441

    Жыл бұрын

    I wish D: PLEASE I FYOU HAVE ONE TELL ME

  • @risingforce9648
    @risingforce9648 Жыл бұрын

    it is work for a 2D game? without any particular shader ? just the default 2d TEMPLATE?

  • @ooomri
    @ooomri2 жыл бұрын

    Any idea why Unity hides this in the Debug inspector?

  • @thisormaybethis
    @thisormaybethis11 ай бұрын

    Would having so many sprites with shadows affect the performance too much?

  • @danielmarchant8727
    @danielmarchant87274 ай бұрын

    Does this work for 2D games? if I have a “wall” in a plane some distance behind the 2D plane could I cast a shadow from a light source in front of the 2D plane

  • @user-qd6wj2ri6w
    @user-qd6wj2ri6w2 ай бұрын

    hey I have a question when I flip my sprite with rotation (cause I am making a shooter) the sprite get darker any idea how to fix it?

  • @jandrogp2039
    @jandrogp2039 Жыл бұрын

    Thanks you so much for this solution, the only problem that i have is that when i flip my character the other side turn into one dark color. Anybody know what is happening? Thanks

  • @maxpitta

    @maxpitta

    5 ай бұрын

    Instead of turning the sprite you could use the scale X value and make it negative (multiplying bu -1). A little workaround. if you have found the solution please tell me that i'm facing the same problem

  • @Name_7667
    @Name_7667 Жыл бұрын

    How can I have the sprite not to take light highlight, but only get the shadow?

  • @tonycezar1645
    @tonycezar16455 ай бұрын

    how to make it work for sprite animations? I managed to make it work with simple sprites, but when it comes to animation the material don't cast any shadow, thanks in advance

  • @Halverto
    @Halverto Жыл бұрын

    Fuck you are awesome

  • @mrpro877
    @mrpro877 Жыл бұрын

    I have a problem when I try to add depth of field effect to the game when the sprites are getting ignored and are blurred as their background, I have been looking for hours and haven't found a fix, somebody knows how do I fix this?

  • @GrandpaWho
    @GrandpaWho2 жыл бұрын

    Can we get this to work in HDRP?

  • @arcday4281
    @arcday42812 жыл бұрын

    Did I understand correctly, this only works for 3D?

  • @kermit5687
    @kermit56872 жыл бұрын

    For some reason my character is affected by light but doesn't have any shadows. Can somebody help me with that?

  • @mimmim25
    @mimmim252 жыл бұрын

    hello, how to produce gradiant shadow for png images? thank you

  • @alvarovillarroelayala8329
    @alvarovillarroelayala8329 Жыл бұрын

    oooooooo bro esto es hermoso¡¡¡ ¿lo pudo usar en mi juego?

  • @ragerungames
    @ragerungames2 жыл бұрын

    Cool. Are you also familiar with shader-graph?

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    I dabble a little. Could be better

  • @ragerungames

    @ragerungames

    2 жыл бұрын

    @@Tarodev cool 🍌s! I am wondering how many years have you been using unity and doing programming? How about a video on your journey since you start and what steps you took in past couple of years to gain this much experience? Also how about Tips for beginners which they can take and learn unity/programming in a better way.

  • @Charles-dt6dh
    @Charles-dt6dh Жыл бұрын

    Is this working on 2D URP projects?

  • @seanlynch4354
    @seanlynch43543 ай бұрын

    Does this affect performance if you have many game object in your scene? Around about 20 in view of the camera at a time

  • @Tarodev

    @Tarodev

    3 ай бұрын

    You shouldn't feel anything at all at 20. Unless you're playing on a calculator

  • @projectjoeart
    @projectjoeart Жыл бұрын

    I've use your material but my character turn into white how can i fix that? Im using now unity 2021 in URP.

  • @petriell0anima
    @petriell0anima Жыл бұрын

    how can i make sprite (SpriteRenderer) cast a shadow on another sprite (SpriteRenderer) using shader graph?

  • @Loki-
    @Loki- Жыл бұрын

    I'm getting Couldn't open include file 'Packages/.../Color.hlsl' at line 790... Fixed it by Edit > Render Pipeline > Generate Shader Includes Now my problem is my sprites are just all black. My shader material it made is pink, where yours is some sphere with a shadow on it.

  • @whiteglint8191
    @whiteglint81912 жыл бұрын

    I am still a bit of a noob with shader graph, I replaced the material and the shadow is displayed correctly, but the actual sprite is purple like if the texture is missing. Anyone knows what could be the problem?

  • @orange_fella

    @orange_fella

    Жыл бұрын

    I've got the same problem. Have you managed to find any solutions? (Edit* I actually just managed to get it to work without the shader. All you seem to need to do is change the rendering mode on a standard material to cutout)

  • @alexisblessing4983

    @alexisblessing4983

    Жыл бұрын

    Could they solve the problem?

  • @alexisblessing4983

    @alexisblessing4983

    Жыл бұрын

    @@orange_fella I already solved it, I had to edit the configuration of the SpriteShadow material, in the "Shader" section, you have to open the tab and select the "Nature" option and finally the "Tree Soft Occlusion Leaves" option. Note: I had previously selected the "Standard" option, but for some strange reason, only one side of the 2D Sprite cast the shadow, the other side was completely invisible. With an additional script for "Billboarding", this invisibility problem was not noticeable. , but it could be seen that from some of its perspectives it did not generate the shadow.

  • @Omen09
    @Omen092 ай бұрын

    hm, finally got around to figuring out shaders, and it turns out you dont need any of that multiplying wirh vertex color , just take from sample texture straight into Base Color and Alpha and it works, if you have other settings correct. Now i wonder what it actually does xd

  • @thomasmuller8118

    @thomasmuller8118

    2 ай бұрын

    can you tell me which version of unity you are using? It does not seem to work for me in 2022.3 (URP) Its always pure black and if I change the smothness it becomes a pixelated screenshot. Super weird edit. omg its so dump. I figured it out from other comments. The back face rendering does not work correctly and only the front worked (in shadow so black) and not the back (bugged so also black)

  • @thomasmuller8118

    @thomasmuller8118

    2 ай бұрын

    the multiplication with vertex color replicates the functionality of the default shader to tint the sprite with the SpriteRenderer.Color value

  • @Omen09

    @Omen09

    2 ай бұрын

    @@thomasmuller8118 hmm interesting, good to know 👍 thought it would work without it, but i didn't need it in my case, thanks mate

  • @trombiseroni
    @trombiseroni2 жыл бұрын

    Why do you need the graph though? Clicking "cast shadows" already make the sprite cast shadows on my project, and I think since forever?

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    Is your sprite using the default sprite material or did you change it?

  • @kepazino
    @kepazino11 ай бұрын

    how to avoid overlapping of the shadows though...

  • @MrSolarholic
    @MrSolarholic Жыл бұрын

    the Original source link is not working

  • @timothypsina
    @timothypsina6 ай бұрын

    Hi, is it possible to make sprite transparent but at the same moment able to receive shadows?

  • @warrentan4452

    @warrentan4452

    5 ай бұрын

    You may select the sprite object and go to the Debug Mode -> Sprite Renderer -> Cast Shadows -> Shadow Only

  • @remijoel1448
    @remijoel14482 жыл бұрын

    But one question.... Won't it have any effect on the performance of the game??

  • @MutambaBrazil

    @MutambaBrazil

    2 жыл бұрын

    I have the same question. And if is there a way to project shadow for a moving object or when the lights in the place moves...

  • @vlakitus
    @vlakitus Жыл бұрын

    Thank you so much for this tutorial, I was facing some issues to create a Shader! Btw, if anyone wants to enable cast shadow option by Script, follow the code: GetComponent().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On; I've created a script and put this code on Start() method and attached to the sprite, don't know if it's right but it works for me. Cheers!

  • @Kopellis
    @Kopellis3 ай бұрын

    when my sprite rotate 180 degrees it goes dark any fix? thank you

  • @Kopellis

    @Kopellis

    3 ай бұрын

    ok i just put a directional light in the opposite site

  • @liandongwei
    @liandongwei Жыл бұрын

    seems like this is not working on unity 2019

  • @LuizHenrique-be9ue
    @LuizHenrique-be9ueАй бұрын

    Hi, this link don't load can you reupload pls?

  • @EVAN-og8xb
    @EVAN-og8xb Жыл бұрын

    not working

  • @katerinatuskova3192
    @katerinatuskova3192 Жыл бұрын

    My sprite is now affected by light but does not cast any shadow. Any idea how to fix that?

  • @dir

    @dir

    Жыл бұрын

    Let me know if you fix it

  • @voldek32167
    @voldek32167 Жыл бұрын

    for me the shadergraph material is pink ; /

  • @batuhanbatuhan4131
    @batuhanbatuhan41312 жыл бұрын

    Why making a var private and adding SerializeField but not making it public? What is private in game dev good for?

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    Did you comment on the wrong video or is this just a random question? Making it public just to serialize it, now makes it available to change from other classes. So for example if I make my spriterenderer reference public, class ABC can now change my spriterenderer sprite. Making it private keeps it... private while also serializing it. Does that make sense? You should ONLY making something public if it's needed by another class.

  • @restushlogic5794
    @restushlogic57942 жыл бұрын

    Still easy, can you make 3d object to pixelated object?

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    You can do that with some shader magic. This is a great asset: assetstore.unity.com/packages/vfx/shaders/fullscreen-camera-effects/propixelizer-177877

  • @restushlogic5794

    @restushlogic5794

    2 жыл бұрын

    @@Tarodev just kidding 😅, I already know the asset. I just want to challange you like Dani maybe ...

  • @Tarodev

    @Tarodev

    2 жыл бұрын

    @@restushlogic5794 haaaaa 😂 I may make a video out of your next suggestion 😜

  • @restushlogic5794

    @restushlogic5794

    2 жыл бұрын

    @@Tarodev Nah... You cannot be serious 🤭

  • @jaulloa21
    @jaulloa21 Жыл бұрын

    I got shadows bby.

  • @Tarodev

    @Tarodev

    Жыл бұрын

    Enjoy them 🙏

  • @jaulloa21

    @jaulloa21

    Жыл бұрын

    @@Tarodev thx 😊

  • @Digimonfusion280
    @Digimonfusion280 Жыл бұрын

    my sprite became pink

  • @stephenkamenar
    @stephenkamenar4 ай бұрын

    the shader is just that pink broken color

  • @draggmaste
    @draggmaste Жыл бұрын

    Don't know what I've done wrong, but all my stuff is just pink :S Edit: I got a step further, now everything is kinda grey

  • @Ayman--Ahmed
    @Ayman--Ahmed2 жыл бұрын

    First comment.

  • @alexisblessing4983
    @alexisblessing4983 Жыл бұрын

    I managed to make the shadows appear on my 2D sprites, it's really cool! What I can't figure out is why the material of the SpriteShadow instead of being transparent is a solid pink, covering my original sprite. Any idea why it happens?

  • @alexisblessing4983

    @alexisblessing4983

    Жыл бұрын

    I already solved it, I had to edit the configuration of the SpriteShadow material, in the "Shader" section, you have to open the tab and select the "Nature" option and finally the "Tree Soft Occlusion Leaves" option. Note: I had previously selected the "Standard" option, but for some strange reason, only one side of the 2D Sprite cast the shadow, the other side was completely invisible. With an additional script for "Billboarding", this invisibility problem was not noticeable. , but it could be seen that from some of its perspectives it did not generate the shadow.