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

Shadows cutting off at ledges

kupo15

Member
Making simple shadows is pretty easy if your ground is always there to cast a shadow but if you have a thin walkway like the edge of a cliff its a little more work to make it look realistic. In this case have the shadow cutoff where there is no ground.

My first thought is blend modes subtraction but all I can think of if easily removing the part of the shadow that is on the floor by using the floor sprite. I essentially instead want to use a reverse bm_subtract where it subtracts the pixels that aren't there to blend with to remove the leftover shadow

What is the best way to do this?

 
S

seanm

Guest
No, the process looks something like this

draw the background to a surface
use blend modes to use that surface as an alpha mask
draw shadow sprite, which can now only be seen ontop of the background
reset blend modes
draw surface

Should be some tutorials kicking around on the old forum


Alternatively, something like this should work. Uses a shader instead.
 

kupo15

Member
Thanks for that video! I don't think that video does what I need or exactly but what you wrote is more in line what I did with this test project. This test works and it'll probably be fine but I'm curious if there is a better way:

Code:
surface_set_target(surf);
draw_background(reiko_ground_3,0,0); // draw ground
draw_sprite_skew_ext(spr_sandbag,0,x,103,1,0.4,0,c_black,0.75,-128,0); // draw shadow
draw_set_blend_mode(bm_subtract);
draw_background(background9,0,0); // remove all pixels from invisible section
draw_set_blend_mode(bm_normal);
surface_reset_target();

draw_surface(surf,32,256); // draw background with shadow
draw_sprite(spr_sandbag,0,x,y-25); // draw player
STAGE BACKGROUND


ALPHA MASK - BACKGROUND9 IN THE CODE

this essentially is the transparency part of the stage background in a solid black that subtracts out of the surface

So it seems like simple surfaces and blend modes achieve this effect
 
Top