Hello,
So I’m making this 2D top down game in which its main feature is the flashlight and its illumination feature. I already managed to get the sprites receive the lightning with the Diffuse material, but I can’t get them to cast shadows, even if I put a 3D object on the scene.
Here is a screenshot of the problem:
I need the objects to cast a shadow behind them, or at least block the lightning since I don’t want the light to go through the walls.
Thank you for your time.
Well,I think using a SpriteRenderer with a Diffuse material is not the only thing you would require .
Diffuse material on a sprite will only create a property of emitting light on the surface where light falls as shown in the image but for actually projecting a shadow on such surface you would require a 3D Plane or a Quad which has a property of receiving shadows since they use a Mesh Renderer and use your Wall sprite as a Texture inside a Material on the Plane or Quad. I hope this helps.
Sprites don’t support shadows, AFAIK, cus they’re not 3d
objects and the shader doesn’t support shadows?
If you want shadows, you have to go 3d/quads. Or use a 2d shadow/lighting asset from asset store.
If this really is the core feature of your game, then you’ll probably want to invest in a custom 2D ray-casting solution. It will be both faster and look better than trying to press the generic lighting system into service for your specific needs.
This blog post is a delightful explanation (with interactive demos right in your browser!) of a very good algorithm for this sort of thing.
So I would suggest, either implement that, or buy an asset that has already implemented it (or if neither of those works out, hire somebody like me to implement it for you).
1 Like
I agree with what JoeStrout had to say, but I have a note for you:
If you’re using a mesh to create shadows, then your problem isn’t that you want the sprites to cast shadows, it’s that you want them to receive shadows. You need to write a shader or modify the existing one.
For the record, it’s not complicated to get the sprite shaders working with shadows, but I recommend reading the manual’s shader reference if you’re going to be doing so; it will come in handy from time to time for at least tweaking shaders to suit your specific needs.
So many ways to achieve it, thank you for the suggestions! I’ll surely try them out and update here if it works.