If your hardware has reasonably flexible render to texture, you can do this kind of effects quite easily, without using any
readbacks.
Render a poly with Z test disabled over the area you are interested in sampling into either destination alpha, or an offscreen
buffer using the screen Z buffer. Set the alpha to 0.
Render the same poly with Z test enabled at the Z of the sun/light. Set the alpha to 255 (or 1.0, according to API
.
You should now have an alpha mask of the visible areas. Using a bilinear filter you can progressively shrink this down to a single
pixel (thus getting an average coverage value), and then use the resulting pixel as a texture to render into the alpha component of
your flare texture. Or you can do as Chris mentions, and blur it outwards to create the illusion of shafts of light, though you'd
probably want to layer up a few sprites tested at different Z's to give it some depth.
Pretty simple effect if your hardware can do it, but extremely effective
Jason G Doig
Bookmarks