next up previous contents index
Next: Clusters Up: Texture Previous: Noise Texture

Bump Mapping

Bump mapping is a technique for making surfaces appear bumpy. Bump mapping is an illusion as the position of the surface is not changed, only the surface normal is modified. This affects the way the surface reflects light. Figure 17 shows a tile texture. There are two limitations of bump mapping. Because the position of the surfae is not changed, the bumps will not cast shadows onto the object. Also where edges of the object can be seen, the bumps do not affect the postion of the surface.

  figure430
Figure 17: Bump Mapping

  class TileTexture : public Texture {
  public:
    TileTexture(int prec, double tile_width, double tile_height, 
                double gap_width) {
      precedence = prec;
      wd = tile_width;
      ht = tile_height;
      gap = gap_width;
    }

    virtual void apply(vector ray_from, vector ray_dir, uint ray_flags,
		       Material *properties, vector hit_point,
		       vector hit_normal, RayTracer *engine,
		       transform tex_transform){
      vector object_hit,noisegrad;
      Matrix::apply(tex_transform[AFT], hit_point, object_hit);


      double x_hit = fmod(object_hit[X], wd+gap);
      double y_hit = fmod(object_hit[Y], ht+gap);

      if (x_hit< 0)
	x_hit = x_hit + wd+gap;
      if (y_hit < 0)
	y_hit = y_hit + ht + gap;

      if (x_hit < gap) {
	double rotate_amount = 90 * (x_hit - gap/2.0) / (gap/2.0);
	Vector::rotate(Z, X, rotate_amount, hit_normal);}
      if (y_hit < gap) {
	double rotate_amount = 90 * (y_hit - gap/2.0) / (gap/2.0);
	Vector::rotate(Z, Y, rotate_amount, hit_normal);}

    };
  
    // Print the texture's parameters for debugging
    virtual void print_tex(void) {
      printf("TileTexture\n");
    }
  
    virtual ~TileTexture(void) {
    }
  private:

    double wd;
    double ht;
    double gap;
  };



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