Jump to content
A 2021 backup has been restored. Forums are closed and work in progress. Join our Discord server for more updates! ×
SoaH City Message Board

How I make a water distortion in GM?


Recommended Posts

You first need to capture the screen. We can do that using a surface and screen_redraw. We just need to create an objDistortion, and on step event, capture the screen like this:

    // Capture the screen
    surface_set_target(screen_surface);
        draw_clear_alpha(c_black, 0);       // Clear surface
        screen_redraw();                    // Call all redraw events
    surface_reset_target();                 // End with screen capture

This way, the only thing we have left is to then draw the surface distorted, wich you probably want to do it using sin, and some kind of angle. I'm uploading an example on how to do this water distortion:

Download it here

With it, it comes two ways: Normal and average x distortion, and another with also distorts y coordinates. Enjoy! :)

Link to comment
Share on other sites

You know, you can still use textures that are not powers of squares in draw_primitive_**** functions. It's just converted to a texture of the lowest square above it's width/height, so as long as you can multiply the text values by tha_actual_width/the_lowest_square_above to get the results you want:

    if (global.capture == false)
    {
        current_angle += angle_increment;

        // Draw the screen as a distorted surface
        angle = current_angle;

        draw_set_alpha(0.7);
        draw_set_color(c_white);
        draw_primitive_begin_texture(pr_trianglestrip,surface_get_texture(screen_surface));


        for (y=0; y<=480; y+=increment)
        {
            // Draw the "y" scanline of the surface, but in a offset, to give the distortion effect
            draw_vertex_texture(view_xview + sin(angle)*wave_offset, view_yview + y, 0, y/480 * 480/512);
            draw_vertex_texture(view_xview + 640 + sin(angle)*wave_offset, view_yview + y, 640/1024, y/480 * 480/512);

            angle += wave_pitch*increment;
        }

        draw_primitive_end();
    }

I didn't experience any significant speed increase (what the increment was set to didn't effect the speed), but it went from 110 fps max to 132 fps max using this method.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...