/*
CreateSkyLights() - ydnar
simulates sky light with multiple suns
*/

static void CreateSkyLights( vec3_t color, float value, int iterations )
{
	int			c, i, j, k, numSuns;
	float		step, start;
	vec3_t		in;
	sun_t		sun;
	
	
	/* dummy check */
	if( value <= 0.0f || iterations < 2 )
		return;
	
	/* calculate some stuff */
	step = 2.0f / (iterations - 1);
	start = -1.0f;
	
	/* basic sun setup */
	VectorCopy( color, sun.color );
	sun.next = NULL;
	
	/* iterate */
	numSuns = 0;
	for( c = 0; c < 2; c++ )
	{
		for( k = 0, in[ 2 ] = start; k < iterations; k++, in[ 2 ] += step )
		{
			/* don't create sky light below the horizon */
			if( in[ 2 ] <= 0.0f )
				continue;
			
			for( j = 0, in[ 1 ] = start; j < iterations; j++, in[ 1 ] += step )
			{
				for( i = 0, in[ 0 ] = start; i < iterations; i++, in[ 0 ] += step )
				{
					if( VectorNormalize( in, sun.direction ) )
					{
						if( c > 0 && numSuns > 0 )
						{
							sun.photons = value / numSuns;
							CreateSunLight( &sun );
						}
						else
							numSuns++;
					}
				}
			}
		}
	}
}