if( !surface_exists(surf) ){
surf = surface_create(room_width,room_height);
}
surface_set_target(surf);
draw_clear_alpha(0,0);
vertex_begin(VBuffer, VertexFormat);
lightCounter = 0;
with (obj_light) {
var lx = x + sprite_width / 2; // the light position, based around the mouse location
var ly = y + sprite_height / 2;
var tile_size = 32; // size of a tile
var tilemap = layer_tilemap_get_id("Floor_1_Walls");
var startx = floor((lx-rad)/tile_size);
var endx = floor((lx+rad)/tile_size);
var starty = floor((ly-rad)/tile_size);
var endy = floor((ly+rad)/tile_size);
/*other.lights[other.lightCounter, 0] = lx;
other.lights[other.lightCounter, 1] = ly;
other.lights[other.lightCounter, 2] = rad;*/
other.lights[other.lightCounter] = lx;
other.lights[other.lightCounter] = ly;
other.lights[other.lightCounter] = rad;
other.lightsX[other.lightCounter] = lx;
other.lightsY[other.lightCounter] = ly;
other.lightsR[other.lightCounter] = rad;
other.lightCounter++;
for(var yy=starty;yy<=endy;yy++)
{
for(var xx=startx;xx<=endx;xx++)
{
var tile = tilemap_get(tilemap,xx,yy);
if( tile!=0 )
{
// get corners of the
var px1 = xx*tile_size; // top left
var py1 = yy*tile_size;
var px2 = px1+tile_size; // bottom right
var py2 = py1+tile_size;
if( !SignTest( px1,py1, px2,py1, lx,ly) ){
ProjectShadow(other.VBuffer, px1,py1, px2,py1, lx,ly );
}
if( !SignTest( px2,py1, px2,py2, lx,ly) ){
ProjectShadow(other.VBuffer, px2,py1, px2,py2, lx,ly );
}
if( !SignTest( px2,py2, px1,py2, lx,ly) ){
ProjectShadow(other.VBuffer, px2,py2, px1,py2, lx,ly );
}
if( !SignTest( px1,py2, px1,py1, lx,ly) ){
ProjectShadow(other.VBuffer, px1,py2, px1,py1, lx,ly );
}
}
}
}
}
vertex_end(VBuffer);
vertex_submit(VBuffer,pr_trianglelist,-1);
surface_reset_target();
shader_set(sh_shadow);
shader_set_uniform_f_array(LightPosRadius, lights);
shader_set_uniform_f_array(LightPosX, lightsX);
shader_set_uniform_f_array(LightPosY, lightsY);
shader_set_uniform_f_array(LightRadius, lightsR);
draw_surface(surf,0,0);
shader_reset();