home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Graphics / graphics-16000.iso / msdos / raytrace / rayshade / src / mount.c < prev    next >
C/C++ Source or Header  |  1992-04-28  |  2KB  |  69 lines

  1. /*
  2.  * mount.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * $Id: mount.c,v 4.0 91/07/17 14:43:17 kolb Exp Locker: kolb $
  17.  *
  18.  * $Log:    mount.c,v $
  19.  * Revision 4.0  91/07/17  14:43:17  kolb
  20.  * Initial version.
  21.  * 
  22.  */
  23. #include "texture.h"
  24. #include "mount.h"
  25.  
  26. /*
  27.  * Create and return a reference to a "mount" texture.
  28.  */
  29. Mount *
  30. MountCreate(cmap, turb, slope)
  31. char *cmap;
  32. Float turb, slope;
  33. {
  34.     Mount *mount;
  35.  
  36.     mount = (Mount *)RayMalloc(sizeof(Mount));
  37.     mount->turb = turb;
  38.     mount->slope = slope;
  39.     mount->cmap = ColormapRead(cmap);
  40.     return mount;
  41. }
  42.  
  43. /*
  44.  * Apply a "mount" texture.
  45.  */
  46. void
  47. MountApply(mount, prim, ray, pos, norm, gnorm, surf)
  48. Mount *mount;
  49. Geom *prim;
  50. Ray *ray;
  51. Vector *pos, *norm, *gnorm;
  52. Surface *surf;
  53. {
  54.     int index;
  55.     Float t;
  56.     Color c;
  57.  
  58.     t = Chaos(pos, 7);
  59.     index = (pos->z + mount->turb*t - mount->slope*(1.-norm->z))*256;
  60.     if (index < 0)
  61.         index = 0;
  62.     if (index > 255)
  63.         index = 255;
  64.  
  65.     ColorMultiply(surf->amb, mount->cmap[index], &surf->amb);
  66.     ColorMultiply(surf->diff, mount->cmap[index], &surf->diff);
  67.     ColorMultiply(surf->spec, mount->cmap[index], &surf->spec);
  68. }
  69.