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

GMS 2 Heat waves effect [SOLVED]

Discussion in 'Programming' started by josyanf1, Sep 16, 2019.

  1. josyanf1

    josyanf1 Member

    Joined:
    Jan 12, 2018
    Posts:
    18
    Hello everyone! In arcade games I have seen that many use this technique of drawing waves with a sprite to give the sensation of heat / fire.

    [​IMG][​IMG]

    Do you know what this effect is really called? Could you give me a hand to recreate it?

    Thanks in advance, regards!
     
  2. nacho_chicken

    nacho_chicken Member

    Joined:
    Jun 21, 2016
    Posts:
    463
    The way retro games achieved this effect was a bit different, since they were drawing things pixel-by-pixel, but this effect should be relatively easy to do via shaders and the sine wave function sin(x).

    Fragment shader:
    Code:
    varying vec2 v_vTexcoord;
    varying vec4 v_vColour;
    
    uniform float Time;
    uniform vec2 Texel;
    
    //Modify the following three consts to change the wave effect to your liking
    const float xSpeed = 0.02;
    const float xFreq = 75.0;
    const float xSize = 1.5;
    
    void main()
    {
        float xWave = sin(Time*xSpeed + v_vTexcoord.y*xFreq) * (xSize*Texel.x);
        gl_FragColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord + vec2(xWave, 0.0));
    }
    Object to draw waves with:
    Code:
    //Create event:
    uTime = shader_get_uniform(shader, "Time");
    uTexel = shader_get_uniform(shader, "Texel");
    
    //Draw event:
    shader_set(shd_wave);
    shader_set_uniform_f(uTime, current_time);
    var tex = sprite_get_texture(spr_background, 0);
    shader_set_uniform_f(uTexel, texture_get_texel_width(tex), texture_get_texel_height(tex));
    draw_sprite_ext(spr_background, 0, x, y, xscale, yscale, 0, c_white, 1);
    shader_reset();
    
     
  3. josyanf1

    josyanf1 Member

    Joined:
    Jan 12, 2018
    Posts:
    18
    Thanks for your help! <3
     
    nacho_chicken likes this.

Share This Page