I have a collsion map, and some places that I want to be light sources. The light source provides light that is actually a shape where I can see the ground. It now looks like this:
So the light goes through the walls. I want to make it look like this:
(I marked the collisions with walls with dark yellow)
So the light rays stop when meeting the wall. I want to get the shape of the correct light, the best would be bitmap containing it)
My first idea was to cast rays from the source and check when they collide with the wall (I know how to do this), but then I would need to cast ray each 0.001 deg for example, so its too much time to generate lights. The next thing is that The light shape isn't always circle, sometimes it can be ellipse or half-ellipse, even triangle or part of the circle. Generally, I have the bitmap with light that doesnt collide anything, and I want to subtract it a bit to make it look like on the second image.
And the last thing, Im using allegro 4.2.1, but all previously mentioned bitmaps are 2-dimmension arrays with 0's and 1's.
Thanx for any help, sorry for long question and my bad english.
(And even with real-time shadows, light still "passes through" walls, which you can see if you have the shadow strength less than 100%.) Shadows require pixel lights.
In Unity 5 you just turn on shadows at your light object, and use the standard shader on any materials that are misbehaving (like your floor or wall). Click to expand...
Pixel lighting by itself doesn't change the fact that lighting is computed on surfaces without regard to other objects; shadows are like a texture that's overlaid on top of things. i.e., light doesn't really "pass through" walls, it's just that walls are irrelevant to how lighting is computed.
In that case you'll need to be a bit more clever. You can simulate this in shaders or use raycasts to see if the light is behind a wall. These options have obvious edge cases that can't be easily resolved.
The basic idea is that you calculate the shadow region of your walls and just not color that.
This article should give you a good start.
In your particular example you can easily brute-force it by checking the line-of-sight from each (empty) pixel to the center of your light source. If you have line-of-sight and the distance is within the falloff, then you have light there. If not, then it's dark.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With