home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / povsrc.sit / SOURCE / TXTTEST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-03  |  5.0 KB  |  185 lines

  1. /****************************************************************************
  2. *                txttest.c
  3. *
  4. *  This module implements "fill-in-the-blank" pre-programmed texture 
  5. *  functions for easy modification and testing. Create new textures here.
  6. *  
  7. *  from Persistence of Vision Raytracer 
  8. *  Copyright 1992 Persistence of Vision Team
  9. *---------------------------------------------------------------------------
  10. *  Copying, distribution and legal info is in the file povlegal.doc which
  11. *  should be distributed with this file. If povlegal.doc is not available
  12. *  or for more info please contact:
  13. *
  14. *       Drew Wells [POV-Team Leader] 
  15. *       CIS: 73767,1244  Internet: 73767.1244@compuserve.com
  16. *       Phone: (213) 254-4041
  17. * This program is based on the popular DKB raytracer version 2.12.
  18. * DKBTrace was originally written by David K. Buck.
  19. * DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
  20. *
  21. *****************************************************************************/
  22. /*
  23.    Some texture ideas garnered from SIGGRAPH '85 Volume 19 Number 3, 
  24.    "An Image Synthesizer" By Ken Perlin.
  25.    Further Ideas Garnered from "The RenderMan Companion" (Addison Wesley)
  26. */
  27.  
  28. #include "frame.h"
  29. #include "vector.h"
  30. #include "povproto.h"
  31. #include "texture.h"
  32.  
  33. /* Test new textures in the routines that follow */
  34.  
  35. /* The painted routines take an x,y,z point on an object and a pointer to the*/
  36. /* object's texture description and return the color at that point           */
  37. /* Similar routines are granite, agate, marble. See txtcolor.c for examples. */ 
  38.  
  39. void painted1 (x, y, z, Texture, colour)
  40. DBL x, y, z;
  41. TEXTURE *Texture;
  42. COLOUR *colour;
  43. {
  44.  
  45.    /* Swirled()  */
  46.  
  47.    VECTOR colour_vector, result;
  48.    register int i;
  49.    register DBL scale = 1.0, temp;
  50.    COLOUR New_Colour;
  51.  
  52.  
  53.    if (Options & DEBUGGING)
  54.       printf ("painted1 %g %g %g\n", x, y, z);
  55.  
  56.    result.x = 0.0;
  57.    result.y = 0.0;
  58.    result.z = 0.0;
  59.  
  60.    for (i = 0; i < 10 ; scale *= 2.0, i++)
  61.    {
  62.       DNoise(&colour_vector,x,y,z);
  63.       temp = Noise (colour_vector.x * 4 * scale,
  64.          colour_vector.y * 4 * scale,
  65.          colour_vector.z * 4 * scale);
  66.       temp = FABS(temp);
  67.       result.x += temp/scale;
  68.       result.y += temp/scale;
  69.       result.z += temp/scale;
  70.    }
  71.  
  72.    temp = result.x;
  73.    if (Texture -> Colour_Map != NULL) {
  74.       Compute_Colour (&New_Colour, Texture->Colour_Map, temp);
  75.       colour -> Red += New_Colour.Red;
  76.       colour -> Green += New_Colour.Green;
  77.       colour -> Blue += New_Colour.Blue;
  78.       colour -> Alpha += New_Colour.Alpha;
  79.       return;
  80.    }
  81.  
  82.    colour -> Red += temp;
  83.    colour -> Green += temp;
  84.    colour -> Blue += temp;
  85.    return;
  86.  
  87. }
  88.  
  89. void painted2 (x, y, z, Texture, colour)
  90. DBL x, y, z;
  91. TEXTURE *Texture;
  92. COLOUR *colour;
  93. {
  94.    int brkindx;
  95.    DBL turb;
  96.    VECTOR TextureTurbulence;
  97.    COLOUR Colour1, Colour2;
  98.  
  99.    /* You could change the parser to take two colors after PAINTED2,           */
  100.    /* but since the colormap is already parsed it's easier to use it during    */
  101.    /* testing. If the texture works out right you can change the parser later. */
  102.    if (Texture -> Colour_Map != NULL)
  103.    {
  104.       Compute_Colour (&Colour1, Texture->Colour_Map, 0.1);
  105.       Compute_Colour (&Colour2, Texture->Colour_Map, 0.9);
  106.    }
  107.    else
  108.    {
  109.       Make_Colour (&Colour1, 1.0, 1.0, 1.0);
  110.       Colour1.Alpha = 0.0;
  111.       Make_Colour (&Colour2, 0.0, 1.0, 0.0);
  112.       Colour2.Alpha = 0.0;
  113.    }
  114.  
  115.  
  116.    if ((turb = Texture->Turbulence) != 0.0)
  117.    {
  118.       DTurbulence (&TextureTurbulence, x, y, z, Texture->Octaves);
  119.       x += TextureTurbulence.x * turb;
  120.       y += TextureTurbulence.y * turb;
  121.       z += TextureTurbulence.z * turb;
  122.    }
  123.  
  124.    brkindx = (int) FLOOR(x) + (int) FLOOR(z);
  125.  
  126.    if (Options & DEBUGGING)
  127.       printf ("checker %g %g %g\n", x, y, z);
  128.  
  129.    if (brkindx & 1){
  130.       colour->Red = Colour1.Red;
  131.       colour->Green = Colour1.Green;
  132.       colour->Blue = Colour1.Blue;
  133.       colour->Alpha = Colour1.Alpha;
  134.    }
  135.    else{
  136.       colour->Red = Colour2.Red;
  137.       colour->Green = Colour2.Green;
  138.       colour->Blue = Colour2.Blue;
  139.       colour->Alpha = Colour2.Alpha;
  140.    }
  141.    return;
  142.  
  143.    ;
  144. }
  145. void painted3 (x, y, z, Texture, colour)
  146. DBL x, y, z;
  147. TEXTURE *Texture;
  148. COLOUR *colour;
  149. {
  150.    /* YOUR NAME HERE */
  151.    ;
  152. }
  153.  
  154. /* The bumpy routines take a point on an object,  a pointer to the          */
  155. /* object's texture description and the surface normal at that point and    */
  156. /* return a peturb surface normal to create the illusion that the surface   */
  157. /* has been displaced.                                                      */
  158. /* Similar routines are ripples, dents, bumps. See txtbump.c for examples.  */ 
  159.  
  160. void bumpy1 (x, y, z, Texture, normal)
  161. DBL x, y, z;
  162. TEXTURE *Texture;
  163. VECTOR *normal;
  164. {
  165. }
  166.  
  167. /* Dan Farmer */
  168. /* Same as bumpy1 except use VAdd for both cases of brkindex */
  169. void bumpy2 (x, y, z, Texture, normal)
  170. DBL x, y, z;
  171. TEXTURE *Texture;
  172. VECTOR *normal;
  173. {
  174. }
  175.  
  176. /* Dan Farmer */
  177. /* Same as bumpy2 except scale AFTER setting brkindex */
  178. void bumpy3 (x, y, z, Texture, normal)
  179. DBL x, y, z;
  180. TEXTURE *Texture;
  181. VECTOR *normal;
  182. {
  183. }
  184.