home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / grafik / raytracing / rayshade-4.0.6.3 / libray / libtext / mount.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-09  |  1.7 KB  |  75 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.  * mount.c,v 4.1 1994/08/09 08:03:08 explorer Exp
  17.  *
  18.  * mount.c,v
  19.  * Revision 4.1  1994/08/09  08:03:08  explorer
  20.  * Bump version to 4.1
  21.  *
  22.  * Revision 1.1.1.1  1994/08/08  04:52:15  explorer
  23.  * Initial import.  This is a prerelease of 4.0.6enh3, or 4.1 possibly.
  24.  *
  25.  * Revision 4.0  91/07/17  14:43:17  kolb
  26.  * Initial version.
  27.  * 
  28.  */
  29. #include "texture.h"
  30. #include "mount.h"
  31.  
  32. /*
  33.  * Create and return a reference to a "mount" texture.
  34.  */
  35. Mount *
  36. MountCreate(cmap, turb, slope)
  37. char *cmap;
  38. Float turb, slope;
  39. {
  40.     Mount *mount;
  41.  
  42.     mount = (Mount *)Malloc(sizeof(Mount));
  43.     mount->turb = turb;
  44.     mount->slope = slope;
  45.     mount->cmap = ColormapRead(cmap);
  46.     return mount;
  47. }
  48.  
  49. /*
  50.  * Apply a "mount" texture.
  51.  */
  52. void
  53. MountApply(mount, prim, ray, pos, norm, gnorm, surf)
  54. Mount *mount;
  55. Geom *prim;
  56. Ray *ray;
  57. Vector *pos, *norm, *gnorm;
  58. Surface *surf;
  59. {
  60.     int index;
  61.     Float t;
  62.     Color c;
  63.  
  64.     t = Chaos(pos, 7);
  65.     index = (pos->z + mount->turb*t - mount->slope*(1.-norm->z))*256;
  66.     if (index < 0)
  67.         index = 0;
  68.     if (index > 255)
  69.         index = 255;
  70.  
  71.     ColorMultiply(surf->amb, mount->cmap[index], &surf->amb);
  72.     ColorMultiply(surf->diff, mount->cmap[index], &surf->diff);
  73.     ColorMultiply(surf->spec, mount->cmap[index], &surf->spec);
  74. }
  75.