How to Make a Water Shader - GameMaker Studio 2

Поделиться
HTML-код
  • Опубликовано: 22 дек 2024

Комментарии • 33

  • @CxR2262
    @CxR2262 5 лет назад +13

    Man, your tutorials are the best on youtube please never stop!!!

  • @squidsheep
    @squidsheep 5 лет назад +7

    Really good tutorial, now understand alot more about shaders!

  • @KnoronOfficial
    @KnoronOfficial 2 года назад +1

    by me its not moving why?

  • @Daboss7173-d9k
    @Daboss7173-d9k 3 года назад +1

    I want the water to be transparent so I can see any sprites under it with the shader too.
    When I try to just assign the shader to that part of a surface I get a crash

  • @carbondog_x86
    @carbondog_x86 4 года назад +1

    Is there a way for me to apply the shader to the background layer only

    • @GameMakerStation
      @GameMakerStation  4 года назад +1

      Well, you have to find a way to draw it manually and apply the shader to that draw call. Also make sure to pass in any necessary uniforms.

  • @Tails2020
    @Tails2020 5 лет назад +3

    Lets say I wanted my water effect to be more intense at the top of the screen instead of the bottom, is there an easy way to do that?

    • @GameMakerStation
      @GameMakerStation  5 лет назад +2

      The Xwave in the shader is multiplied by v_vTexcoord.y for that effect, so instead try multiplying it with (1.0 - v_vTexcoord.y). That should invert the value and the effect.

    • @Tails2020
      @Tails2020 5 лет назад +2

      Thank you! I was able to use this on other shaders too, not just water. Very helpful, thanks for the tutorial! :)

  • @wozatronics
    @wozatronics 3 года назад

    Greetings Matharoo, great Tut as usual, can you please tell me how to have the water effect intensity the same from top to bottom?
    Thanks.
    Paul.

  • @bobelpatron4280
    @bobelpatron4280 3 года назад

    I'm getting a error when trying to get the x of the texel uniform, the compile error tab says it's because I'm referring to 'x' but it's just exactly of you written it in the video. I removed the x and in works fine but I'm confused about it

    • @bengelman2600
      @bengelman2600 2 года назад

      Same here

    • @bengelman2600
      @bengelman2600 2 года назад

      I had the uniform as float texel, changed it to vec2 texel and now .x works

  • @0hexadecimalF
    @0hexadecimalF 4 года назад +1

    Thanks for this tutorial.
    I tried this on my android phone but the shader stops running after 65 secs. Tested a few times.
    However in windows it works well and the shader runs all the time.
    Anyone knows why this restriction on android phone?
    I am wondering if this is "android only" problem.

    • @GameMakerStation
      @GameMakerStation  4 года назад

      No idea why that would happen... I suggest posting on the GMC forum: forum.yoyogames.com/

    • @wozatronics
      @wozatronics 3 года назад +2

      Greetings, I had the same problem, I got some help from Russel at YoYo.
      "Hi,
      Our QA team have reviewed your attached project and ask that you add 'precision highp float;' to the top of your SH_Water.fsh. At present you are passing 'current_time' in as a float and that is overflowing a medium precision float that is used by default on Android. "
      SH_Water.fsh.
      //
      // Simple passthrough fragment shader
      //
      precision highp float;
      varying vec2 v_vTexcoord;
      varying vec4 v_vColour;

  • @elcomecucas2.034
    @elcomecucas2.034 5 лет назад

    Hello, I could not understand what you explained in the video because I speak Spanish, can you explain how each line of code works?

    • @GameMakerStation
      @GameMakerStation  5 лет назад +1

      Hey, I made a new video about shaders, especially for beginners. Watch it here: ruclips.net/video/mVao4aP0Hg0/видео.html
      Hope that helps you understand how shaders work!

  • @josecreative
    @josecreative 4 года назад

    can i have the shader code. beacuse i copy it by hand and gives me errors

  • @soveryme8127
    @soveryme8127 3 года назад

    Thank you so much
    It helped a lot! :D

  • @ManjeetKumar-xk8jf
    @ManjeetKumar-xk8jf 7 лет назад +2

    Great tutorial you are truely awesome.

  • @Jordanpost7
    @Jordanpost7 Год назад

    Why can’t you just be able to check a box that says reflect? Why is there so much convoluted coding for a simple reflection?

  • @FoxyOfJungle
    @FoxyOfJungle 6 лет назад

    It Works perfectly in GMS 1.4 , Thanks.

    • @matiasr.28
      @matiasr.28 6 лет назад

      Can you pass me the project... Please? I don't understand why I have some errors.

    • @FoxyOfJungle
      @FoxyOfJungle 6 лет назад +2

      *VERTEX SHADER*
      //
      // Simple passthrough vertex shader
      //
      attribute vec3 in_Position; // (x,y,z)
      //attribute vec3 in_Normal; // (x,y,z) unused in this shader.
      attribute vec4 in_Colour; // (r,g,b,a)
      attribute vec2 in_TextureCoord; // (u,v)
      varying vec2 v_vTexcoord;
      varying vec4 v_vColour;
      void main()
      {
      vec4 object_space_pos = vec4( in_Position.x, in_Position.y, in_Position.z, 1.0);
      gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * object_space_pos;
      v_vColour = in_Colour;
      v_vTexcoord = in_TextureCoord;
      }
      *PIXEL SHADER*
      //
      // Simple passthrough fragment shader
      //
      varying vec2 v_vTexcoord;
      varying vec4 v_vColour;
      uniform float Time;
      uniform vec2 Texel;
      const float Xspeed = 0.01;
      const float Xfreq = 20.0;
      const float Xsize = 5.0;
      const float Yfreq = 100.0;
      const float Ysize = 20.0;
      void main()
      {
      //X wave
      float Xwave = sin(Time*Xspeed + v_vTexcoord.y*Xfreq) * (Xsize*Texel.x) * v_vTexcoord.y;
      float Ywave = sin(Time*Xspeed + v_vTexcoord.y*Yfreq) * (Ysize*Texel.y) * v_vTexcoord.y;
      gl_FragColor = v_vColour * texture2D( gm_BaseTexture, v_vTexcoord + vec2(Xwave,Ywave));
      }
      *CREATE EVENT*
      image_speed=0
      uniTime = shader_get_uniform(shader_water,"Time");
      uniTexel = shader_get_uniform(shader_water,"Texel");
      *DRAW EVENT*
      shader_set(shader_water)
      shader_set_uniform_f(uniTime, current_time)
      var tex = sprite_get_texture(sprite_index,image_index)
      shader_set_uniform_f(uniTexel,texture_get_texel_width(tex),texture_get_texel_height(tex))
      draw_self()
      shader_reset()

    • @matiasr.28
      @matiasr.28 6 лет назад

      Thank you.

  • @Scentient07
    @Scentient07 5 лет назад

    dnd?

    • @deffyme7357
      @deffyme7357 5 лет назад +1

      You're so lucky, they don't have laugh reacts on here... We'd smash it.

    • @Victorcxx
      @Victorcxx 4 года назад

      @@deffyme7357 LOL :D

  • @maniksinghgamer5099
    @maniksinghgamer5099 4 года назад

    Please try panjad

  • @stevegreen3442
    @stevegreen3442 5 лет назад

    Xwave should use cos...

    • @GameMakerStation
      @GameMakerStation  5 лет назад

      It's a sin wave. We're not dealing with trig here.