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

Blend two surfaces and only blend them if there's already color

G

GhostRacCooN

Guest
Hi, I'm making a game that is top down with a slightly tilted view and I'm having some trouble with blood splatter. Basically since walls that are towards the camera are "in shadow" I need to detect and spawn darker blood there to keep the perspective. I've set up the collision and I can detect when I hit one of these top walls but I'm having trouble blending the blood surface with the wall surface.


Here is the code:

//Draw the walls
surface_set_target(wallmask);
var tileMap = layer_tilemap_get_id(layer_get_id("Layer_Walls"));
draw_tilemap(tileMap,0,0);
surface_reset_target();
draw_surface(wallmask, 0, 0);

surface_set_target(bloodsurface);
gpu_set_blendmode(bm_subtract);
draw_set_color(c_black);
draw_surface(wallmask, 0, 0);
gpu_set_blendmode(bm_normal);
surface_reset_target();

draw_surface(bloodsurface, 0, 0);

Basically my idea was to draw the Walls to a surface, leaving the floor and other areas black. Then draw the blood splatter on top of that and subtract wherever there are black tiles. But I can only seem to get the opposite effect. Ive also tried using gpu_set_colorwriteenable and gpu_set_blendmode_ext but I think I'm misunderstanding the documentation.

Here's the results, first rendering the wallsurface and then when I try to blend the blood surface onto it:
gamemaker.png
So yeah, I want the opposite effect, blood on the walls but not on the floor so I can keep the perspective look later on.

I'm sure this is really easy but I've been trying for some days now and I just cant figure it out. Any help would be appreciated.
 
Z

Zachary_tzy

Guest
Hi, I'm making a game that is top down with a slightly tilted view and I'm having some trouble with blood splatter. Basically since walls that are towards the camera are "in shadow" I need to detect and spawn darker blood there to keep the perspective. I've set up the collision and I can detect when I hit one of these top walls but I'm having trouble blending the blood surface with the wall surface.


Here is the code:

//Draw the walls
surface_set_target(wallmask);
var tileMap = layer_tilemap_get_id(layer_get_id("Layer_Walls"));
draw_tilemap(tileMap,0,0);
surface_reset_target();
draw_surface(wallmask, 0, 0);

surface_set_target(bloodsurface);
gpu_set_blendmode(bm_subtract);
draw_set_color(c_black);
draw_surface(wallmask, 0, 0);
gpu_set_blendmode(bm_normal);
surface_reset_target();

draw_surface(bloodsurface, 0, 0);

Basically my idea was to draw the Walls to a surface, leaving the floor and other areas black. Then draw the blood splatter on top of that and subtract wherever there are black tiles. But I can only seem to get the opposite effect. Ive also tried using gpu_set_colorwriteenable and gpu_set_blendmode_ext but I think I'm misunderstanding the documentation.

Here's the results, first rendering the wallsurface and then when I try to blend the blood surface onto it:
View attachment 22572
So yeah, I want the opposite effect, blood on the walls but not on the floor so I can keep the perspective look later on.

I'm sure this is really easy but I've been trying for some days now and I just cant figure it out. Any help would be appreciated.
Maybe you could try drawing the 2 things you want to blend onto the same surface, for example.
Code:
surface_set_target(blended_surface)
draw_clear_alpha(c_black, 1)
gpu_set_blendmode(bm_subtract)
// draw tile
// draw blood
surface_reset_target()
gpu_set_blendmode(bm_normal)
// draw surface
I'm not sure though but you can try that.
 
Top