next up previous contents index
Next: Fog Up: More Mirage Features Previous: PointAtAffect

Background and Foreground

  Rays may miss every object in the scene to be rendered; in this case, Mirage says that the rays hit the 'background'. These rays are assigned the background color, which is stored in the variable background_color.

  Color::assign(background_color, 1.0, 1.0, 1.0);

You may not want just one colour in the background. To vary the background colour there is a BackgroundTexture class.   You write a class and define it to be a subclass of the BackgroundTexture class. You assign your background texture to the variable background_texture.

The example background texture shows a daytime sky. The colour varies from dark blue at the top of the scene to light blue at the horizon. The hills in the picture are a heightfield primitive. Heightfield primitives are explained in 17.1.

 figure530
Figure 21: Daytime Sky Background Texture

 background_texture = new Daytime_Sky_Texture();


.
.
.


class Daytime_Sky_Texture :public BackgroundTexture{
public:
  Daytime_Sky_Texture() {};

  virtual void apply(vector ray_from, vector ray_dir, 
		  short ray_flags, color hit_color, 
		  RayTracer * engine);

  virtual void print_tex(void){};

};

void Daytime_Sky_Texture::apply(vector ray_from, vector ray_dir, 
		  short ray_flags, color hit_color, 
		  RayTracer * engine)
{
  Vector::normalise(ray_dir,"Daysky apply");
  vector vert;
  Vector::assign(vert,0,0,1);
  double c = Vector::dot(vert,ray_dir);  //c= costheta
  c = fabs(c);                           //absolute value
  c= acos(c);                            //c=theta in rad
  c= RAD2DEG(c);                         //in deg
  if (c<30)                               
    Color::assign(hit_color,0,0,1.0);    //top 30 degrees blue
  else
    {c=c - 30;                           //fade to white from 30 to 105 
    c = c /75;                      
    Color::assign(hit_color,c,c,1.0);} 
}

Textures can also be applied to the foreground.  Foreground textures are applied in precisely the same way as background textures, but are applied in front of all objects in the scene. Each ray's colour is found and then the foreground texture is called to modify this. This is useful when applying camera effects like lensflares.

Foreground textures are defined in the same way as background textures. You write a class and define it to be a subclass of the BackgroundTexture class. You assign your foreground texture to the variable foreground_texture. The example lensflare  is created with the lensflare project in the Mirage example projects directory.

 figure536
Figure 22: Lensflare: a Foreground Texture



Sophie Day
Fri Feb 20 15:47:19 NZDT 1998