Hi, so I'm trying to make a lighting system for my 2D RPG using surfaces, which are quite new to me.
My problem is that the bm_subtract blendmode seems to be doing weird things.
The first image shows what my lighting system currently looks like.
The effect is managed by an object called objDarkness, which is on a layer with depth 100.
This is the draw event code
var camera = view_get_camera(0);
if !surface_exists(light_surface) {
var cam_width = camera_get_view_width(camera);
var cam_height = camera_get_view_height(camera);
light_surface = surface_create(cam_width, cam_height);
}
surface_set_target(light_surface);
draw_clear(#0F0720);
camera_apply(camera);
gpu_set_blendmode(bm_subtract);
draw_sprite(sprRuinStairLightmask, 0, 0, 0);
gpu_set_blendmode(bm_normal);
surface_reset_target();
'sprRuinStairLightmask' is the second image. It's supposed to 'cut holes' into the overlay color of #0F720, creating the effect of light.
But bm_subtract seems to be behaving a bit weirdly, since the rims around the circles of light seem to be shades of black and not the dark purple they're supposed to be. I don't know what causes this.
It looks like it thinks the overlay color is black and it's reducing the alpha of this imaginary black background. I've tried switching the code around in order, I tried drawing a literal colored rectangle instead of using draw clear, but none of it worked.
The surface is drawn in post-draw:
gpu_set_blendenable(false);
draw_surface(application_surface, 0, 0);
gpu_set_blendenable(true);
draw_set_alpha(0.8);
draw_surface_stretched(light_surface, 0, 0, window_get_width(), window_get_height());
draw_set_alpha(1);
I have to draw the application_surface manually 'cause I used application_draw_enable(false) in the create event. If I don't, then Gamemaker overrides my surface code for some reason, still don't quite understand how that works, but I know it's intended.