Lighting Help

So I built a lighting system that projects 4 black triangles from the corners of the object casting the shadow. It works for the most part, and changing depth according to distance from the player means shadows will be drawn over objects that are further away and don't have line of sight to the player.



issue is there's some area where the shadows will be drawn at a weird angle and overlap blocks they shouldn't be. You can see it in the bottom right and upper right hand corners. I've tried lots of different things but can't seem to figure out anything that works. Has anyone else worked on a similar system like this?
 

NightFrost

Member
I guess this is the same shadow-caster code I've seen before, relying on drawing black triangles from wall corners to screen edge to create the shadow&light effect. It totally relies on drawing the triangles beneath the wall pieces to hide its "crimes" which is those partial shadows. You'll just have to move the shadow generator to a layer beneath the terrain. If you want to hide walls that are not in player line of sight, use collision_line to player from all of their four corners, and if all four come up with collisions then player cannot see them. Of course, only measure from those that are on screen (rectangle_in_rectangle check of view corners versus wall corners).
 
I guess this is the same shadow-caster code I've seen before, relying on drawing black triangles from wall corners to screen edge to create the shadow&light effect. It totally relies on drawing the triangles beneath the wall pieces to hide its "crimes" which is those partial shadows. You'll just have to move the shadow generator to a layer beneath the terrain. If you want to hide walls that are not in player line of sight, use collision_line to player from all of their four corners, and if all four come up with collisions then player cannot see them. Of course, only measure from those that are on screen (rectangle_in_rectangle check of view corners versus wall corners).
Now see that was my idea too, but the values for the collision detection are inconsistent in a way that makes me think there's just some part of GMS2 I'm not getting.



So here each line goes from it's corner to the corner of the player, or more specifically to the corner pixel -1.Or more specifically the x, y pairs are:

1,1
30,1
1, 30
30, 30

to help with detection

Each sprite is 32x32 on a 32 pixel grid. Each of the four numbers here represents the number of collisions per corner.

Ideally each block should have "symmetrical" values, but you can see each corner gives a different value. The top left and bottom right corner are symmetrical at 0110 but the top right and bottom left are completely different. I assume they should be 1001.

Is there an offset I'm missing?
 
Top