Shaders [SOLVED] Dark outline around sprites introduced when I added a shader and surface to project

Tony M

Member
Hi, I have successfully implemented a full screen wave shader that I adapted from here: https://marketplace.yoyogames.com/assets/261/free-shaders

The shader itself works quite well, but has unfortunately introduced an issue with my sprites. Sprites with semi transparent edges (anti-aliasing) now get rendered with a dark outline. Not sure if it has something to do with the full screen surface and the gpu blending.

Below shows my game using the shader and surface, you can see the black outline.

first.png

Next screen shows my images as the are suppose to appear (no black outline, semi alpha edges).
second.png

In my game, if I jump back to the original room, the black outline disappears but I get artifacts from the red block.
third.png
So its a strange problem that I am totally stuck with.

Here is the code from my Shader Controlling object:
Code:
// Create Event


uni_time = shader_get_uniform(shd_wave_horizontal,"time");
var_time_var = 0.0;

uni_wave_left = shader_get_uniform(shd_wave_horizontal,"wave_left");
var_wave_left = 0.0;

uni_wave_right = shader_get_uniform(shd_wave_horizontal,"wave_right");
var_wave_right = 0.0;


wave_triggered = false;
wave_thickness = 0.5;
wave_speed = 0.05;

surf = surface_create(camera_get_view_width(view_camera[0]), camera_get_view_height(view_camera[0]));
view_set_surface_id(0, surf);
Code:
// Step event

var_time_var+=0.04;

if keyboard_check_released(vk_space) {
    wave_triggered = true;
    var_wave_left = 0.0;
    var_wave_right = 0.0;
}


if (wave_triggered) {
   
    var_wave_right = clamp(var_wave_right + wave_speed, 0.0,1.0);
    if (var_wave_right > wave_thickness) {
        var_wave_left = clamp(var_wave_left + wave_speed, 0.0,1.0);
    }
   
    if (var_wave_left == 1.0) {
        wave_triggered = false;
    }
   
}
Code:
// Draw GUI event

    draw_set_color(c_white);
   
    if (wave_triggered) {
        shader_set(shd_wave_horizontal);
        shader_set_uniform_f(uni_time, var_time_var);
        shader_set_uniform_f(uni_wave_left, var_wave_left);
        shader_set_uniform_f(uni_wave_right, var_wave_right);
    }

draw_surface(surf,0,0);
shader_reset();
Also, the GMS2 source code that demonstrates this specific issue can be found here:
https://github.com/sidfishgames/gms2_shader_issue

Any help is greatly appreciated.
 
Last edited:

Tony M

Member
I've been investigating my issue a little further and found this other person had the same issue and resolved it (https://www.reddit.com/r/gamemaker/comments/6tcbn9/alpha_glitches_on_surfaces/). Unfortunately, it looks like their Reddit account is no longer active. They mention using gpu_set_colorwriteenable and gpu_set_blendable correctly to resolve it, but I have tried applying it to my code (above) in several ways without any luck. Below code is what they said worked for them:

Code:
surface_set_target(sur_newroom);
draw_clear(c_white);
gpu_set_blendenable(false);
gpu_set_colorwriteenable(true,true,true,false);
draw_surface(application_surface,0,0);
gpu_set_colorwriteenable(true,true,true,true);
gpu_set_blendenable(true);
surface_reset_target();
Does anyone have any ideas on how I can apply this to my code as everything I have tried has failed?
 

Tony M

Member
After playing around, I eventually got my issue resolved. Below is the working code for my Draw GUI event.

Code:
// Draw GUI Event

if (!surface_exists(surf)) {
    surf = surface_create(camera_get_view_width(view_camera[0]), camera_get_view_height(view_camera[0]));
        view_set_surface_id(0, surf);

} else {

    draw_set_color(c_white);
    
        if (wave_triggered) {
            shader_set(shd_wave_horizontal);
            shader_set_uniform_f(uni_time, var_time_var);
            shader_set_uniform_f(uni_wave_left, var_wave_left);
            shader_set_uniform_f(uni_wave_right, var_wave_right);
        }

    draw_clear(c_white);
    gpu_set_blendenable(false);
    gpu_set_colorwriteenable(true,true,true,false);

    draw_surface(surf,0,0);

    gpu_set_colorwriteenable(true,true,true,true);
    gpu_set_blendenable(true);

shader_reset();

}
 
Top