Legacy GM [SOLVED] Black hole space distort (bend) effect?


How to make the object (black hole) do this effect? Maybe shader or something else?

This is how it needs to look like:
It's gravity is so powerful, that bends space around itself! \( o_o)/

Thanks for your future help =)


Yeah that looks like a shader effect. A pixel passthrough where read position is calculated according to some gravity style formula. The sample picture looks more than just a simple pinch though, more like some sort of gravity lensing effect.
Oh, sh... That's amazing! Can I use it, please? :eek:
I wouldn't have posted it if I wanted you not to use it.

Inside the fragment shader, there is a function called "distort", which has been heavily simplified from a much more complicated refraction process I found somewhere online. Now, it does not produce exactly the same results, but it still looks pretty nice. If you find you would like to experiment with other distortions, you can rewrite the code inside of that "distort" function. And the starting basis of a new distort function would be vec2 B = T - 0.5; which just transforms the texture coordinates (of the sprite) so that the middle of the sprite is has coordinates (0,0). The return value is T plus some offset. In the distort function I wrote, the offset has been calculated such that it fades to zero at the edge of a circle that fits within the sprite.

Also note that the texture coordinates of the sprite are assumed to be in the range 0 to 1, so the sprite needs to be marked "used for 3d" in gms1, or "seperate texture page" in gms 2.

ALSO, the blackhole should be drawn after everything else, so either give it a lower depth than everything else, or else draw it in the end draw event. Actually, anything you don't want to be distorted by its "gravity" should be drawn after it.
Last edited: