1. Hey! Guest! The 35th GMC Jam will take place between November 28th, 12:00 UTC - December 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GM:S 1.4 [SOLVED] Black hole space distort (bend) effect?

Discussion in 'Programming' started by Edwin, Sep 21, 2018.

  1. Edwin

    Edwin Member

    Joined:
    Jul 15, 2018
    Posts:
    417
    How to make the object (black hole) do this effect? Maybe shader or something else?

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

    Thanks for your future help =)
     
  2. NeZvers

    NeZvers Member

    Joined:
    Mar 24, 2018
    Posts:
    320
    First thing that pops in mind is shaders, but for that I don't know any ready to use, so you need to learn shader programming.
    Other way not so flexible but make sprite animation of it.
     
  3. NightFrost

    NightFrost Member

    Joined:
    Jun 24, 2016
    Posts:
    1,977
    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.
     
  4. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    2,185
    Last edited: Sep 21, 2018
    TheSly, HayManMarc and Edwin like this.
  5. Edwin

    Edwin Member

    Joined:
    Jul 15, 2018
    Posts:
    417
  6. flyingsaucerinvasion

    flyingsaucerinvasion Member

    Joined:
    Jun 20, 2016
    Posts:
    2,185
    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: Sep 23, 2018
    Edwin likes this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice