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
"If you want to build it yourself here's the blueprint". That line is just music to my ears.
Nice one! Love these kind of super compressed tutorials.
It can't be any more concise. Matt, you the best!
Thank you so much for this video! I've searched a few hours before finding a tutorial that actually work x')
Nice video! I can’t wait for the procedural animation tutorial i’m so teased 🤩🥺
@Tarodev
2 жыл бұрын
Lol it's under construction
Great video, short and simple!
You are a legend for making this video. Almost all the other ones are outdated.
This channel sure is good. I watched some previous videos and have just one advice keep it simple ;D
Awesome, You are DOPE! Thank you for what you do for the community! Stay free from tyranny!
You are the new BRACKEYS. Thanks a bunch. 😌
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
2 жыл бұрын
Came to the coment section to state the same, this man is a treasure
@Tarodev
2 жыл бұрын
Thanks boys, appreciate the glowing compliment!
@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
2 жыл бұрын
@@jesusmgw This is the perfect way to describe how i feel about his videos.
Superb ! Shown a lot in a short video
Very great!! Thanks for sharing this awesome tip!! It's really appreciated :D
Oh man... what a god, this is huge, thank you
BEAUTIFUL
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
2 жыл бұрын
Just a terrain with some noise :)
Nice and too the point! Weird it's so locked away!
I love everything you do
@Tarodev
2 жыл бұрын
Oh diru
hmmm this didn't work for me, the sprite just disappears, any idea how to fix it?
Best video on the whole channel
@Tarodev
2 жыл бұрын
Lol damn bro
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
Just found your channel, really good content, +1 sub. Thank you.
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?
This actually also works with the UI image component without the need to change anything in Debug mode
Thanks for the helpful info. Do you know if this would also work for a Spine character rig?
ON THE POINT, THANKS!!
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
Pure gold
NOiCE !!
quick and easy
For people who might not be able to cast shadows, check URP asset > Lighting > Main Light & Additional Lights > Cast Shadows.
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 ;)
Best Video on the topic! But how do you do it in 2D? No one online is explaining that well.
Badabing, Badaboom!
@Tarodev
2 жыл бұрын
You got it blobby boi
You need to set the "Alpha Clip" to true in the shader's Graph Settings to make this work.
@xisu8167
Жыл бұрын
hi nicholas, could you describe where this alphac lip button is in unity? Thanks!
@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.
Omg badabingbadaboom thank you
Sweet
Barabin barabum, thank you.
Thank you Tardev :) , Question, Can it be used for match 3 games for particles to have shadows ? if so , how is the performance course
Haunting background music 🤣
Nice Twice👌
@Tarodev
2 жыл бұрын
x2 nice?
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
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.
Hey Loved the video. I have all the settings working but the sprites are not casting shadows. So confused right now :/
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
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!
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?
Hi thank you but is there a way to rotate the shadow a bit for sprites in isometric view
Lol the ending 😂
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
Жыл бұрын
Turn Cull Off
@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
hi , i was looking for this , but can you tell if this worked with URP
Great video, works like a charm! But I have one question, how to add normal map in this way? Thanks
@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
9 ай бұрын
@@quarterpaul5712 Thanks dude!
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)
will this work with URP? Sorry I'm new and I'm really having a hard time with lighting
It doesnt allow me to place it in material slot.
very awesome little tutorial like always, smooth editing, nice graphics and ... what the f*** was that weird looking creature at the end xD?
@Tarodev
2 жыл бұрын
Just a little discord meme 😜 come join
Good! Is there a tutorial to make 2D sprite drop shadow in 2D world?
@jakenirmal5441
Жыл бұрын
I wish D: PLEASE I FYOU HAVE ONE TELL ME
it is work for a 2D game? without any particular shader ? just the default 2d TEMPLATE?
Any idea why Unity hides this in the Debug inspector?
Would having so many sprites with shadows affect the performance too much?
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
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?
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
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
How can I have the sprite not to take light highlight, but only get the shadow?
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
Fuck you are awesome
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?
Can we get this to work in HDRP?
Did I understand correctly, this only works for 3D?
For some reason my character is affected by light but doesn't have any shadows. Can somebody help me with that?
hello, how to produce gradiant shadow for png images? thank you
oooooooo bro esto es hermoso¡¡¡ ¿lo pudo usar en mi juego?
Cool. Are you also familiar with shader-graph?
@Tarodev
2 жыл бұрын
I dabble a little. Could be better
@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.
Is this working on 2D URP projects?
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
3 ай бұрын
You shouldn't feel anything at all at 20. Unless you're playing on a calculator
I've use your material but my character turn into white how can i fix that? Im using now unity 2021 in URP.
how can i make sprite (SpriteRenderer) cast a shadow on another sprite (SpriteRenderer) using shader graph?
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.
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
Жыл бұрын
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
Жыл бұрын
Could they solve the problem?
@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.
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
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
2 ай бұрын
the multiplication with vertex color replicates the functionality of the default shader to tint the sprite with the SpriteRenderer.Color value
@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
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
2 жыл бұрын
Is your sprite using the default sprite material or did you change it?
how to avoid overlapping of the shadows though...
the Original source link is not working
Hi, is it possible to make sprite transparent but at the same moment able to receive shadows?
@warrentan4452
5 ай бұрын
You may select the sprite object and go to the Debug Mode -> Sprite Renderer -> Cast Shadows -> Shadow Only
But one question.... Won't it have any effect on the performance of the game??
@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...
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!
when my sprite rotate 180 degrees it goes dark any fix? thank you
@Kopellis
3 ай бұрын
ok i just put a directional light in the opposite site
seems like this is not working on unity 2019
Hi, this link don't load can you reupload pls?
not working
My sprite is now affected by light but does not cast any shadow. Any idea how to fix that?
@dir
Жыл бұрын
Let me know if you fix it
for me the shadergraph material is pink ; /
Why making a var private and adding SerializeField but not making it public? What is private in game dev good for?
@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.
Still easy, can you make 3d object to pixelated object?
@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
2 жыл бұрын
@@Tarodev just kidding 😅, I already know the asset. I just want to challange you like Dani maybe ...
@Tarodev
2 жыл бұрын
@@restushlogic5794 haaaaa 😂 I may make a video out of your next suggestion 😜
@restushlogic5794
2 жыл бұрын
@@Tarodev Nah... You cannot be serious 🤭
I got shadows bby.
@Tarodev
Жыл бұрын
Enjoy them 🙏
@jaulloa21
Жыл бұрын
@@Tarodev thx 😊
my sprite became pink
the shader is just that pink broken color
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
First comment.
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
Жыл бұрын
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.