Archived

This topic is now archived and is closed to further replies.

edwinnie

LensFlares outside/inside building

Recommended Posts

ok! i was wondering how to determine if the lensflares should update, considering that the player can be inside or outside the building, and the building should occlude the light source(if it is outside the building). currently, i have not added lightmapping yet. so my light source kinda bleeds into the building, showing the lens flares(inside building) as well. need some advice... edwinz

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
A simple raycast is the most compatible way to do it and if you don''t have thousands of flares to brute force check it''s kinda free (provided you have some partitioning data structure and stuff, of course sectoring the lens flare is even better). Another way to do it if you have fast access to Zbuffer (usually you don''t on PC) is to transform the flare position in 3d, project it to screen space and check the depth in ZBuffer at this position. If it''s closer (within epsilon) to the camera than your flare depth then the flare is obstructed. There must be some other way but I don''t know them! (8

Share this post


Link to post
Share on other sites
Perhaps a more important question is where is this lens that is creating the visual effect? Unless someone is carrying around a camera and you are looking through that camera, is there any lens flare?

Karg

Share this post


Link to post
Share on other sites
Sure, if you''re going for mood and dramatics.

Movies have lens flares, occasionally. It helps make it seem more like a story instead of a simulation.

Share this post


Link to post
Share on other sites
You could abuse the occlusion query to check for flare/glow visibility. The deferred version can be used for multiple checks per frame. It will still create a command stream bubble, but far smaller than a direct zbuffer read. If you do it at the end of the frame, then it should be pretty efficient. You''ll need a hardware occlusion capable card, though.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you have deferred occlusion query, then render an 8x8 pixel square centered on the sun, and make the flare intensity the same as the proportion of pixels that passed.

If you want support for lower-end cards, then, right before you clear your backbuffer, you read back the Z value of the pixel in the center of the sun. If it''s not 1.0, then the center of the sun is occluded, and you fade out your flare; else the center of the sun is visible and you fade in the sun.

Share this post


Link to post
Share on other sites
I use the destination alpha to decide this for me. I use the GL_COMBINE_ARB tex env mode to do the Alpha blending in 2 texture units, then I use glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_ONE); when I draw the sun glare. This lets me only draw the sun glare where the Destination Alpha is < 1.

Using this method, you can also make some objects glow a bit by giving them an alpha value of 0.8 or so. Also this works nice for clouds by not having the sun glare be drawn on top of clouds. They can pass over the sun and block the glare.



Waramp.

"Before you insult a man, walk a mile in his shoes.
That way, when you do insult him, you''ll be a mile away, and you''ll have his shoes."

Share this post


Link to post
Share on other sites
What works really well and what ive noticed a lot of games/demos doing now is a alpha fade out of lens flares. Basically you raytrace a line from the eye position to the flare position, if it hits something set a flag otherwise just draw it as normal with full alpha. If the flag was set then gradually fade out the flare by reducing alpha. I''m pretty sure UT2K3 does this.

Another nice trick is to see how far the flare position in screenspace is from the corner or edge of the screen and to determine an alpha value on that..so the center of the screen would be a very bright flare.

Share this post


Link to post
Share on other sites
quote:
Original post by Chronos-
What works really well and what ive noticed a lot of games/demos doing now is a alpha fade out of lens flares. Basically you raytrace a line from the eye position to the flare position, if it hits something set a flag otherwise just draw it as normal with full alpha. If the flag was set then gradually fade out the flare by reducing alpha. I''m pretty sure UT2K3 does this.


Many old games did that too. I find it horrible, it just looks so fake. Matter of taste, I guess. But if you want smooth flares, either cast multiple rays, or use a deferred occlusion query on a small pixel block. Both methods will give you a fractional alpha.

If you really want to create a very unique flare, then take the directional visibility distribution of this pixel block into account, and distort the flare accordingly. That works really well for very large and bright glows and flares (such as from directly looking into the sun) with eg. a mountain covering half of the sun disc.

Share this post


Link to post
Share on other sites
I haven''t done it yet, but I was actually going to make the flares shrink and expand when they pass into and out of view. Simply fading them out wouldn''t look right to me.

Share this post


Link to post
Share on other sites