Search the Community
Showing results for tags 'pixelmap'.
Found 1 result
Creating mask that cut light/sprite to pixel map terrainI try to create mask that clip sprite(light) in this way that we will see shadows. Lets assume: 1. Draw a pixel map where black pixel means rock, white means air. 2. Draw black lightmap on it (black sprite on whole map, with MULTIPLY blending) 3. Draw an light(sprite with ADD blending) on lightmap texture by PIXI,RenderTexure these 3 steps allow us to create lightmaping on map, but lights always will go through walls. So we need to use masking. 1. use Bresenham Algorithm for rasterize Circle (with radius of our light = half of width of texture) result is array of pixels XY that create circle. 2. sort these pixels based on angle (from 0 to 360) so we have then polygon/circle data array. 3, create a mask based on these data now we have masked light but nothing is changed, now we need to raycast from center of light to each pixel on circle again with Bresenham Algorithm 1. use Bresenham Algorithm for rasterize Line from center of light/sprite to each point on circle, result is pixels on the radius/line, if one of them are Rock/black pixel - change this position/pixelXY on circle to collision position. 2. apply mask now we see occlusion to the pixels (rock/air) on map, and shadows. But.. it is too slow!! I've searched a lot of stuff to find a better way, but have nothing. Someone knows a better way for occlusion lights/sprites to pixel map(rock/air)?