home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / GRAPHICS / MISC / DKBTRACE.ZIP / DKB.DOC < prev    next >
Encoding:
Text File  |  1990-08-09  |  66.1 KB  |  1,474 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.                 DKBtrace Ray-Tracer, Amiga/IBM Version 2.04
  8.  
  9.                 "It's free, and it's well worth the price!"
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.      This program was written by:
  18.  
  19.                          David Buck
  20.                          22C Sonnet Cres.
  21.                          Nepean, Ontario
  22.                          Canada, K2H 8W7
  23.  
  24.      It has been made freely distributable.  The author retains the copyright
  25.      to the program but authorizes free distribution by BBS'es, networks or
  26.      by magnetic media.  The distributer may choose to charge for the cost of
  27.      the disk but should not sell the software for profit.  Non-profit
  28.      organizations such as clubs may charge for the software so long as the
  29.      price is reasonable (less than $5.00 more than the cost of the disk) and
  30.      so long as the buyers are informed that the program is freely
  31.      distributable. 
  32.  
  33.      The images and data files generated by the raytracer are the property of
  34.      the user of the software and may be used for any purpose without
  35.      restriction.
  36.  
  37.      The author makes no guarantees or warantees with this program and claims
  38.      no responsibility for any damage or loss of time caused by this program.
  39.      Bug reports may be sent to the author but the author is under no
  40.      obligation to provide bug fixes, features, or any support for this
  41.      software.
  42.  
  43.      I would also like to place the following conditions on the use of this
  44.      program:
  45.  
  46.      1) that it should not be used as part of any commercial package without
  47.         my explicit written consent.
  48.  
  49.      2) if you make any neat and interesting pictures, please send them to
  50.         me.
  51.  
  52.      3) If you make any changes to the source code, please let me know.  I'd
  53.         like to see what you've done.
  54.  
  55.      4) This text file should accompany the program.
  56.  
  57.  
  58.  
  59.      I can be reached on the following BBS'es
  60.  
  61.      ATX       (613) 526-4141
  62.      OMX       (613) 731-3419
  63.      Mystic    (613) 731-0088 or (613) 731-6698
  64.      FidoNet   1:163/109.9
  65.      Bitnet    David_Buck@Carleton.CA
  66.  
  67.  
  68.  
  69.  
  70. Section 0.1 - Recent Update History:
  71.  
  72.      Version 1.2 First release
  73.      Version 2.0 Conversion to the IBM done by Aaron A. Collins
  74.                  New textures, Specular and Phong highlighting added by
  75.                  Aaron A. Collins
  76.                  Triangle, Smooth Triangle, Sphere, Plane support added by
  77.                  David Buck
  78.                  RAW, IFF and GIF image mapping added by David Buck and Aaron
  79.                  Collins
  80.                  Transparency and Fog added by David Buck
  81.                  GIF file reader by Steve Bennett (used with permission)
  82.                  New Noise and DNoise functions by Robert Skinner
  83.                    (used with permission)
  84.      Version 2.01-2.04
  85.              "Cosmetic" releases with some minor bugs fixed, etc.  See the
  86.         file WHATS.NEW for a more complete change log.
  87.  
  88.      Aaron Collins can be reached on the following BBS'es
  89.  
  90.      Lattice BBS                   (708) 916-1200
  91.      The Information Exchange BBS  (708) 945-5575
  92.      Stillwaters BBS               (708) 403-2826
  93.  
  94.      AAC: As of August 1990, there is be a Ray-Trace specific BBS in the
  95.      (708) Area Code (Chicago suburbia) for all you Traceaholics out there.
  96.      It's called the "You Can Call Me RAY" BBS.  The phone number of this new
  97.      BBS is (708) 358-5611. I am Co-Sysop of that board.  There is also a new
  98.      Ray-Trace and Computer-Generated Art specific SIG on Compuserve, just say
  99.      GO COMART, and look in LIB 16 for Ray-Trace specific stuff.  And now,
  100.      back to the DOCS...
  101.  
  102.      Version 2.0 includes ANSI-C function prototyping for ALL functions,
  103.      TARGA format output file capability, and a reversal of the order of
  104.      writing screen data from the original DKB/QRT "RAW" file format.  For
  105.      IBM's, it has a crude VGA 320x200 by 256 color display rendering
  106.      ability.  If the image requested is larger than 320x200, every other
  107.      pixel horizontally and vertically is dropped from the display to keep it
  108.      all on the screen.
  109.  
  110.      Version 2.0 compiles under Microsoft C 6.0 and Turbo-C 2.0 on the IBM
  111.      P.C. and Lattice C 5.05 on the Amiga.  The only file which contains the
  112.      ANSI extensions is dkbproto.h, so for non-ANSI compilers, you only need
  113.      to remove the declaration of the parameters in the config.h file and the
  114.      whole thing should compile.  There are several example config.h files for
  115.      Amiga, IBM, and Unix.  The appropriate one should be copied over CONFIG.H
  116.      and the MAKEFILE should be edited for your particular system and compiler
  117.      configuration before compilation.
  118.  
  119.      Version 2.0 has a significant difference from prior releases:  Speed!
  120.      The new primitives of SPHERE, PLANE, TRIANGLE, etc. greatly speed up
  121.      tracing.  Another significant speed-up is that world X-Y-Z values beyond
  122.      10 Million or so are ignored, and ray tracing beyond that distance will
  123.      cease.  This produces 2 minor peculiarities:
  124.  
  125.  
  126.  
  127.      1)   A black stripe at the horizon point of Pre-2.0 scene description
  128.           .data files that have "ground" and "sky" planes defined.  The
  129.           planes were traced out to a much greater "infinity" so this effect
  130.           was unnoticeable, prior to version 2.0.
  131.      2)   Tiny black pixels in the texture, or "Surface Acne".
  132.  
  133.      This is usually caused by rays being refracted or reflected such that
  134.      the ray does not happen to hit any object, and eventually becomes black
  135.      in color as it gets too far away and gets clipped.  This effect can be
  136.      minimized by enclosing the scene with distant "walls", "floors", or
  137.      placing "ocean floors" beneath water, etc.  So far, no scenes have
  138.      required placing such planes behind the camera, unless an "environment
  139.      map" of sorts is desired.  See SKYTEST.DAT for several examples of
  140.      spurious distant planes.  If your "acne" still doesn't go away, it may
  141.      be due to a large pixel sample area and it's accidentally picking a point
  142.      which is just inside the primitive being hit.  This is a more tricky
  143.      problem to solve, and anti-aliasing the image will definitely help if
  144.      this sort of thing occurs.
  145.  
  146.      For IBM's, the program PICLAB by the Stone Soup Group offers excellent
  147.      image post-processing features and has direct TARGA 16/24/32 file format
  148.      compatibility, and will serve to palette map and translate the TARGA
  149.      images into .GIF's, etc.  The commercial application AUTODESK ANIMATOR
  150.      offers a CONVERT utility that also does an excellent job of palette
  151.      mapping a TARGA to .GIF format.  COLORIX VGA PAINT also offers TARGA
  152.      format reading and conversion facilities.  There is another utility
  153.      called PHIPS, by TerraVision, that also performs the necessary color-
  154.      reduction actions.  Those of you  with real TARGA boards can view the
  155.      files directly in 16 million colors and are lucky and should know it!
  156.      For those of us on more realistic budgets, check out the new Hercules
  157.      Graphics Workstation card.  This is really slick, as it's a S-VGA card,
  158.      PLUS it has a 24 BIT COLOR MODE (like a TARGA!!) that supports reading
  159.      in .TGA files (from what I've heard).  This is supposedly about $700
  160.      with 1 meg of video RAM - MUCH cheaper than real TARGA hardware!
  161.  
  162.      The Stone Soup Group also produces FRACTINT, the best fractal/Mandelbrot
  163.      program available at ANY price (and it too is FREE!) for the PC.  I
  164.      (AAC) have borrowed their Public Domain .GIF file reading routines for
  165.      the Image Map texture.  Here is their Copyright Notice from the GIF
  166.      Decoder module:
  167.  
  168.       * DECODER.C - An LZW decoder for GIF
  169.       * Copyright (C) 1987, by Steven A. Bennett
  170.       *
  171.       * Permission is given by the author to freely redistribute and include
  172.       * this code in any program as long as this credit is given where due.
  173.       *
  174.       * In accordance with the above, I want to credit Steve Wilhite, who
  175.       * wrote the code which this is heavily inspired by...
  176.       *
  177.       * GIF and 'Graphics Interchange Format' are trademarks (tm) of
  178.       * Compuserve, Incorporated, an H&R Block Company.
  179.  
  180.  
  181.  
  182. Section 0.5 - Program Description:
  183.  
  184.  
  185.      This program is a ray tracer written completely in C.  It supports
  186.      arbitrary quadric surfaces (spheres, ellipsoids, cones, cylinders,
  187.      planes, etc.), constructive solid geometry, and various shading models
  188.      (reflection, refraction, marble, wood, and many others).  It also has
  189.      special-case code to handle spheres, planes, triangles, and smooth
  190.      triangles.  By using these special primitives, the rendering can be done
  191.      much more quickly than by using the more general quadrics. 
  192.      In order to create pictures with this program, you must describe the   
  193.      objects in the world.  This description is a text file called   
  194.      "<filename>.data", and <filename> defaults to "object" if not specified.
  195.      Normally, such files are difficult to write and to read.  In order to
  196.      make this task easier, the program contains a two-pass parser to read
  197.      the data file.  It allows the user to easily create complex worlds from
  198.      simple components.  Since the parser allows include files, the user may
  199.      put the object descriptions into different files and combine them all
  200.      into one final image.
  201.  
  202.      This manual is divided into four main sections.  The first section   
  203.      describes the command-line parameters for the program.  The second
  204.      section describes the syntax and semantics of the description language. 
  205.      Some sample worlds and their corresponding images are provided on the
  206.      disk.  The third section details how to display and convert the images
  207.      using various postprocesors, and section four has a collection of handy
  208.      hints for using the tracer most effectively as well as some quick start
  209.      procedures. 
  210.  
  211.  
  212. Section 1 - Command Line Parameters
  213.  
  214.      This program is designed to be run from the CLI, although it can be run
  215.      from the Workbench if desired.  From the CLI, the program accepts
  216.      various parameters:
  217.  
  218.      -wxxx     width of the picture in pixels
  219.                (On the Amiga, use 319 for full-sized pictures)
  220.      -hxxx     height of the picture in pixels
  221.                (On the Amiga, use 400 for full-sized pictures)
  222.  
  223.      +v        verbose option - print out the scan line number.
  224.      -v        disable verbose option
  225.  
  226.      +f        produce an output file
  227.      -f        don't produce an output file
  228.  
  229.                If the +f option is used, the ray tracer will produce an
  230.                output file of the picture.  This output file describes each
  231.                pixel with 24 bits (8 bits for red, 8 for green, and 8 for
  232.                blue). A post processor (Amiga only) called "DumpToIFF" can
  233.                convert this format to hi-res HAM format (320 x 400) making
  234.                reasonable choices for the colour registers.  For compati-
  235.                bility, the format of the dump file is the same as the format 
  236.                for the QRT ray tracer.  With Version 2.0, you can substitute
  237.                the "t" character for the "f" character and produce output
  238.                files directly in the Truevision (R) TARGA 24 format.  This
  239.                format is remarkably like the QRT/DKB raw format, so it was
  240.                easily done, and allows for a wider range of post-processing
  241.                programs to be used.  The extension .TGA is normally used for
  242.                such files, but any may be chosen.
  243.  
  244.      +d        display the picture while tracing
  245.      -d        don't display the picture while tracing
  246.  
  247.                If the +d option is used, then the picture will be displayed
  248.                while the program performs the ray tracing.  On the Amiga,
  249.                this picture is not as good as the one created by "DumpToIFF"
  250.                because it does not try to make optimum choices for the colour
  251.                registers.  Version 2.0 will produce a display on an IBM-PS/2
  252.                compatible VGA/MCGA display in 320x200 x 256 colours if the +d
  253.                option is given (Anyone for adding in SVGA resolutions??) but
  254.                the same basic caveat is still applicable: A good post-
  255.                processor will make better choices of the most popular colors
  256.                in the image to map to the display. 
  257.  
  258.      +p        wait for prompt (beep and pause) before quitting
  259.      -p        finish without waiting
  260.  
  261.                The +p option makes the program wait for a carriage return
  262.                before exiting (and closing the graphics screen).  This gives
  263.                you time to admire the final picture before destroying it. 
  264.  
  265.  
  266.   -ifilename   set the input filename
  267.   -ofilename   set output filename
  268.  
  269.                If your input file is not "Object.data", then you can use -i
  270.                to set the filename.  The default output filename will be
  271.                "data.display" on Amiga's, and either "data.dis" or "data.tga"
  272.                on IBM's, depending on the output file format that is being
  273.                used.  If you want a different output file name, use the -o
  274.                option.
  275.  
  276.      +a[xxx]   anti-alias - xxx is an optional tolerance level (default 0.3)
  277.      -a        don't anti-alias
  278.  
  279.                The +a option enables adaptive anti-aliasing.  The number
  280.                after the +a option determines the threshold for the anti-
  281.                aliasing.  If the colour of a pixel differs from its neighbor
  282.                (to the left or above) by more than the threshold, then the
  283.                pixel is subdivided and super-sampled.  The samples are
  284.                jittered to introduce noise and make the pictures look better. 
  285.                If the anti-aliasing threshold is 0.0, then every pixel is
  286.                supersampled.  If the threshold is 1.0, then no anti-aliasing
  287.                is done.  Good values seem to be around 0.2 to 0.4. 
  288.  
  289.      +x        allow early exit by hitting any key (IBM only)
  290.      -x        lock in trace until finished        (IBM only)
  291.  
  292.                On the IBM, the -x option disables the ability to abort the
  293.                trace by hitting a key.  If you are unusually clumsy or have
  294.                CATS that stomp on your keyboard (like I do - AAC :-)), you
  295.                may want to use it.  If you are writing a file, the system
  296.                will recognize ^C at the end of line if BREAK is on (on the
  297.                IBM).  If you aren't writing a file, you won't be able to
  298.                abort the trace until it's done.
  299.  
  300.                This option was meant for big, long late-nite traces that take
  301.                ALL night (or longer!), and you don't want them interrupted by
  302.                anything less important than a natural disaster such as hur-
  303.                ricane, fire, flood, famine, etc.
  304.  
  305.      -bxxx     use an output file buffer of xxx kilobytes.
  306.                (if 0, flush the file on every line - this is the default)
  307.  
  308.                The -b option allows you to assign large buffers to the output
  309.                file.  This reduces the amount of time spent writing to the
  310.                disk and prevents unnecessary wear (especially for floppies). 
  311.                If this parameter is zero, then as each scanline is finished,
  312.                the line is written to the file and the file is flushed.  On
  313.                most systems, this operation insures that the file is written
  314.                to the disk so that in the event of a system crash or other
  315.                catastrophic event, at least part of the picture has been
  316.                stored properly on disk.
  317.  
  318.  
  319.      -sxxx     start tracing at line number xxx.
  320.      -exxx     end tracing at line number xxx.
  321.  
  322.                The -s option is provided for when some natural or unnatural
  323.                catastrophe has occurred, and you want to restart the trace at
  324.                a given line number after the crash.  One is subtracted from
  325.                the given line number if anti-aliasing is activated (the prior
  326.                line's being computed is required for the anti-aliasing mech-
  327.                anism to function properly).  It can also be used to re-render
  328.                parts of an image (perhaps with anti-aliasing turned on).  A
  329.                separate utility can then merge the new lines into the old
  330.                file.  The particularly faint of heart or weak of power supply
  331.                may want to batch the image in "strips" of 10-20 lines and
  332.                concatenate them later.
  333.  
  334.      -qx       rendering quality
  335.  
  336.                The -q option allows you to specify the image rendering
  337.                quality.  The parameter can range from 0 to 9.  The values
  338.                correspond to the following quality levels:
  339.  
  340.                0,1  Just show colours.  Ambient lighting only.
  341.                2,3  Show Diffuse and Ambient light
  342.                4,5  Render shadows
  343.                6,7  Create surface textures
  344.                8,9  Compute reflected, refracted, and transmitted rays.
  345.  
  346.                The default is -q9 (maximum quality) if not specified.
  347.  
  348.                You may specify the default parameters by modifying the file
  349.                "trace.def" which contains the parameters in the above format. 
  350.                This filename contains a complete command line as though you 
  351.                had typed it in, and is processed before any options supplied
  352.                on the command line are recognized.
  353.  
  354.  
  355.  
  356. Section 2 - The Object Description Language
  357.  
  358.      The Object Description Language allows the user to describe the world in
  359.      a readable and convenient way.
  360.  
  361.      The language delimits comments by the left and right braces ({ and }). 
  362.      Nested comments are allowed, but no sane person uses them anyway, right?
  363.      
  364.      The language allows include files to be specified by placing the line:
  365.  
  366.      INCLUDE "filename"
  367.  
  368.      at any point in the input file (Include files may be nested).
  369.  
  370.  
  371.  
  372.  
  373. Section 2.1 - The Basic Data Types
  374.  
  375.      There are several basic types of data:
  376.  
  377.   Float
  378.      Floats are represented by an optional sign (+ or -), some digits, an   
  379.      optional decimal point, and more digits.  It does not support the "e"  
  380.      notation for exponents.  The following are valid floats:
  381.  
  382.      1.0  -2.0  -4  +34
  383.  
  384.   Vector
  385.      Vectors are arrays of three floats.  They are bracketed by angle
  386.      brackets ( < and > ), and the three terms usually represent x, y, and z.
  387.      For example:
  388.  
  389.      < 1.0  3.2  -5.4578 >
  390.  
  391.   Colour
  392.      A colour consists of a red component, a green component, a blue
  393.      component, and possibly an alpha component.  All four components are
  394.      floats in the range 0.0 to 1.0.  The syntax for Colours is the word
  395.      "COLOUR" followed by any or all of the RED, GREEN, BLUE or ALPHA
  396.      components in any order.
  397.  
  398.      For example:
  399.  
  400.      COLOUR  RED 1.0  GREEN 1.0  BLUE 1.0
  401.      COLOUR  BLUE 0.56
  402.      COLOUR  GREEN 0.45 RED 0.3 ALPHA 0.3
  403.  
  404.      Alpha is a transparency indicator.  If an object's colour contains some 
  405.      transparency, then you can see through it.  If Alpha is 0.0, the object 
  406.      is totally opaque.  If it is 1.0, it is totally transparent.
  407.  
  408.      For those people who spell "Colour" the American way as "Color", the   
  409.      program also accepts "COLOR" as equivalent to "COLOUR" in all instances.
  410.  
  411.   COLOUR_MAP
  412.      For wood, marble, spotted, agate, granite, and gradient texturing, the
  413.      user may specify arbitrary colours to use for the texture.  This is done
  414.      by a colour map or "colour spline".  When the object is being textured,
  415.      a number between 0.0 and 1.0 is generated which is then used to form the
  416.      colour of the point.  A Colour map specifies the mapping used to change
  417.      these numbers into colours.  The syntax is as follows:
  418.  
  419.      COLOUR_MAP
  420.           [start_value end_value colour1 colour2]
  421.           [start_value end_value colour1 colour2]
  422.           ...
  423.      END_COLOUR_MAP
  424.  
  425.      The value is located in the colour map and the final colour is
  426.      calculated by a linear interpolation between the two colours in the
  427.      located range.
  428.  
  429. Section 2.2 - The More Complex Data Types
  430.  
  431.      The data types used to describe the objects in the world are a bit more 
  432.      difficult to describe.  To make this task easier, the program allows
  433.      users to describe these types in two ways.  The first way is to define
  434.      it from first principles specifying all of the required parameters.  The
  435.      second way allows the user to define an object as a modification of
  436.      another object (the other object is usually defined from first
  437.      principles but is much simpler).  Here's how it works:
  438.  
  439.      You can use the term DECLARE to declare a type of object with a certain 
  440.      description.  The object is not included in the world but it can be used
  441.      as a "prototype" for defining other objects, as this basic example
  442.      shows:
  443.  
  444.      DECLARE Sphere = QUADRIC
  445.           <1.0 1.0 1.0>
  446.           <0.0 0.0 0.0>
  447.           <0.0 0.0 0.0>
  448.           -1.0
  449.      END_QUADRIC
  450.  
  451.      To then reference the declaration elsewhere in your source file or in
  452.      another included one, and to actually include the object in the world,
  453.      you would define the object using object definition syntax, like this:
  454.  
  455.      OBJECT
  456.           QUADRIC Sphere
  457.                SCALE <20.0 20.0 20.0>
  458.           END_QUADRIC
  459.           COLOUR White
  460.           AMBIENT 0.2
  461.           DIFFUSE 0.8
  462.      END_OBJECT
  463.      The real power of declaration becomes apparent when you declare several
  464.      primitive types of objects and then define an object with several
  465.      component shapes, using either COMPOSITE methods or the CSG methods
  466.      INTERSECTION, UNION, or DIFFERENCE.  More on those later.  Also, using
  467.      the DECLARE keyword can make several objects share a texture without the
  468.      need for each object to store a duplicate copy of the same texture, for
  469.      more efficient memory usage.   Example:
  470.  
  471.      OBJECT         { A Hot dog in a Hamburger Bun (?) }
  472.           UNION
  473.                QUADRIC Sphere
  474.                     SCALE <20.0, 10.0, 20.0>
  475.                END_QUADRIC
  476.                QUADRIC Cylinder_X
  477.                     SCALE <40.0, 20.0, 20.0>
  478.                END_QUADRIC
  479.           END_UNION
  480.      END_OBJECT
  481.  
  482.  
  483.   Viewpoint
  484.      The viewpoint tells the ray tracer the location and orientation of the 
  485.      camera.  The viewpoint is described by four vectors - Location,
  486.      Direction, Up, and Right.  Location determines where the camera is
  487.      located.  Direction  determines the direction that the camera is
  488.      pointed.  Up determines the "up" direction of the camera.  Right
  489.      determines the direction to the right of the camera.
  490.  
  491.      A first principle's declaration of a viewpoint would look like this:   
  492.      
  493.      VIEWPOINT
  494.           LOCATION < 0.0  0.0  0.0>
  495.           DIRECTION < 0.0  0.0  1.0>
  496.           UP < 0.0  1.0  0.0 >
  497.           RIGHT < 1.0  0.0  0.0>
  498.      END_VIEWPOINT
  499.  
  500.      This format becomes cumbersome, however, because the vectors must be   
  501.      calculated by hand.  This is especially difficult when the vectors are
  502.      not lined up with the X, Y, and Z axes as they are in the above example. 
  503.      To make it easier to define the viewpoint, you can define one viewpoint,
  504.      then modify the description.  For example,
  505.  
  506.      VIEWPOINT
  507.           LOCATION < 0.0  0.0  0.0>
  508.           DIRECTION < 0.0  0.0  1.0>
  509.           UP < 0.0  1.0  0.0 >
  510.           RIGHT < 1.0  0.0  0.0 >
  511.           TRANSLATE < 5.0  3.0  4.0 >
  512.           ROTATE < 30.0  60.0  30.0 >
  513.      END_VIEWPOINT
  514.  
  515.      In this example, the viewpoint is created, then translated to another
  516.      point in space and rotated by 30 degrees about the X axis, 60 degrees
  517.      about the Y axis, and 30 degrees about the Z axis.
  518.  
  519.      Unfortunately, even this is somewhat cumbersome.  So, in version 2.0,
  520.      you can now specify two more parameters:
  521.  
  522.           SKY <vector>
  523.           LOOK_AT <vector>
  524.  
  525.      The SKY keyword tells the viewpoint where the sky is.  It tries to keep 
  526.      the camera's UP direction aligned as closely as possible to the sky. 
  527.      The LOOK_AT keyword tells the camera to look at a specific point.  The
  528.      camera is rotated as required to point directly at that point.  By
  529.      changing the  SKY vector, you can twist the camera while still looking
  530.      at the same point.
  531.  
  532.      Note that a pinhole camera model is used, so no focus or depth-of-field 
  533.      effects are supported at this time.
  534.    
  535.  
  536.      Version 2.0 of the raytracer includes the ability to render fog.  To add 
  537.      fog to a scene, place the following declaration outside of any object  
  538.      definitions:
  539.  
  540.      FOG
  541.           COLOUR  ... the fog colour
  542.           200.0   ... the fog distance
  543.      END_FOG
  544.  
  545.   Shapes
  546.      Shapes describe the shape of an object without mentioning any surface  
  547.      characteristics like colour, lighting and reflectivity.  The most
  548.      general shape used by this system is called a Quadric Surface.  Quadric
  549.      Surfaces can produce shapes like spheres, cones, and cylinders.  The
  550.      easiest way to define these shapes is to include the standard file
  551.      "BasicShapes.data" into your program and to transform these shapes
  552.      (using TRANSLATE, ROTATE, and SCALE) into the ones you want.  To be
  553.      complete, however, I will describe the mathematical principles behind
  554.      quadric surfaces.  Those who are not interested in the mathematical
  555.      details can skip to the next section.
  556.  
  557.      A quadric surface is a surface in three dimensions which satisfies the 
  558.      following equation:
  559.  
  560.  
  561.      A y**2  + B y**2  + C z**2
  562.      + D xy    + E xz    + F yz
  563.      + G x     + H y     + I z    + J = 0
  564.  
  565.  
  566.      (Did you really want to know that?  I didn't think so. :-)  DKB)
  567.  
  568.      Different values of A,B,C,...J will give different shapes.  So, if you
  569.      take any three dimensional point and use its x, y, and z coordinates in
  570.      the above equation, the answer will be 0 if the point is on the surface
  571.      of the object.  The answer will be negative if the point is inside the
  572.      object and positive if the point is outside the object.  Here are some
  573.      examples:
  574.  
  575.      X**2 + Y**2 + Z**2 - 1 = 0     Sphere
  576.      X**2 + Y**2 - 1 = 0            Cylinder along the Z axis
  577.      X**2 + Y**2 + Z = 0            Cone along the Z axis
  578.  
  579.      General quadric surfaces can be defined as follows:
  580.  
  581.      QUADRIC
  582.           < A B C >
  583.           < D E F >
  584.           < G H I >
  585.           J
  586.      END_QUADRIC
  587.  
  588.  
  589. Section 2.3 - Quadric surfaces the easy way
  590.  
  591.      Now that doesn't sound so hard, does it?  Well, actually, it does.  Only 
  592.      the hard-core graphics fanatic would define his objects using the
  593.      QUADRIC definition directly.  Even I don't do it that way and I know how
  594.      it works (Well, at least I worked it out once or twice :-) - DKB).
  595.  
  596.      Fortunately, there is an easier way. The file "BasicShapes.data" already
  597.      includes the definitions of many quadric surfaces.  They are centered
  598.      about the origin (0,0,0) and have a radius of 1.  To use them, you can
  599.      define shapes as follows:
  600.  
  601.  
  602.      INCLUDE "BasicShapes.data"
  603.  
  604.      QUADRIC
  605.           Cylinder_X
  606.           SCALE < 50.0  50.0  50.0 >
  607.           ROTATE < 30.0  10.0  45.0 >
  608.           TRANSLATE < 2.0  5.0  6.0 >
  609.      END_QUADRIC
  610.  
  611.  
  612.      You may have as many transformation lines (scale, rotate, and translate)
  613.      as you like in any order.  Usually, however, it's easiest to do a scale
  614.      first, one or more rotations, then finally a translation.  Otherwise,
  615.      the results may not be what you expect. (The transformations always
  616.      transform the object about the origin.  If you have a sphere at the
  617.      origin and you translate it then rotate it, the rotation will spin the
  618.      sphere around the origin like planets about the sun).
  619.  
  620.  
  621.  
  622. Section  2.4 - Spheres
  623.  
  624.      Since spheres are so common in ray traced graphics, A SPHERE primitive
  625.      has been added to the system.  This primitive will render much more
  626.      quickly than the corresponding quadric shape.  The syntax is:
  627.       
  628.      SPHERE  <center> radius END_SPHERE
  629.  
  630.      You can also add translations, rotations, and scaling to the sphere. 
  631.      For example, the following two objects are identical:
  632.  
  633.      OBJECT
  634.           SPHERE  < 0.0 25.0 0.0 > 10.0 END_SPHERE
  635.           COLOR Blue
  636.           AMBIENT 0.3
  637.           DIFFUSE 0.7
  638.      END_OBJECT
  639.  
  640.      OBJECT
  641.           SPHERE  < 0.0 0.0 0.0 > 1.0
  642.                TRANSLATE <0.0  25.0  0.0> 
  643.                SCALE <10.0  10.0  10.0>
  644.           END_SPHERE
  645.           COLOR Blue
  646.           AMBIENT 0.3
  647.           DIFFUSE 0.7
  648.      END_OBJECT
  649.  
  650.      Note that Spheres may only be scaled uniformly. You cannot use:
  651.  
  652.      SCALE <10.0 5.0 2.0>
  653.  
  654.      on a sphere.  If you need oblate spheroids such as this, use a scaled
  655.      quadric "Sphere" shape instead.
  656.  
  657. Section  2.5 - Planes
  658.  
  659.      Another primitive provided to speed up the raytracing is the PLANE. 
  660.      This is a flat infinite plane.  To declare a PLANE, you specify the
  661.      direction of the surface normal to the plane (the UP direction) and the
  662.      distance from the origin of the plane to the world's origin.  As with
  663.      spheres, you can translate, rotate, and scale planes.  Examples:
  664.  
  665.      PLANE <0.0  1.0  0.0> -10.0 END_PLANE   { A plane in the X-Z axes 10
  666.                                              units below the world origin. }
  667.  
  668.      PLANE <0.0  1.0  0.0>  10.0 END_PLANE   { A plane in the X-Z axes 10
  669.                                              units above the world origin. }
  670.  
  671.      PLANE <0.0  0.0  1.0>  -10.0 END_PLANE  { A plane in the X-Y axes 10
  672.                                              units behind the world origin.}
  673.  
  674.  
  675. Section  2.6 - Triangles
  676.  
  677.      In order to make more complex objects than the class of quadrics will
  678.      permit, a new primitive shape for triangles has been added.  There are
  679.      two different types of triangles:  flat shaded triangles and smooth
  680.      shaded (Phong) triangles.
  681.  
  682.      Flat shaded triangles are defined by listing the three vertices of the 
  683.      triangle.  For example:
  684.    
  685.      TRIANGLE  < 0.0   20.0  0.0>
  686.                < 20.0  0.0   0.0>
  687.                <-20.0  0.0   0.0>
  688.      END_TRIANGLE
  689.  
  690.      The smooth shaded triangles use Phong Normal Interpolation to calculate
  691.      the surface normal for the triangle.  This makes the triangle appear to
  692.      be a smooth curved surface.  In order to define a smooth triangle,
  693.      however, you must supply not only the vertices, but also the surface
  694.      normals at those vertices.  For example:
  695.    
  696.      SMOOTH_TRIANGLE
  697.           {      points             surface normals     }
  698.           <  0.0  30.0  0.0 >    <0.0   0.7071   -0.7071>
  699.           < 40.0 -20.0  0.0 >    <0.0   -0.8664  -0.5   >
  700.           <-50.0 -30.0  0.0 >    <0.0   -0.5     -0.8664>
  701.      END_SMOOTH_TRIANGLE
  702.  
  703.      As with the other shapes, triangles can be translated, rotated, and
  704.      scaled.
  705.  
  706.      NOTE:  Triangles cannot be used in CSG INTERSECTION or DIFFERENCE types
  707.      (described next) since triangles have no clear "inside".  The CSG UNION
  708.      type works acceptably but with no difference from a COMPOSITE object.
  709.  
  710.  
  711. Section 2.7 - Constructive Solid Geometry (CSG)
  712.  
  713.      This ray tracer supports Constructive Solid Geometry in order to make
  714.      the object definition abilities more powerful.  Constructive Solid
  715.      Geometry allows you to define shapes which are the union, intersection,
  716.      or difference of other shapes.  Unions superimpose the two shapes.  This
  717.      has the same effect as defining two separate objects, but is simpler to
  718.      create and/or manipulate.  Intersections define the space where the two
  719.      surfaces meet.  Differences allow you to cut one object out of another.
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.  
  728.      CSG Intersections, Unions, and Differences can consist of two or more
  729.      shapes.  They are defined as follows:
  730.  
  731.      OBJECT
  732.           INTERSECTION
  733.                QUADRIC
  734.                     ...
  735.                END_QUADRIC
  736.  
  737.                QUADRIC
  738.                     ...
  739.                END_QUADRIC
  740.  
  741.                QUADRIC
  742.                     ...
  743.                END_QUADRIC
  744.           END_INTERSECTION
  745.           ...
  746.      END_OBJECT
  747.  
  748.      UNION or DIFFERENCE may be used instead of INTERSECTION.  The order of
  749.      the shapes doesn't matter except for the DIFFERENCE shapes.  For CSG
  750.      differences, the first shape is visible and the remaining shapes are cut
  751.      out of the first (in reverse order from version 1.2 DIFFERENCE's).
  752.  
  753.      Constructive solid geometry shapes may be translated, rotated, or scaled
  754.      in the same way as a Quadric surface.  The quadric surfaces making up
  755.      the CSG object may be individually translated, rotated, and scaled as
  756.      well.
  757.  
  758.      When using CSG, it is often useful to invert an shape so that it's
  759.      inside-out.  The INVERSE keyword can be used to do this for any SPHERE,
  760.      PLANE, or QUADRIC.  When INVERSE is used, the "inside" of the object is
  761.      flipped to be the "outside".  For Planes, "inside" is defined to be "in
  762.      the opposite direction to the "normal" or "up" direction.
  763.  
  764.      Note that performing an INTERSECTION between an shape and some other
  765.      INVERSE shapes is the same as performing a DIFFERENCE.  In fact, the
  766.      DIFFERENCE is actually implemented in this way.
  767.  
  768. Section  2.8 - Objects
  769.  
  770.      There is more to defining an object than just its shape.  You must tell
  771.      the ray tracer about the properties of the surface like colour, alpha,
  772.      reflectivity, refractivity, the index of refraction, and so on. To do
  773.      this, you must define Objects.
  774.  
  775.  
  776.  
  777.  
  778.  
  779.  
  780.  
  781.      A typical object definition looks something like this:
  782.  
  783.      OBJECT
  784.           QUADRIC Sphere
  785.                TRANSLATE < 40.0 40.0 60.0 >
  786.           END_QUADRIC
  787.  
  788.           TEXTURE
  789.                0.05
  790.           END_TEXTURE
  791.  
  792.           AMBIENT  0.3
  793.           DIFFUSE   0.7
  794.           REFLECTION  0.3
  795.           REFRACTION  0.3
  796.           IOR 1.05
  797.           COLOUR RED 1.0 GREEN 1.0 BLUE 1.0 ALPHA 0.5
  798.      END_OBJECT
  799.  
  800.      The following keywords may be used when defining objects:
  801.  
  802.      AMBIENT value
  803.      -    Ambient light is light that is scattered everywhere in the room. 
  804.           An object lit only by ambient light will appear to have the same
  805.           brightness over the entire surface.  The default value is very
  806.           little ambient light (0.3).  The value can range from 0.0 to 1.0.
  807.  
  808.      DIFFUSE value
  809.      -    Diffuse light is light coming from a light source that is scattered
  810.           in all directions.  An object lit only by diffuse light looks like
  811.           a rubber ball with a spot light shining on it.  The value can range
  812.           from 0.0 to 1.0.  By default, there is mostly diffuse lighting
  813.           (0.7).
  814.  
  815.      BRILLIANCE value
  816.      -    Objects can be made to appear more metallic by increasing their
  817.           brilliance.  This controls the tightness of the basic diffuse
  818.           illumination on objects and minorly adjusts the appearance of
  819.           surface shininess.  The default value is 1.0.  Higher values from
  820.           3.0 to about 10.0 can give objects a somewhat more shiny or
  821.           metallic appearance.  This is best used in concert with either
  822.           SPECULAR or PHONG highlighting.
  823.  
  824.      REFLECTION value
  825.      -    By setting the reflection value to be non-zero, you can give the
  826.           object a mirrored finish.  It will reflect all other objects in the
  827.           room.  The value can range from 0.0 to 1.0.  By default there is no
  828.           reflection.
  829.  
  830.  
  831.  
  832.  
  833.  
  834.      REFRACTION value
  835.      -    By setting the refraction value to be non-zero, the object is made
  836.           transparent.  Light will be refracted through the object like a
  837.           lens.  The value can be set between 0.0 and 1.0.  There is no
  838.           refraction by default.
  839.      IOR value
  840.      -    If the object is refracting light, then the IOR or Index of
  841.           Refraction should be set.  This determines how dense the object is.
  842.           A value of 1.0 will give no refraction.  The Index of Refraction
  843.           for Air is 1.0, Water is 1.33, glass is 1.5, and diamond is 2.4.
  844.  
  845.      PHONG value
  846.      -    Controls the amount of Phong Specular Reflection highlighting on
  847.           the object.  Causes bright shiny spots on the object, the colour of
  848.           the light source that is being reflected.  The size of the spot is
  849.           defined by the value given for PHONGSIZE below.  PHONG's value is
  850.           typically from 0.0 to 1.0, where 1.0 causes complete saturation of
  851.           the object's colour to the light source's colour at the brightest
  852.           area (center) of the highlight.  There is no PHONG highlighting
  853.           given by default.
  854.  
  855.      PHONGSIZE value
  856.      -    Controls the size of the PHONG Highlight on the object, sort of an
  857.           arbitrary "glossiness" factor.  Values range from 1.0 (Very Dull)
  858.           to 100 (Highly Polished).  Default PHONGSIZE is 40 (plastic?) if
  859.           not specified.  This is simulating the fact that slightly reflect-
  860.           ive objects, especially metallic ones, have microscopic facets,
  861.           some of which are facing in the mirror direction.  The more that
  862.           are facing that way, the shinier the object appears, and the
  863.           tighter the specular highlights become.  Phong measures the average
  864.           of facets facing in the mirror direction from the light sources to
  865.           the viewer.
  866.  
  867.      SPECULAR value
  868.      -    Very similar to PHONG Specular Highlighting, but a better model is 
  869.           used for determining light ray/object intersection, so a more
  870.           credible spreading of the highlights occur near the object
  871.           horizons, supposedly.  PHONG is thus included for mostly academic
  872.           reasons, but try them both and you decide which you like better.
  873.           This effect is most obvious for light sources behind objects.  The
  874.           size of the spot is defined by the value given for ROUGHNESS below. 
  875.           Like PHONG, SPECULAR values are typically from 0.0 to 1.0 for full
  876.           saturation.  Default is no SPECULAR highlighting.
  877.  
  878.      ROUGHNESS value
  879.      -    Controls the size of the SPECULAR Highlight on the object, relative
  880.           to the object's "roughness".  Values range from 1.0 (Very Rough) to
  881.           0.001 (Very Smooth).  The default value if not specified is 0.05
  882.           (Plastic?).  The roughness or average directional distribution of
  883.           the microfacets is facing in the same direction as the perpen-
  884.           dicular surface "normal" cause the most notable reflection of the
  885.           highlight to the observer.
  886.  
  887.      COLOUR value
  888.      -    The colour of an object can be set by using this option.  The value
  889.           is a colour or a colour constant.  For example:
  890.  
  891.      COLOUR RED 1.0  BLUE 0.4
  892.  
  893.           - or -
  894.  
  895.      DECLARE Yellow = COLOUR RED 1.0 GREEN 1.0
  896.           ...
  897.      COLOUR Yellow
  898.  
  899.  
  900.      TRANSLATE vector
  901.      ROTATE vector
  902.      SCALE vector
  903.      -    Objects can be translated, rotated, and scaled just like surfaces.
  904.           This feature is included for consistency.
  905.  
  906.      LIGHT_SOURCE
  907.      -    If the LIGHT_SOURCE keyword is used in the definition of an object,
  908.           then the object is included in the list of light sources.  It can
  909.           light objects and produce shadows.  (You should also specify the
  910.           COLOUR of the light source).  Light sources have a peculiar re-
  911.           striction:  The light source MUST be TRANSLATED to it's final
  912.           position in the scene, so the normal way to define a light source
  913.           is a sphere or quadric centered about the origin, then TRANSLATED
  914.           to where desired in the final scene.  For example:
  915.  
  916.      OBJECT
  917.           SPHERE <0.0  0.0  0.0> 2.0 END_SPHERE   {could be a quadric, too.}
  918.           TRANSLATE <100.0  120.0  40.0>
  919.  
  920.           LIGHT_SOURCE
  921.           COLOUR RED 1.0 GREEN 1.0 BLUE 1.0
  922.           AMBIENT 1.0
  923.           DIFFUSE 0.0
  924.      END_OBJECT
  925.  
  926.  
  927.      TEXTURE
  928.      -    The texture feature is an experiment into functionally based
  929.           modelling.  This feature allows you to assign more interesting
  930.           colouring schemes to objects.  Many procedural surface textures are
  931.           provided, and by using different colour maps with them, nearly
  932.           infinite permutations are possible.  For example, you can make some
  933.           object look like wood or marble, etc.
  934.  
  935.  
  936.  
  937.  
  938.  
  939.  
  940.      The basic TEXTURE syntax is as follows:
  941.  
  942.      TEXTURE
  943.           0.05
  944.           WOOD
  945.           TURBULENCE 0.2
  946.           TRANSLATE < 1.0 2.0 3.0 >
  947.           ROTATE < 0.0 10.0 40.0 >
  948.           SCALE < 10.0 10.0 10.0 >
  949.      END_TEXTURE
  950.  
  951.      The transformations are optional.  They allow you to transform the
  952.      texture independent of the object itself.  If you are doing animation,
  953.      then the transformations should be the same as the object
  954.      transformations so that  the texture follows the object.
  955.  
  956.      The floating-point value given immediately following the texture keyword
  957.      is an optional "texture randomness" value, which causes a minor random
  958.      scattering of calculated colour values and produces a sort of "dithered" 
  959.      appearance.
  960.  
  961.      Instead of using WOOD, you may use MARBLE, BOZO, CHECKER, or a handful
  962.      of other interesting textures.  The WOOD and MARBLE textures are
  963.      perturbed by a turbulence function.  This makes them look more random
  964.      and irregular than they would normally appear.  The amount of turbulence
  965.      can be changed by the TURBULENCE keyword followed by a number.  Values
  966.      from 0.1 to 0.3 seem to give the best results.  The default is 0.0, or
  967.      no turbulence.
  968.  
  969.      Note some of the textures given are coloration textures, such as MARBLE,
  970.      WOOD CHECKER, GRANITE, and AGATE.  These work with colour maps, and have
  971.      default "colour maps" they resort to if none are given.  The rest of the
  972.      textures available are "surface perturbation" textures, and do not dir-
  973.      ectly affect the colour of the object, but rather the surface's apparent
  974.      orientation in space. Examples of this are WAVES, RIPPLES, DENTS, BUMPS,
  975.      and WRINKLES.  Note that any given texture may include up to two actual
  976.      textures, one coloration and one surface perturbation choice per
  977.      texture.  This would allow rippled wood, or dented granite combinations, 
  978.      etc., but keep in mind that any transformations applied to one texture
  979.      (i.e. TRANSLATE or SCALE) will also transform the other one in the same
  980.      fashion.
  981.  
  982.  
  983.      The following textures are available:
  984.  
  985.      CHECKER texturing gives a checker-board appearance.  This option works
  986.      best on planes.  When using the CHECKER texturing, you must specify two
  987.      colours immediately following the word CHECKER.  These colours are the
  988.      colours of alternate squares in the checker pattern.  The default
  989.      orientation of the CHECKER texture is on an X-Z plane (good for ground
  990.      work, etc.) but to use it on an object which has mostly X-Y orientation
  991.      (such as a sphere, for instance), you must ROTATE the texture.
  992.  
  993.      To rotate the CHECKER texture onto an X-Y plane:
  994.  
  995.      TEXTURE
  996.           CHECKER COLOUR White COLOUR Red
  997.           SCALE <10.0 10.0 10.0>
  998.           ROTATE <-90.0 0.0 0.0>   { Checkers now in the X-Y plane... }
  999.      END_TEXTURE
  1000.  
  1001.      As mentioned above, for coloration textures such as WOOD, MARBLE, and
  1002.      BOZO, etc., you may change the colouring scheme by using a colour map.
  1003.      This map allows you to convert numbers from 0.0 to 1.0 (which are
  1004.      generated by the ray tracer) into ranges of colours. For example, the
  1005.      default BOZO colouring can be specified by:
  1006.  
  1007.      TEXTURE
  1008.           BOZO
  1009.           COLOUR_MAP
  1010.                [0.0 0.4 COLOUR White COLOUR White]
  1011.                [0.4 0.6 COLOUR Green COLOUR Green]
  1012.                [0.6 0.8 COLOUR Blue COLOUR Blue]
  1013.                [0.8 1.0 COLOUR Red COLOUR Red]
  1014.           END_COLOUR_MAP
  1015.      END_TEXTURE
  1016.  
  1017.      BOZO texture basically takes a noise function and maps it onto the
  1018.      surface of an object.  This "noise" is defined for every point in space.
  1019.      If two points are close together, they will have noise values that are
  1020.      close together.  If they are far apart, their noise values will be
  1021.      fairly random relative to each other.
  1022.  
  1023.      The easiest way to see how it works is to try it.  With a good choice of
  1024.      colours it produces some of the most realistic looking cloudscapes you
  1025.      have ever seen.  Try a cloud color map such as:
  1026.  
  1027.      TEXTURE
  1028.           BOZO
  1029.           TURBULENCE 1.0      { A blustery day.  For a calmer one, try 0.2 }
  1030.           COLOUR_MAP
  1031.                [0.0 0.5  COLOUR RED 0.5 GREEN 0.5 BLUE 1.0  {blue to blue}
  1032.                     COLOUR RED 0.5 GREEN 0.5 BLUE 1.0]
  1033.                [0.5 0.6  COLOUR RED 0.5 GREEN 0.5 BLUE 1.0  {blue to white}
  1034.                     COLOUR RED 1.0 GREEN 1.0 BLUE 1.0]
  1035.                [0.6 1.001 COLOUR RED 1.0 GREEN 1.0 BLUE 1.0 {white to grey}
  1036.                     COLOUR RED 0.5 GREEN 0.5 BLUE 0.5]
  1037.           END_COLOUR_MAP
  1038.           SCALE <800.0 800.0 800.0>
  1039.           TRANSLATE <200.0 400.0 100.0>
  1040.      END_TEXTURE
  1041.  
  1042.      (Check out sunset.dat for a really neat (but slow) sky pattern)
  1043.  
  1044.  
  1045.  
  1046.      The color map above indicates that for small values of texture, use a
  1047.      sky blue color solidly until about halfway turbulent, then fade through
  1048.      to white on a fairly narrow range.  As the white clouds get more turb-
  1049.      ulent and solid towards the center, pull the color map toward grey to
  1050.      give them the appearance of holding water vapor (like typical clouds).
  1051.      SPOTTED - Spotted texture is a sort of swirled random spotting of the
  1052.      colour of the object.  If you've ever seen a metal organ pipe you know
  1053.      about what it looks like (a galvanized garbage can is close...)  Play
  1054.      with this one, it might render a decent cloudscape during a very stormy 
  1055.      day (?).  No extra keywords are required.  Should work with colour maps.
  1056.      With small scaling values, looks like masonry or concrete.
  1057.  
  1058.      AGATE - this texture is similar to Marble, but uses a different turb-
  1059.      ulence function.  The TURBULENCE keyword has no effect, and as such it
  1060.      is always very turbulent.
  1061.  
  1062.      GRADIENT - this is a specialized texture that uses approximate local
  1063.      coordinates of an object to control colour map gradients.  This texture
  1064.      ONLY works with colour maps (one MUST be given!) and has a special <X,
  1065.      Y, Z> triple given after the GRADIENT keyword, which specifies any (or
  1066.      all) axes to perform the gradient action on.  (Example: a Y gradient
  1067.      <0.0, 1.0, 0.0> will give an "altitude colour map", along the Y axis).
  1068.      Values other than 0.0 are taken as 1.0 and others are meaningless.  For
  1069.      smooth repeating gradients, you should use a nearly "circular" colour
  1070.      map, that is, one in which the first colour value (0.0) is the same as
  1071.      the last one (1.001) so it "wraps around" and will cause smooth
  1072.      repeating gradient patterns.  Scaling the texture is normally required
  1073.      to achieve the number of repeating shade cycles you want. 
  1074.      Transformation of the texture is useful to prevent a "mirroring" effect
  1075.      from either side of the central 0 axes.  Here is an example of a
  1076.      gradient texture which uses a sharp "circular" color mapped gradient
  1077.      rather than a smooth one, and uses both X and Y gradients to get a
  1078.      diagonally-oriented gradient.  It produces a dandy candy cane texture!
  1079.  
  1080.      TEXTURE
  1081.           GRADIENT < 1.0 1.0 0.0 >
  1082.           COLOUR_MAP
  1083.                [0.00 0.25  COLOUR RED 1.0 GREEN 0.0 BLUE 0.0
  1084.                     COLOUR RED 1.0 GREEN 0.0 BLUE 0.0]
  1085.                [0.25 0.75  COLOUR RED 1.0 GREEN 1.0 BLUE 1.0
  1086.                     COLOUR RED 1.0 GREEN 1.0 BLUE 1.0]
  1087.                [0.75 1.001 COLOUR RED 1.0 GREEN 0.0 BLUE 0.0
  1088.                     COLOUR RED 1.0 GREEN 0.0 BLUE 0.0]
  1089.           END_COLOUR_MAP
  1090.           SCALE <30.0 30.0 30.0>
  1091.           TRANSLATE <30.0 -30.0 0.0>
  1092.      END_TEXTURE
  1093.  
  1094.  
  1095.      You may also specify a TURBULENCE value with the gradient to give a    
  1096.      more irregular colour gradient.  This may help to do neat things like
  1097.      fire or coronas.
  1098.  
  1099.      GRANITE - A colouring texture.  This uses a simple 1/f fractal noise
  1100.      function to give a pretty darn good grey granite texture.  Typically
  1101.      used with small scaling values (2.0 to 5.0).  Also looks good with a
  1102.      little dithering (texture randomness).  Should work with colour maps, so
  1103.      try your hand at pink granite or alabaster!
  1104.  
  1105.      RIPPLES - As mentioned above, you may optionally specify a surface
  1106.      perturbation texture which can be used in conjunction with the above
  1107.      coloration textures.  RIPPLES is one example of a surface perturbation
  1108.      texture.  This texture makes the surface look like ripples of water. 
  1109.      The RIPPLES option requires a value to determine how deep the ripples
  1110.      are:
  1111.  
  1112.      TEXTURE
  1113.           WOOD
  1114.           RIPPLES 0.3
  1115.           TRANSLATE < 1.0 2.0 3.0 >
  1116.           ROTATE < 0.0 10.0 40.0 >
  1117.           SCALE < 10.0 10.0 10.0 >
  1118.      END_TEXTURE
  1119.  
  1120.      (In this case, the WOOD, MARBLE, or BOZO, etc. keywords are optional).
  1121.      If a different colouring is specified (WOOD, MARBLE, or BOZO), then the
  1122.      COLOUR parameter is ignored (except for light sources where it gives the
  1123.      light colour or when rendering with a low -q option).
  1124.  
  1125.      WAVES - Another option that you may want to experiment with is called
  1126.      WAVES. This works in a similar way to RIPPLES except that it makes waves
  1127.      with different frequencies.  The effect is to make waves that look more
  1128.      like deep ocean waves. (I haven't done much testing on WAVES, so I can't
  1129.      guarantee that it works very well).
  1130.  
  1131.      Both WAVES and RIPPLES respond to a texturing option called PHASE. The
  1132.      PHASE option allows you to create animations in which the water seems to
  1133.      move.  This is done by making the PHASE increment slowly between frames. 
  1134.      The range from 0.0 to 1.0 gives one complete cycle of a wave.
  1135.  
  1136.      BUMPS - Approximately the same turbulence function as SPOTTED, but uses
  1137.      the derived value to perturb the surface normal.  This gives the
  1138.      impression of a "bumpy" surface, random and irregular, sort of like an
  1139.      orange.  After the BUMPS keyword, supply a single floating point value
  1140.      for the amount of surface perturbation.  Values typically range from 0.0
  1141.      (No Bumps) to 1.0 (Extremely Bumpy).  Values beyond 1.0 may do wierd
  1142.      things.
  1143.  
  1144.      DENTS - Also a surface normal perturbing texture.  Interesting when used
  1145.      with metallic textures, it gives impressions into the metal surface that
  1146.      look like dents.  A single value is supplied after the DENTS keyword to
  1147.      indicate the amount of denting required.  Values range from 0.0 (No
  1148.      Dents) to 1.0 (Fairly Dented).  Use larger values at your own risk...
  1149.      Scale the texture to make the pitting more or less frequent.
  1150.  
  1151.  
  1152.      WRINKLES - This is sort of a 3-D (normal perturbing) GRANITE.  It uses
  1153.      a similar 1/f fractal noise function to perturb the surface normal in 3D
  1154.      space.  With ALPHA values of greater than 0.0, could look like wrinkled
  1155.      cellophane.  Requires a single value after the WRINKLES keyword to
  1156.      indicate the amount of wrinkling desired.  Values from 0.0 (No Wrinkles)
  1157.      to 1.0 (Very Wrinkled) are typical.
  1158.  
  1159.  
  1160.      IMAGEMAP - This is a very special coloration texture that allows you to
  1161.      import a bitmapped file in RAW format (the format output by the ray-
  1162.      tracer), IFF format or Compuserve GIF format and map that bitmap onto an
  1163.      object.  In the texture of an object, you must give the IMAGEMAP key-
  1164.      word, the format, and a file name.  The syntax is:          
  1165.  
  1166.           IMAGEMAP [gradient] RAW "filename [ONCE]"
  1167.      or   IMAGEMAP [gradient] IFF "filename [ONCE]"
  1168.      or   IMAGEMAP [gradient] GIF "filename [ONCE]"
  1169.  
  1170.      The texture will then be mapped onto the object as a repeating pattern.
  1171.      The ONCE keyword places only one image onto the object instead of an
  1172.      infinitely repeating tiled pattern.  When ONCE is used, the object's
  1173.      default colour is used as the colour outside of the image.
  1174.  
  1175.  
  1176.      By default, the image is mapped onto the XY plane in the range (0.0,
  1177.      0.0) to (1.0, 1.0).  If you would like to change this default, you may
  1178.      use an optional gradient <x, y, z> vector after the word IMAGEMAP.  This
  1179.      vector indicates which axes are to be used as the u and v (local surface
  1180.      X-Y) axes. The vector should contain one positive number and one
  1181.      negative number to indicate the u and v axes, respectively.  You may
  1182.      translate, rotate, and scale the texture to map it onto the object's
  1183.      surface as desired.  Here is an example:
  1184.  
  1185.      INCLUDE "BasicShapes.data"
  1186.  
  1187.      OBJECT
  1188.           QUADRIC Plane_XY END_QUADRIC
  1189.           TRANSLATE <0.0  -20.0  0.0>
  1190.  
  1191.           TEXTURE
  1192.                { make this texture use the x and z axes for the mapping. }
  1193.                IMAGEMAP <1.0  0.0  -1.0> GIF "image.gif"
  1194.                SCALE <40.0 40.0 40.0>
  1195.           END_TEXTURE
  1196.      END_OBJECT
  1197.  
  1198.      When I was bored with nothing to do, I decided that it would be neat to
  1199.      have turbulent texture maps.  So, I said - "what the hell!"  You can
  1200.      specify TURBULENCE with texture maps and it will perturb the image.  It
  1201.      may give some bizarre results.  Is this useful?  I dunno.  It was easy
  1202.      to do so I did it.  Try it out and see what you get.
  1203.  
  1204. Section 2.9 - Composite Objects
  1205.  
  1206.      Often it's useful to combine several objects together to act as a whole.
  1207.      A car, for example, consists of wheels, doors, a roof, etc.  A composite
  1208.      object allows you to combine all of these pieces into one object.  This
  1209.      has two advantages.  It makes it easier to move the object as a whole
  1210.      and it allows you to speed up the ray tracing by defining bounding
  1211.      shapes that contain the objects.  (Rays are first tested to see if they
  1212.      intersect the bounding shape.  If not, the entire composite object is
  1213.      ignored).  Composite objects are defined as follows:
  1214.  
  1215.      COMPOSITE
  1216.           OBJECT
  1217.                ...
  1218.           END_OBJECT
  1219.  
  1220.           OBJECT
  1221.                ...
  1222.           END_OBJECT
  1223.           ...
  1224.  
  1225.           SCALE < 2.0 2.0 2.0 >
  1226.           ROTATE < 30.0 45.0 160.0 >
  1227.           TRANSLATE < 100.0 20.0 40.0 >
  1228.      END_COMPOSITE
  1229.  
  1230.      Composite objects can contain other composite objects as well as regular
  1231.      objects.  Composite objects cannot be light sources (although any number
  1232.      of their components can).  This is because it is nearly impossible to
  1233.      determine the true "center" of the composite object, and our light
  1234.      sources are pinpoint ray sources from the center of the light source
  1235.      object, wherever that may be.
  1236.  
  1237.  
  1238. Section 2.95 - Bounding Shapes
  1239.  
  1240.      Let's face it.  This program is no speed demon.  You can save yourself
  1241.      a lot of time, however, if you use bounding shapes around any complex
  1242.      objects.  Bounding shapes tell the ray tracer that the object is totally
  1243.      enclosed by a simple shape.  When tracing rays, the ray is first tested
  1244.      against the simple bounding shape.  If it strikes the bounding shape,
  1245.      then the ray is further tested against the more complicated object
  1246.      inside.
  1247.  
  1248.      To use bounding shapes, you simply include the following lines into the
  1249.      declaration of your OBJECT or COMPOSITE_OBJECT:
  1250.  
  1251.      BOUNDED_BY
  1252.           a shape
  1253.      END_BOUND
  1254.  
  1255.  
  1256.  
  1257.      An example of a Bounding Shape:
  1258.  
  1259.      OBJECT
  1260.           INTERSECTION
  1261.                SPHERE <0.0 0.0 0.0> 2.0 END_SPHERE
  1262.                PLANE <0.0 1.0 0.0> 0.0 END_PLANE
  1263.                PLANE <1.0 0.0 0.0> 0.0 END_PLANE
  1264.           END_INTERSECTION
  1265.  
  1266.           BOUNDED_BY
  1267.                SPHERE <0.0 0.0 0.0> 2.0 END_SPHERE
  1268.           END_BOUND
  1269.      END_OBJECT
  1270.  
  1271.      The best bounding shape is a SPHERE since this shape is highly
  1272.      optimized.  Any shape may be used, however.
  1273.  
  1274. Section 3 - Showing the final pictures
  1275.  
  1276.      When the ray tracer draws the picture on the screen, it does not make
  1277.      good choices for the colour registers.  Without knowing all the needed
  1278.      colours ahead of time, only approximate guesses can be made.  A post-
  1279.      processor is really needed to view the final image correctly.  A post-
  1280.      processor has been provided for the Amiga which scans the picture and
  1281.      chooses the best possible colour registers.  It then redisplays the
  1282.      picture.  For the Amiga, "DumpToIFF" can optionally save this picture in
  1283.      IFF format.  The syntax for the DumpToIFF post-processor is:
  1284.  
  1285.      DumpToIFF filename
  1286.  
  1287.      where the filename is the one given in the -o parameter of the ray
  1288.      tracer.  If you didn't specify the -o option, then use:
  1289.  
  1290.      DumpToIFF data.dis
  1291.  
  1292.      If you want to save to an IFF file, then put the name of the IFF file
  1293.      after the name of the data file:
  1294.  
  1295.      DumpToIFF data.dis picture
  1296.  
  1297.      This will create a file called "picture" which contains the IFF image.
  1298.  
  1299.      For the IBM, you will probably want to use the -t option and write the
  1300.      image out in TARGA 24 format.  If you have a TARGA or compatible display
  1301.      adapter, you may view the picture in the full 16 million colors (that's
  1302.      why they still cost the big $$ bucks).  If you don't, there are several
  1303.      post-processing programs available to convert the TARGA true-color image
  1304.      into a more suitable color-mapped image (such as .GIF).  If you have a
  1305.      VGA or MCGA adapter capable of 320x200 by 256 colors, then you may use
  1306.      the -d option which will display the image as it generates using only
  1307.      approximate screen colors.  No hardware test is performed, so if you
  1308.      don't have a VGA or MCGA, -> DON'T <- use the -d option!
  1309.  
  1310.      When displaying the image to screen, a HSV conversion method is used
  1311.      (hue, saturation, value).  This is a convenient way of translating
  1312.      colors from a "true color" format (16 million) down a "colour mapped"
  1313.      format of something reasonable (like 256), while still approximating the
  1314.      color as closely as the available display hardware permits.  As
  1315.      mentioned previously, the tracer has no way of knowing which colors will
  1316.      be finally used in the image, nor can it deal properly with all of the
  1317.      colors which will be generated (up to 16M), so only 4 shades each of 64
  1318.      possible hues are mapped into the palette DAC, as well as black, white,
  1319.      and two grey levels. The advantage a post-processor has in choosing
  1320.      mapped colors is that it can throw away all the unused colors in the
  1321.      palette map, and thereby free up some space for making better gradient
  1322.      shades of the colors that are actually used.
  1323.  
  1324.      There are several available image processing programs that can do this,
  1325.      a public domain one that is very good is PICLAB, by the Stone Soup Group 
  1326.      (the folks who brought you FRACTINT).  The procedure is to load the
  1327.      TARGA file, then use the MAKEPAL command to generate a 256 color map
  1328.      which is the histogram-weighted average of the most-used colors in the
  1329.      image (You could also PLOAD a palette file from FRACTINT or one you
  1330.      previously had saved using PSAVE).  You then MAP the palette onto the
  1331.      image one of two ways:
  1332.  
  1333.      1)   If the DITHER variable is OFF, a nearest-match-color-fit is used,
  1334.           which can sometimes produce unwanted "banding" of colored regions
  1335.           (called false contours).
  1336.      2)   If the DITHER variable is ON, then a standard dither is used to
  1337.           determine final color values.  This is much better at blending the
  1338.           color bands, but can produce noise in reflections and make mirrors
  1339.           appear dirty or imperfect.
  1340.  
  1341.      Then you would typically SHOW the image or GSAVE it into GIF format. 
  1342.      While the picture is still in the unmapped form (TARGA, etc.) you can
  1343.      perform a variety of advanced image processing transformations and
  1344.      conversions, so save the .TGA or .RAW files you make (in case you ever
  1345.      get a TARGA card, or give them to a friend who has one!).
  1346.  
  1347.      A commercial product that also does a good job of nearest-match-color-
  1348.      fit is the CONVERT utility of The AutoDesk Animator.  However, the
  1349.      dither effect is not as good as that of PICLAB.  To convert the file in
  1350.      AA's CONVERT, you LOAD TARGA, then in the CONVERT menu, go to the SCALE
  1351.      function and just hit RENDER.  Click on the DITHER (lights up with an
  1352.      asterisk when on) if you want it to use it's dithering.  CONVERT will
  1353.      scale (if asked to) and then do a histogram of total used colors like
  1354.      PICLAB, but then makes 7 passes on the color map and image to determine
  1355.      shading thresholds of each hue.  This nearly eliminates the color
  1356.      banding (false contours) without resorting to dithering.  By now you
  1357.      must get the feeling DITHER is a 4-letter word.  If you have a low-
  1358.      resolution display, it is.  If you have too few colors, however, it can
  1359.      be a saving grace.  At resolutions of 640x400 or higher the "spray
  1360.      paint" effect of dithering and anti-aliasing is much less noticeable,
  1361.      and effects a much smoother blending appearance.
  1362.  
  1363. Section 4 - Handy Hints/Quick Start
  1364.  
  1365.      -    To see a quick version of your picture, use -w64 -h80 as command
  1366.           line parameters on the Amiga.  For the IBM, try -w80 -h50.  This
  1367.           displays the picture in a small rectangle so that you can see how
  1368.           it will look.
  1369.  
  1370.      -    Try using the sample default files for different usages - QUICK.DEF
  1371.           shows a fast postage-stamp rendering (80x50, as above) to the
  1372.           screen only, LOCKED.DEF will display the picture with anti-aliasing
  1373.           on (takes forever) with no abort (do this before you go to bed...).
  1374.           The normal default options file TRACE.DEF is read and you can
  1375.           supersede this with another .DEF file by specifying it on the
  1376.           command line, for example:
  1377.  
  1378.           trace -iworld.dat -oworld.out quick.def
  1379.  
  1380.      -    When translating light sources, translate the OBJECT, not the
  1381.           QUADRIC surface.  The light source uses the center of the object as
  1382.           the origin of the light.
  1383.  
  1384.      -    When animating objects with solid textures, the textures must move
  1385.           with the object, i.e. apply the same ROTATE or TRANSLATE functions
  1386.           to the texture as to the object itself.
  1387.  
  1388.      -    You can declare constants for most of the data types in the program
  1389.           including floats and vectors.  By combining this with INCLUDE
  1390.           files, you can easily separate the parameters for an animation into
  1391.           a separate file.
  1392.  
  1393.      -    The amount of ambient light plus diffuse light should be less than
  1394.           or equal to 1.0.  The program accepts any value, but may produce
  1395.           strange results.
  1396.  
  1397.      -    When using ripples, don't make the ripples too deep or you may get
  1398.           strange results (the dreaded "digital zits"!).
  1399.  
  1400.      -    Wood textures usually look better when they are scaled to different
  1401.           values in x, y, and z, and rotated to a different angle.
  1402.  
  1403.      -    You can sort of dither a colour by placing a floating point number
  1404.           into the texture record:
  1405.  
  1406.           TEXTURE
  1407.                0.05
  1408.           END_TEXTURE
  1409.  
  1410.           This adds a small random value to the intensity of the diffuse
  1411.           light on the object.  Don't make the number too big or you may get
  1412.           strange results.
  1413.  
  1414.           Better results can be obtained, however, by doing the dithering in
  1415.           a post-processor.
  1416.  
  1417.  
  1418.      -    You can compensate for non-square aspect ratios on the monitors by
  1419.           making the RIGHT vector in the VIEWPOINT longer or shorter.  A good
  1420.           value for the Amiga is about 1.333.  This seems ok for IBM's too at
  1421.           320x200 resolution.  If your spheres and circles aren't round, try
  1422.           varying it.
  1423.  
  1424.      -    If you are importing images from other systems, you may find that
  1425.           the shapes are backwards (left-to-right inverted) and no rotation
  1426.           can make them right.  All you have to do is negate the terms in the
  1427.           RIGHT vector of the viewpoint to flip the camera left-to-right.
  1428.  
  1429.      -    By making the DIRECTION vector in the VIEWPOINT longer, you can
  1430.           achieve the effect of a zoom lens.
  1431.  
  1432.      -    When rendering on the Amiga, use a resolution of 319 by 400 to
  1433.           create a full sized HAM picture.
  1434.  
  1435.  
  1436. Section 5 - Known Bugs
  1437.      There is a bug in the code to use Vector constants.  The fix involves
  1438.      re-working the parser quite a bit and I don't want to do that now.
  1439.  
  1440.  
  1441. Section 6 - Concluding remarks
  1442.  
  1443.      I'm sure that there are bugs in the code somewhere, but I've done my
  1444.      best to remove all the bugs I could find.  I also think that the object
  1445.      description language needs to be re-worked.  Its current syntax is a bit 
  1446.      cumbersome.  The system could also use a good graphical interface  :-).
  1447.  
  1448.      To that end, a conversion utility is supplied which will take in a
  1449.      Sculpt-Animate 4-D object and map it into DKB's primitive TRIANGLES. 
  1450.      For the IBM, we have heard, but cannot confirm, there is a utility
  1451.      around which will convert AUTOCAD .DXF files into Sculpt-4D files.  If
  1452.      anybody has it or any info about it, please contact either David Buck or
  1453.      Aaron Collins.
  1454.  
  1455.      The IBM version is also supplied with two stand-alone TARGA-24 utilities
  1456.      which were written by Aaron A. Collins.  These are HALFTGA, which will
  1457.      chop a TARGA-24 file in half in both X and Y dimensions for low-
  1458.      resolution systems, and another file called GLUETGA which will paste
  1459.      together several TARGA-24 files (of any resolution) into one.  This is
  1460.      principally for concatenating together several partial (interrupted)
  1461.      trace output files into one.
  1462.  
  1463.      I would like to thank Rick Mallett from Carleton University for his help
  1464.      in testing this program, for his comments and suggestions, and for
  1465.      creating the data file for ROMAN.DATA - awesome!
  1466.  
  1467.      I would also like to thank my beta testers for all the help, bug reports,
  1468.      suggestions, comments, and time spent.  This version of the ray tracer
  1469.      wouldn't have been possible without them.  Thanks guys.
  1470.  
  1471. Enjoy,
  1472. David Buck
  1473.  
  1474.