• 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!

GameMaker [Solved] Using clipping masks with transparent sprites

Tails1000

Member
Sorry the title isn't clear, I don't know how to properly explain what I'm struggling with...
I know how to use clipping masks with completely opaque sprites, but once I try it with sprites that have transparency in them the effect doesn't work.

Here's what I'm dealing with visually. The left is what I have in-game, the right is what I want (created in photoshop)


I'm using a simple gradient circle sprite in the project. Here is the code:

Code:
//Draw Event//

draw_rectangle_color(0,0,room_width,room_height,c_orange,c_orange,c_blue,c_blue,0)

if !surface_exists(surf) {
    surf = surface_create(room_width,room_height)
}
surface_set_target(surf)
draw_clear_alpha(c_black,0)

gpu_set_blendenable(false)
draw_circle(500,100,70,0)
gpu_set_blendenable(true);

gpu_set_blendmode_ext(bm_dest_alpha,bm_inv_dest_alpha);
gpu_set_alphatestenable(true);
draw_sprite_ext(spr_light,1,mouse_x,mouse_y,1,1,0,c_white,1)
gpu_set_alphatestenable(false);
gpu_set_blendmode(bm_normal);

surface_reset_target()

draw_surface(surf,0,0)

I've been looking up tutorials and trying to find others with a similar problem, but I can't seem to find out what I'm doing wrong or if it's even a quick fix.
If anyone sees where I'm making a mistake I'd love to know. Thank you in advance for your assistance! :)
 

Kyon

Member
What if you remove all those "blendenable" and "testenable" lines. Does that help?
Also what about this blendmode:
Code:
gpu_set_blendmode_ext(bm_zero, bm_inv_src_alpha);
 

Tails1000

Member
What if you remove all those "blendenable" and "testenable" lines. Does that help?
Also what about this blendmode:
gpu_set_blendmode_ext(bm_zero, bm_inv_src_alpha)
I removed those lines and I did see how unnecessary they were, though my problem isn't completely solved :/
This is my new code:
Code:
draw_rectangle_color(0,0,room_width,room_height/3,c_orange,c_orange,c_blue,c_blue,0)


if !surface_exists(surf) {
    surf = surface_create(room_width,room_height)
}
surface_set_target(surf)
gpu_set_colorwriteenable(false,false,false,true);

draw_clear_alpha(0,0)
draw_sprite(spr_light2,1,200,100)

gpu_set_colorwriteenable(true,true,true,true);
gpu_set_blendmode_ext(bm_dest_alpha,bm_inv_dest_alpha);

draw_sprite_ext(spr_light,1,mouse_x,mouse_y,1,1,0,c_white,1)

gpu_set_blendmode(bm_normal);
surface_reset_target()

draw_surface(surf,0,0)

And here are the new results:

The left is the above code, while the right is that other blendmode you suggested. The right is a cool effect but not exactly what I'm looking for.

My main issue is that whenever I try to turn my mask transparent it also affects the alpha of the overlay, which is exactly what I'm trying to avoid.
I've followed this tutorial: https://www.yoyogames.com/blog/430/dynamic-rendering-masks
But I'm unable to achieve the same results even when following the code to a tee.

Though I do appreciate your reply! I'll keep playing around with it and post the solution if I find it
 

Tails1000

Member
Alright, I managed to solve my problem using this tutorial: https://yal.cc/gamemaker-draw-clip/
Unfortunately the solution involves using either 2 surfaces or shaders, which I was hoping to avoid.
But regardless the effect is exactly what I was looking for, so problem solved :)

Code:
draw_rectangle_color(0,0,room_width,room_height/3,c_orange,c_orange,c_blue,c_blue,0)

if !surface_exists(surf) {
    surf = surface_create(room_width,room_height)
    surface_set_target(surf)
    draw_clear(c_black)
    gpu_set_blendmode(bm_subtract)
    draw_circle(128, 128, 70, false);
    gpu_set_blendmode(bm_normal)
    surface_reset_target();
}
if !surface_exists(surf2) {
    surf2 = surface_create(room_width,room_height)
    
}
surface_set_target(surf2)
draw_clear_alpha(c_white, 0);
draw_sprite(spr_light,1,mouse_x , mouse_y );
gpu_set_blendmode(bm_subtract)
draw_surface(surf, 0, 0);
gpu_set_blendmode(bm_normal)
surface_reset_target();
draw_surface(surf2, 0, 0)
 
Top