Godot Version
4.4 RC3
Question
To my surprise, I cannot find a working way of adding a shadow to my MeshInstance2D with SphereMesh in it. I simply want something like this:
I’ve tried this shader (and various other shaders on GodotShaders), but sadly it doesn’t work as advertised for me:
2D shadows shader (v2) - Godot Shaders
Is there a working solution for drop shadows with the basic controls, like XY offset, size, blur and color?
Thank you!
You need to add this shader to Sprite2D, if you add it to any other node, shader will not work as you suspected.
So, the problem is - If I were to use Sprite2D, then I need it to work on a MeshTexture with a Mesh in it, as far as I understand - Sprite2D → MeshTexture is completely broken in Godot 4, it just does not render at all.
- Add Sprite2D, add texture to it.
- Convert it to MeshInstance2D, and setup it.
(Select Sprite2D → Editor will show button with title Sprite2D near the “View” and “Skeleton options” buttons → Click → Convert to MeshInstace2d)
- Add material with shader to your new MeshInstance2D
If I run the game, all MeshInstace2D will render with shader shadows.
Unfortunately using raster images won’t work in my case. You see, I’m creating an audio visualizer and the peaks are made from MeshInstance2D → Mesh → CapsuleMesh, because in Godot there are no 2D vector primitives for some reason, but there are 3D ones I can use with MeshInstance2D. So these peaks react to sound, it’s an audio visualizer. I mean, it’s technically possible to create something similar with raster graphics I guess, but that’s a dirty-hacky approach, so I don’t want to do it like that. I want to keep is simple and parametric. Thanks for your tips though, but I’m afraid they are not applicable in my case.