Object glow

Discussion in 'Programming' started by Acr515, Jun 21, 2016.

  1. Acr515

    Acr515 Member GMCJam Champ

    Joined:
    Jun 21, 2016
    Posts:
    36
    Is there a simple way to put a glow effect around an object, similar to the one in the image editor? I want this so I can indicate to the player what objects they can interact with, so the glow will be created whenever they're a certain distance from something. I don't want to have to create sub-images for every sprite and do the glow effect in the image editor.
     
  2. Snail Man

    Snail Man Member

    Joined:
    Jun 20, 2016
    Posts:
    282
    What I would do is make a single glow sprite that's pretty large, then you can use the draw event to draw the glow sprite below any object, and scale the glow sprite if you want to.

    To make an object glow, you would just need to put in its draw event
    Code:
    draw_sprite(spr_glow, 0, x, y); //draw the glow sprite
    draw_self(); draw the object's sprite on top
     
  3. obscene

    obscene Member

    Joined:
    Jun 21, 2016
    Posts:
    2,433
  4. Acr515

    Acr515 Member GMCJam Champ

    Joined:
    Jun 21, 2016
    Posts:
    36
    Hang on, I don't quite understand this. Do I need a glow map for every object that I want a glow for? If that's true, then I might as well just give every object the image editor glow effect.
     
  5. obscene

    obscene Member

    Joined:
    Jun 21, 2016
    Posts:
    2,433
    I personally don't know... I haven't used it. But if it does, that would be pointless. But it's a free download so I'd try it. I know there has to be a shader to do this.... I have a shader that draws things white and I have another shader that draws things blurred. Combine the two and you got what you need (but I can't combine shaders because I'm shader-dumb. :p )
     
  6. Acr515

    Acr515 Member GMCJam Champ

    Joined:
    Jun 21, 2016
    Posts:
    36
    I have absolutely no idea how to use shaders, so I guess I'll just use Snail Man's method although it isn't ideal and just see how it looks.
     
  7. obscene

    obscene Member

    Joined:
    Jun 21, 2016
    Posts:
    2,433
    If you can find a shader that works it's actually easy to use....

    /// Draw Event

    shader_set(shader);
    draw stuff
    shader_reset();
     
    Lonewolff likes this.
  8. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,730
    You could draw multiple copies of the sprite at positions around the object, with additive blending and transparency. Like this crude example:
    Code:
    if(can_interact){
      draw_set_blend_mode(bm_add)
      for(c = 0;c < 360;c += 18){
        draw_sprite_ext(sprite_index,image_index,x+lengthdir_x(4,c),y+lengthdir_y(4,c),image_xscale,image_yscale,image_angle,image_blend,image_alpha*0.25)
      }
      draw_set_blend_mode(bm_normal)
    }
    draw_self()
     
    Snail Man and Acr515 like this.
  9. Acr515

    Acr515 Member GMCJam Champ

    Joined:
    Jun 21, 2016
    Posts:
    36
    I like this one. I tweaked it a little bit, and it looks pretty nice. Thanks!
     
    Snail Man likes this.
  10. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,730
    No problems! :3

    18 is a factor of 360, so if it feels a bit odd, that's why I chose that instead of, say, 15. (Which is also a factor of 360, but... NEVER MIND xD). If you need to draw a lot of glowing objects at once, you might want to increase the step factor a bit... and also keep in mind that each time you change blend modes, you're forcing a texture batch change which can impact the performance, so if you need to draw tons of glowing objects this way, you should change the blend mode ONCE and then draw all the glows, then change it back.

    Probably nothing you need to care about right now, but worth keeping in mind for later.
     
    Acr515 likes this.
  11. Snail Man

    Snail Man Member

    Joined:
    Jun 20, 2016
    Posts:
    282
    Don't forget to set the topic prefix to 'solved'!
     
    Acr515 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