

This is handy as we can then scale this unit vector by an even amount, otherwise if your especially close to the block, one edge might be really close (and on screen), while the other is off into the distance. Next we want to make these "unit" vectors, that is a vector of length 1.0. We do this by doing working out Point1X-LightX and Point1Y-LightY, and Point2X-LightX and Point2Y-LightY. The trick in ProjectShadow is to get the vector from the light to each point in the line supplied. Vertex_submit(VBuffer,pr_trianglelist,-1) ProjectShadow(VBuffer, px1,py2, px1,py1, lx,ly )

ProjectShadow(VBuffer, px2,py2, px1,py2, lx,ly ) ProjectShadow(VBuffer, px2,py1, px2,py2, lx,ly )

ProjectShadow(VBuffer, px1,py1, px2,py1, lx,ly ) So, let's change our processing loop to actually build our buffers. This is handy, as it means we only need to project edges FACING the light.įor now, we'll just project all 4 edges and see what happens. Now, the sharper pencils among you will notice that the front 2 edges, project the same shape as the rear - they just start at a different point closer to the light. The rays that project from the back of the block is the shadow volume we're after. With this done, now we're ready to build some shadow volumes, but before we do, how do we cast a shadow anyway? Let's go back to our light radius image, and this time project from the centre light to the one of the blocks - each corner to be more precise.
GAME MAKER STUDIO 2 LIGHTING CODE
So, now we're ready to actually do something! First, let's add some code to the create event of this object to handle the vertex buffer and the vertex format we'll be using. Next, we'll loop through this tile box and look for tiles that aren't empty - like this for(var yy=starty yy<=endy yy++) Var tilemap = layer_tilemap_get_id("walls") ĭraw_rectangle(startx*tile_size,starty*tile_size, endx*tile_size,endy*tile_size,true) īy placing this in the draw event of an object (placed at the light location), it will select the tile range we're going to process, and draws a box around it, clamped to tile boundaries. var lx = mouse_x // the light position, based around the mouse location To process these all we need to do is loop over these tiles, and find out if there is a wall there or not.
