Hychan
Member
I followed that one tutorial (https://www.yoyogames.com/blog/419/realtime-2d-lighting-in-gamemaker-studio-2-part-1) to achieve a dynamic lighting system in my top-down game (which was a pain, because the article refuses to load, and I had to find an archive of it. Do y'all know why they took this tutorial down?). With the knowledge in that tutorial, I was able to reach this point:
My game's collision is grid-based, since I'm generating procedural dungeon layouts, which is why I decided to just use Gamemaker's vertex functions instead of using a shader. If the tutorial above doesn't load for you, basically I'm looping through all visible grid cells and building a primitive which casts a shadow behind each wall cell relative to the player's position. This runs decently enough (still haven't dropped under 60 fps).
My problem, though, is that I need the first wall to be visible to the player, while every wall behind that needs to still be hidden by the shadow of the first wall, to hide secret rooms and such. I tried offsetting each grid tile's x and y positions relative to the player before casting the shadow, using this code:
but that gives this result, which is atrocious:
I also tried just increasing the size of each grid cell, to fill in the gaps between squares, which gave me this result:
This is ALMOST the effect I'm looking for, but there are still gaps if you get close enough to the walls.
Am I approaching this problem from the wrong angle? Should I try using a shader instead, or is there a different way to build a primitive which would fill in the gaps between cells?
My game's collision is grid-based, since I'm generating procedural dungeon layouts, which is why I decided to just use Gamemaker's vertex functions instead of using a shader. If the tutorial above doesn't load for you, basically I'm looping through all visible grid cells and building a primitive which casts a shadow behind each wall cell relative to the player's position. This runs decently enough (still haven't dropped under 60 fps).
My problem, though, is that I need the first wall to be visible to the player, while every wall behind that needs to still be hidden by the shadow of the first wall, to hide secret rooms and such. I tried offsetting each grid tile's x and y positions relative to the player before casting the shadow, using this code:
GML:
var px1 = (i*16); // top left
var py1 = (t*16);
var px2 = ((i*16)+16); // bottom right
var py2 = ((t*16)+16);
var center_x, center_y;
center_x = mean(px1,px2);
center_y = mean(py1,py2);
px1+=lengthdir_x(24,point_direction(x,y,center_x,center_y));
py1+=lengthdir_y(24,point_direction(x,y,center_x,center_y));
px2+=lengthdir_x(24,point_direction(x,y,center_x,center_y));
py2+=lengthdir_y(24,point_direction(x,y,center_x,center_y));
I also tried just increasing the size of each grid cell, to fill in the gaps between squares, which gave me this result:
This is ALMOST the effect I'm looking for, but there are still gaps if you get close enough to the walls.
Am I approaching this problem from the wrong angle? Should I try using a shader instead, or is there a different way to build a primitive which would fill in the gaps between cells?