• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Sprite fade transitions using surfaces

Hello everybody, I'm trying to make a simple fade effect between two sprites and i got in to a problem.
This is what I am expecting to get
fade1.png
I created 2 sprites with the pictures and a simple background with a blue dot in the middle.
Now what I want is the first image starts to fade away at the same time the second image starts appearing, to achieve this i just created 2 variables "fade_in" and "fade_out" that varies its values from 1 to 0 according to the situation, now in the draw event i put this:
GML:
draw_sprite_ext(sImage1,0,0,0,1,1,0,c_white,fade_out);
draw_sprite_ext(sImage2,0,0,0,1,1,0,c_white,fade_in);
But the actual result is this:
fade2.png
The pixels of the intersection gets alpha values diferent from 1 and the background gets visible. I know this is working as intended but how can I get the transition without the transparency problem?

The only solution that comes in to my mind is to draw the first image, then in a second surface draw the background and the second picture, and finally draw the surface with the "fade_in" variable wich is what I used to achieve the first pic:
GML:
draw_sprite_ext(sImage1,0,300,0,1,1,0,c_white,1);    //Draw the first pic in the application surface


surface_set_target(surf1);                               

draw_sprite_ext(sBackground,0,0,0,1,1,0,c_white,1);    //Draw the background in the surface

draw_sprite_ext(sImage2,0,0,0,1,1,0,c_white,1);        //Draw the second pic in the surface

surface_reset_target();

draw_surface_ext(surf1,300,0,1,1,0,c_white,fade_in);//Draw the surface with the alpha value
To get things worse, I actually need to draw all this using surfaces, wich its a mess when trying to use alpha values so this is what I learned:
GML:
gpu_set_blendmode_ext(bm_one, bm_inv_src_alpha);    //Setting the blendmode

surface_set_target(surf3);
draw_clear_alpha(c_black,0);
shader_set(sh_premultiply_alpha);        //Using a provided shader to premultiply the alpha
draw_sprite_ext(sImage1,0,0,0,1,1,0,c_white,fade_out);
draw_sprite_ext(sImage2,0,0,0,1,1,0,c_white,fade_in);
shader_reset();
surface_reset_target();

draw_surface_ext(surf3,600,0,1,1,0,c_white,1);
gpu_set_blendmode(bm_normal);
The solution that comes in to my mind is to somehow set the alpha value of the pixels en the intersections to 1 in the surface, but how can I do this??
fad3.png
Hope you guys can help me. I'm providing the .yyz I used to show this in case someone is interested.
 
Shaders can do this:
vec4 frag_result = vec4(mix(frag1.rgb, frag2.rgb, alpha), 1.0);
Thanks in advance, but i forgot to mention that my knowledge of shaders is basically zero, I used the premultiply_alpha shader provided in this video to fix alpha issues when using surfaces
 
Top