Jump to content

Creating mask that cut light/sprite to pixel map terrain


hashi
 Share

Recommended Posts

I 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)? 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...