1. ## sun flare algorithm

Toying around with a space scene and I'm working on getting the flare to occur when the sun spot is near the center of the screen (full intensity) and deminish with the distance from center.

I don't want it to occur from the edges of the screen though, I only want to fade the flare in and out based on a region smaller then the screen. If the screen is 640 by 480, then the point in which the flare would begin is when the sun spot passes into a 320 by 240 region (centered).

The flare intensity should be 0 outside of the region, and 1.0 at dead center.

Any one know a good formula?

2. There is a good algorithm for this in Special Effects Game Programming. It is written for DirectX 8, but it is still a very good book to have in your collection.

Special Effects Game Programming with DirectX

http://www.amazon.com/gp/product/193...Fencoding=UTF8

As you can see it is older, but that does not mean it doesn't show you some very important principles concerning special effects. I don't rate a book based on it's source code but rather more on content and principles presented.

It is DirectX based, but I'm sure you can port the effect to GL.

I also wrote some code way back when to simulate looking into the sun or some other bright object. Essentially you draw a quad the size of the screen using the color of the light being simulated. The alpha value of the vertices of the quad is a direct function of the distance to the light source from the camera or object. As you get closer, alpha increases and therefore the result is a very bright screen.

You can use simply DOT3 lighting for this effect. Alter the alpha values based on the dot product.

Code:
void Camera::DoWhiteOut(D3DXVECTOR3 LightPos,D3DXCOLOR LightColor,float fcoef)
{
D3DXVECTOR3 toLight=Pos-LightPos;
D3DXVec3Normalize(&toLight,&toLight);

float dot=D3DXVec3Dot(&ToLight,&Look);

if (dot>0)
{
for (int i=0;i<4;i++)
{

WhiteOutVertex[i].Diffuse=D3DXCOLOR(LightColor.r,LightColor.g,LightColor.b,dot);
}
}
}