Fast pixelshader 2D raytracing
- by heishe
I'd like to do a simple 2D shadow calculation algorithm by rendering my environment into a texture, and then use raytracing to determine what pixels of the texture are not visible to the point light (simply handed to the shader as a vec2 position) .
A simple brute force algorithm per pixel would looks like this:
line_segment = line segment between current pixel of texture and light source
For each pixel in the texture:
{
if pixel is not just empty space && pixel is on line_segment
output = black
else
output = normal color of the pixel
}
This is, of course, probably not the fastest way to do it. Question is: What are faster ways to do it or what are some optimizations that can be applied to this technique?