Fuzzy surface?

4

42ndPotato

Guest
Hullo.

I've been trying to add shockwave distortion effects to my game, and recently found this video by Gaming Reverends on one approach to do it :
The code/demo project used for the video was also up for download, so I stole borrowed most of the code and implemented it into my game project, and works for the most part.

However, I've been running into a problem where whenever I draw a shockwave, the game permanently looks a lot more fuzzy? I admittedly don't have enough experience with draw GUI events and draw_surface stuff so I don't reall know how to deal with this problem.

PettyTheftFuzz.png

Does anyone know how to fix this?

Here's the code I use in a Draw GUI Begin event, which is a slightly modified version of the code found in Gaming Reverend's demo project. If anything's unclear feel free to call me out for it.
GML:
/// @description MAIN

// just draw the application surface if the list of waves is empty.
// else draw the application surface distorted by the shader:

//display_set_gui_size(view_wport[0], view_hport[0]);

var wave_list_size = ds_list_size(list_of_waves);

if (wave_list_size <= 0)
{
    //draw_surface(application_surface, 0, 0);
    application_surface_draw_enable(true);
    shader_reset();
    //gpu_set_blendenable(true);
} else {
    
    // set values based on sliders. In a game you'd use constants inside the shader instead
    var fx_strength    = 0.70 * 0.2 - 0.1;
    var aberration    = 0.65 * 2 - 1;
    //var subimage    = 0;
        
    // create waves surface:
    if (!surface_exists(srf_waves)) {
        srf_waves = surface_create(view_w * srf_waves_scale, view_h * srf_waves_scale);
        tex_waves = surface_get_texture(srf_waves);
    }
    
    gpu_set_texfilter(true);
    
    // draw wave sprite to waves surface:
    surface_set_target(srf_waves);
        draw_clear_alpha($FF7F7F, 1);
        gpu_set_blendmode_ext(bm_dest_color, bm_src_color);
        shader_set(shd_add_normals);
        
        var w, this_wave;
        //var wave_list_size = ds_list_size(list_of_waves);
        for (w = 0; w < wave_list_size; w++) {
            this_wave = list_of_waves[|w];
            if (this_wave[|waveparam.age] >= 0) {
            draw_sprite_ext(this_wave[|waveparam.wavesprite], this_wave[|waveparam.waveindex],
                            (this_wave[|waveparam.xx] - camera_get_view_x(view_camera[0])) * srf_waves_scale, //- camera_get_view_x(view_camera[0])
                            (this_wave[|waveparam.yy] - camera_get_view_y(view_camera[0])) * srf_waves_scale, //- camera_get_view_y(view_camera[0])
                            this_wave[|waveparam.scale] * srf_waves_scale,
                            this_wave[|waveparam.scale] * srf_waves_scale,
                            0, c_white, this_wave[|waveparam.alpha]);
            }
        }
        
        shader_reset();
        gpu_set_blendmode(bm_normal);
        surface_reset_target();
    
        // draw application surface with waves surface as 2nd texture:
        gpu_set_texfilter_ext(0, false);
        shader_set(shader);
            shader_set_uniform_f(u_fx_strength, fx_strength);
            shader_set_uniform_f(u_aspect, aspect);
            shader_set_uniform_f(u_aberration, aberration);
            texture_set_stage(u_tex_waves, tex_waves);
            draw_surface(application_surface, 0, 0);
        shader_reset();
    
        gpu_set_texfilter(false);
    

    // debug only: draw waves surface if toggle 0 in toggle group 1 is active:
    //switch (toggle_get_group_active(1)) {
    //    case 0: break;
    //    case 1: draw_surface_ext(srf_waves, 0, 0, 1 / srf_waves_scale, 1 / srf_waves_scale, 0, c_white, 0.8); break;
    //    case 2: draw_surface_ext(srf_waves, 0, 0, 1, 1, 0, c_white, 1);
    //}
    
    
    // debug only: draw waves information when space is pressed:
    if (true) {
        var txt1 = "wave:\nage:\nscale:\nalpha: ";
        var txt2;
        
        draw_text(10, 10, "waves: " + string(wave_list_size));
        for (w = 0; w < wave_list_size; w++) {
            this_wave = list_of_waves[|w];
            txt2 =    string_format(w,                            0, 0) +    "\n" +
                    string_format(this_wave[|waveparam.age],    0, 0) + "\n" +
                    string_format(this_wave[|waveparam.scale],    0, 1) + "\n" +
                    string_format(this_wave[|waveparam.alpha],    0, 2);
            draw_text(10 + w * 120,         40, txt1);
            draw_text(10 + w * 120 + 60, 40, txt2);
        }
    }
}

shader_reset();
//*/
 

rytan451

Member
When are your waves being cleared? It would probably be in an alarm or step event, an the code should involve list_of_waves, waveparam.age, and possibly ds_list_delete.

As a quick sidenote, you should probably transition away from using a ds_list for your wave data, and use structs instead.
 
4

42ndPotato

Guest
When are your waves being cleared? It would probably be in an alarm or step event, an the code should involve list_of_waves, waveparam.age, and possibly ds_list_delete.

As a quick sidenote, you should probably transition away from using a ds_list for your wave data, and use structs instead.
That happens in the step event:
GML:
// WAVE AGE:
//-----------------------------------------------------------------------------
var wave_list_size = ds_list_size(list_of_waves);
if (wave_list_size > 0) {
    var w, this_wave;
    for (w = 0; w < wave_list_size; w++) {
        this_wave = list_of_waves[|w];
        this_wave[|waveparam.age]    += this_wave[|waveparam.wavespeed]//slider_get_value(0);
        
        if (this_wave[|waveparam.age] < this_wave[|waveparam.life]) {
            this_wave[|waveparam.scale]    = tween_cubic_out_simple(this_wave[|waveparam.age] / this_wave[|waveparam.life]) * this_wave[|waveparam.maxscale];
            this_wave[|waveparam.alpha]    = 1 - tween_quadratic_out_simple(this_wave[|waveparam.age] / this_wave[|waveparam.life]);
        } else {
            ds_list_destroy(this_wave);
            ds_list_delete(list_of_waves, w);
            w--;
            wave_list_size--;
        }
    }
}
 
Top