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

  1. /*
  2.  * gloss.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: gloss.c,v 4.0 91/07/17 14:42:30 kolb Exp Locker: kolb $
  17.  *
  18.  * $Log:    gloss.c,v $
  19.  * Revision 4.0  91/07/17  14:42:30  kolb
  20.  * Initial version.
  21.  * 
  22.  */
  23. #include "texture.h"
  24. #include "gloss.h"
  25.  
  26. Gloss *
  27. GlossCreate(glossiness)
  28. Float glossiness;
  29. {
  30.     Gloss *gloss;
  31.  
  32.     gloss = (Gloss *)RayMalloc(sizeof(Gloss));
  33.     gloss->glossy = 1. - glossiness;
  34.     return gloss;
  35. }
  36.  
  37. void
  38. GlossApply(gloss, prim, ray, pos, norm, gnorm, surf)
  39. Gloss *gloss;
  40. Geom *prim;
  41. Ray *ray;
  42. Vector *pos, *norm, *gnorm;
  43. Surface *surf;
  44. {
  45.     Vector uaxis, vaxis, point, norminc;
  46.     extern void UnitCirclePoint();
  47.  
  48.     /*
  49.      * Find coordinate system with norm as the Z axis.
  50.      */
  51.     VecCoordSys(norm, &uaxis, &vaxis);
  52.     /*
  53.      * Find point on unit circle based on sample #.
  54.      */
  55.     UnitCirclePoint(&point, ray->sample);
  56.     /*
  57.      * Perturb normal appropriately.
  58.      */
  59.     VecComb(gloss->glossy * point.x, uaxis,
  60.         gloss->glossy * point.y, vaxis,
  61.         &norminc);
  62.     VecAdd(*norm, norminc, norm);
  63.     /*
  64.      * Renormalize.
  65.      */
  66.     (void)VecNormalize(norm);
  67. }
  68.