Thread: sun flare algorithm

  1. #1
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704

    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?
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    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);
         }
       }
    }
    Last edited by VirtualAce; 01-21-2006 at 10:34 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Implement of a Fast Time Series Evaluation Algorithm
    By BiGreat in forum C Programming
    Replies: 7
    Last Post: 12-04-2007, 02:30 AM
  2. Replies: 4
    Last Post: 12-10-2006, 07:08 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM