I’m going crazy trying to do this but I’m still very new to the whole shaders thing and it’s extremely confusing to me. I’m making a 2D game in a 3D environment and I need my sprites to cast and receive shadows using the Universal Rendering Pipeline. So far I’ve found shaders working on the Built-in Pipeline but none on URP, and I’ve no idea how to turn CG into HLSL to make it work. Is there a simple way to modify a shader based on the Sprite-Lit-Default or should I be using the Shader Graph? If so, how?
I know it’s an unusual thing to ask but I’m getting desperate over this, if I can’t figure it out I may well forget about this project.
Okay so I’m gonna just reply to myself as I figured it out by contrasting many sources and trying to understand how shaders work. Please don’t delete this as it could be helpful to anyone finding himself in the same situation. Create a Shader Graph as following:
This shader applied to a Sprite Renderer will Cast Shadow, Receive Shadow, the option to add a Normal Map, to change the Sprite’s Color, and change the Sprite’s Opacity.
It’s not perfect tho, I’d like to add the option to make the Sprite visible through walls and maybe also to add an Outline, if anyone knows how I’m listening!
So an update for anyone who’s having the same problem as me, I fixed it! Turns out something went wrong on unity’s end I think. I recreated the shader exactly as I did before, and I put it on a cube to see if it would cast a shadow.
This worked, but the sprites still didn’t work.
To get the shadows working on sprites, open the inspector in debug mode, and in the sprite renderer component you can turn on casting shadows.
I’ve tried setting this shader up, but instead of causing the sprite to cast shadows, it just turns the sprite into a “shadow”. IE: I’m just changing the color/transparency of the sprite that this shader/material is attached to.
Originally my project was in 2D, and I just flipped the switch to set it to 3D.