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

  1. /*
  2.  * blotch.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: blotch.c,v 4.0 91/07/17 14:41:31 kolb Exp Locker: kolb $
  17.  *
  18.  * $Log:    blotch.c,v $
  19.  * Revision 4.0  91/07/17  14:41:31  kolb
  20.  * Initial version.
  21.  * 
  22.  */
  23. #include "texture.h"
  24. #include "blotch.h"
  25.  
  26. /*
  27.  * Create and return a reference to a "blotch" texture.
  28.  */
  29. Blotch *
  30. BlotchCreate(mix, surf)
  31. Float mix;
  32. Surface *surf;
  33. {
  34.     Blotch *blotch;
  35.  
  36.     blotch = (Blotch *)RayMalloc(sizeof(Blotch));
  37.     blotch->mix = mix;
  38.     blotch->surf = surf;
  39.     return blotch;
  40. }
  41.  
  42. /*
  43.  * Apply "blotch" texture.
  44.  */
  45. /*ARGSUSED*/
  46. void
  47. BlotchApply(blotch, prim, ray, pos, norm, gnorm, surf)
  48. Blotch *blotch;
  49. Geom *prim;
  50. Ray *ray;
  51. Vector *pos, *norm, *gnorm;
  52. Surface *surf;
  53. {
  54.     Float val;
  55.  
  56.     /*
  57.      * "mix" represents the 'average' noise value at a point.
  58.      */
  59.     val = Noise3(pos);
  60.     if (val > blotch->mix) {
  61.         val = (val - blotch->mix) / (1. - blotch->mix);
  62.         SurfaceBlend(surf, blotch->surf, 1. - val, val);
  63.     }
  64. }
  65.