home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / gems / gemsii / voxelcac.c < prev    next >
Text File  |  1991-10-02  |  3KB  |  98 lines

  1.  
  2. \fBWhen Spawning a Refraction Ray:\fC
  3. Mask = 0x01 << Spawning_ray_level;
  4. path = path | Mask;               /* Turn on correct bit. */
  5. trace( /* refraction ray */ );
  6. path = path & ~Mask;
  7.  
  8. \fBWhen Spawning Reflection Ray:\fC
  9. Mask = 0x01 << Spawning_ray_level;
  10. path = path & ~Mask;              /* Turn off correct bit. */
  11. trace( /* reflection ray */ );
  12. .hl
  13.  
  14. typedef struct _stree {
  15.     TRIANGLE_REC   *last_object;
  16.     TRIANGLE_REC  **last_voxel;
  17.     struct _stree  *refraction_ray;
  18.     struct _stree  *reflection_ray;
  19. } SHADOW_TREE;
  20.  
  21. float check_shadowing(ray, light, path, Spawning_ray_level)
  22. RAY_REC   *ray;   /* ray from shading point to light source */
  23. LIGHT_REC *light; /* the light source we are interested in */
  24. int        path;  /* bit table describing current position in vision ray tree */
  25. int        Spawning_ray_level; /* level of the ray spawning this shadow ray */
  26. {
  27.     unsigned int  Mask;
  28.     SHADOW_TREE  *cache;
  29.  
  30.     cache = light->cache_tree;
  31.     Mask = 0x01;
  32.     /* If the spawning ray's level is 0 (primary ray), then we */
  33.     /* use the head of the cache_tree. */
  34.     for (i = 0; i < Spawning_ray_level; ++i) {
  35.         if (Mask & path) cache = cache->refraction_ray;
  36.         else             cache = cache->reflection_ray;
  37.         Mask = Mask << 1; /* Shift mask left 1 bit */
  38.     }
  39.  
  40.     if (cache->last_object != NULL) {
  41.         /* intersect_object() marks object as having been */
  42.         /* intersected by this ray. */
  43.         hit = intersect_object( ray, cache->last_object, &object);
  44.  
  45.         if (hit) {
  46.             return(1.0); /* full shadowing */
  47.         }
  48.         cache->last_object = NULL; /* object was not hit */
  49.  
  50.         if (cache->last_voxel != NULL) { /* implied !hit */
  51.  
  52.             /* intersect_object_in_voxel_for_shadows() returns hit = TRUE */
  53.             /* on first affirmed intersection with an opaque object. */
  54.             /* It ignores transparent objects altogether. */
  55.             hit = intersect_objects_in_voxel_for_shadows( ray,
  56.                                          cache->last_voxel, &object);
  57.             if (hit) {
  58.                 cache->last_object = object;
  59.                 return(1.0);
  60.             }
  61.             cache->last_voxel = NULL; /* voxel did not supply a hit */
  62.         }
  63.     }
  64.  
  65.     /* traverse_voxels_for_shadows() DOES intersect transparent objects and */
  66.     /* sorts the intersections for proper attenuation of the light          */
  67.     /* intensity. If multiple objects are hit, then one of the              */
  68.     /* intersections must be transparent, and the object returned is the    */
  69.     /* transparent one. Tracing of the shadow ray halts once the light      */
  70.     /* source has been reached. */
  71.     hit = traverse_voxels_for_shadows(ray, &object, &voxel, &shadow_percent);
  72.  
  73.     if (!hit) {
  74.         cache->last_object = NULL;
  75.         cache->last_voxel  = NULL;
  76.         return(0.0); /* No shadowing was found. */
  77.     }
  78.     if (object->transparency_value > 0.0) {
  79.         /* the object is transparent */
  80.         cache->last_object = NULL;
  81.         cache->last_voxel  = NULL;
  82.     }
  83.     else {
  84.         /* The object was NOT transparent, cache the info. */
  85.         cache->last_object = object;
  86.         cache->last_voxel  = voxel;
  87.     }
  88.     return ( shadow_percent );
  89. }
  90.  
  91.  
  92. - Andrew Pearce, Alias, someplace in Toronto - pearce@alias.com
  93.  
  94.  
  95.  
  96.  
  97.  
  98.