![]() I've wrote a custom sound engine within GMS so now I have total control for matching the gain of the different sounds while still allowing the player to lower or raise the master volume for the SFX independent from the Music master or the General master volume. I've been focusing elsewhere.įINALLY I've fixed a bug that's been bugging me (no pun intended) for a long time, where the SFX volumes where brutally uneven (including classic mega loud machine gun bullets). I've started work in multi-control compatibility, but I'll get deeper into that later. We do this by testing which side of the vector (the edge of the block) the light is on.I've finally get rid of every bug, but there are no big changes since last update. ![]() As mentioned above we can get the same result by only casting the leading 2 edges. Lastly, let's fix the need to project all 4 edges. Moving the mouse around you'll also get the shadows moving around and projecting the right direction. So, if you putting all this together, increase the rad variable in the create event to 256 and you'll get something like the image below. Len = (1.0*SHADOW_LENGTH) / sqrt( (Bdx*Bdx)+(Bdy*Bdy) ) // unit length scaler * Shadow length Len = (1.0*SHADOW_LENGTH)/sqrt( (Adx*Adx)+(Ady*Ady) ) // unit length scaler * Shadow length ![]() shadows are infinite - almost, just enough to go off screen / cast a shadow of this line segment from the point light This will give us our distant points to help make up our "QUAD". Once we have our unit vectors, we can scale these by a large amount and add on the positions. For example, if you want to move at a steady speed even if you're going diagonally (since x++ y++ will make you go faster diagonally, than in a straight line), you would use a unit vector and multiply by the speed you wish to go. Unit length vectors are used all over the place in computing, from normals on 3D models for lighting, to motion directional vectors. Adx = PointX-LightX Īdx and Ady now comprise a vector of a length of 1, that is sqrt( (Adx*Adx)+(Ady*Ady) ) = 1.0. This keeps them both the same size, and the projection even. 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. 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. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |