home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 505b.lha / DKBTrace_v2.11 / doc / dkb211.doc.pp / dkb211.doc
Text File  |  1991-05-05  |  157KB  |  3,681 lines

  1.                         DKBTrace Ray-Tracer,
  2.                           Version 2.11
  3.               "It's free, and it's well worth the price!"
  4.  
  5.  
  6. This program was written by:
  7.  
  8.     David Buck
  9.     22C Sonnet Cres.
  10.     Nepean, Ontario
  11.     Canada, K2H 8W7
  12.  
  13. It has been made freely distributable.  The author retains the
  14. copyright to the program but authorizes free distribution by BBS'es,
  15. networks or by magnetic media.  The distributor may choose to charge
  16. for the cost of the disk but must not sell the software for profit.
  17. Non-profit organizations such as clubs may charge for the software so
  18. long as the price is reasonable (less than $5.00 more than the cost of
  19. the disk) and so long as the buyers are informed that the program is
  20. freely distributable. 
  21.  
  22. The images and data files generated by the raytracer are the property
  23. of the user of the software and may be used for any purpose without
  24. restriction. 
  25.  
  26. The author makes no guarantees or warranties with this program and
  27. claims no responsibility for any damage or loss of time caused by this
  28. program. Bug reports may be sent to the author but the author is under
  29. no obligation to provide bug fixes, features, or any support for this
  30. software. 
  31.  
  32. I would also like to place the following conditions on the use of this program:
  33.  
  34.  1) that it should not be used as part of any commercial package without my
  35.     explicit written consent.
  36.  2) if you make any neat and interesting pictures, please send them to me.
  37.  3) If you make any changes to the source code, please let me know. I'd like
  38.     to see what you've done.
  39.  4) This text file should accompany the program.
  40.  
  41.  
  42. I can be reached on the following BBS'es:
  43.  
  44.     OMX       (613) 731-3419
  45.     Mystic    (613) 731-0088 or (613) 731-6698
  46.     FidoNet   1:163/109.9
  47.     Internet  dbuck@ccs.carleton.ca
  48.     CIS       70521,1371
  49.     "You can call me Ray"   (708) 358-5611
  50.  
  51. Aaron Collins (IBM port) can be reached on the following BBS'es
  52.  
  53.     "You can call me Ray"   (708) 358-5611
  54.  
  55. AAC:  As of July of 1990, there is a Ray-Trace specific BBS in the (708) Area
  56. Code (Chicago suburbia) for all you Traceaholics out there.  The phone number
  57. of this new BBS is (708) 358-5611.  I am Co-Sysop of that board, and David is
  58. a frequent caller.  There is now also a Ray-Trace and Computer-Generated Art
  59. specific SIG on Compuserve, GO COMART.  And now, back to the DOCS... 
  60.  
  61. The GIF file reader was written by Steven A. Bennett.  Here's his copyright
  62. notice:
  63.  
  64.     * DECODER.C - An LZW decoder for GIF
  65.     * Copyright (C) 1987, by Steven A. Bennett
  66.     *
  67.     * Permission is given by the author to freely redistribute and include
  68.     * this code in any program as long as this credit is given where due.
  69.     *
  70.     * In accordance with the above, I want to credit Steve Wilhite, who
  71.     * wrote the code which this is heavily inspired by...
  72.     *
  73.     * GIF and 'Graphics Interchange Format' are trademarks (tm) of
  74.     * Compuserve, Incorporated, an H&R Block Company.
  75.  
  76. The Noise and DNoise functions (used for texturing) were written by
  77. Robert Skinner and used here with his permission. 
  78.  
  79.  
  80.  
  81. This manual is divided into the following sections:
  82.    1) Program Description
  83.    2) Program History and Information
  84.    3) Getting Started
  85.    4) Command Line Parameters
  86.    5) A Tutorial Walkthrough
  87.    6) The Scene Description Language
  88.    7) Displaying the Images
  89.    8) DKBTrace Utilities
  90.    9) How it All Works (or How to Get What You Want)
  91.   10) Common Questions and Answers
  92.   11) Converting Data Files from Versions Prior to 2.10
  93.   12) Handy Hints
  94.   13) Compiling the Code
  95.   14) Porting to Different Platforms
  96.   15) References
  97.   16) Concluding Remarks
  98.  
  99. Some sample worlds and their corresponding images are provided with this
  100. distribution.  To be honest, the images I usually create are dull boring
  101. test files.  Other people, however, have created some really spectacular
  102. images.  Looking at the data files for these will give you some ideas and
  103. help you design your own data files.
  104.  
  105.  
  106.  
  107.  
  108. 1)  Program Description
  109.  
  110.  
  111. This program is a ray tracer written completely in C.  It supports
  112. arbitrary quadric surfaces (spheres, ellipsoids, cones, cylinders,
  113. planes, etc.), constructive solid geometry, and various shading models
  114. (reflection, refraction, marble, wood, and many others).  It also has
  115. special-case code to handle spheres, planes, triangles, and smooth
  116. triangles.  By using these special primitives, the rendering can be
  117. done much more quickly than by using the more general quadrics.  In
  118. order to create pictures with this program, you must describe the
  119. objects in the world.  This description is a text file called
  120. "<filename>.data", and <filename> defaults to "object" if not
  121. specified.  Normally, such files are difficult to write and to read.
  122. In order to make this task easier, the program contains a parser to
  123. read the data file.  It allows the user to easily create complex
  124. worlds from simple components.  Since the parser allows include files,
  125. the user may put the object descriptions into different files and
  126. combine them all into one final image. 
  127.  
  128.  
  129.  
  130. 2)  Program History and Information
  131.  
  132.  
  133. Version 1.2:
  134.     Initial Amiga release.
  135.  
  136. Version 2.0:
  137.     First release Version 2.0 Conversion to the IBM done by Aaron A. Collins
  138.     New textures, Specular and Phong highlighting added by Aaron A. Collins.
  139.     Triangle, Smooth Triangle, Sphere, Plane support added by David Buck
  140.     RAW, IFF and GIF image mapping added by David Buck and Aaron Collins
  141.     Transparency and Fog added by David Buck
  142.     GIF format file reader by Steve Bennett (used with permission)
  143.     New Noise and DNoise functions by Robert Skinner (used with permission)
  144.     TARGA format output file capability added by Aaron A. Collins
  145.     ANSI-C function prototyping for ALL functions,
  146.     Reversal of the order of writing screen data from the original DKB/QRT
  147.        "RAW" file format.
  148.     For IBM's, it has a crude VGA 320x200 by 256 color display rendering
  149.        ability.
  150.  
  151.     Version 2.0 compiles under Turbo-C 2.0 on the IBM P.C. and Lattice C
  152.     5.05 on the Amiga.  The only file which contains the ANSI extensions
  153.     is dkbproto.h, so for non-ANSI compilers, you only need to remove the
  154.     declaration of the parameters in the config.h file and the whole thing
  155.     should compile.  There are several example config.h files for Amiga,
  156.     IBM, and Unix.  The appropriate one should be copied over CONFIG.H,
  157.     and the MAKEFILE should be edited for your particular system and
  158.     compiler configuration before compilation. 
  159.     
  160.     Version 2.0 has a significant difference from prior releases:  Speed!
  161.     The new primitives of SPHERE, PLANE, TRIANGLE, etc. greatly speed up
  162.     tracing.  Another significant speed-up is that world X-Y-Z values
  163.     beyond 10 Million or so are ignored, and ray tracing beyond that
  164.     distance will cease.  This produces 2 minor peculiarities:
  165.  
  166.      1)   A black stripe at the horizon point of Pre-2.0 scene description
  167.           .data files that have "ground" and "sky" planes defined.  The
  168.           planes were traced out to a much greater "infinity" so this effect
  169.           was unnoticeable, prior to version 2.0.
  170.  
  171.      2)   Tiny black pixels in the texture, or "Surface Acne".
  172.  
  173.  
  174.     This is usually caused by rays being refracted or reflected such that
  175.     the ray does not happen to hit any object, and eventually becomes
  176.     black in color as it gets too far away and gets clipped.  This effect
  177.     can be minimized by enclosing the scene with distant "walls",
  178.     "floors", or placing "ocean floors" beneath water, etc.  So far, no
  179.     scenes have required placing such planes behind the camera, unless an
  180.     "environment map" of sorts is desired.  See SKYTEST.DAT for several
  181.     examples of spurious distant planes.  If your "acne" still doesn't go
  182.     away, it may be due to a large pixel sample area and it's accidentally
  183.     picking a point which is just inside the primitive being hit.  This is
  184.     a more tricky problem to solve, and anti-aliasing the image will
  185.     definitely help if this sort of thing occurs. 
  186.  
  187. Version 2.10:
  188.     A few unofficial releases were made between 2.01 and 2.10.  The following
  189.     points capture the major changes:
  190.  
  191.     - Less memory is required for image mapped GIF and IFF files.
  192.     - The output format command-line option was changed to +fx where 'x'
  193.       denotes the output format.
  194.     - The display option +d now takes an optional extra character +dx
  195.       where 'x' is system-dependent.  This allows you to specify the graphics
  196.       mode by a command-line switch.
  197.     - The tokenizing pass has been removed.  It's now called directly by the
  198.       parser.
  199.     - The environment variable DKBOPT is used in addition to the trace.def file
  200.       and the command-line options.
  201.     - The numbers in the data file can now use full scientific notation
  202.       eg. 10.23e-4
  203.     - The +c option was added to continue an aborted trace.
  204.     - You can now colour or texture each component of the CSG's separately.
  205.     - Layered textures implemented (see the section on textures).
  206.     - When using GIF and IFF images for image mapping, you can now indicate that
  207.       specified registers are partially or completely transparent.
  208.     - Textures are now transformed whenever the object or shape they are attached
  209.       to are transformed.
  210.     - The texture CHECKER_TEXTURE has been added.
  211.     - All keywords relating to the appearance of the surface have been made
  212.       illegal in an object definition unless they are inside a TEXTURE block.
  213.     - The "basicshapes.data" file has been split up into shapes.dat, colors.dat,
  214.       and textures.dat.  These files have also been expanded with more useful
  215.       declarations.
  216.     - The -l command-line parameter has been added to support library
  217.       directories.
  218.  
  219. Version 2.11:
  220.     - Quartic surfaces (4th order) added by Alexander Enzmann.
  221.     - Parser now accepts ^Z as a whitespace
  222.     - Keyword END_SMOOTH_TRIANGLE added (previously, END_TRIANGLE was used.)
  223.  
  224. 3)  Getting Started
  225.  
  226. If you've been reading this document diligently until now, you'll probably
  227. want to go in and display some images to see what the raytracer does.
  228. Here's what you need to do:
  229.  
  230.    1) Put the file "sunset.dat" into your current directory.
  231.    2) Make sure the files "colors.dat", "shapes.dat", and "textures.dat"
  232.       are present.
  233.    3) Set up the default parameters.  This can be done by creating a file
  234.       called "trace.def" or by setting the DKBOPT environment variable.
  235.       In either case, use the following line (you may change these defaults
  236.       to suit your system):
  237.  
  238.          -w320 -h400 -v +f +d +p +x -a
  239.  
  240.       Meaning:
  241.          -v    - Don't be verbose, i.e. don't show line numbers during trace.
  242.          +f    - Write an output file in "dump" or "Targa" format (machine
  243.                  specific; IBM default is "Targa", Amiga default is "dump".
  244.          +d    - Display the image while rendering (on some systems, an
  245.                  additional character may follow this option to specify the
  246.                  graphics mode to use for the display).
  247.          -w320 - Make the image 320 pixels wide.
  248.          -h400 - Make the image 400 pixels high.
  249.          +p    - Prompt before exitting to let you look at the picture.
  250.          +x    - Allow exitting with a key hit before the trace is finished.
  251.          -a    - Don't Antialias (Antialiasing smooths out jagged edges).
  252.  
  253.    4) To render a scene, type:
  254.  
  255.          dkbxxx -isunset.dat -osunset.dis
  256.            ^
  257.            |_____ See note below:
  258.  
  259.  
  260.       Meaning:
  261.          dkbxxx - On different systems, the name of the executable may vary.
  262.                  Check to see what it is on your system.  For the Amiga,
  263.                  for example, two versions are supplied: dkb881 and dkbieee
  264.                  for systems with and without a floating-point accelerator.
  265.                  For the IBM, DKB.EXE is the 20286 optimized/uses 80287 math
  266.                  coprocessor version, and DKBNO87.EXE is the plain 8086/no
  267.          8087 math coprocessor version.
  268.  
  269.          -isunset.dat
  270.                - Read the input file "sunset.dat"
  271.  
  272.          -osunset.dis
  273.                - Call the output file "sunset.dis" - this is the usual file
  274.              name extension for "dump" format.  "Targa" format files
  275.          (default for IBM's) generally use the extension ".tga".
  276.  
  277.  
  278.    5) Once the image has been rendered, you must use a post-processor to
  279.       create the final viewable image file (i.e. an IFF or GIF file), unless
  280.       you possess 24-bit display hardware and can view the generated output
  281.       files directly.  The post-processor used depends on your system.  See
  282.       the section "Displaying the Images" for more details on post-processing
  283.       the image.
  284.  
  285. The following section gives a detailed description of the command-line
  286. options.
  287.  
  288.  
  289.  
  290. 4)  Command Line Parameters
  291.  
  292. This program is designed to be run from a command line.  The command-line
  293. parameters may be specified in any order.  Repeated parameters overwrite
  294. the previous values.  Parameters may also be specified in a file called
  295. "trace.def" or by the environment variable "DKBOPT".
  296.  
  297.      -wxxx     width of the picture in pixels
  298.                (On the Amiga, use 320 for full-sized pictures)
  299.      -hxxx     height of the picture in pixels
  300.                (On the Amiga, use 400 for full-sized pictures)
  301.  
  302.      +v        verbose option - print out the scan line number.
  303.      -v        disable verbose option
  304.  
  305.      +f[x]     produce an output file
  306.      -f        don't produce an output file
  307.  
  308.                If the +f option is used, the ray tracer will produce an
  309.                output file of the picture.  This output file describes each
  310.                pixel with 24 bits.  Currently, three formats of output files
  311.                are supported:
  312.  
  313.                   +fd    (default) - Dump format (QRT-style)
  314.                   +fr              - Raw format - three files for R, G and B.
  315.                   +ft              - Uncompressed Targa-24 format
  316.  
  317.  
  318.                Normally, a post-processor is required to create the final
  319.                finished image from the data file.  See the section on
  320.                "Displaying the Images" for details.
  321.  
  322.  
  323.      +d[x]     display the picture while tracing
  324.      -d        don't display the picture while tracing
  325.  
  326.                If the +d option is used, then the picture will be displayed
  327.                while the program performs the ray tracing.  On most systems,
  328.                this picture is not as good as the one created by the post-
  329.                processor because it does not try to make optimum choices for
  330.                the colour registers.
  331.  
  332.  
  333.                Depending on the system, a letter may follow the +d option to
  334.                specify the graphics mode to use.
  335.  
  336.                   All systems:
  337.                     +d      Default Format (same as +d0)
  338.  
  339.                   Amiga:
  340.                     +d0     Ham format
  341.                     +dE     Ham-E format
  342.  
  343.                   IBM:
  344.                     +d0     Autodetect (S)VGA type
  345.                     +d1     Standard VGA 320x200
  346.                     +d2     Simulated SVGA 360x480
  347.                     +d3     Tseng Labs 3000 SVGA 640x480
  348.                     +d4     Tseng Labs 4000 SVGA 640x480
  349.                     +d5     AT&T VDC600 SVGA 640x400
  350.                     +d6     Oak Technologies SVGA 640x480
  351.                     +d7     Video 7 SVGA 640x480
  352.                     +d8     Video 7 Vega (Cirrus) VGA 360x480
  353.                     +d9     Paradise SVGA 640x480
  354.                     +dA     Ahead Systems Ver. A SVGA 640x480
  355.                     +dB     Ahead Systems Ver. B SVGA 640x480
  356.                     +dC     Chips & Technologies SVGA 640x480
  357.                     +dD     ATI SGVA 640x480
  358.                     +dE     Everex SVGA 640x480
  359.                     +dF     Trident SVGA 640x480
  360.                     +dG     VESA Standard SVGA Adapter 640x480
  361.  
  362.  
  363.      +p        wait for prompt (IBM: beep and pause) before quitting
  364.      -p        finish without waiting
  365.  
  366.                The +p option makes the program wait for a carriage return
  367.                before exitting (and closing the graphics screen).  This gives
  368.                you time to admire the final picture before destroying it. 
  369.  
  370.  
  371.   -ifilename   set the input filename
  372.   -ofilename   set output filename
  373.  
  374.                If your input file is not "Object.dat", then you can use -i
  375.                to set the filename.  The default output filename will be
  376.                "data.dis" for dump mode, "data.red", "data.grn" or "data.blu"
  377.                for raw mode, and "data.tga" for Targa mode.  If you want a
  378.                different output file name, use the -o option.
  379.  
  380.                (on IBM's, the default extensions for raw mode are ".r8",
  381.                ".g8", and ".b8" to conform to PICLAB's "raw" format).
  382.  
  383.      +a[xxx]   anti-alias - xxx is an optional tolerance level (default 0.3)
  384.      -a        don't anti-alias
  385.  
  386.                The +a option enables adaptive anti-aliasing.  The number
  387.                after the +a option determines the threshold for the anti-
  388.                aliasing.  If the colour of a pixel differs from its neighbor
  389.                (to the left or above) by more than the threshold, then the
  390.                pixel is subdivided and super-sampled.
  391.  
  392.                If the anti-aliasing threshold is 0.0, then every pixel is
  393.                supersampled.  If the threshold is 1.0, then no anti-aliasing
  394.                is done.  Good values seem to be around 0.2 to 0.4.
  395.  
  396.                The super-samples are jittered to introduce noise and make the
  397.                pictures look better.  Note that the jittering "noise" is non-
  398.                random and repeatable in nature, based on an object's 3-D
  399.                orientation in space.  Thus, it's okay to use anti-aliasing for
  400.                animation sequences, as the anti-aliased pixels won't vary and
  401.                flicker annoyingly from frame to frame.
  402.            
  403.      +x        allow early exit by hitting any key (IBM only)
  404.      -x        lock in trace until finished        (IBM only)
  405.  
  406.                On the IBM, the -x option disables the ability to abort the
  407.                trace by hitting a key.  If you are unusually clumsy or have
  408.                CATS that stomp on your keyboard (like I do - AAC :-)), you
  409.                may want to use it.  If you are writing a file, the system
  410.                will recognize ^C at the end of line if the system "BREAK"
  411.                is "ON".  If you aren't writing a file, you won't be able to
  412.                abort the trace until it's done.
  413.  
  414.                This option was meant for big, long late-nite traces that take
  415.                ALL night (or longer!), and you don't want them interrupted by
  416.                anything less important than a natural disaster such as hur-
  417.                ricane, fire, flood, famine, etc.
  418.  
  419.      -bxxx     use an output file buffer of xxx kilobytes.
  420.                (if 0, flush the file on every line - this is the default)
  421.  
  422.                The -b option allows you to assign large buffers to the output
  423.                file.  This reduces the amount of time spent writing to the
  424.                disk and prevents unnecessary wear (especially for floppies). 
  425.                If this parameter is zero, then as each scanline is finished,
  426.                the line is written to the file and the file is flushed.  On
  427.                most systems, this operation insures that the file is written
  428.                to the disk so that in the event of a system crash or other
  429.                catastrophic event, at least part of the picture has been
  430.                stored properly on disk.
  431.  
  432.      +c        Continue Rendering
  433.  
  434.                If, for some reason, you abort a raytrace while it's in progress
  435.                or if you used the -exxx option (below) to end the raytrace
  436.                prematurely, you can use the +c option to continue the raytrace
  437.                when you get back to it.  This option reads in the previously
  438.                generated output file, displays the image to date on the screen,
  439.                then proceeds with the raytracing.  In many cases, this feature
  440.                can save you a lot of rendering time when things go wrong.
  441.  
  442.                (If you want to impress your friends with the speed of your
  443.                computer, take an image you've already rendered and use +c
  444.                in the command-line.  It renders REAL fast that way!  :-)
  445.  
  446.      -sxxx     start tracing at line number xxx.
  447.      -exxx     end tracing at line number xxx.
  448.  
  449.                The -s option allows you to start rendering an image starting
  450.                from a specific scan line.  This is useful for rendering part
  451.                of a scene to see what it looks like without having to render
  452.                the entire scene from the top.  Alternatively, you can render
  453.                groups of scanlines on different systems and concatenate them
  454.                later.  WARNING: If you are merging output files from different
  455.                systems, make sure that the random number generators are the
  456.                same.  If not, the textures from one will not blend in with the
  457.                textures from the other.  There is an example of a standard
  458.                ANSI "C" random number generator in the file IBM.C.  Cut it
  459.                out and paste it into your machine-specific .C file if you
  460.                plan to try "distributed processing" and are not sure if you
  461.                need this standardization.
  462.  
  463.                The -s option has no effect when continuing a raytrace using
  464.                the +c option.  The renderer will figure out where to restart.
  465.  
  466.      -qx       rendering quality
  467.  
  468.                The -q option allows you to specify the image rendering quality,
  469.                for quickly rendering images for testing.  The parameter can
  470.                range from 0 to 9.  The values correspond to the following
  471.                quality levels:
  472.  
  473.                0,1  Just show colours.  Ambient lighting only.
  474.                2,3  Show Diffuse and Ambient light
  475.                4,5  Render shadows
  476.                6,7  Create surface textures
  477.                8,9  Compute reflected, refracted, and transmitted rays.
  478.  
  479.                The default is -q9 (maximum quality) if not specified.
  480.  
  481.                You may specify the default parameters by modifying the file
  482.                "trace.def" which contains the parameters in the above format. 
  483.                This filename contains a complete command line as though you 
  484.                had typed it in, and is processed before any options supplied
  485.                on the command line are recognized.
  486.  
  487.  
  488.      -lpath    The -l option may be used to specify a "library" pathname to
  489.                look into for data files to include or for images.  Up to 10
  490.                -l options may be used to specify a search path.  The home
  491.                (current) directory will be searched first followed by the
  492.                indicated library directories in order.
  493.  
  494.      +z        The +z option is an undocumented feature.  You will not see any
  495.                references to it in this or any other documentation file for
  496.                DKBTrace.  In fact, no other section of the document will even
  497.                admit that it was mentioned here. If you really want to know
  498.                what it does, then you will have to look into the source code
  499.                (trace.c) and read the comment just above the +z option that
  500.                says "Turn on debugging print statements."  The full purpose
  501.                of this option will, therefore, be left as an exercise for
  502.                the reader, but believe me - it's nothing terribly exciting.
  503.  
  504.                (For those people who run the raytracer on super-fast systems
  505.                and want to slow it down, you may try this option. :-)
  506.  
  507.  
  508.  
  509. 5)  A Tutorial Walkthrough
  510.  
  511.  
  512. This section, is designed to get you up and running designing your own
  513. pictures without all the nit-picky details.  Once you've made a few
  514. of your own data files, you'll probably want to advance to the next
  515. section to fill in the gaps.
  516.  
  517. 5.1)    The First Image
  518.  
  519. Let's get right to the meat of the matter and create the data file for a
  520. simple picture.  Since raytracers thrive on spheres, that's what we'll render
  521. first.
  522.  
  523. First we have to create a viewpoint to tell the computer where our camera is
  524. and where it's looking.  To do this, we use 3D coordinates.  The usual
  525. coordinate system for DKBTrace has Y pointing up, X pointing to the right, and
  526. Z pointing into the screen as follows:
  527.  
  528.  
  529.                 ^Y
  530.                 |
  531.                 |   /Z
  532.                 |  /
  533.                 | /
  534.                 |/       X
  535.                 |-------->
  536.  
  537.  
  538.  
  539. Using your personal favorite text editor (i.e., user interface), create a file
  540. called "picture1.dat".  Now, type in the following (note:  The input is case
  541. sensitive, so be sure to get capital and lowercase letters correct):
  542.  
  543.       INCLUDE "colors.dat"
  544.       INCLUDE "shapes.dat"
  545.       INCLUDE "textures.dat"
  546.  
  547.       VIEW_POINT
  548.          LOCATION  <0 0 0>
  549.          DIRECTION <0 0 1>
  550.          UP        <0 1 0>
  551.          RIGHT     <1.33333 0 0>
  552.       END_VIEW_POINT
  553.  
  554.  
  555. The first INCLUDE statement reads in definitions for various useful colours.
  556. (Being a proud Canadian, I spell colour the proper way with a "u".  To avoid
  557. confusing the rest of the world, however, I've set up the raytracer to allow
  558. either spelling of the word.)
  559.  
  560. The second and third include statements read in some useful shapes and textures
  561. respectively.  When you get a chance, have a look through them to see
  562. but a few of the many possible shapes and textures available.
  563.  
  564. Include files may be nested, if you like.  The total pre-defined number of
  565. INCLUDE'd files (nested or not) per scene is 10.
  566.  
  567. Filenames specified in the INCLUDE statements will be searched for in the home
  568. (current) directory first, and if not found, will then be searched for in
  569. directories specified by any "-l" (library path) options active.  This would
  570. facilitate keeping all your "include" (.inc) files, shapes.dat, colors.dat,
  571. and textures.dat in an "include" subdirectory, and giving an "-l" option on
  572. the command line to where your library of include files are.
  573.  
  574.  
  575. This viewpoint declaration puts our camera at the center of the universe
  576. (LOCATION <0 0 0>) pointing into the Z direction (DIRECTION <0 0 1>) and with
  577. the camera being held upright (UP <0 1 0>).  The final term compensates for
  578. the aspect ratio of the screen (RIGHT <1.33333 0 0>).  If your computer has
  579. square pixels, you may want to change this to "RIGHT <1.0 0 0>".  For details
  580. on exactly how the camera works, see the section "How it All Works". 
  581.  
  582.  
  583. Now, let's place a red sphere into the world:
  584.  
  585.       OBJECT
  586.          SPHERE <0 0 3> 1 END_SPHERE
  587.          TEXTURE
  588.             COLOUR Red
  589.          END_TEXTURE
  590.       END_OBJECT
  591.  
  592. This sphere is 3 units away from the camera and has a radius of 1.  Note that
  593. any parameter that changes the appearance of the surface (as opposed to the
  594. shape of the surface) is called a texture parameter and MUST be placed into a
  595. TEXTURE-END_TEXTURE block.  In this case, we are just setting the colour.
  596.  
  597. One more detail - we need a light source:
  598.  
  599.       OBJECT
  600.          SPHERE <0 0 0> 1 END_SPHERE
  601.          TEXTURE
  602.             COLOUR White
  603.          END_TEXTURE
  604.          TRANSLATE <2 4 -3>     {This is 2 units to our right, 4 units above,}
  605.                                 {and 3 units behind our camera.}
  606.          LIGHT_SOURCE
  607.          COLOUR White
  608.       END_OBJECT
  609.  
  610.  
  611. (Note:  For light sources, ALWAYS declare them to be centered at the origin
  612. <0 0 0>, then use TRANSLATE to put them where you want.  If you don't do this,
  613. the light source won't work right. We must also specify the colour of the
  614. light source OUTSIDE the TEXTURE block because the renderer doesn't want to
  615. work out the whole surface colour just to get the colour of the light it
  616. emits.)
  617.  
  618. That's it!  Close the file and render a small picture of it:
  619.  
  620.       trace -w80 -h100 -f -ipicture1.dat
  621.  
  622. On the IBM, the command line would be:
  623.  
  624.       dkb -w80 -h50 -f -ipicture1.dat
  625.  
  626. (Or "dkbno87 (etc.)" if you have an 8086/8088 system or no math co-processor).
  627.  
  628. 5.2)    Phong Highlights
  629.  
  630. You've now rendered your first picture.  I know you want to run out and show
  631. all your friends how amazing your computer is to be able to generate such an
  632. incredible picture, but just wait a few minutes - you ain't seen nothin' yet.
  633. (For those people who complained that the picture took too long to draw, just
  634. wait - you ain't seen nothin' yet, either...)
  635.  
  636. Let's add a nice little specular highlight (shiny spot) to the sphere.  It
  637. gives it that neat "computer graphics" look.  Change the definition of the
  638. sphere to this:
  639.  
  640.       OBJECT
  641.          SPHERE <0 0 3> 1 END_SPHERE
  642.          TEXTURE
  643.             COLOUR Red
  644.             PHONG 1.0
  645.          END_TEXTURE
  646.       END_OBJECT
  647.  
  648. Now render this.  In all seriousness, the PHONG highlight does add a lot of
  649. credibility to the picture.  You'll probably want to use it in many of your
  650. pictures.
  651.  
  652. 5.3)    Textures
  653.  
  654. One of the really nice features of this raytracer is its sophisticated
  655. textures.  Change the definition of our sphere to the following and then
  656. re-render it:
  657.  
  658.       OBJECT
  659.          SPHERE <0 0 3> 1 END_SPHERE
  660.          TEXTURE
  661.             Dark_Wood
  662.             SCALE <0.2 0.2 0.2>
  663.             PHONG 1.0
  664.          END_TEXTURE
  665.       END_OBJECT
  666.  
  667.  
  668. The textures are set up by default to give you one "feature" across a sphere
  669. of radius 1.0.  A "feature" is roughly defined as a colour transition.  For
  670. example, a wood texture would have one band on a sphere of radius 1.0.  By
  671. scaling the wood by <0.2 0.2 0.2>, we shrink the texture to give us about five
  672. bands. Please note that this is not a hard and fast rule.  It's only meant to
  673. give you a rough idea for the scale to use for a texture.  Don't start
  674. reporting problems if you get three bands instead of five.  This rule of thumb
  675. just puts you in the ballpark.
  676.  
  677. One note about the SCALE operation.  You can magnify or shrink along each
  678. direction separately.  The first term tells how much to magnify or shrink in
  679. the left-right direction.  The second term controls the up-down direction and
  680. the third term controls the front-back direction.
  681.  
  682. I encourage you to look through the "textures.dat" file to see what textures
  683. are defined there and try them out.  Some of them are quite spectacular.
  684.  
  685. 5.4)    Other Shapes
  686.  
  687. So far, we've just defined spheres.  There are several other kinds of shapes
  688. that can be rendered by DKBTrace.  Let's try one out with a computer graphics
  689. standard - a checkered floor.  Add the following object to your .dat file:
  690.  
  691.       OBJECT
  692.          PLANE <0.0 1.0 0.0> -1.0 END_PLANE
  693.          TEXTURE
  694.             CHECKER
  695.                COLOUR RED 1.0
  696.                COLOUR BLUE 1.0
  697.          END_TEXTURE
  698.       END_OBJECT
  699.  
  700.  
  701. The object defined here is an infinite plane.  The vector <0.0 1.0 0.0> is the
  702. surface normal of the plane (i.e., if you where standing on the surface, the
  703. normal points straight up.)  The number afterward is the distance that the
  704. plane is displaced along the normal - in this case, we move the floor down one
  705. unit so that the sphere (radius 1) is resting on it.  The checker texture
  706. specifies the two colours to use in the checker pattern.
  707.  
  708. Looking at the floor, you'll notice that the wooden ball casts a shadow on the
  709. floor.  Shadows are calculated accurately (well, almost - more later) by the
  710. raytracer.
  711.  
  712.  
  713. Another kind of shape you can use is called a quadric surface.  To be totally
  714. honest, the shapes you've been using so far have been quadrics.  Spheres and
  715. planes are types of quadric surfaces.  There are many other quadric surfaces
  716. however.  These are all described by a certain kind of mathematical formula
  717. (see the section on Quadrics in the next chapter).  They include cylinders,
  718. cones, paraboloids (like a satellite dish), hyperboloids (saddle-shaped) and
  719. ellipsoids as well as the spheres and planes we've used so far.
  720.  
  721. All quadrics except for ellipsoids and spheres are infinite in at least one
  722. direction.  For example, a cylinder has no top or bottom - it goes to infinity
  723. at each end.  Quadrics all have one common feature - if you draw any straight
  724. line through a quadric, it will hit the surface at most twice.  A torus
  725. (donut), for example, is not a quadric since a line can hit the surface up to
  726. four times going through.
  727.  
  728. Enough talk - let's render one of these "quadrics"...  While we're at it,
  729. we'll add a few features to the surface.  Add the following definition to your
  730. .dat file:
  731.  
  732.       OBJECT
  733.          QUADRIC Cylinder_Y END_QUADRIC
  734.          TEXTURE
  735.             COLOUR GREEN 0.5
  736.             REFLECTION 0.5
  737.          END_TEXTURE
  738.          SCALE <0.4  0.4  0.4>
  739.          TRANSLATE <2 0 5>
  740.       END_OBJECT
  741.  
  742.  
  743. This object is a cylinder along the Y (up-down) axis.  It's green in colour
  744. and has a mirrored surface (hence the reflection of 0.5) this means that half
  745. the light coming from the sphere is reflected from other objects in the room.
  746. A reflection of 1.0 is a perfect mirror.
  747.  
  748. The object has been shrunk by scaling it by <0.4 0.4 0.4>.  Note that since
  749. the cylinder is infinite along the Y axis, the middle term is kind of
  750. pointless.  One four tenths of infinity is still infinity.  (Don't use 0,
  751. though.  That will definitely cause a fatal crash!)  Finally, the cylinder has
  752. been moved back and to the right so you can see it more clearly.
  753.  
  754. 5.5)    Constructive Solid Geometry
  755.  
  756. The shapes we've talked about so far are nice, but not terribly useful on
  757. their own for making realistic scenes.  It's hard to make interesting objects
  758. when you're limited to spheres, infinite cylinders, infinite planes, and so
  759. forth.  
  760.  
  761. Constructive Solid Geometry (CSG) is a technique for taking these simple
  762. building blocks and combining them together.  You can use a cylinder to bore a
  763. hole through a sphere.  You can use planes to cap cylinders and turn them into
  764. flat circular disks (that are no longer infinite).
  765.  
  766. Before getting into CSG, however, let me talk about inside and outside.  Every
  767. primitive (except triangles - I'll talk about this later) divides the world
  768. into two regions.  One region is inside the surface and one is outside.  So,
  769. given any point in space, you can say it's either inside or outside any
  770. particular primitive object (well, it could be exactly on the surface, but
  771. usually numerical inaccuracies will put it to one side or the other).  Even
  772. planes have an inside and an outside.  By definition, the surface normal of
  773. the plane points towards the outside of the plane.  (For a simple floor, for
  774. example, the space above the floor is "outside" and the space below the floor
  775. is "inside".  For simple floors this in unimportant, but for planes as parts
  776. of CSG's it becomes much more important).
  777.  
  778. CSG uses the concepts of inside and outside to combine shapes together.  Take
  779. the following situation:
  780.  
  781. Note: The diagrams shown here demonstrate the concepts in 2D and are indended
  782.       only as an analogy to the 3D case.  Note that the triangles supported by
  783.       DKBTrace cannot be used in CSG (except for unions) since they have no
  784.       inside and outside.
  785.  
  786.   * = Shape A
  787.   % = Shape B
  788.  
  789.                      *  0
  790.                     * *    %
  791.                    *   *  % %
  792.                   *     *%   %
  793.                  *  1   %*    %
  794.                 *      %  * 2  %
  795.                *      % 3  *    %
  796.               *******%*******    %
  797.                     %             %
  798.                    %%%%%%%%%%%%%%%%%
  799.  
  800.  
  801. There are three CSG operations you can use:
  802.  
  803.    1) UNION A B END_UNION
  804.         A point is inside the union if it is inside A OR it's inside B
  805.         (or both).  This gives an "additive" effect to the component
  806.         objects:
  807.  
  808.                      *
  809.                     * *    %
  810.                    *   *  % %
  811.                   *     *%   %
  812.                  *  1       2 %
  813.                 *       3      %
  814.                *                %
  815.               *******%           %
  816.                     %             %
  817.                    %%%%%%%%%%%%%%%%%
  818.  
  819.  
  820.    2) INTERSECTION A B END_INTERSECTION
  821.         A point is inside the intersection if it's inside both A AND B.  This
  822.         "logical AND's" the shapes and gets the common part, most useful for
  823.         "clipping" infinite shapes off, etc:
  824.  
  825.  
  826.                         %*
  827.                        %  *
  828.                       % 3  *
  829.                      %*******
  830.  
  831.    3) DIFFERENCE A B END_DIFFERENCE
  832.         A point is inside the difference if it's inside A but not inside B.
  833.         The results is a "subtraction" of the 2nd shape from the first shape:
  834.  
  835.  
  836.                      *
  837.                     * *
  838.                    *   *
  839.                   *     *
  840.                  *  1   %
  841.                 *      %
  842.                *      %
  843.               *******%
  844.  
  845. Let's give a concrete example by drilling a yellow hole through our sphere.
  846. Go to the definition of the sphere and change it to read the following:
  847.  
  848.  
  849.       OBJECT
  850.          DIFFERENCE
  851.             SPHERE <0 0 3> 1 END_SPHERE
  852.             QUADRIC
  853.                Cylinder_Z
  854.                SCALE <0.2 0.2 0.2>
  855.                COLOUR Yellow
  856.             END_QUADRIC
  857.          END_DIFFERENCE
  858.          TEXTURE
  859.             Dark_Wood
  860.             SCALE <0.2 0.2 0.2>
  861.             PHONG 1.0
  862.          END_TEXTURE
  863.       END_OBJECT
  864.  
  865. One more point about CSG operations.  You can flip a shape inside-out by
  866. putting the keyword INVERSE into the shape's definition.  This keyword will
  867. not change the appearance of the shape unless you're using CSG.  In the case
  868. of CSG, it gives you more flexibility.  For example:
  869.  
  870.    INTERSECTION B A-INVERSE END_INTERSECTION
  871.  
  872.                    
  873.                            %
  874.                           % %
  875.                          %   %
  876.                          *    %
  877.                           * 2  %
  878.                            *    %
  879.                      %*******    %
  880.                     %             %
  881.                    %%%%%%%%%%%%%%%%%
  882.  
  883. (Note that a DIFFERENCE is really just an INTERSECTION of one shape with the
  884. INVERSE of another.  This happens to be how DIFFERENCE is actually implemented
  885. in the code.)
  886.  
  887. 5.6)    Advanced Textures
  888.  
  889. The textures available in DKBTrace are 3D solid textures.  This means that the
  890. texture defines a colour for any 3D point in space.  Just like a real block of
  891. marble or wood, there is colour all through the block - you just can't see it
  892. until you carve away the wood or marble that's in the way.  Similarly, with a
  893. 3D solid texture, you don't see all the colours in the texture - you only see
  894. the colours that happen to be visible at the surface of the object.
  895.  
  896. As you've already seen, you can scale, translate, and rotate textures.  In
  897. fact, you could make an animation in which the objects stay still and the
  898. textures translate and rotate through the object.  The effect would be like
  899. watching a time-lapse film of a cloudy sky - the clouds would not only move,
  900. but they would also change shape smoothly.
  901.  
  902. Often, textures are perturbed by noise.  This "turbulence" distorts the
  903. texture so it doesn't look quite so perfect.  Try changing the sphere in the
  904. above example to have the following texture:
  905.  
  906.          TEXTURE
  907.             Dark_Wood
  908.             TURBULENCE 0.0
  909.             SCALE <0.2 0.2 0.2>
  910.             PHONG 1.0
  911.          END_TEXTURE
  912.  
  913. When you compare this with the original image, you'll see that the pattern is
  914. much more boring.
  915.  
  916. Finally, many textures use colour maps.  A colour map translates a number
  917. between 0.0 and 1.0 into a colour.  The number typically represents the
  918. distance into a vein of colour - the further into the vein you get, the more
  919. the colour changes.  Here's a typical colour map.  Try this out on the sphere
  920. defined above by changing the definition to this:
  921.  
  922.  
  923.       OBJECT
  924.          SPHERE <0 0 3> 1 END_SPHERE
  925.          TEXTURE
  926.             WOOD
  927.             SCALE <0.2 0.2 0.2>
  928.             COLOUR_MAP
  929.                 [0.0 0.3  COLOUR Red   COLOUR Green]
  930.                 [0.3 0.6  COLOUR Green COLOUR Blue]
  931.                 [0.6 1.01 COLOUR Blue  COLOUR Red]
  932.             END_COLOUR_MAP
  933.             PHONG 1.0
  934.          END_TEXTURE
  935.       END_OBJECT
  936.  
  937.  
  938. This means that as the texture enters into a vein of wood, it changes colour
  939. smoothly from red to green, from green to blue, and from blue to red again.
  940. As it leaves the vein, the transition occurs in reverse.  (Since there is no
  941. turbulence on the wood by default, the veins of colour should show up quite
  942. well.)
  943.  
  944. You can get more "bang for your buck" from textures by using ALPHA properties
  945. of colour.  Every colour you define in DKBTrace is a combination of red,
  946. green, blue and alpha.  The red, green and blue are simple enough.  The alpha
  947. determines how transparent that colour is.  A colour with an alpha of 1.0 is
  948. totally transparent.  A colour with an alpha of 0.0 is totally opaque.  Here's
  949. a neat texture to try:
  950.  
  951.  
  952.    TEXTURE
  953.       TURBULENCE 0.5
  954.       BOZO
  955.       COLOUR_MAP
  956.           { transparent to transparent }
  957.           [0.0 0.6   COLOUR RED 1.0 GREEN 1.0 BLUE 1.0 ALPHA 1.0
  958.                      COLOUR RED 1.0 GREEN 1.0 BLUE 1.0 ALPHA 1.0]
  959.  
  960.           { transparent to white }
  961.           [0.6 0.8   COLOUR RED 1.0 GREEN 1.0 BLUE 1.0 ALPHA 1.0
  962.                      COLOUR RED 1.0 GREEN 1.0 BLUE 1.0]
  963.  
  964.           { white to grey }
  965.           [0.8 1.001 COLOUR RED 1.0 GREEN 1.0 BLUE 1.0
  966.                      COLOUR RED 0.8 GREEN 0.8 BLUE 0.8]
  967.       END_COLOUR_MAP
  968.       SCALE <0.4  0.08  0.4>
  969.    END_TEXTURE
  970.  
  971. This is my (famous) cloud texture.  It creates white clouds with grey linings.
  972. The texture is transparent in the places where the clouds disappear so you can
  973. see through it to the objects that are behind.
  974.  
  975. Now for one more feature which is new for 2.10 (hold onto your hats!)  You can
  976. now layer textures one on top of another to create more sophisticated textures.
  977. For example, suppose I want a wood-coloured cloudy texture.  What I do is put
  978. the wood texture down first followed by my cloud texture.  Wherever the cloud
  979. texture is transparent, the wood texture shows through.  Change your sphere to
  980. the following and you'll see.
  981.  
  982.  
  983.       OBJECT
  984.          SPHERE <0 0 3> 1 END_SPHERE
  985.          TEXTURE        { This is the wood texture we used earlier. }
  986.             Dark_Wood
  987.             TURBULENCE 0.0
  988.             SCALE <0.2 0.2 0.2>
  989.             PHONG 1.0
  990.          END_TEXTURE
  991.          TEXTURE        { This is the cloud texture we just defined. }
  992.             TURBULENCE 0.5
  993.             BOZO
  994.             COLOUR_MAP
  995.                 { transparent to transparent }
  996.                 [0.0 0.6   COLOUR RED 1.0 GREEN 1.0 BLUE 1.0 ALPHA 1.0
  997.                            COLOUR RED 1.0 GREEN 1.0 BLUE 1.0 ALPHA 1.0]
  998.       
  999.                 { transparent to white }
  1000.                 [0.6 0.8   COLOUR RED 1.0 GREEN 1.0 BLUE 1.0 ALPHA 1.0
  1001.                            COLOUR RED 1.0 GREEN 1.0 BLUE 1.0]
  1002.       
  1003.                 { white to grey }
  1004.                 [0.8 1.001 COLOUR RED 1.0 GREEN 1.0 BLUE 1.0
  1005.                            COLOUR RED 0.8 GREEN 0.8 BLUE 0.8]
  1006.             END_COLOUR_MAP
  1007.             SCALE <0.4  0.08  0.4>
  1008.          END_TEXTURE
  1009.       END_OBJECT
  1010.  
  1011. Each successive texture is layered on top of the previous textures.  In the
  1012. places where you can see through the upper texture, you see through to the
  1013. lower textures.
  1014.  
  1015.  
  1016. 5.7)    Walk-through Wrap-up
  1017.  
  1018. In this walk-through, I've only tried to show the highlights of the raytracer
  1019. without getting into all possible options and features.  To get all of those,
  1020. you'll have to read through the following section on the Object Description
  1021. Language.  Hopefully it will be fairly straight forward now that you have a
  1022. feel for the language and how it works.  Hopefully you'll find that the
  1023. textual interface provided by DKBTrace isn't quite as scary as people think at
  1024. first.
  1025.  
  1026.  
  1027.  
  1028. 6)  The Scene Description Language
  1029.  
  1030. The Scene Description Language allows the user to describe the world in a
  1031. readable and convenient way.
  1032.  
  1033. The language delimits comments by the left and right braces ({ and }). Nested
  1034. comments are allowed, but no sane person uses them anyway, right?
  1035.      
  1036. The language allows include files to be specified by placing the line:
  1037.  
  1038.     INCLUDE "filename"
  1039.  
  1040. at any point in the input file (Include files may be nested).  The filename
  1041. must be enclosed in double quotes and may be up to 40 characters long,
  1042. including the two double-quote (") characters.  You may have at most 10
  1043. INCLUDE'd files per scene trace, whether nested or not.
  1044.  
  1045.  
  1046.  
  1047. 6.1)    The Basic Data Types
  1048.  
  1049.      There are several basic types of data:
  1050.  
  1051. 6.1.1)  Float
  1052. Floats are represented by an optional sign (-), some digits, an optional
  1053. decimal point, and more digits.  Version 2.10 now supports the "e" notation
  1054. for exponents.  The following are valid floats:
  1055.  
  1056.      1.0  -2.0  -4  34  3.4e6 2e-5
  1057.  
  1058. 6.1.2)  Vector
  1059. Vectors are arrays of three floats.  They are bracketed by angle brackets
  1060. ( < and > ), and the three terms usually represent x, y, and z.  For example:
  1061.  
  1062.      < 1.0  3.2  -5.4578 >
  1063.  
  1064. Vectors typically refer to relative points.  For example, the vector:
  1065.  
  1066.      <1 2 3>
  1067.  
  1068. means the point that's 1 unit to the right, 2 units up, and 3 units in front.
  1069. "Of what?" you ask?  Well, usually it's relative to the center of the
  1070. "universe" at <0 0 0>.
  1071.  
  1072. In a few places here and there, vectors are used as a convenient notation but
  1073. don't represent a point in space. This is the case for the transformations
  1074. TRANSLATE, ROTATE, and SCALE.
  1075.  
  1076.    TRANSLATE <x y z>       - move the object x units to the right,
  1077.                              y units up, and z units away from us.
  1078.  
  1079.    SCALE     <xs ys zs>    - scale the object by xs units in the left/right
  1080.                              direction, ys units in the up/down direction
  1081.                              and zs units in the front/back direction.
  1082.  
  1083.    ROTATE    <xr yr zr>    - rotate the object xr degrees about the X axis,
  1084.                              then yr degrees about the Y axis, then zr degrees
  1085.                              about the Z axis.  (note that the order matters)
  1086.  
  1087. To work out the rotation directions, you must perform the famous "Computer
  1088. Graphics Aerobics" exercise.  Hold up your left hand.  point your thumb in the
  1089. positive direction of the axis you want to rotate about.  Your fingers will
  1090. curl in the positive direction of rotation.  This is the famous "left-hand
  1091. coordinate system".  If you want to use a right-hand system, as some CAD
  1092. systems do, the RIGHT vector in the VIEW_POINT needs to be changed.  See the
  1093. detailed description of the VIEW_POINT, and use your right hand for the
  1094. "Aerobics".
  1095.                        _
  1096.                      _| |_  _
  1097.                    _| | | |/ \
  1098.                   | | | | |  |
  1099.                   | | | | |  V
  1100.                   | | | | |   
  1101.                   | | | | |
  1102.                   |       \____
  1103.                   |         ___|
  1104.                   \        /
  1105.                    |      /
  1106.                    |     |
  1107.                    |     |
  1108.                    |     |
  1109.  
  1110.  
  1111. 6.1.3)  Colour
  1112.  
  1113. A colour consists of a red component, a green component, a blue component, and
  1114. possibly an alpha component.  All four components are floats in the range 0.0
  1115. to 1.0.  The syntax for Colours is the word "COLOUR" followed by any or all of
  1116. the RED, GREEN, BLUE or ALPHA components in any order.
  1117.  
  1118. For example:
  1119.  
  1120.      COLOUR  RED 1.0  GREEN 1.0  BLUE 1.0
  1121.      COLOUR  BLUE 0.56
  1122.      COLOUR  GREEN 0.45 RED 0.3 BLUE 0.1 ALPHA 0.3
  1123.  
  1124. Alpha is a transparency indicator.  If an object's colour contains some
  1125. transparency, then you can see through it.  If Alpha is 0.0, the object is
  1126. totally opaque.  If it is 1.0, it is totally transparent.
  1127.  
  1128. For those people who spell "Colour" the American way as "Color", the program
  1129. will also accept "COLOR" as equivalent to "COLOUR" in all instances.
  1130.  
  1131.  
  1132. 6.1.4)  Colour Maps
  1133.  
  1134. For wood, marble, spotted, agate, granite, and gradient texturing, the user
  1135. may specify arbitrary colours to use for the texture.  This is done by a
  1136. colour map or "colour spline".  When the object is being textured, a number
  1137. between 0.0 and 1.0 is generated which is then used to form the colour of the
  1138. point.  A Colour map specifies the mapping used to change these numbers into
  1139. colours.  The syntax is as follows:
  1140.  
  1141.      COLOUR_MAP
  1142.           [start_value end_value colour1 colour2]
  1143.           [start_value end_value colour1 colour2]
  1144.           ...
  1145.      END_COLOUR_MAP
  1146.  
  1147. The numeric value between 0.0 and 1.0 is located in the colour map and the
  1148. final colour is calculated by a linear interpolation (a smooth blending)
  1149. between the two colours in the located range.
  1150.  
  1151.  
  1152. 6.2)    The More Complex Data Types
  1153.  
  1154. 6.2.1)  Declare
  1155.  
  1156. The data types used to describe the objects in the world are a bit more
  1157. difficult to describe.  To make this task easier, the program allows users to
  1158. describe these types in two ways.  The first way is to define it from first
  1159. principles specifying all of the required parameters.  The second way allows
  1160. the user to define an object as a modification of another object (the other
  1161. object is usually defined from first principles but is much simpler).  Here's
  1162. how it works:
  1163.  
  1164. You can use the term DECLARE to declare a type of object with a certain
  1165. description.  The object is not included in the world but is made known to the
  1166. program that it can be used as a "prototype" for defining other objects by the
  1167. name given, as this basic example shows:
  1168.  
  1169.      DECLARE Sphere = QUADRIC   { First Principles definition of a sphere }
  1170.           <1.0 1.0 1.0>
  1171.           <0.0 0.0 0.0>
  1172.           <0.0 0.0 0.0>
  1173.           -1.0
  1174.      END_QUADRIC
  1175.  
  1176. To then reference the declaration elsewhere in your source file or in another
  1177. included one, and to actually include the object in the world, you would
  1178. define the object using the DECLARE'd object's name, like this:
  1179.  
  1180.      OBJECT
  1181.           QUADRIC Sphere
  1182.                SCALE <20.0 20.0 20.0>
  1183.           END_QUADRIC
  1184.           TEXTURE
  1185.              COLOUR White
  1186.              AMBIENT 0.2
  1187.              DIFFUSE 0.8
  1188.           END_TEXTURE
  1189.      END_OBJECT
  1190.  
  1191. The real power of declaration becomes apparent when you declare several
  1192. primitive types of objects and then define an object with several component
  1193. shapes, using either COMPOSITE methods or the CSG methods INTERSECTION, UNION,
  1194. or DIFFERENCE.  Also, using the DECLARE keyword to pre- define textures can
  1195. make several objects share a texture without the need for each object to store
  1196. a duplicate copy of the same texture, for more efficient memory usage.
  1197. Example:
  1198.  
  1199.      DECLARE Dull TEXTURE  { A Basic, Boring Texture }
  1200.           AMBIENT 0.3
  1201.           DIFFUSE 0.7
  1202.      END_TEXTURE
  1203.  
  1204.      OBJECT         { A Hot dog in a Hamburger Bun (?) }
  1205.           UNION
  1206.                QUADRIC Sphere
  1207.                     SCALE <20.0, 10.0, 20.0>
  1208.             TEXTURE Dull END_TEXTURE
  1209.                END_QUADRIC
  1210.                QUADRIC Cylinder_X
  1211.                     SCALE <40.0, 20.0, 20.0>
  1212.             TEXTURE Dull END_TEXTURE
  1213.                END_QUADRIC
  1214.           END_UNION
  1215.      END_OBJECT
  1216.  
  1217.  
  1218. Layered textures, new to version 2.10, may also be DECLARE'd.  The DECLARE
  1219. mechanism keeps looking for successive TEXTURE definitions and will layer them
  1220. onto the same texture until another DECLARE (or any other statement except
  1221. another TEXTURE) is encountered in the input data file.  For example:
  1222.  
  1223.  DECLARE Cloud_Wood TEXTURE  { This is the cloudy wood texture used earlier. }
  1224.    Dark_Wood
  1225.    TURBULENCE 0.0
  1226.    SCALE <0.2 0.2 0.2>
  1227.    PHONG 1.0
  1228.  END_TEXTURE
  1229.  TEXTURE        { This is layered onto the wood texture just defined. }
  1230.    TURBULENCE 0.5
  1231.    BOZO
  1232.    COLOUR_MAP
  1233.      { transparent to transparent }
  1234.      [0.0 0.6   COLOUR RED 1.0 GREEN 1.0 BLUE 1.0 ALPHA 1.0
  1235.      COLOUR RED 1.0 GREEN 1.0 BLUE 1.0 ALPHA 1.0]
  1236.  
  1237.      { transparent to white }
  1238.      [0.6 0.8   COLOUR RED 1.0 GREEN 1.0 BLUE 1.0 ALPHA 1.0
  1239.      COLOUR RED 1.0 GREEN 1.0 BLUE 1.0]
  1240.  
  1241.      { white to grey }
  1242.      [0.8 1.001 COLOUR RED 1.0 GREEN 1.0 BLUE 1.0
  1243.      COLOUR RED 0.8 GREEN 0.8 BLUE 0.8]
  1244.    END_COLOUR_MAP
  1245.    SCALE <0.4  0.08  0.4>
  1246.  END_TEXTURE
  1247.  
  1248. DECLARE (etc.) { Ends the definition of the layered "Cloud_Wood" texture. }
  1249.  
  1250. 6.2.2)  Viewpoint
  1251.  
  1252. The viewpoint tells the ray tracer the location and orientation of the camera.
  1253. The viewpoint is described by four vectors - Location, Direction, Up, and
  1254. Right.  Location determines where the camera is located.  Direction determines
  1255. the direction that the camera is pointed.  Up determines the "up" direction of
  1256. the camera.  Right determines the direction to the right of the camera.
  1257.  
  1258. A first principle's declaration of a viewpoint would look like this:
  1259.      
  1260.      VIEWPOINT
  1261.           LOCATION < 0.0  0.0  0.0>
  1262.           DIRECTION < 0.0  0.0  1.0>
  1263.           UP < 0.0  1.0  0.0 >
  1264.           RIGHT < 1.0  0.0  0.0>
  1265.      END_VIEWPOINT
  1266.  
  1267. This format becomes cumbersome, however, because the vectors must be hand
  1268. calculated.  This is especially difficult when the vectors are not lined up
  1269. with the X, Y, and Z axes as they are in the above example. To make it easier
  1270. to define the viewpoint, you can define one viewpoint, then modify the
  1271. description.  For example,
  1272.  
  1273.      VIEWPOINT
  1274.           LOCATION < 0.0  0.0  0.0>
  1275.           DIRECTION < 0.0  0.0  1.0>
  1276.           UP < 0.0  1.0  0.0 >
  1277.           RIGHT < 1.0  0.0  0.0 >
  1278.           TRANSLATE < 5.0  3.0  4.0 >
  1279.           ROTATE < 30.0  60.0  30.0 >
  1280.      END_VIEWPOINT
  1281.  
  1282. In this example, the viewpoint is created, then translated to another point in
  1283. space and rotated by 30 degrees about the X axis, 60 degrees about the Y axis,
  1284. and 30 degrees about the Z axis.
  1285.  
  1286. Unfortunately, even this is somewhat cumbersome.  So, in version 2.0 and
  1287. above, you can now specify two more parameters:
  1288.  
  1289.           SKY <vector>
  1290.           LOOK_AT <vector>
  1291.  
  1292. The SKY keyword tells the viewpoint where the sky is.  It tries to keep the
  1293. camera's UP direction aligned as closely as possible to the sky. The LOOK_AT
  1294. keyword tells the camera to look at a specific point.  The camera is rotated
  1295. as required to point directly at that point.  By changing the SKY vector, you
  1296. can twist the camera while still looking at the same point.
  1297.  
  1298. One subtle point:  the SKY direction is not necessarily the same as the UP
  1299. direction.  For example, consider the following situation:
  1300.  
  1301.           S^
  1302.            | /U
  1303.            |/
  1304.            C
  1305.             \
  1306.              \
  1307.               \
  1308.                O
  1309.  
  1310. If you said that the camera C has a SKY direction S and is looking at O, the
  1311. up direction will not point to the sky.  UP's like putting an antenna on your
  1312. camera.  If you point the camera downwards, the antenna will no longer point
  1313. straight up.
  1314.  
  1315. The RIGHT vector, as was mentioned previously, controls the aspect ratio of
  1316. the screen display.  It also determines the "handedness" of the coordinate
  1317. system in use.  A normal (left-handed) RIGHT statement would be:
  1318.  
  1319.     RIGHT < 1.3333 0.0 0.0 >
  1320.  
  1321. To use a right-handed coordinate system, as is popular in some CAD programs
  1322. and some other ray-tracers, such as Sculpt for the Amiga, use a RIGHT like:
  1323.  
  1324.     RIGHT < -1.3333 0.0 0.0 >
  1325.  
  1326. Some CAD systems also have the peculiar conception that the Z axis is the
  1327. "elevation" and is the "UP" direction instead of the Y axis.  If this is the
  1328. case you will want to change your "UP" statement to:
  1329.  
  1330.     UP < 0.0 0.0 1.0 >
  1331.  
  1332.  
  1333. Note that a pinhole camera model is used, so no focus or depth-of-field
  1334. effects are supported at this time.  For more detailed information on the
  1335. camera model, see the section "How it All Works."
  1336.  
  1337. 6.2.3)  Fog
  1338.  
  1339. Version 2.0 of the raytracer includes the ability to render fog.  To add fog
  1340. to a scene, place the following declaration outside of any object definitions:
  1341.  
  1342.      FOG
  1343.           COLOUR  {... the fog colour}
  1344.           200.0   {... the fog distance}
  1345.      END_FOG
  1346.  
  1347. The fog to colour ratio is calculated as 1-exp(-depth/distance), so at
  1348. depth 0, the colour is pure (1.0) with no fog (0.0).  At the fog distance,
  1349. you'll get 63% of the colour from the object's colour and 37% from the
  1350. fog colour.
  1351.  
  1352. 6.2.4)  Shapes
  1353.  
  1354. Shapes describe the shape of an object without mentioning any surface
  1355. characteristics like colour, surface lighting and reflectivity.
  1356.  
  1357. 6.2.4.1)    Quadric Shapes
  1358.  
  1359. The most general shape used by this system is called a Quadric Surface.
  1360. Quadric Surfaces can produce shapes like spheres, cones, cylinders,
  1361. paraboloids (dish shapes), and hyperboloids (saddle or hourglass shapes).
  1362.  
  1363. The easiest way to define these shapes is to include the standard file
  1364. "shapes.dat" into your program and to transform these shapes (using TRANSLATE,
  1365. ROTATE, and SCALE) into the ones you want.  To be complete, however, I will
  1366. describe the mathematical principles behind quadric surfaces.  Those who are
  1367. not interested in the mathematical details can skip to the next section. 
  1368.  
  1369. The quadric:
  1370.  
  1371.       QUADRIC
  1372.           <A B C>
  1373.           <D E F>
  1374.           <G H I>
  1375.           J
  1376.       END_QUADRIC
  1377.  
  1378. defines a surface in three dimensions which satisfies the following equation:
  1379.  
  1380.  
  1381.        A y**2  + B y**2  + C z**2
  1382.      + D xy    + E xz    + F yz
  1383.      + G x     + H y     + I z    + J = 0
  1384.  
  1385.  
  1386. (Did you really want to know that?  I didn't think so. :-)  DKB)
  1387.  
  1388. Different values of A,B,C,...J will give different shapes.  So, if you take
  1389. any three dimensional point and use its x, y, and z coordinates in the above
  1390. equation, the answer will be 0 if the point is on the surface of the object.
  1391. The answer will be negative if the point is inside the object and positive if
  1392. the point is outside the object.  Here are some examples:
  1393.  
  1394.      X**2 + Y**2 + Z**2 - 1 = 0     Sphere
  1395.      X**2 + Y**2 - 1 = 0            Cylinder along the Z axis
  1396.      X**2 + Y**2 - Z**2 = 0         Cone along the Z axis
  1397.  
  1398.  
  1399. 6.2.4.2)    Quadric surfaces the easy way
  1400.  
  1401. Now that doesn't sound so hard, does it?  Well, actually, it does.  Only the
  1402. hard-core graphics fanatic would define his objects using the QUADRIC
  1403. definition directly.  Even I don't do it that way and I know how it works
  1404. (Well, at least I worked it out once or twice :-) - DKB).
  1405.  
  1406. Fortunately, there is an easier way. The file "shapes.dat" already includes
  1407. the definitions of many quadric surfaces.  They are centered about the origin
  1408. < 0 0 0 > and have a radius of 1.  To use them, you can define shapes simply
  1409. as follows:
  1410.  
  1411.       INCLUDE "colors.dat"
  1412.       INCLUDE "shapes.dat"      { This is the important one for this example }
  1413.       INCLUDE "textures.dat"
  1414.  
  1415.      QUADRIC
  1416.           Cylinder_X
  1417.           SCALE < 50.0  50.0  50.0 >
  1418.           ROTATE < 30.0  10.0  45.0 >
  1419.           TRANSLATE < 2.0  5.0  6.0 >
  1420.      END_QUADRIC
  1421.  
  1422.  
  1423. You may have as many transformation lines (scale, rotate, and translate) as
  1424. you like in any order.  Usually, however, it's easiest to do a scale first,
  1425. one or more rotations, then finally a translation.  Otherwise, the results may
  1426. not be what you expect. (The transformations always transform the object about
  1427. the origin.  If you have a sphere at the origin and you translate it then
  1428. rotate it, the rotation will spin the sphere around the origin like planets
  1429. about the sun).
  1430.  
  1431.  
  1432.  
  1433. 6.2.4.3)    Spheres
  1434.  
  1435. Since spheres are so common in ray traced graphics, A SPHERE primitive has
  1436. been added to the system.  This primitive will render much more quickly than
  1437. the corresponding quadric shape.  The syntax is:
  1438.  
  1439.      SPHERE  <center> radius END_SPHERE
  1440.  
  1441. You can also add translations, rotations, and scaling to the sphere. For
  1442. example, the following two objects are identical:
  1443.  
  1444.      OBJECT
  1445.           SPHERE  < 0.0 25.0 0.0 > 10.0 END_SPHERE
  1446.           TEXTURE
  1447.              COLOR Blue
  1448.              AMBIENT 0.3
  1449.              DIFFUSE 0.7
  1450.           END_TEXTURE
  1451.      END_OBJECT
  1452.  
  1453.      OBJECT
  1454.           SPHERE  < 0.0 0.0 0.0 > 1.0
  1455.                TRANSLATE <0.0  25.0  0.0> 
  1456.                SCALE <10.0  10.0  10.0>
  1457.           END_SPHERE
  1458.           TEXTURE
  1459.              COLOR Blue
  1460.              AMBIENT 0.3
  1461.              DIFFUSE 0.7
  1462.           END_TEXTURE
  1463.      END_OBJECT
  1464.  
  1465. Note that Spheres may only be scaled uniformly. You cannot use:
  1466.  
  1467.      SCALE <10.0 5.0 2.0>
  1468.  
  1469. on a sphere.  If you need oblate (flattened) spheroids, use a scaled quadric
  1470. "Sphere" shape instead, as it can be arbitrarily scaled in any dimension.
  1471.  
  1472. 6.2.4.4)    Planes
  1473.  
  1474. Another primitive provided to speed up the raytracing is the PLANE. This is a
  1475. flat infinite plane.  To declare a PLANE, you specify the direction of the
  1476. surface normal to the plane (the UP direction) and the distance from the
  1477. origin of the plane to the world's origin. As with spheres, you can translate,
  1478. rotate, and scale planes.  Examples:
  1479.  
  1480.      PLANE <0.0  1.0  0.0> -10.0 END_PLANE   { A plane in the X-Z axes 10
  1481.                                              units below the world origin. }
  1482.  
  1483.      PLANE <0.0  1.0  0.0>  10.0 END_PLANE   { A plane in the X-Z axes 10
  1484.                                              units above the world origin. }
  1485.  
  1486.      PLANE <0.0  0.0  1.0>  -10.0 END_PLANE  { A plane in the X-Y axes 10
  1487.                                              units behind the world origin.}
  1488.  
  1489.  
  1490.  
  1491. 6.2.4.5)    Triangles
  1492.  
  1493. In order to make more complex objects than the class of quadrics will
  1494. permit, a new primitive shape for triangles has been added.  There are
  1495. two different types of triangles:  flat shaded triangles and smooth
  1496. shaded (Phong) triangles.
  1497.  
  1498. Flat shaded triangles are defined by listing the three vertices of the 
  1499. triangle.  For example:
  1500.    
  1501.      TRIANGLE  < 0.0   20.0  0.0>
  1502.                < 20.0  0.0   0.0>
  1503.                <-20.0  0.0   0.0>
  1504.      END_TRIANGLE
  1505.  
  1506. The smooth shaded triangles use Phong Normal Interpolation to calculate the
  1507. surface normal for the triangle.  This makes the triangle appear to be a
  1508. smooth curved surface.  In order to define a smooth triangle, however, you
  1509. must supply not only the vertices, but also the surface normals at those
  1510. vertices.  For example:
  1511.    
  1512.      SMOOTH_TRIANGLE
  1513.           {      points             surface normals     }
  1514.           <  0.0  30.0  0.0 >    <0.0   0.7071   -0.7071>
  1515.           < 40.0 -20.0  0.0 >    <0.0   -0.8664  -0.5   >
  1516.           <-50.0 -30.0  0.0 >    <0.0   -0.5     -0.8664>
  1517.      END_SMOOTH_TRIANGLE
  1518.  
  1519. As with the other shapes, triangles can be translated, rotated, and scaled.
  1520.  
  1521. NOTE 1:  Triangles cannot be used in CSG INTERSECTION or DIFFERENCE types
  1522. (described next) since triangles have no clear "inside".  The CSG UNION type
  1523. works acceptably, but with no real difference from a COMPOSITE made up of
  1524. TRIANGLE primitives.
  1525.  
  1526. NOTE 2:  To be honest, I don't expect mere mortals to work out the surface
  1527. normals of triangles.  Ideally, you'd have another program generate them for
  1528. you.  See the section on "Common Questions and Answers" for details on how
  1529. this might be done.
  1530.  
  1531.  
  1532. 6.2.4.6)    Quartic Surfaces
  1533.  
  1534. Quartic surfaces are 4th order surfaces, and can be used to describe a large
  1535. class of shapes including the torus, the lemniscate, etc.  The general
  1536. equation for a quartic equation in three variables is (hold onto your hat):
  1537.  
  1538.    a00 x^4     + a01 x^3 y   + a02 x^3 z   + a03 x^3     + a04 x^2 y^2 + 
  1539.    a05 x^2 y z + a06 x^2 y   + a07 x^2 z^2 + a08 x^2 z   + a09 x^2 + 
  1540.    a10 x y^3   + a11 x y^2 z + a12 x y^2   + a13 x y z^2 + a14 x y z + 
  1541.    a15 x y     + a16 x z^3   + a17 x z^2   + a18 x z     + a19 x +
  1542.    a20 y^4     + a21 y^3 z   + a22 y^3     + a23 y^2 z^2 + a24 y^2 z +
  1543.    a25 y^2     + a26 y z^3   + a27 y z^2   + a28 y z     + a29 y +
  1544.    a30 z^4     + a31 z^3     + a32 z^2     + a33 z       + a34
  1545.  
  1546. To declare a quartic surface requires that each of the coefficients 
  1547. (a0 -> a34) be placed in order into a single long vector of 35 terms.
  1548.  
  1549. As an example, the following object declaration is for a torus having major
  1550. radius 6.3 minor radius 3.5 (Making the maximum width just under 10).
  1551.  
  1552.      { Torus having major radius sqrt(40), minor radius sqrt(12) }
  1553.      OBJECT
  1554.       QUARTIC
  1555.       < 1.0   0.0   0.0    0.0     2.0   0.0   0.0   2.0   0.0 -104.0
  1556.         0.0   0.0   0.0    0.0     0.0   0.0   0.0   0.0   0.0    0.0
  1557.         1.0   0.0   0.0    2.0     0.0  56.0   0.0   0.0   0.0    0.0
  1558.         1.0   0.0 -104.0   0.0   784.0 >
  1559.       END_QUARTIC
  1560.       BOUNDED_BY
  1561.        SPHERE <0 0 0> 10 END_SPHERE
  1562.       END_BOUND
  1563.      END_OBJECT
  1564.  
  1565. The code to calculate Ray-Surface intersections for quartics is somewhat
  1566. slower than that for intersections with quadric surfaces.  Benchmarks on
  1567. a stock 8Mhz AT (with FPU) give results of around 1400 solutions per second
  1568. for 2nd order equations (quadrics) vs 444 per second for 3rd order equations
  1569. and 123 per second for 4th order equations (quartics).  So clever use of
  1570. bounding shapes can make a big difference in processing time.
  1571.  
  1572. While a great deal of time has gone into debugging the code for handling
  1573. quartic surfaces, I know for a fact that there are bad combinations of
  1574. surface equations and lighting orientations that cause math errors (crash).
  1575. If this happens to you, as the joke goes, "then don't DO that."
  1576.  
  1577. Here are some surfaces to get you started.
  1578.  
  1579. A Torus can be represented by the equation:
  1580.  
  1581.    x^4 + y^4 + z^4 + 2 x^2 y^2 + 2 x^2 z^2 + 2 y^2 z^2
  1582.    -2 (r0^2 + r1^2) x^2 + 2 (r0^2 - r1^2) y^2 - 2 (r0^2 - r1^2) z^2
  1583.    + (r0^2 - r1^2)^2 = 0
  1584.  
  1585. Where r0 is the "major" radius of the torus - the distance from the hole
  1586. of the donut to the middle of the ring of the donut, and r1 is the "minor"
  1587. radius of the torus - the distance from the middle of the ring of the donut
  1588. to the outer surface.  Described another way, a torus is a circle that is
  1589. revolved around an axis.  The major radius is the distance from the axis to
  1590. the center of the circle, the minor radius is the radius of the circle. (If
  1591. this were a Mac I could put a drawing in here to show you...)
  1592.  
  1593. Note that scaling surfaces like a torus scales everything. In order to change
  1594. the relationship between the size of the hole and the size of the ring, it is
  1595. necessary to enter new coefficients for the torus.
  1596.  
  1597. The only coefficients of the 35 that need to be filled in are:
  1598.  
  1599.     a0  = a20 = a30 = 1,
  1600.     a4  = a7  = a23 = 2,
  1601.     a9  = a32       = -2 (r0^2 + r1^2)
  1602.     a25             = 2 (r0^2 - r1^2)
  1603.     a34             = 2 (r0^2 - r1^2)^2
  1604.  
  1605. the torus can then be rotated and translated into position once its shape
  1606. has been defined. (See 'TORUS.DAT')
  1607.  
  1608. A generalization of the lemniscate of Gerono can be represented by the
  1609. equation:
  1610.  
  1611.    c^2 x^4 - a^2 c^2 x^2 + y^2 + z^2 = 0
  1612.  
  1613. where good start values are a = 1.0 and c = 1.0, giving the coefficients:
  1614.  
  1615.    a0 = a25 = a32 = 1,
  1616.    a9 = -1
  1617.  
  1618. (See the example file "LEMNISCA.DAT" for a more complete example)
  1619.  
  1620. A generalization of a piriform can be represented by the equation:
  1621.  
  1622.    -b c^2 x^4 - a c^2 x^3 + y^2 + z^2 = 0
  1623.  
  1624. where good start values are a = 4, b = -4, c = 1, giving the coefficients
  1625.  
  1626.    a0 = 4,
  1627.    a3 = -4,
  1628.    a25 = a32 = 1
  1629.  
  1630. (See the file "PIRIFORM.DAT" for more on this...)
  1631.  
  1632. There are really so many different QUARTIC shapes, we can't even begin to
  1633. list or describe them all.  If you are interested and mathematically inclied,
  1634. an excellent reference book for curves and surfaces where you'll find more
  1635. QUARTIC shape formulas is:
  1636.  
  1637.    "The CRC Handbook of Mathematical Curves and Surfaces"
  1638.    David von Seggern
  1639.    CRC Press
  1640.    1990
  1641.  
  1642.  
  1643. 6.2.4.7)    Constructive Solid Geometry (CSG)
  1644.  
  1645. This ray tracer supports Constructive Solid Geometry in order to make the
  1646. object definition abilities more powerful.  Constructive Solid Geometry allows
  1647. you to define shapes which are the union, intersection, or difference of other
  1648. shapes.  Unions superimpose the two shapes.  This has the same effect as
  1649. defining two separate objects, but is simpler to create and/or manipulate.
  1650. Intersections define the space where the two surfaces meet.  Differences allow
  1651. you to cut one object out of another.
  1652.  
  1653. CSG Intersections, Unions, and Differences can consist of two or more shapes.
  1654. They are defined as follows:
  1655.  
  1656.      OBJECT
  1657.           INTERSECTION
  1658.                QUADRIC
  1659.                     ...
  1660.                END_QUADRIC
  1661.  
  1662.                QUADRIC
  1663.                     ...
  1664.                END_QUADRIC
  1665.  
  1666.                QUADRIC
  1667.                     ...
  1668.                END_QUADRIC
  1669.           END_INTERSECTION
  1670.           ...
  1671.      END_OBJECT
  1672.  
  1673. UNION or DIFFERENCE may be used instead of INTERSECTION.  The order of the
  1674. shapes doesn't matter except for the DIFFERENCE shapes.  For CSG differences,
  1675. the first shape is visible and the remaining shapes are cut out of the first
  1676. (in reverse order from version 1.2 DIFFERENCE's).
  1677.  
  1678. Constructive solid geometry shapes may be translated, rotated, or scaled in
  1679. the same way as a Quadric surface.  The quadric surfaces making up the CSG
  1680. object may be individually translated, rotated, and scaled as well.
  1681.  
  1682. When using CSG, it is often useful to invert an shape so that it's inside-out.
  1683. The INVERSE keyword can be used to do this for any SPHERE, PLANE, or QUADRIC.
  1684. When INVERSE is used, the "inside" of the object is flipped to become the
  1685. "outside".  For Planes, "inside" is defined to be "in the opposite direction
  1686. to the "normal" or "up" direction.
  1687.  
  1688. Note that performing an INTERSECTION between an shape and some other INVERSE
  1689. shapes is the same as performing a DIFFERENCE.  In fact, the DIFFERENCE is
  1690. actually implemented in this way in the code.
  1691.  
  1692. 6.2.5)  Objects
  1693.  
  1694. There is more to defining an object than just its shape.  You must tell the
  1695. ray tracer about the properties of the object like surface colour, alpha,
  1696. reflectivity, refractivity, the index of refraction, and so on.  This may be
  1697. done by specifying it in the shape or the object.  Generally, an OBJECT
  1698. definition will contain two pieces of information about an object: First, what
  1699. shape it is, and second, what it's looks like (on the surface and throughout).
  1700. A typical object definition looks something like this:
  1701.  
  1702.      OBJECT
  1703.           QUADRIC Sphere
  1704.                TRANSLATE < 40.0 40.0 60.0 >
  1705.           END_QUADRIC
  1706.  
  1707.           TEXTURE
  1708.              AMBIENT  0.3
  1709.              DIFFUSE   0.7
  1710.              REFLECTION  0.3
  1711.              REFRACTION  0.3
  1712.              IOR 1.05
  1713.              COLOUR RED 1.0 GREEN 1.0 BLUE 1.0 ALPHA 0.5
  1714.           END_TEXTURE
  1715.      END_OBJECT
  1716.  
  1717. The following keywords may be used when defining objects:
  1718.  
  1719. 6.2.5.1)    COLOUR value
  1720.  
  1721. When used on an OBJECT (i.e., not inside a TEXTURE block), the COLOUR keyword
  1722. determines what colour to use for a low quality rendering when TEXTURE's are
  1723. ignored.  See the +q option for details on setting the low-quality option.
  1724.  
  1725. Example:
  1726.  
  1727.      COLOUR RED 1.0  BLUE 0.4
  1728.  
  1729.           - or -
  1730.  
  1731.      DECLARE Yellow = COLOUR RED 1.0 GREEN 1.0
  1732.           ...
  1733.      COLOUR Yellow
  1734.  
  1735.  
  1736. 6.2.5.2)    TRANSLATE vector
  1737. 6.2.5.3)    ROTATE vector
  1738. 6.2.5.4)    SCALE vector
  1739.  
  1740. Objects can be translated, rotated, and scaled just like surfaces.  If an
  1741. object is transformed, all textures attached to the object at that time are
  1742. transformed as well.  This means that if you have a TRANSLATE, ROTATE, or
  1743. SCALE before a TEXTURE, the texture will NOT be transformed.  If the SCALE
  1744. TRANSLATE, or ROTATE is after the TEXTURE, the texture will be transformed.
  1745.  
  1746. 6.2.5.5)    LIGHT_SOURCE
  1747.  
  1748. If the LIGHT_SOURCE keyword is used in the definition of an object, then the
  1749. object is included in the list of light sources.  It can light objects and
  1750. produce shadows.  (You should also specify the COLOUR of the light source, it
  1751. will usually be "White").  Light sources have a peculiar restriction:  The
  1752. light source MUST be TRANSLATED to its final position in the scene, so the
  1753. normal way to define a light source is a sphere or quadric centered about the
  1754. origin, then TRANSLATED to where desired in the final scene.  For example:
  1755.  
  1756.      OBJECT
  1757.           SPHERE <0.0  0.0  0.0> 2.0 END_SPHERE   {could be a quadric, too.}
  1758.           TRANSLATE <100.0  120.0  40.0>
  1759.  
  1760.           LIGHT_SOURCE
  1761.           COLOUR White      { This is the colour of the light emitted }
  1762.           TEXTURE
  1763.              COLOUR White   { This is the surface colour of the sphere }
  1764.              AMBIENT 1.0
  1765.              DIFFUSE 0.0
  1766.           END_TEXTURE
  1767.      END_OBJECT
  1768.  
  1769.  
  1770. NOTE: You MUST specify the colour of the light outside the TEXTURE block. This
  1771.       allows the renderer to quickly determine the colour of the light source
  1772.       without having to plow through the textures.  Any colour information
  1773.       inside the TEXTURE block is used to render the light source object itself
  1774.       if it is visible in the scene.  The subtle difference between the
  1775.       actual sphere object and the light ray emanation point (the center of
  1776.       the sphere) is why LIGHT_SOURCE's must be defined at (0,0,0) then
  1777.       TRANSLATE'd to where you want them.  It ties together and TRANSLATE's
  1778.       both the object itself and the light ray source point to the specified
  1779.       point in the scene.  Usually, light sources have an AMBIENT value of 1.0
  1780.       and a DIFFUSE of 0.0, but this is not a hard and fast rule.
  1781.  
  1782. 6.2.6)  TEXTURE
  1783.  
  1784. The texture feature is an experiment into functionally based modelling.  This
  1785. feature allows you to assign colouring schemes to objects.  Many procedural
  1786. surface textures are provided, and by using different colour maps with them,
  1787. nearly infinite permutations are possible.  For example, you can make some
  1788. object look like wood or marble, etc.  In DKBTrace, any parameter that changes
  1789. the appearance of the surface MUST be put into a TEXTURE block.
  1790.  
  1791. The basic TEXTURE syntax is as follows:
  1792.  
  1793.      TEXTURE
  1794.           0.05
  1795.           WOOD
  1796.           TURBULENCE 0.2
  1797.           TRANSLATE < 1.0 2.0 3.0 >
  1798.           ROTATE < 0.0 10.0 40.0 >
  1799.           SCALE < 10.0 10.0 10.0 >
  1800.      END_TEXTURE
  1801.  
  1802. Transformations are optional.  They allow you to transform the texture
  1803. independent of the object itself.  If you are doing animation, then the
  1804. transformations should be the same as the object transformations so that the
  1805. texture follows the object through 3-D space.
  1806.  
  1807. The floating-point value given immediately following the texture keyword is an
  1808. optional "texture randomness" value, which causes a minor random scattering of
  1809. calculated colour values and produces a sort of "dithered" appearance.  Note
  1810. this is BAD, BAD, BAD for animations!!  This is the ONLY "truly random" thing
  1811. in all of DKB, and will produce a most annoying flicker of flying pixels on
  1812. any textures animated with a "randomness" value used.
  1813.  
  1814. Instead of using WOOD, you may use MARBLE, BOZO, CHECKER, or a handful of
  1815. other interesting textures.  The WOOD and MARBLE textures are perturbed by a
  1816. turbulence function.  This makes them look more random and irregular than they
  1817. would normally appear.  The amount of turbulence can be changed by the
  1818. TURBULENCE keyword followed by a number.  Values from 0.1 to 0.3 seem to give
  1819. the best results.  The default is 0.0, or no turbulence. 
  1820.  
  1821. Note some of the textures given are coloration textures, such as MARBLE, WOOD
  1822. CHECKER, GRANITE, and AGATE.  These work with colour maps, and have default
  1823. "colour maps" they resort to if none are given.  The rest of the textures
  1824. available are "surface perturbation" textures, and do not directly affect the
  1825. colour of the object, but rather the surface's apparent orientation in space.
  1826. Examples of this are WAVES, RIPPLES, DENTS, BUMPS, and WRINKLES.  Note that
  1827. any given texture may include up to two actual textures, one coloration and
  1828. one surface perturbation choice per texture.  This would allow rippled wood,
  1829. or dented granite combinations, etc., but, keep in mind that any texture
  1830. transformations applied to one texture (i.e. TRANSLATE or SCALE) will also
  1831. transform the other one in the same fashion.
  1832.  
  1833.  
  1834. As of version 2.10, it is possible to create layered textures. If you use more
  1835. that one texture block, the raytracer will compute the colour of the last
  1836. texture and if there's any transparency in the colour (i.e., any alpha), it
  1837. will mix in some of the colour from the underlying textures.
  1838.  
  1839. IMPORTANT NOTE:  As of version 2.10, the keywords in this following section
  1840.                  CANNOT be used outside of a TEXTURE-END_TEXTURE structure.
  1841.                  This is a change in the input language from prior versions.
  1842.  
  1843. The following object surface lighting characteristics are available:
  1844.  
  1845. 6.2.6.1)    AMBIENT value
  1846.  
  1847. Ambient light is light that is scattered everywhere in the room.  An object
  1848. lit only by ambient light will appear to have the same brightness over the
  1849. entire surface.  The default value is very little ambient light (0.3).  The
  1850. value can range from 0.0 to 1.0. 
  1851.  
  1852. 6.2.6.2)    DIFFUSE value
  1853.  
  1854. Diffuse light is light coming from a light source that is scattered in all
  1855. directions.  An object lit only by diffuse light looks like a rubber ball with
  1856. a spot light shining on it.  The value can range from 0.0 to 1.0.  By default,
  1857. there is mostly diffuse lighting (0.7).
  1858.  
  1859. 6.2.6.3)    BRILLIANCE value
  1860.  
  1861. Objects can be made to appear more metallic by increasing their brilliance.
  1862. This controls the tightness of the basic diffuse illumination on objects and
  1863. minorly adjusts the appearance of surface shininess.  The default value is
  1864. 1.0.  Higher values from 3.0 to about 10.0 can give objects a somewhat more
  1865. shiny or metallic appearance.  This is best used in concert with either the
  1866. SPECULAR or PHONG highlighting.
  1867.  
  1868. 6.2.6.4)    REFLECTION value
  1869.  
  1870. By setting the reflection value to be non-zero, you can give the object a
  1871. mirrored finish.  It will reflect all other objects in the room.  The value
  1872. can range from 0.0 to 1.0.  By default there is no reflection. 
  1873.  
  1874. 6.2.6.5)    REFRACTION value
  1875.  
  1876. By setting the refraction value to be non-zero, the object is made transparent.
  1877. Light will be refracted through the object like a lens.  The value can be set
  1878. between 0.0 and 1.0.  There is no refraction by default. 
  1879.  
  1880. NOTE 1:  New for 2.10:  In order to refraction to work properly, you must have
  1881.          some ALPHA component in the surface colour.  In the places where the
  1882.          ALPHA is high, the refracted light can get through.  In places where
  1883.          the ALPHA is low, the refracted light is suppressed.  This is a
  1884.          change in the input language from prior versions.
  1885.  
  1886. NOTE 2:  The refracted light is filtered by (takes on) the surface colour.
  1887.  
  1888. NOTE 3:  In layered textures, the REFRACTION and IOR keywords MUST be in the
  1889.          last texture, otherwise they will not take effect.
  1890.  
  1891. NOTE 4:  If a texture has an ALPHA component and no value for REFRACTION was
  1892.          supplied, the renderer will simply transmit the ray through the
  1893.          surface with no bending.
  1894.  
  1895. 6.2.6.6)    IOR value
  1896.  
  1897. If the object is refracting light, then the IOR or Index of Refraction should
  1898. be set.  This determines how dense the object is.  A value of 1.0 will give no
  1899. refraction.  The Index of Refraction for air is 1.0, water is 1.33, glass is
  1900. 1.5, and diamond is 2.4. 
  1901.  
  1902. 6.2.6.7)    PHONG value
  1903.  
  1904. Controls the amount of Phong Specular Reflection highlighting on the object.
  1905. Causes bright shiny spots on the object, the colour of the light source that
  1906. is being reflected.  The size of the spot is defined by the value given for
  1907. PHONGSIZE below.  PHONG's value is typically from 0.0 to 1.0, where 1.0 causes
  1908. complete saturation of the object's colour to the light source's colour at the
  1909. brightest area (center) of the highlight.  There is no PHONG highlighting
  1910. given by default. 
  1911.  
  1912. 6.2.6.8)    PHONGSIZE value
  1913.  
  1914. Controls the size of the PHONG Highlight on the object, sort of an arbitrary
  1915. "glossiness" factor.  Values range from 1.0 (Very Dull) to 100 (Highly
  1916. Polished).  Default PHONGSIZE is 40 (plastic?) if not specified.  This is
  1917. simulating the fact that slightly reflective objects, especially metallic
  1918. ones, have microscopic facets, some of which are facing in the mirror
  1919. direction.  The more that are facing that way, the shinier the object appears,
  1920. and the tighter the specular highlights become.  Phong measures the average of
  1921. facets facing in the mirror direction from the light sources to the viewer. 
  1922.  
  1923. 6.2.6.9)    SPECULAR value
  1924.  
  1925. Very similar to PHONG Specular Highlighting, but a better model is used for
  1926. determining light ray/object intersection, so a more credible spreading of the
  1927. highlights occur near the object horizons, supposedly.  PHONG is thus included
  1928. for mostly academic reasons, but try them both and you decide which you like
  1929. better.  This effect is most obvious for light sources behind objects.  The
  1930. size of the spot is defined by the value given for ROUGHNESS below.  Like
  1931. PHONG, SPECULAR values are typically from 0.0 to 1.0 for full saturation.
  1932. Default is no SPECULAR highlighting.
  1933.  
  1934. Note that Specular and Phong highlights are NOT mutually exclusive.  It is
  1935. possible to specify both and they will both take effect.  Normally, however,
  1936. you will only specify one or the other.
  1937.  
  1938. 6.2.6.10)   ROUGHNESS value
  1939.  
  1940. Controls the size of the SPECULAR Highlight on the object, relative to the
  1941. object's "roughness".  Values range from 1.0 (Very Rough) to 0.001 (Very
  1942. Smooth).  The default value, if not specified, is 0.05 (Plastic?).  The
  1943. roughness or average directional distribution of the microfacets facing in the
  1944. same direction as the perpendicular surface "normal" cause the most notable
  1945. reflection of the highlight to the observer.
  1946.  
  1947.  
  1948. The following advanced procedural textures are available:
  1949.  
  1950. 6.2.6.11)   CHECKER - A colouring texture.
  1951.  
  1952. CHECKER texturing gives a checker-board appearance.  This option works best on
  1953. planes.  When using the CHECKER texturing, you must specify two colours
  1954. immediately following the word CHECKER.  These colours are the colours of
  1955. alternate squares in the checker pattern.  The default orientation of the
  1956. CHECKER texture is on an X-Z plane (good for ground work, etc.) but to use it
  1957. on an object which has mostly X-Y orientation (such as a sphere, for
  1958. instance), you must ROTATE the texture. 
  1959.  
  1960. To rotate the CHECKER texture onto an X-Y plane:
  1961.  
  1962.      TEXTURE
  1963.           CHECKER COLOUR White COLOUR Red
  1964.           SCALE <10.0 10.0 10.0>
  1965.           ROTATE <-90.0 0.0 0.0>   { Checkers now in the X-Y plane... }
  1966.      END_TEXTURE
  1967.  
  1968. 6.2.6.12)   CHECKER_TEXTURE - A colouring texture.
  1969.  
  1970. I've had many requests for a checker pattern to allow you to alternate between
  1971. wood and marble or any other two textures.  So, in version 2.10, I've added a
  1972. texture called CHECKER_TEXTURE that takes two textures instead of two colours.
  1973.  
  1974. In order to support layered textures, I've made the syntax a bit more verbose
  1975. than it would be otherwise.  The syntax is:
  1976.  
  1977.     TEXTURE
  1978.        CHECKER_TEXTURE
  1979.           TEXTURE ... put in a texture here ... END_TEXTURE
  1980.           TEXTURE ... add optional layers on top of that one ... END_TEXTURE
  1981.        TILE2
  1982.           TEXTURE ... this is the second tile texture END_TEXTURE
  1983.           TEXTURE ... a texture layered on top of the second tile END_TEXTURE
  1984.        END_CHECKER_TEXTURE
  1985.        AMBIENT ...
  1986.        DIFFUSE ...
  1987.    END_TEXTURE
  1988.  
  1989. Note that the textures in CHECKER_TEXTURE only use the surface colouring
  1990. texture information.  Information about AMBIENT, DIFFUSE, REFLECTION, etc.
  1991. and surface normal information (WAVES, RIPPLES) are ignored inside the
  1992. CHECKER_TEXTURE. (hey, what do you want for a 10 minute change?)
  1993.  
  1994.  
  1995. 6.2.6.13)   BOZO - A colouring texture.
  1996.  
  1997. BOZO texture basically takes a noise function and maps it onto the surface of
  1998. an object.  This "noise" is well-defined for every point in space.  If two
  1999. points are close together, they will have noise values that are close
  2000. together.  If they are far apart, their noise values will be fairly random
  2001. relative to each other. 
  2002.  
  2003. As mentioned above, for coloration textures such as WOOD, MARBLE, and BOZO,
  2004. etc., you may change the colouring scheme by using a colour map.  This map
  2005. allows you to convert numbers from 0.0 to 1.0 (which are generated by the ray
  2006. tracer) into ranges of colours. For example, the default BOZO colouring can be
  2007. specified by:
  2008.  
  2009.      TEXTURE
  2010.           BOZO
  2011.           COLOUR_MAP
  2012.                [0.0 0.4 COLOUR White COLOUR White]
  2013.                [0.4 0.6 COLOUR Green COLOUR Green]
  2014.                [0.6 0.8 COLOUR Blue COLOUR Blue]
  2015.                [0.8 1.0 COLOUR Red COLOUR Red]
  2016.           END_COLOUR_MAP
  2017.      END_TEXTURE
  2018.  
  2019. The easiest way to see how it works is to try it.  With a good choice of
  2020. colours it produces some of the most realistic looking cloudscapes you have
  2021. ever seen indoors!  Try a cloud color map such as:
  2022.  
  2023.      TEXTURE
  2024.           BOZO
  2025.           TURBULENCE 1.0      { A blustery day.  For a calmer one, try 0.2 }
  2026.           COLOUR_MAP
  2027.                [0.0 0.5  COLOUR RED 0.5 GREEN 0.5 BLUE 1.0  {blue to blue}
  2028.                     COLOUR RED 0.5 GREEN 0.5 BLUE 1.0]
  2029.                [0.5 0.6  COLOUR RED 0.5 GREEN 0.5 BLUE 1.0  {blue to white}
  2030.                     COLOUR RED 1.0 GREEN 1.0 BLUE 1.0]
  2031.                [0.6 1.001 COLOUR RED 1.0 GREEN 1.0 BLUE 1.0 {white to grey}
  2032.                     COLOUR RED 0.5 GREEN 0.5 BLUE 0.5]
  2033.           END_COLOUR_MAP
  2034.           SCALE <800.0 800.0 800.0>
  2035.           TRANSLATE <200.0 400.0 100.0>
  2036.      END_TEXTURE
  2037.  
  2038. The color map above indicates that for small values of texture, use a sky blue
  2039. color solidly until about halfway turbulent, then fade through to white on a
  2040. fairly narrow range.  As the white clouds get more turbulent and solid towards
  2041. the center, pull the color map toward grey to give them the appearance of
  2042. holding water vapor (like typical clouds). 
  2043.  
  2044. Check out sunset.dat for a really neat (but slow) sky pattern using ALPHA.
  2045.  
  2046.  
  2047. 6.2.6.14)   SPOTTED - A colouring texture.
  2048.  
  2049. Spotted texture is a sort of swirled random spotting of the colour of the
  2050. object.  If you've ever seen a metal organ pipe up close you know about what
  2051. it looks like (a galvanized garbage can is close...) Play with this one, it
  2052. might render a decent cloudscape during a very stormy day (?).  No extra
  2053. keywords are required.  Should work with colour maps.  With small scaling
  2054. values, looks like masonry or concrete.
  2055.  
  2056. 6.2.6.15)   AGATE - A colouring texture.
  2057.  
  2058. This texture is similar to Marble, but uses a different turbulence function.
  2059. The TURBULENCE keyword has no effect, and as such it is always very turbulent.
  2060.  
  2061. 6.2.6.16)   GRADIENT - A colouring texture.
  2062.  
  2063. This is a specialized texture that uses approximate local coordinates of an
  2064. object to control colour map gradients.  This texture ONLY works with colour
  2065. maps (one MUST be given!) and has a special <X, Y, Z> triple given after the
  2066. GRADIENT keyword, which specifies any (or all) axes to perform the gradient
  2067. action on.  Example: a Y gradient <0.0 1.0 0.0> will give an "altitude colour
  2068. map", along the Y axis.  Values given other than 0.0 are taken as 1.0.
  2069.  
  2070. For smooth repeating gradients, you should use a "circular" colour map, that
  2071. is, one in which the first colour value (0.0) is the same as the last one
  2072. (1.001) so that it "wraps around" and will cause smooth repeating gradient
  2073. patterns.  Scaling the texture is normally required to achieve the number of
  2074. repeating shade cycles you want.  Transformation of the texture is useful to
  2075. prevent a "mirroring" effect from either side of the central 0 axes.  Here is
  2076. an example of a gradient texture which uses a sharp "circular" color mapped
  2077. gradient rather than a smooth one, and uses both X and Y gradients to get a
  2078. diagonally-oriented gradient.  It produces a dandy candy cane texture! 
  2079.  
  2080.      TEXTURE
  2081.           GRADIENT < 1.0 1.0 0.0 >
  2082.           COLOUR_MAP
  2083.                [0.00 0.25  COLOUR RED 1.0 GREEN 0.0 BLUE 0.0
  2084.                     COLOUR RED 1.0 GREEN 0.0 BLUE 0.0]
  2085.                [0.25 0.75  COLOUR RED 1.0 GREEN 1.0 BLUE 1.0
  2086.                     COLOUR RED 1.0 GREEN 1.0 BLUE 1.0]
  2087.                [0.75 1.001 COLOUR RED 1.0 GREEN 0.0 BLUE 0.0
  2088.                     COLOUR RED 1.0 GREEN 0.0 BLUE 0.0]
  2089.           END_COLOUR_MAP
  2090.           SCALE <30.0 30.0 30.0>
  2091.           TRANSLATE <30.0 -30.0 0.0>
  2092.      END_TEXTURE
  2093.  
  2094. You may also specify a TURBULENCE value with the gradient to give a more
  2095. irregular colour gradient.  This may help to do neat things like fire or
  2096. corona effects.
  2097.  
  2098.  
  2099. 6.2.6.17)   GRANITE - A colouring texture.
  2100.  
  2101. This texture uses a simple 1/f fractal noise function to give a pretty darn
  2102. good grey granite texture.  Typically used with small scaling values (2.0 to
  2103. 5.0).  Also looks good with a little dithering (texture randomness).  Should
  2104. work with colour maps, so try your hand at pink granite or alabaster! 
  2105.  
  2106. 6.2.6.18)   RIPPLES - A surface perturbation texture.
  2107.  
  2108. As mentioned earlier, you may specify a surface perturbation texture which
  2109. can be used in conjunction with the above coloration textures.  RIPPLES makes
  2110. a surface look like ripples of water.  The RIPPLES option requires a value to
  2111. determine how deep the ripples are:
  2112.  
  2113.      TEXTURE
  2114.           WOOD
  2115.           RIPPLES 0.3
  2116.           TRANSLATE < 1.0 2.0 3.0 >
  2117.           ROTATE < 0.0 10.0 40.0 >
  2118.           SCALE < 10.0 10.0 10.0 >
  2119.      END_TEXTURE
  2120.  
  2121. (In this case, the WOOD, MARBLE, or BOZO, etc. keywords are optional).  If a
  2122. different colouring is specified (WOOD, MARBLE, or BOZO), then the COLOUR
  2123. parameter is ignored (except for light sources where it gives the light colour
  2124. or when rendering with a low -q option).
  2125.  
  2126.  
  2127. 6.2.6.19)   WAVES - A surface perturbation texture.
  2128.  
  2129. Another option that you may want to experiment with is called WAVES.  This
  2130. works in a similar way to RIPPLES except that it makes waves with different
  2131. frequencies.  The effect is to make waves that look more like deep ocean
  2132. waves. (I haven't done much testing on WAVES, so I can't guarantee that it
  2133. works very well). 
  2134.  
  2135. Both WAVES and RIPPLES respond to a texturing option called PHASE.  The PHASE
  2136. option allows you to create animations in which the water seems to move.  This
  2137. is done by making the PHASE increment slowly between frames.  The range from
  2138. 0.0 to 1.0 gives one complete cycle of a wave.
  2139.  
  2140. The WAVES and RIPPLES textures also respond to a keyword called FREQUENCY.  If
  2141. you increase the frequency of the waves, they get closer together.  If you
  2142. decrease it, they get farther apart.
  2143.  
  2144.  
  2145. 6.2.6.20)   BUMPS - A surface perturbation texture.
  2146.  
  2147. Approximately the same turbulence function as SPOTTED, but uses the derived
  2148. value to perturb the surface normal.  This gives the impression of a "bumpy"
  2149. surface, random and irregular, sort of like an orange.  After the BUMPS
  2150. keyword, supply a single floating point value for the amount of surface
  2151. perturbation.  Values typically range from 0.0 (No Bumps) to 1.0 (Extremely
  2152. Bumpy).  Values beyond 1.0 may do weird things.
  2153.  
  2154. 6.2.6.21)   DENTS - A surface perturbation texture.
  2155.  
  2156. Also a surface normal perturbing texture.  Interesting when used with metallic
  2157. textures, it gives impressions into the metal surface that look like dents.  A
  2158. single value is supplied after the DENTS keyword to indicate the amount of
  2159. denting required.  Values range from 0.0 (Showroom New) to 1.0 (Insurance
  2160. Wreck).  Use larger values at your own risk, they will raise your rates,
  2161. anyway... ;-) Scale the texture to make the pitting more or less frequent.
  2162.  
  2163. 6.2.6.22)   WRINKLES - A surface perturbation texture.
  2164.  
  2165. This is sort of a 3-D (normal perturbing) GRANITE.  It uses a similar 1/f
  2166. fractal noise function to perturb the surface normal in 3-D space.  With ALPHA
  2167. values of greater than 0.0, could look like wrinkled cellophane.  Requires a
  2168. single value after the WRINKLES keyword to indicate the amount of wrinkling
  2169. desired.  Values from 0.0 (No Wrinkles) to 1.0 (Very Wrinkled) are typical.
  2170.  
  2171. 6.2.6.23)   IMAGEMAP - A colouring texture.
  2172.  
  2173. This is a very special coloration texture that allows you to import a
  2174. bitmapped file in DUMP format (the format output by the ray-tracer), IFF
  2175. format or Compuserve GIF format and map that bitmap onto an object.  In the
  2176. texture of an object, you must give the IMAGEMAP keyword, the format, and a
  2177. file name.  The syntax is:
  2178.  
  2179.           IMAGEMAP [gradient] DUMP "filename" [ONCE]
  2180.      or   IMAGEMAP [gradient] IFF "filename" [ONCE]
  2181.      or   IMAGEMAP [gradient] GIF "filename" [ONCE]
  2182.  
  2183. The texture will then be mapped onto the object as a repeating pattern.  The
  2184. ONCE keyword places only one image onto the object instead of an infinitely
  2185. repeating tiled pattern.  When ONCE is used, the colour outside the mapped
  2186. texture is set to transparent.  You can use the layered textures to
  2187. place other textures or colours below the image.
  2188.  
  2189. In version 2.10 and up, you can specify the ALPHA values for the colour
  2190. registers of IFF or GIF pictures (at least for the modes that use colourmaps).
  2191. You can do this by putting the keyword ALPHA immediately following the
  2192. filename followed by the register value and transparency.  If the ALL keyword
  2193. is used instead of a register number, then all colours in that colourmap get
  2194. that alpha value.
  2195.  
  2196. Eg.
  2197.           IMAGEMAP <1.0 -1.0 0.0> IFF "mypic.iff"
  2198.              ALPHA ALL 0.0
  2199.  
  2200.    ...or     ALPHA 0   0.5
  2201.              ALPHA 1   1.0
  2202.              ALPHA 2   0.3
  2203.              ...
  2204.  
  2205.           ONCE
  2206.           ...
  2207.  
  2208.  
  2209. By default, the image is mapped onto the X-Y plane in the range (0.0, 0.0) to
  2210. (1.0, 1.0).  If you would like to change this default, you may use an optional
  2211. gradient <x, y, z> vector after the word IMAGEMAP.  This vector indicates
  2212. which axes are to be used as the u and v (local surface X-Y) axes.  The vector
  2213. should contain one positive number and one negative number to indicate the "u"
  2214. and "v" axes, respectively.  You may translate, rotate, and scale the texture
  2215. to map it onto the object's surface as desired.  Here is an example:
  2216.  
  2217.      INCLUDE "shapes.data"
  2218.  
  2219.      OBJECT
  2220.           QUADRIC Plane_XY END_QUADRIC
  2221.           TRANSLATE <0.0  -20.0  0.0>
  2222.  
  2223.           TEXTURE
  2224.                { make this texture use the x and z axes for the mapping. }
  2225.                IMAGEMAP <1.0  0.0  -1.0> GIF "image.gif"
  2226.                SCALE <40.0 40.0 40.0>
  2227.           END_TEXTURE
  2228.      END_OBJECT
  2229.  
  2230. Filenames specified in the IMAGEMAP statements will be searched for in the home
  2231. (current) directory first, and if not found, will then be searched for in
  2232. directories specified by any "-l" (library path) options active.  This would
  2233. facilitate keeping all your imagemaps (.dis, .gif or .iff) files in a
  2234. "textures" subdirectory, and giving an "-l" option on the command line to where
  2235. your library of imagemaps are. 
  2236.  
  2237. When I was bored with nothing to do, I decided that it would be neat to have
  2238. turbulent texture maps.  So, I said - "what the hell!"  You can specify
  2239. TURBULENCE with texture maps and it will perturb the image.  It may give some
  2240. bizarre results.  Is this useful?  I dunno.  It was easy to do so I did it.
  2241. Try it out and see what you get.
  2242.  
  2243.  
  2244. 6.2.7)  Composite Objects
  2245.  
  2246. Often it's useful to combine several objects together to act as a whole.  A
  2247. car, for example, consists of wheels, doors, a roof, etc.  A composite object
  2248. allows you to combine all of these pieces into one object.  This has two
  2249. advantages.  It makes it easier to move the object as a whole and it allows
  2250. you to speed up the ray tracing by defining bounding shapes that contain the
  2251. objects.  (Rays are first tested to see if they intersect the bounding shape.
  2252. If not, the entire composite object is ignored).  Composite objects are
  2253. defined as follows:
  2254.  
  2255.      COMPOSITE
  2256.           OBJECT
  2257.                ...
  2258.           END_OBJECT
  2259.  
  2260.           OBJECT
  2261.                ...
  2262.           END_OBJECT
  2263.           ...
  2264.  
  2265.           SCALE < 2.0 2.0 2.0 >
  2266.           ROTATE < 30.0 45.0 160.0 >
  2267.           TRANSLATE < 100.0 20.0 40.0 >
  2268.      END_COMPOSITE
  2269.  
  2270. Composite objects can contain other composite objects as well as regular
  2271. objects.  Composite objects cannot be light sources (although any number of
  2272. their components can).  This is because it is nearly impossible to determine
  2273. the true "center" of the composite object, and our light sources are pinpoint
  2274. ray sources from the center of the light source object, wherever that may be.
  2275.  
  2276.  
  2277. 6.3)    Bounding Shapes
  2278.  
  2279. Let's face it.  This program is no speed demon.  You can save yourself a lot
  2280. of time, however, if you use bounding shapes around any complex objects.
  2281. Bounding shapes tell the ray tracer that the object is totally enclosed by a
  2282. simple shape.  When tracing rays, the ray is first tested against the simple
  2283. bounding shape.  If it strikes the bounding shape, then the ray is further
  2284. tested against the more complicated object inside.
  2285.  
  2286. NOTE:  Don't use bounding shapes instead of CSG to clip objects.  You will not
  2287.        get the result you want.  For the raytracer to work properly, you must
  2288.        have the entire object inside the bounding shape.
  2289.  
  2290. To use bounding shapes, you simply include the following lines into the
  2291. declaration of your OBJECT or COMPOSITE_OBJECT:
  2292.  
  2293.      BOUNDED_BY
  2294.           a shape
  2295.      END_BOUND
  2296.  
  2297. An example of a Bounding Shape:
  2298.  
  2299.      OBJECT
  2300.           INTERSECTION
  2301.                SPHERE <0.0 0.0 0.0> 2.0 END_SPHERE
  2302.                PLANE <0.0 1.0 0.0> 0.0 END_PLANE
  2303.                PLANE <1.0 0.0 0.0> 0.0 END_PLANE
  2304.           END_INTERSECTION
  2305.  
  2306.           BOUNDED_BY
  2307.                SPHERE <0.0 0.0 0.0> 2.0 END_SPHERE
  2308.           END_BOUND
  2309.      END_OBJECT
  2310.  
  2311. The best bounding shape is a SPHERE since this shape is highly optimized.  Any
  2312. shape may be used, however, if more convenient.
  2313.  
  2314.  
  2315.  
  2316. 7)  Displaying the Images
  2317.  
  2318. When the ray tracer draws the picture on the screen, it doesn't make good
  2319. choices for the colour registers.  Without knowing all the needed colours
  2320. ahead of time, only approximate guesses can be made.  Usually, a post-
  2321. processor is really needed to view the final image correctly.
  2322.  
  2323. 7.1)    Amiga Systems
  2324.  
  2325. A post-processor has been provided for the Amiga which scans the picture and
  2326. chooses the best possible colour registers.  It then redisplays the picture.
  2327. For the Amiga, "DumpToIFF" can optionally save this picture in IFF format.
  2328. The syntax for the DumpToIFF post-processor is:
  2329.  
  2330.      DumpToIFF filename
  2331.  
  2332. where the filename is the one given in the -o parameter of the ray tracer.  If
  2333. you didn't specify the -o option, then use:
  2334.  
  2335.      DumpToIFF data.dis
  2336.  
  2337. If you want to save to an IFF file, then put the name of the IFF file after
  2338. the name of the data file:
  2339.  
  2340.      DumpToIFF data.dis picture
  2341.  
  2342. This will create a file called "picture" which contains the IFF image.
  2343.  
  2344.  
  2345. An alternative approach is to buy the commercial package called "The Art
  2346. Department" from ASDG.  You can then use the +fr option of the raytracer to
  2347. produce raw files which can be read in to TAD using Sculpt mode.  You can also
  2348. render using +fd to produce a dump format file, and use d2iff to convert this
  2349. to a 24-bit IFF image to load into TAD.
  2350.  
  2351.  
  2352. 7.2)    IBM Systems
  2353.  
  2354. For the IBM, you will probably want to use the +ft option (default if +f is
  2355. given) and write the image out in Targa-24 format.  If you have a Targa or
  2356. compatible display adapter, you may view the picture in the full 16 million
  2357. colors (that's why they still cost the big $$ bucks, but Hercules and Everex,
  2358. notably, are introducing their lower-priced SVGA-compatible 24-bit color display
  2359. systems for the IBM PC and compatibles).  If you don't have one of these, there
  2360. are several different post-processing programs available to convert the TARGA
  2361. true-color image into a more suitable color-mapped image (such as .GIF).  If
  2362. you have a VGA/MCGA or SVGA adapter capable of 320x200 by 256 colors or better,
  2363. then you may use the +d option which will display the image as it generates
  2364. using only approximate screen colors.  The +d option will Autodetect the type
  2365. of display adapter card you have and briefly say what kind it found before
  2366. displaying the picture.  If you say +dx where x is one of the predefined IBM
  2367. (S)VGA display adapter types, no hardware test is performed, so if you don't
  2368. have that type of (S)VGA card, -> DON'T <- use that particular +dx option!
  2369.  
  2370. When displaying the image to screen, a HSV conversion method is used (hue,
  2371. saturation, value).  This is a convenient way of translating colors from a
  2372. "true color" format (16 million) down a "colour mapped" format of something
  2373. reasonable (like 256), while still approximating the color as closely as the
  2374. available display hardware permits.  As mentioned previously, the tracer has
  2375. no way of knowing which colors will be finally used in the image, nor can it
  2376. deal properly with all of the colors which will be generated (up to 16M), so
  2377. only 4 shades each of 64 possible hues are mapped into the palette DAC, as
  2378. well as black, white, and two grey levels. The advantage a post-processor has
  2379. in choosing mapped colors is that it can throw away all the unused colors in
  2380. the palette map, and thereby free up some space for making better gradient
  2381. shades of the colors that are actually used.
  2382.  
  2383. There are several available image processing programs that can do this, a
  2384. public domain one that is very good is PICLAB, by the Stone Soup Group (the
  2385. folks who brought you FRACTINT).  The procedure is to load the TARGA file,
  2386. then use the MAKEPAL command to generate a 256 color map which is the
  2387. histogram-weighted average of the most-used colors in the image (You could
  2388. also PLOAD a palette file from FRACTINT or one you previously had saved using
  2389. PSAVE).  You then MAP the palette onto the image one of two ways:
  2390.  
  2391.      1)   If the DITHER variable is OFF, a nearest-match-color-fit is used,
  2392.           which can sometimes produce unwanted "banding" of colored regions
  2393.           (called false contours).
  2394.      2)   If the DITHER variable is ON, then a standard dither is used to
  2395.           determine final color values.  This is much better at blending the
  2396.           color bands, but can produce noise in reflections and make mirrors
  2397.           appear dirty or imperfect.
  2398.  
  2399. Then you would typically SHOW the image or GSAVE it into GIF format.  While
  2400. the picture is still in the unmapped form (TARGA, etc.) you can perform a
  2401. variety of advanced image processing transformations and conversions, so save
  2402. the .TGA or .RAW files you make (in case you ever get a TARGA card, or give
  2403. them to a friend who has one!).
  2404.  
  2405. A commercial product that also does a good job of nearest-match-color-fit is
  2406. the CONVERT utility of The AutoDesk Animator.  However, the dither effect is
  2407. not as good as that of PICLAB.  To convert the file in AA's CONVERT, you LOAD
  2408. TARGA, then in the CONVERT menu, go to the SCALE function and just hit RENDER.
  2409. Click on the DITHER (lights up with an asterisk when on) if you want it to use
  2410. it's dithering.  CONVERT will scale (if asked to) and then do a histogram of
  2411. total used colors like PICLAB, but then makes 7 passes on the color map and
  2412. image to determine shading thresholds of each hue.  This nearly eliminates the
  2413. color banding (false contours) in a lot of cases without resorting to good 'ol
  2414. dithering.  By now you must get the feeling DITHER is a 4-letter word.  If
  2415. you have a low-resolution display, it is.  If you have too few colors,
  2416. however, it can be a saving grace.  At resolutions of 640x400 or higher the
  2417. "spray paint" effect of dithering and anti-aliasing is much less noticeable,
  2418. and effects a much smoother blending appearance.
  2419.  
  2420. A new package to show up in the public domain/shareware circles for the IBM
  2421. is something called Image Alchemy, by Handmade Software.  It will convert
  2422. TARGA format to GIF files and do a decent job of palette selection and
  2423. dithering.  To use it simply say "ALCHEMY file.tga file.gif -g -8 -c256".
  2424. It also features a quick-and-dirty display mode where it uses a standardized
  2425. palette in much the same way DKB's +d option does, but offers dithering of the
  2426. image while using the pre-defined palette, for a somewhat better quick display.
  2427.  
  2428.  
  2429. 7.3)    Unix Systems
  2430.  
  2431. I don't have many details on Unix systems, but I hear that the FBM utilities
  2432. work well to convert the Dump format files into various formats of images.
  2433. For people with access to anonymous FTP over USENET, the FBM utilities are
  2434. available from nl.cs.emu.edu (128.2.222.56) in directory /usr/mlm/ftp.
  2435.  
  2436.  
  2437.  
  2438. 8)  DKBTrace Utilities
  2439.  
  2440. In many cases, creating data files for DKBTrace is difficult and tedious.  To
  2441. help remedy this problem, I and various other people have developed some
  2442. utilities to create data files.  These utilities are described below.
  2443.  
  2444. As well, there are some utilities that perform operations on the image files
  2445. created by DKBTrace.  These utilities convert between various formats and
  2446. allow you to modify or merge output files together.
  2447.  
  2448. I'd like to thank all the people who wrote these utilities and sent them to
  2449. me.  If anybody else comes up with other utilities, please let me know and
  2450. I'll include them in the distribution.
  2451.  
  2452. Some of these utilities are written in BASIC in IBM systems.  As such, they
  2453. are not easily portable from system to system.  If anyone wants to convert
  2454. them to C, let me know and I'll post the C versions.
  2455.  
  2456. 8.1)    Data File Creation Utilities
  2457.  
  2458. The data creation utilities fall into two categories:  Those that convert from
  2459. some other format into DKB format, and those that generate DKB files using
  2460. algorithmic techniques.  These utilities are described below.
  2461.  
  2462. 8.1.1)  SA2DKB
  2463.  
  2464. This program converts Sculpt-Animate 3D & 4D data files into DKB format.  It
  2465. currently only supports the basic triangles and textures. It doesn't support
  2466. smooth triangles (it treats them like normal triangles), light sources,
  2467. cameras, or floors. 
  2468.  
  2469. (This utility was formerly called "Sculpt2DKB" but the IBM systems out there
  2470. kept calling it "SCULPT2D", then couldn't figure out what a 2D program had to
  2471. do with raytracing or what the nonexistent Amiga program called "Sculpt-2D"
  2472. was :-)
  2473.  
  2474. 8.1.2)  DXF2DKB
  2475.  
  2476. This utility converts AutoCAD DXF (Drawing eXchange Format) files into
  2477. DKBTrace format scene description files.  It was written by Aaron Collins.  It
  2478. does not support all of the DXF primitives, but will suffice for simple
  2479. objects and scenes after EXPLODE'ing and DXFOUT'ing then in AutoCAD.
  2480.  
  2481. 8.1.3)  ShellGen
  2482.  
  2483. ShellGen is a BASIC program written by Dan Farmer.  It's based on a short code
  2484. fragment from Clifford Pickover's book "Computers, Pattern, Chaos, and Beauty"
  2485. (St. Martin's Press).  This code fragment was reprinted in Ray Tracing News
  2486. Issue 3.3.
  2487.  
  2488. As far as I know, the BASIC program only works on IBM's.  It does, however,
  2489. allow you to change the parameters and see a quick outline of what the result
  2490. will look like.
  2491.  
  2492. For those people without IBM's, I've changed the original code fragment to at
  2493. least output a DKB-format file.  No user interface has been provided, however.
  2494.  
  2495. 8.1.4)  Twister
  2496.  
  2497. Twister is a C program written by Drew Wells (CIS 73767,1244).  It creates
  2498. data files for twisted shapes.  The program uses a text interface and prompts
  2499. the user with a question/answer format.
  2500.  
  2501. 8.1.5)  Chem2DKB
  2502.  
  2503. Chem2DKB is an IBM BASIC program written by Dan Farmer.  It takes models
  2504. generated by the CHEM.EXE program written by Larry Puhl.
  2505.  
  2506. 8.1.6)  Lissajou
  2507.  
  2508. This is an IBM BASIC program written by Dan Farmer.  It creates data files for
  2509. lissajous figures.  The basic algorithms were from Clifford Pickover.  See
  2510. Scientific American Jan. '91 and Omni Feb '90 for examples.
  2511.  
  2512.  
  2513. 8.2)    Output File Manipulation Utilities
  2514.  
  2515. These utilities perform some useful manipulations on the dump format and Targa
  2516. format output files from DKBTrace.  I'd like to thank the people who wrote
  2517. these utilities and provided them for general distribution.
  2518.  
  2519. 8.2.1)  dump2i24   (DumpToIFF24)
  2520.  
  2521. This program was written by Helge E. Rasmussen (her@compel.dk).  It converts
  2522. the dump format files produced by DKBTrace into 24-bit IFF format files.
  2523. These files can then be read by a variety of programs including "The Art
  2524. Department" by ASDG.
  2525.  
  2526. 8.2.2)  catdump
  2527.  
  2528. This utility was written by Ville Saari vsaari@niksula.hut.fi (and copyright
  2529. by the Ferry Island Pixelboys.)  It takes two or more partially rendered files
  2530. in DKBTrace's dump format and merges them into one file.  This is useful for
  2531. all sorts of things like rendering different parts on different computers and
  2532. combining the results. 
  2533.  
  2534. NOTE:  Be careful if you combine pictures produced on different systems.  If
  2535. the random number generator works differently between the two systems, the
  2536. textures may look completely different from one another.  So long as you
  2537. use the same executable, you should be fine.
  2538.  
  2539. 8.2.3)  combdump  (combine dump)
  2540.  
  2541. This utility was also written by Ville Saari.  It takes two images generated
  2542. with DKBTrace with slightly different viewpoints, and creates one dump-format
  2543. image file to be viewed with RED-BLUE or RED-GREEN 3D glasses.  The program
  2544. allows you to compensate for the exact filtering characteristics of your
  2545. glasses to get the best possible result.
  2546.  
  2547. 8.2.4)  dump2mtv
  2548.  
  2549. This is yet another utility written by Ville Saari.  This one converts
  2550. DKBTrace dump format files onto MTV format used by the MTV and RayShade
  2551. raytracers.
  2552.  
  2553. 8.2.5)  dump2raw
  2554.  
  2555. The dump2raw utility was written by Aaron Collins to convert the dump format
  2556. output of DKBTrace into three separate files for red, green, and blue.  On the
  2557. IBM, the extensions for these files are "r8", "g8", and "b8".  On the other
  2558. systems, they are "red", "grn" and "blu".
  2559.  
  2560. Version 2.10 of the raytrace allows you to use the +fr option to output raw
  2561. format files directly without the need for a conversion program like this.
  2562.  
  2563. 8.2.6)  halftga
  2564.  
  2565. The halftga utility (written by Aaron Collins) shrinks a Targa-format file to
  2566. exactly half its original size.  This file can then be converted into a GIF
  2567. image and used in an IMAGE_MAP statement.  For systems with little memory
  2568. available for imagemaps, this command can be a life-saver. 
  2569.  
  2570. 8.2.7)  gluetga
  2571.  
  2572. This utility (by Aaron Collins) is similar to catdump but works for Targa
  2573. format files.  It takes several partially-rendered Targa files and glues them
  2574. together into one image. 
  2575.  
  2576. 8.2.8)  tga2dump
  2577.  
  2578. This utility was written by Aaron Collins.  It converts Targa format 16, 24,
  2579. and 32 bit images into DKB's dump format for use in image-mapping.
  2580.  
  2581.  
  2582. 8.3)    Animation Utilities
  2583.  
  2584. One of the most frequent questions I'm asked is whether or not DKBTrace
  2585. supports animation.  The answer is no, not directly.  However, I have made
  2586. some changes to the program to provide frame-to-frame consistency so you can
  2587. use it for animation if you want to.  The problem, then, is creating the data
  2588. files for each individual frame.  That's what this section is all about.
  2589.  
  2590. 8.3.1)  RayScene
  2591.  
  2592. Although RayScene is not being distributed with this raytracer, I thought I'd
  2593. at least mention it and tell you where you can get it.  RayScene is a program
  2594. that creates data files for DKBTrace based on a high-level (higher-level?)
  2595. description of the motion of the camera and the objects.  It was written by
  2596. Jari K{hk|nen (hole@tolsun.oulu.fi) and Panu Hassi (oldfox@tolsun.oulu.fi) and
  2597. is available by anonymous FTP from tolsun.oulu.fi (128.214.5.6) in the
  2598. directory /pub/rayscene or from iear.arts.rpi.edu in the directory
  2599. /pub/graphics/ray/rayscene.
  2600.  
  2601.  
  2602. This explanation of RayScene was sent to me by Panu Hassi;
  2603.  
  2604.    "I've tried animation with DBW before DKBTrace2.0 was released.  
  2605.     The procedure was this: First I wrote the first scene file, copied it 
  2606.     for NUMBER_OF_FRAMES times and then edited some parts of those files 
  2607.     to create movement etc.  If something went wrong (I accidentally edited 
  2608.     wrong value etc), I had to edit all those scene files again to make the
  2609.     changes.  Not so nice if there are 100 files to edit...
  2610.     
  2611.     So a friend of mine, Jari K{hk|nen, and I decided to write RayScene to
  2612.     make that process even a little easier.  With RayScene the process
  2613.     goes like this:  you create a scene file and mark the places that 
  2614.     should be changed with a variable, like:
  2615.  
  2616.     BOUNDED_BY                              
  2617.          SPHERE <0.0 0.0 0.0> #sphere_size# END_SPHERE
  2618.     END_BOUND
  2619.     
  2620.     Then you create another file where the values for these variables are
  2621.     listed.  Rayscene simply creates N scene files inserting current value of
  2622.     each variable to proper place.  That's all :D
  2623.     
  2624.     We have included couple of simple utilities that help with creating
  2625.     those variable values, but the original scene files are still created
  2626.     'manually'.  Still, the results have been really nice.  There are 
  2627.     several animations for Amiga and PC in tolsun.oulu.fi."
  2628.  
  2629. 9)  How it All Works (or How to Get What You Want)
  2630.  
  2631. The information in this section is designed for people who are reasonably
  2632. familiar with the raytracer and want more information on how things work so
  2633. they can push it to its limits.  You probably don't need this level of detail
  2634. to make interesting data files, but if you suddenly get confused about
  2635. something the program did, this section may help you figure it out.
  2636.  
  2637. 9.1)    Viewpoints
  2638.  
  2639. Viewpoints can be completely defined by four vectors.  The LOCATION is easy.
  2640. That's where the camera is.  The DIRECTION is a vector that starts at the
  2641. LOCATION and points to the center of a window.  The UP vector starts at the
  2642. center of the window and points to the center of the top edge.  The RIGHT
  2643. vector starts at the center of the window and points to the center of the
  2644. right edge. 
  2645.  
  2646.                               |\
  2647.                               | \
  2648.                               |  \
  2649.                               |   \
  2650.                               |  ^ \
  2651.                               |  |Up|
  2652.                               |  |  |
  2653.                               |  |  |
  2654.     Location *------------------->  |
  2655.                 Direction     |   \ |Right
  2656.                               |    \|
  2657.                               \     |
  2658.                                \    |
  2659.                                 \   |
  2660.                                  \  |
  2661.                                   \ |
  2662.                                    \|
  2663.  
  2664. The window is then divided up according to the resolution you specified and
  2665. rays are fired through the pixels out into the world.  For an eye ray,
  2666. therefore, the equation of the ray is:
  2667.  
  2668.    Location + t (Direction + ((height - y)*UP) + (x*RIGHT))
  2669.  
  2670. where "t" is a parameter that determines the distance from the eye to the
  2671. object being tested.  The Y coordinate is inverted by subtracting it from
  2672. height because most graphics systems put 0,0 in the top left corner of the
  2673. screen.
  2674.  
  2675. This viewpoint model is very flexible.  It allows you to use left-handed or
  2676. right-handed coordinate systems.  It also doesn't require that the DIRECTION,
  2677. UP, and RIGHT vectors be mutually orthogonal.  If you want, you can distort
  2678. the camera to get really bizarre results.
  2679.  
  2680. Once the basic four vectors are specified, it's possible to use the SKY and
  2681. LOOK_AT vectors to point the camera.  You must specify the SKY vector first,
  2682. but let me describe the LOOK_AT vector first.  LOOK_AT tells the camera to
  2683. rotate in such a way that the LOOK_AT point appears in the center of the
  2684. screen.  To do this, the camera first turns in the left-to-right direction
  2685. (longitude in Earth coordinates) until it's lined up with the LOOK_AT point.
  2686. It then turns in the up/down direction (latitude in Earth coordinates) until
  2687. it's looking at the desired point.
  2688.  
  2689. Ok, now we're looking at the proper point.  What else do we have to specify?
  2690. If you're looking at a point, you can still turn your camera sideways and
  2691. still be looking at the same spot.  This it the orientation that the SKY
  2692. direction determines.  The camera will try to position itself so that the
  2693. camera's UP direction lines up as closely as possible to the SKY direction.
  2694.  
  2695. Put another way - in airplane terms, the LOOK_AT vector determines your
  2696. heading (north, south, east, or west), and your pitch (climbing or
  2697. descending).  The SKY vector determines your banking angle.
  2698.  
  2699. 9.2)    Ray-Object Intersections
  2700.  
  2701. For every pixel on the screen, the raytracer fires at least one ray through
  2702. that pixel into the world to see what it hits.  For each hit (well, almost),
  2703. it calculates rays to each of the light sources to see if that point is
  2704. shadowed from that light source.  For reflecting objects, a reflected ray is
  2705. traced.  For refracting objects, a refracting ray is traced.  That all adds up
  2706. to a lot of rays.
  2707.  
  2708. Every ray is tested against every object in the world to see if the ray hits
  2709. that object. This is what slows down the raytracer.  You can make things
  2710. easier by using simple bounding shapes on your objects.
  2711.  
  2712. Fortunately, all ray-object intersections for all shapes in DKBTrace can be
  2713. solved by a simple quadratic equation.  This is why QUADRICs are used in
  2714. DKBTrace.  Solving for things like B-Splines, Bezier Splines, NURBS, Torus',
  2715. etc. is a lot more complicated.  That's why I haven't implemented primitives
  2716. for these shapes.
  2717.  
  2718. 9.3)    Transparency and Refraction
  2719.  
  2720. This section get really complicated because of the way transparency and
  2721. refraction are implemented.  If you don't really care, skip to the next
  2722. section. If you don't mind slogging through this and getting confused, then
  2723. read on.
  2724.  
  2725. - you've been warned -
  2726.  
  2727. The way that transparency and refraction work has changed slightly from
  2728. previous versions.  Now, transparency and refraction work together instead of
  2729. separately.
  2730.  
  2731. First, let me distinguish between reflected light and filtered light.  Suppose
  2732. you painted a table with patches of colour.  You then took some red sand and
  2733. sprinkled it on top of the various colours.  The red sand will tint the
  2734. colours red, but you will still see some of the original colour.  If, instead,
  2735. you took a sheet of red plexiglass and put it on top of the table, all you
  2736. could see would be shades of red.  That's because the plexiglass filter ONLY
  2737. allows the red colour to show through.
  2738.  
  2739. In DKBTrace, the layered textures work like the red sand - the colours on top
  2740. mix with the underlying colours depending on the density (ALPHA) of the
  2741. distribution.
  2742.  
  2743. Refraction, however, works like a filter.  The surface colour determines that
  2744. colours of light are allowed to pass from the inside of the object to the
  2745. outside, and vice versa.  Here are some filter colours:
  2746.  
  2747.    RED 1.0  GREEN 0.0  BLUE 0.0   ALPHA 1.0    - a red filter
  2748.    RED 1.0  GREEN 1.0  BLUE 1.0   ALPHA 1.0    - clear glass
  2749.    RED 0.0  GREEN 0.0  BLUE 0.0   ALPHA 1.0    - a dark filter - this will
  2750.                                                  appear black.
  2751.  
  2752. Now, consider the following layered textures:
  2753.  
  2754.    TEXTURE COLOUR Green ALPHA 0.6 END_TEXTURE
  2755.    TEXTURE COLOUR Yellow ALPHA 0.3 REFRACTION 0.5 END_TEXTURE
  2756.  
  2757. (Keep in mind that the last texture is on top.)
  2758.  
  2759. NOTE: In layered textures, only the REFRACTION component of the LAST entry has
  2760. any effect.
  2761.  
  2762. The colour you get is calculated like this:
  2763.  
  2764.          ____  Full Brightness
  2765.          |
  2766.          |
  2767.          |
  2768.          |
  2769.          |
  2770.          |   7/10 of pixel's colour is Yellow
  2771.          |
  2772.          |
  2773.          |
  2774.          |
  2775.          |
  2776.          |---
  2777.          |    
  2778.       -  |   3/10 (alpha) left over for underlying colour
  2779.      |   |
  2780.      |   |
  2781.      |   ----  Full Darkness
  2782.      |
  2783.      |
  2784.      |
  2785.      |
  2786.      |   ____  From the 3/10 available:
  2787.      |   |
  2788.      |   |
  2789.      |-> |   4/10 is green
  2790.          |
  2791.          |
  2792.          |---6/10 (alpha) is available for refraction
  2793.          |
  2794.          |
  2795.          |
  2796.          |
  2797.          |-- 5/10 of that (6/10) is passed through from refraction
  2798.          |        and filtered by the combined filter colour
  2799.          |        (yellow filtered by green).
  2800.          |
  2801.          |
  2802.          |
  2803.          ----
  2804.  
  2805.  
  2806.  
  2807. So, the top texture layer supplies some fraction of the light that reflects off
  2808. the surface of the object.  If the ALPHA was non-zero, it allows the lower 
  2809. textures to supply the remainder.  If, after all the textures are processed,
  2810. there's still some fraction left over, it is applied to the light that's
  2811. refracted through the object.
  2812.  
  2813. This algorithm probably doesn't coincide with reality, but neither does the rest
  2814. of the raytracer, so I'm not terribly concerned about it.
  2815.  
  2816. 9.4)    Textures, Noise, and Turbulence
  2817.  
  2818. If there's one thing that DKBTrace is known for, it's textures.  Here's how
  2819. they really work.  If you want some good reading material, check out "An Image
  2820. Synthesizer" by Ken Perlin in the SIGGRAPH '84 Conference Proceedings.
  2821.  
  2822. Let's start with a marble texture.  Real marble is created when different
  2823. colours of sediments are laid down one on top of another and compressed to
  2824. form solid rock.
  2825.  
  2826. For example, take a simple block of marble:
  2827.           ___________
  2828.          /          /|
  2829.         /          / |
  2830.        /__________/  |
  2831.        |   Red    | /|
  2832.        |----------|/ |
  2833.        |  White   | /|
  2834.        |----------|/ |
  2835.        |   Red    | /|
  2836.        |----------|/ |
  2837.        |  White   | /
  2838.        |__________|/
  2839.  
  2840. If you carve a shape put of this block of marble, you will get red and white
  2841. bands across it.
  2842.  
  2843. Now, consider wood.  The rings in wood are created when the tree grows a new
  2844. outer shell every year.  Hence, we have concentric cylinders of colours:
  2845.  
  2846.                 ______
  2847.                /      /
  2848.               /      / \
  2849.              /      /   \
  2850.             /      /     \
  2851.            /      /      |
  2852.           /______/       |
  2853.          / _____ \       |
  2854.         / / ___ \ \      |
  2855.        / / / _ \ \ \     /    (how do you draw a log in ASCII??!!)
  2856.       / / / / \ \ \ \   /
  2857.       | | | | | | | |  /
  2858.       | | | |O| | | | /
  2859.       | | | | | | | |/
  2860.       \ \ \ \_/ / / /
  2861.        \ \ \___/ / /
  2862.         \ \_____/ /
  2863.          \_______/
  2864.  
  2865. Cutting a shape out of a piece of wood will tend to give you rings of colour.
  2866.  
  2867. Now, this is fine, but the textures are still a bit boring.  For the next
  2868. step, we blend the colours together to create a nice smooth transition.  This
  2869. makes the texture look a bit better.  The problem, though, is that it's too
  2870. regular - real marble and wood aren't so perfect.
  2871.  
  2872. Before we make our wood and marble look any better, let's look at how we make
  2873. noise.  Noise (in raytracing) is sort of like a random number generator, but
  2874. it has the following properties:
  2875.  
  2876.    1) It's defined over 3D space i.e., it takes x, y, and z and returns the
  2877.       noise value there.
  2878.    2) If two points are far apart, the noise values at those points are
  2879.       relatively random.
  2880.    3) If two points are close together, the noise values at those points are
  2881.       close to each other.
  2882.  
  2883. You can visualize this as having a large room and a thermometer that ranges
  2884. from 0.0 to 1.0.  Each point in the room has a temperature.  Points that are
  2885. far apart have relatively random temperatures.  Points that are close together
  2886. have close temperatures. The temperature changes smoothly, but randomly as we
  2887. move through the room.
  2888.  
  2889. Now, let's place an object into this room along with an artist.  The artist
  2890. measures the temperature at each point on the object and paints that point a
  2891. different colour depending on the temperature.  What do we get?  BOZO texture!
  2892.  
  2893. Another function used in texturing is called DNoise.  This is sort of like
  2894. noise except that instead of giving a temperature, it gives a direction.  You
  2895. can think of it as the direction that the wind is blowing at that spot.
  2896.  
  2897. Finally, we have a function called turbulence which uses DNoise to push a
  2898. particle around a few times - each time going half as far as before.
  2899.  
  2900.          P ------------------------->
  2901.                   First Move        /
  2902.                                    /
  2903.                                   /
  2904.                                  /Second
  2905.                                 /  Move
  2906.                                /
  2907.                         ______/
  2908.                         \
  2909.                          \
  2910.                           \
  2911.                            Q - Final point.
  2912.  
  2913. This is what we use to create the "interesting" marble and wood texture.  We
  2914. locate the point we want to colour (P), then push it around a bit using
  2915. Turbulence to get to a final point (Q) then look up the colour of point Q in
  2916. our ordinary boring wood and marble textures.  That's the colour that's used
  2917. for the point P.
  2918.  
  2919. (Did you really want to know all that?  Do you really care?  I dunno.)
  2920.  
  2921. 9.5)    Layered Textures
  2922.  
  2923. As of version 2.10, DKBTrace supports layered textures.  Here's how that
  2924. works.
  2925.  
  2926. Each object and each shape has a texture that may be attached to it.  By
  2927. default, shapes have no texture, but objects have a default texture.
  2928. Internally, textures are marked as being constant or variable.  A constant
  2929. texture is one that was DECLAREd as a texture and is being shared by many
  2930. shapes and objects.  Variable textures are textures that have been declared
  2931. totally within the object or have used a DECLAREd texture and modified it in a
  2932. destructive way.  The idea here is that we want to save on memory by sharing
  2933. textures if possible. 
  2934.  
  2935. If you have several texture blocks for an object or a shape, they are placed
  2936. into a linked list (First-in Last-out).  For example, take the following
  2937. definition:
  2938.  
  2939.    OBJECT
  2940.       SPHERE <0 0 0> 1 END_SPHERE
  2941.       TEXTURE WOOD END_TEXTURE
  2942.       TEXTURE MARBLE END_TEXTURE
  2943.    END_OBJECT
  2944.  
  2945. Here's what happens while parsing this object:  Since this is an object (as
  2946. opposed to a shape - SPHERE, PLANE, etc.), it starts out with the default
  2947. texture attached.
  2948.  
  2949.    ________      _________
  2950.    |      |      |       |
  2951.    |      |----->|Default|
  2952.    |Object|      |Texture|
  2953.    |      |      |_______|
  2954.    |      |
  2955.    |______|
  2956.  
  2957. When the parser sees the first TEXTURE block, it looks to see what it has
  2958. linked.  Since the thing that's linked is the default texture (not a copy), it
  2959. discards it and puts in the new texture.
  2960.  
  2961.    ________      _________
  2962.    |      |      |       |
  2963.    |      |----->| WOOD  |
  2964.    |Object|      |Texture|
  2965.    |      |      |_______|
  2966.    |      |
  2967.    |______|
  2968.  
  2969. On the next texture, it sees that the texture isn't the default one, so it
  2970. adds the second texture into the linked list.
  2971.  
  2972.    ________      _________      _________
  2973.    |      |      |       |      |       |
  2974.    |      |----->|MARBLE |----->| WOOD  |
  2975.    |Object|      |Texture|      |Texture|
  2976.    |      |      |_______|      |_______|
  2977.    |      |
  2978.    |______|
  2979.  
  2980.  
  2981. Now for a problem.  If you want to specify the REFRACTION of the texture, the
  2982. raytracer must first calculate the surface colour.  It does this by marching
  2983. through the texture list and mixing all the colours.  When it's finished, it
  2984. checks the ALPHA value of the surface colour and decides whether it should
  2985. trace a refracting ray.  Where does it get the REFRACTION value and the index
  2986. of refraction?  It simply takes the one in the topmost (the last one defined)
  2987. texture.  I don't see any reason to have refraction values for any other
  2988. textures in the layer as it applies to the whole object.
  2989.  
  2990. 9.6)    Image Mapping
  2991.  
  2992. One major problem people have when designing data files for DKBTrace is how to
  2993. position images onto the desired surfaces.  With version 2.10, this problem
  2994. becomes slightly easier since the image can be mapped onto the object in the
  2995. object's natural coordinate system.  Thereafter, when the object is
  2996. translated, rotated, or scaled, the image map will follow it.
  2997.  
  2998. The image mapping that DKBTrace currently supports is called a "parallel
  2999. projection" mapping.  This technique is simple (that's why I implemented it
  3000. :-), but it's not perfect.  It works like a slide projector casting the
  3001. desired image onto the scene.  The difference, however, is that the image
  3002. never gets larger as you move further away from the slide projector.  In fact,
  3003. there is no real slide projector.  Consider the following cross section:
  3004.  
  3005.  
  3006. Image to Map
  3007.     |                 _________
  3008.     V                 \       /            /\        ___________________
  3009.                        \     /            /  \       \                 /
  3010. ----A-------------------A   A------------A    A-------A---------------A-->
  3011.     B                    B B            B      B       BB           BB
  3012.     C                     C            C        C        CCCC   CCCC
  3013.     D                                 D          D           DDD
  3014.     E                                E            E
  3015.     F                               F              F
  3016. ----G------------------------------G                G-------------------->
  3017.                                   /                  \
  3018.                                  /____________________\
  3019.  
  3020. This two dimensional example shows an image with colours A,B,C,D,E,F, and G
  3021. being mapped onto three objects.  The raytracer performs a similar operation
  3022. to map a 2D picture onto a 3D object.  Note that objects cannot shadow each
  3023. other from the image being mapped.  This means that the image will also appear
  3024. on the back of the object as a mirror image.
  3025.  
  3026. The mapping takes the original image (regardless of the size) and maps it onto
  3027. the range 0,0 to 1,1 in two of the 3D coordinates.  Which two coordinates is
  3028. specified by the gradient vector provided after the image.  This vector must
  3029. contain one positive number, one negative number, and one zero.  The positive
  3030. number identifies the u axis (the left-right direction in the image) and the
  3031. negative number represents the v axis (the picture's up-down direction).  Note
  3032. that the magnitude of the number is irrelevant.
  3033.  
  3034. For example:
  3035.  
  3036.     IMAGEMAP <1 -1 0> GIF "filename"
  3037.  
  3038. will map the GIF picture onto the square from <0 0 0> to <1 1 0> like this:
  3039.  
  3040.         Y
  3041.         ^
  3042.         |
  3043.         |
  3044.         |          
  3045.       1 |----------
  3046.         |   Top  R|
  3047.         |L       i|
  3048.         |e       g|
  3049.         |f       h|
  3050.         |t       t|
  3051.         | Bottom  |
  3052.         ----------------> X
  3053.                   1
  3054.  
  3055. If we reversed the vector, the picture would be transposed:
  3056.  
  3057.     IMAGEMAP <-1 1 0> GIF "filename"
  3058.  
  3059. produces:
  3060.  
  3061.         Y
  3062.         ^
  3063.         |
  3064.         |
  3065.         |          
  3066.       1 |----------
  3067.         |B Right  |
  3068.         |o       T|
  3069.         |t       o|
  3070.         |t       p|
  3071.         |o        |
  3072.         |m  Left  |
  3073.         ----------------> X
  3074.                   1
  3075.  
  3076. Once the image orientation has been determined, it can be translated, rotated,
  3077. and scaled as desired to map properly onto the object.
  3078.  
  3079.  
  3080.  
  3081. 9.7)    Output File Formats
  3082.  
  3083. People always ask me to describe the output file formats of DKBTrace.  I
  3084. received so many requests for this that I decided to put it into the document.
  3085.  
  3086. The normal "default" output format is "dump" format.  This is based on QRT
  3087. format and goes like this, where each character is a hex digit:
  3088.  
  3089. Header:
  3090.      wwww hhhh          - width, height (16 bits each, LSB first)
  3091.  
  3092. For each data line:
  3093.      llll               - line number (16 bits, LSB first, 0 to LINES-1)
  3094.      rr rr rr rr rr ... - the red components for that line
  3095.                           (8 bits each - 0=dark, 255=bright)
  3096.  
  3097.      gg gg gg gg gg ... - the green components for that line
  3098.                           (8 bits each - 0=dark, 255=bright)
  3099.  
  3100.      bb bb bb bb bb ... - the blue components for that line
  3101.                           (8 bits each - 0=dark, 255=bright)
  3102.  
  3103. Note that this format is slightly different from QRT's.
  3104.  
  3105.  
  3106. The "+fr" option of the raytracer produces "raw" files.  These are simply
  3107. three files with no header information and no line number information - just
  3108. the raw data.
  3109.  
  3110. The "+ft" option writes out Targa format.  Specifically, the fields are:
  3111.  
  3112. Header:
  3113.    00 00 02 00 00      - Fixed header information for uncompressed type 2 image
  3114.    00 00 00
  3115.    0000                - Horizontal offset always is at 0000
  3116.    llll                - Vertical offset (1st line number, 16 bits, LSB first)
  3117.    wwww hhhh           - width, height of image (16 bits each, LSB first)
  3118.    18 20               - 24 bits per pixel, Top-down raster
  3119.  
  3120. For each line:
  3121.    bb gg rr bb gg rr ... - blue, green, and red data, 8 bits for each pixel.
  3122.  
  3123.  
  3124.  
  3125.  
  3126. 10) Common Questions and Answers
  3127.  
  3128. I often get asked the same questions again and again.  I usually take this to
  3129. mean that the documentation is not complete or not sufficiently clear.  In
  3130. order to correct this problem, I've added some sections to the document
  3131. describing the features in more detail.  I've also collected some of the more
  3132. popular questions and answered them here:
  3133.  
  3134.      Q: Will you be implementing radiosity?
  3135.      A: I don't expect so.  The techniques for radiosity are quite involved
  3136.         and time consuming (although they are getting faster).  The amount of
  3137.         effort required to implement radiosity is beyond my current plans.
  3138.  
  3139.      Q: Do you intend make DKBTrace RenderMan compatible?
  3140.      A: Probably not.  RenderMan is a specification that requires much more
  3141.         functionality than DKBTrace currently provides.  The camera models,
  3142.         modelling primitives, and shading language of RenderMan are all very
  3143.         involved and difficult to implement.  As well, RenderMan is not well
  3144.         suited to a raytracing approach.  Don't expect to see DKBTrace
  3145.         RenderMan compatible in the near (or distant) future.  Note, though
  3146.         that several of the DKBTrace textures are similar to those obtainable
  3147.         by RenderMan.
  3148.  
  3149.      Q: I defined a light source but the shadows and lighting are all wrong.
  3150.      A: Light sources must be defined at the origin (0,0,0) and translated to
  3151.         the proper place.  The reason for this is to allow the diffuse lighting
  3152.         calculations to quickly determine where the center of the light source
  3153.         is.  It's a very difficult task to calculate the center of an object
  3154.         (in general), so I simply take the place that the object was translated
  3155.         to as the center of the light source.
  3156.  
  3157.      Q: I keep running out of memory.  What can I do?
  3158.      A: Buy more memory :-)  But seriously, you can decrease the memory
  3159.         requirements for any given picture in several ways:
  3160.           1) DECLARE texture constants and use them (textures are shared).
  3161.           2) Don't modify the texture that you are sharing.  On the first
  3162.              modify, the texture is copied and (therefore) takes up more space.
  3163.           3) Put the object transformations before the texture structure.  This
  3164.              prevents the texture from being transformed (and hence, copied.
  3165.              This may not always be desirable, though).
  3166.           4) Use UNIONS instead of COMPOSITE objects to put pieces together.
  3167.              (previous versions of the raytracer didn't allow this because
  3168.              the texture applied to the entire object.  Version 2.10 and up
  3169.              allow you to change the texture on a per-shape basis.)
  3170.           5) Use fewer or smaller image maps.
  3171.           6) Use GIF or IFF (non-HAM) images for image maps.  These are stored
  3172.              internally as 8 bits per pixel with a colour table instead of
  3173.              24 bits per pixel.
  3174.           
  3175.      Q: I get a floating point exception error on certain pictures. 
  3176.         What's wrong?
  3177.      A: Oh no! Not another one!  The raytracer (obviously) performs MANY
  3178.         floating point operations when tracing a scene.  If I had to check
  3179.         each one for overflow or underflow, the program would be much longer
  3180.         and I would be much closer to going insane trying to locate all
  3181.         possible cases.  If you get this problem, I'd suggest that you
  3182.         first look through your data file to make sure you're not doing
  3183.         something stupid like:
  3184.  
  3185.           - Scaling something by 0.0 in ANY dimension
  3186.           - Making the LOOK_AT point the same as the LOCATION
  3187.           - Defining triangles with two points the same (or nearly the same)
  3188.           - Using the zero vector for normals.
  3189.  
  3190.         If it doesn't seem to be one of these problems, let me know, but there
  3191.         may not be a lot I can do because overflows can occur almost anywhere.
  3192.         Sorry.  If you do have such troubles, you can try to isolate the
  3193.         problem in the input data file by commenting out objects or groups
  3194.         of objects until you narrow it down to a particular section that
  3195.         fails.  Then try commenting out the individual characteristics of the
  3196.         offending object.
  3197.  
  3198.      Q: No matter how much I scale a Cylinder, I can't make it fit on the
  3199.         screen.  How big is it and how much do I have to scale it?
  3200.      A: Cylinders (like most quadrics) are infinitely long.  No matter how
  3201.         much you scale them, they still won't fit on the screen.  To make a
  3202.         capped cylinder, you must use CSG:
  3203.  
  3204.            INTERSECTION
  3205.               QUADRIC Cylinder_Y END_QUADRIC
  3206.               PLANE <0.0 1.0 0.0> 1.0 END_PLANE
  3207.               PLANE <0.0 -1.0 0.0> 1.0 END_PLANE
  3208.            END_INTERSECTION
  3209.  
  3210.         Cylinders CAN be scaled in cross-section, the two vectors NOT in the
  3211.         name of the cylinder (X and Z, in our example above) can be scaled
  3212.         to control the width and thickness of the cylinder.  Scaling the Y
  3213.         value (which is normally infinite) is meaningless, unless you have
  3214.         "capped" it as above, then scaling the entire INTERSECTION object
  3215.         in the Y dimension will control the height of the cylinder.
  3216.  
  3217.      Q: Why don't you define a primitive for a 6-sided box?
  3218.      A: Because you can do it so easily with CSG:
  3219.  
  3220.            INTERSECTION
  3221.               PLANE < 1.0  0.0  0.0> 1.0 END_PLANE
  3222.               PLANE <-1.0  0.0  0.0> 1.0 END_PLANE
  3223.               PLANE < 0.0  1.0  0.0> 1.0 END_PLANE
  3224.               PLANE < 0.0 -1.0  0.0> 1.0 END_PLANE
  3225.               PLANE < 0.0  0.0  1.0> 1.0 END_PLANE
  3226.               PLANE < 0.0  0.0 -1.0> 1.0 END_PLANE
  3227.            END_INTERSECTION
  3228.  
  3229.      Q: Are planes 2D objects or are they 3D but infinitely thin?
  3230.      A: Neither.  Planes are 3D objects that divide the world into two
  3231.         half-spaces.  The space in the direction of the surface normal is
  3232.         considered outside and the other space is inside. In other words,
  3233.         planes are 3D objects that are infinitely thick.
  3234.  
  3235.                             ^
  3236.                             |
  3237.                             |
  3238.                             |  Outside
  3239.                      _______|_______
  3240.                                Inside
  3241.  
  3242.  
  3243.      Q: Can DKBTrace render soft shadows?
  3244.      A: No.  This would require a lot more programming work and a lot more
  3245.         calculation time.  You can place an unturbulated WOOD texture
  3246.         "filter" over a lamp in a can, and use a colour map going from dark
  3247.         (ALPHA 0.0) around the edges to clear (ALPHA 1.0) at the center,
  3248.         and get a soft-shadow-like effect for a "spotlight".
  3249.  
  3250.      Q: I'd like to go through the program and hand-optimize the assembly code
  3251.         in places to make it faster.  What should I optimize?
  3252.      A: Don't bother.  With hand optimization, you'd spend a lot of time to
  3253.         get perhaps a 5-10% speed improvement at the cost of total loss of
  3254.         portability.  If you use a better ray-surface intersection algorithm,
  3255.         you should be able to get an order of magnitude or more improvement.
  3256.         Check out some books and papers on raytracing for useful techniques.
  3257.         Specifically, check out "Spatial Subdivision" and "Ray Coherence"
  3258.         techniques.
  3259.  
  3260.      Q: Objects on the edges of the screen seem to be distorted.  Why?
  3261.      A: If the DIRECTION vector of the viewpoint is not very long, you may
  3262.         get distortion at the edges of the screen.  The reason for this is that
  3263.         the viewpoint's screen is flat:
  3264.  
  3265.  
  3266.                                | /\  This object looks small
  3267.                                | \/
  3268.                                |
  3269.                                |
  3270.                                *   <---- * = Projection of objects onto screen.
  3271.                                |
  3272.                                |
  3273.                Viewpoint --> V * /\  This object looks big
  3274.                                * \/
  3275.                                |
  3276.                                |
  3277.                                |
  3278.                                |<---- viewing screen.
  3279.                                |
  3280.                                |
  3281.  
  3282.      Q: How do you position image maps without a lot of trial and error?
  3283.      A: By default, images will be mapped onto the range 0,0 to 1,1 in the
  3284.         appropriate plane.  You should be able to translate, rotate, and
  3285.         scale the image from there.
  3286.  
  3287.      Q: What's the difference between ALPHA and REFRACTION?
  3288.      A: The difference is a bit subtle.  Alpha is a component of a colour that
  3289.         determines how much light can pass through that colour.  Refraction is
  3290.         a property of a surface that determines how much light can come from
  3291.         inside the surface.  See the section above on Transparency and
  3292.         Refraction for more details.
  3293.  
  3294.      Q: How do you calculate the surface normals for smooth triangles?
  3295.      A: When I implemented smooth triangles, I never really expected anyone to
  3296.         manually calculate the surface normals.  There are two ways of getting
  3297.         another program to calculate them for you.
  3298.  
  3299.           1) Depending on the type of input to the program, you may be able to
  3300.              calculate the surface normals directly.  For example, if you have
  3301.              a program that converts B-Spline or Bezier Spline surfaces into
  3302.              DKB-format files, you can calculate the surface normals from the
  3303.              surface equations.
  3304.  
  3305.           2) If your original data was a polygon or triangle mesh, then it's
  3306.              not quite so simple.  You have to first calculate the surface
  3307.              normals of all the triangles.  This is easy to do - you just use
  3308.              the vector cross-product of two sides (make sure you get the
  3309.              vectors in the right order).  Then, for every vertex, you average
  3310.              the surface normals of the triangles that meet at that vertex.
  3311.              These are the normals you use for smooth triangles.
  3312.  
  3313.      Q: When I render parts of a picture on different systems, the textures
  3314.         don't match when I put them together.  Why?
  3315.      A: The appearance of a texture depends on the particular random number
  3316.         generator used on your system.  DKBTrace seeds the random number
  3317.         generator with a fixed value when it starts, so the textures will be
  3318.         consistent from one run to another or from one frame to another so
  3319.         long as you use the same executables.  Once you change executables,
  3320.         you will likely change the random number generator and, hence, the
  3321.         appearance of the texture.  There is an example of a standard ANSI
  3322.         random number generator provided in IBM.C, include it in your machine-
  3323.         specific code if you are having consistency problems.
  3324.  
  3325.      Q: What's the difference between a COLOUR declared inside a TEXTURE
  3326.         and one that's in a shape or an object and not in a texture?
  3327.      A: The colour in the texture specifies the colour to use for qualities
  3328.         5 and up.  The colour on the shape and object are used for faster
  3329.         rendering in qualities 4 and lower and for the colour of light sources.
  3330.         See the -q option for details on the quality parameter.
  3331.  
  3332.  
  3333.      Q: I created an object that passes through its bounding volume.  At times,
  3334.         I can see the parts of the object that are outside the bounding volume.
  3335.         Why does this happen?
  3336.      A: Bounding volumes are NOT designed to change the shape of the object.
  3337.         They are strictly a realtime improvement feature.  The raytracer trusts
  3338.         you when you say that the object is enclosed by a bounding volume.  The
  3339.         way it uses bounding volumes is very simple:  If the ray hits the
  3340.         bounding volume (or the ray's origin is inside the bounding volume),
  3341.         then the object is tested against that ray.  Otherwise, we ignore the
  3342.         object.  If the object extends beyond the bounding volume, anything goes.
  3343.         The results are undefined.  It's quite possible that you could see the
  3344.         object outside the bounding volume and it's also possible that it could
  3345.         be invisible.  It all depends on the geometry of the scene.
  3346.  
  3347.      Q: Will you be writing a Graphical User Interface for DKB?
  3348.      A: No, but several other people have expressed an interest in writing
  3349.         one.  I'd like to form a mailing list to get all these people in touch
  3350.         with each other, so if you have an interest in this, please let me
  3351.         know.
  3352.  
  3353.      Q: When will the next version be available?
  3354.      A: If I told you, I'd be lying because I don't know.  I'm finding that
  3355.         releasing an official version of a program like this is a major
  3356.         effort.  It requires not only the changes to the code, but also
  3357.         changes to the documentation.  Sometimes (as with this release), I
  3358.         have to change the older data files to conform to the new syntax.
  3359.         Usually, I have to spend a lot of time re-rendering scenes that used
  3360.         to work to make sure they still do.  That combined with sending the
  3361.         files to beta testers, getting feedback, making fixes, and re-issuing
  3362.         the changes adds up to a lot of work.  I don't expect I'll be doing
  3363.         it terribly often.
  3364.  
  3365.         Bottom line - If I say "next week", don't believe me.  I'm probably
  3366.         wrong.
  3367.  
  3368.  
  3369.  
  3370. 11) Converting Data Files from Versions Prior to 2.10
  3371.  
  3372. Unfortunately, version 2.10 changed the format of the data files.  These
  3373. changes were mostly to avoid confusion - especially in the case of layered
  3374. textures.  There were also some changes that were made to allow more flexible
  3375. library objects.  This section details the changes in the data file format and
  3376. why it was necessary to make those changes.  I'm sorry that you have to go
  3377. back through all your old data files and edit them all, but I think you'll
  3378. agree (I hope you'll agree :-) that the changes are for the better.
  3379.  
  3380.    1) The following keywords are no longer accepted outside of a TEXTURE block:
  3381.         AMBIENT, DIFFUSE, BRILLIANCE, REFLECTION, REFRACTION, IOR, PHONG,
  3382.         PHONG_SIZE, SPECULAR, ROUGHNESS
  3383.  
  3384.       Reason: For layered textures, it's not clear which texture these keywords
  3385.               apply to if they're not in a TEXTURE block.  I was really getting
  3386.               messed up in the implementation trying to locate the proper
  3387.               references for these keywords.  It's much cleaner to only allow
  3388.               them inside a TEXTURE block.
  3389.  
  3390.    2) A new texture called COLOUR (or COLOR) has been added.  This texture
  3391.       simply specifies a simple colour to use.
  3392.  
  3393.       Reason:  It's useful to be able to declare a TEXTURE with the colour
  3394.                embedded inside it.  Besides, I had to provide some way of
  3395.                specifying a simple colour after I made the following change:
  3396.  
  3397.    3) The keyword "COLOUR" or "COLOR" when used outside of a TEXTURE block
  3398.       is only used to provide a colour for low-quality renderings (ones where
  3399.       the -q value is 5 or below.
  3400.  
  3401.       Reason:  This is the same reason as for change 1.  For layered textures,
  3402.                it wasn't clear what the object or shape colour meant when the
  3403.                texture itself contained colour information.  Rather than have
  3404.                a convoluted searching scheme (which I tried at first, then
  3405.                abandoned due to difficulties in explaining it), I decided to
  3406.                keep it simple.  If you want a simple colour, put it in a
  3407.                TEXTURE block.
  3408.  
  3409.    4) When an object or shape is transformed, the textures attached to it are
  3410.       transformed as well.
  3411.  
  3412.       Reason:  Previously, you couldn't DECLARE objects with textures, then
  3413.                create identical copies of them in different places.  This was
  3414.                especially annoying when you create an object that has an image
  3415.                mapped onto it.  As soon as you moved the object, the image was
  3416.                left behind.  Unfortunately, this means that the texture trans-
  3417.                formations inside TEXTURE blocks in old data files would double
  3418.                transform the texture, and must be removed.
  3419.  
  3420.    5) The interaction between ALPHA colours and REFRACTION has changed.
  3421.       Previously, there was no interaction at all.  If you had a surface that
  3422.       contained an ALPHA colour, you could see through the surface.  If the
  3423.       surface had refraction, you could also see through.  With the new
  3424.       release, ALPHA and REFRACTION in combination tell you how much light
  3425.       is passed through from the inside of the object.
  3426.  
  3427.       To make things a bit easier, if an object has an ALPHA component but the
  3428.       REFRACTION is 0.0 (or unspecified), the renderer will simply transmit the
  3429.       ray through the object without any refractive bending.
  3430.  
  3431.       Reason:  It seemed to make sense.  The code for ALPHA was doing the same
  3432.                work as the code for REFRACTION except for actually bending
  3433.                the ray.  Now, you can create objects that are partially opaque
  3434.                and partially transparent. Where they are transparent, the light
  3435.                passing through the object is bent by the index of refraction.
  3436.                Makes sense, no?
  3437.  
  3438.    6) When you use an IMAGEMAP with the ONCE option, the colour outside the
  3439.       mapped image is transparent (RED 1.0 GREEN 1.0 BLUE 1.0 ALPHA 1.0).
  3440.  
  3441.       Reason:  This allows you to see the underlying textures.
  3442.  
  3443.  
  3444.    7) I've remove "BasicShapes.data" and replaced it with "shapes.dat",
  3445.       "colors.dat", and "textures.dat".
  3446.  
  3447.  
  3448.       Reason:  The old name didn't apply any more (since it contained more than
  3449.                just shapes).  Also, I was tired of the IBM people using the
  3450.                name "BASICSHA.DAT" :-).
  3451.  
  3452.    8) The textures in textures.dat (formerly BasicShapes.data) were previously
  3453.       scaled to <10.0 10.0 10.0>.  This scaling has been removed.
  3454.  
  3455.       Reason:  The factor of 10.0 seemed to be a totally arbitrary scale factor
  3456.                that someone used.  I'd like to keep the scaling factors up to
  3457.                the users.
  3458.  
  3459. 12) Handy Hints
  3460.  
  3461.      -    To see a quick version of your picture, use -w64 -h80 as command
  3462.           line parameters on the Amiga.  For the IBM, try -w80 -h50.  This
  3463.           displays the picture in a small rectangle so that you can see how
  3464.           it will look.
  3465.  
  3466.      -    Try using the sample default files for different usages - QUICK.DEF
  3467.           shows a fast postage-stamp rendering (80x50, as above) to the
  3468.           screen only, LOCKED.DEF will display the picture with anti-aliasing
  3469.           on (takes forever) with no abort (do this before you go to bed...).
  3470.           The normal default options file TRACE.DEF is read and you can
  3471.           supersede this with another .DEF file by specifying it on the
  3472.           command line, for example:
  3473.  
  3474.           trace -iworld.dat -oworld.out quick.def
  3475.  
  3476.      -    When translating light sources, translate the OBJECT, not the
  3477.           QUADRIC surface.  The light source uses the center of the object as
  3478.           the origin of the light.
  3479.  
  3480.      -    When animating objects with solid textures, the textures must move
  3481.           with the object, i.e. apply the same ROTATE or TRANSLATE functions
  3482.           to the texture as to the object itself.  This is now done automatic-
  3483.           ally in version 2.10 if the transformations are placed _after_ the
  3484.           TEXTURE block.
  3485.  
  3486.      -    You can declare constants for most of the data types in the program
  3487.           including floats and vectors.  By combining this with INCLUDE files,
  3488.           you can easily separate the parameters for an animation into a
  3489.           separate file.
  3490.  
  3491.      -    The amount of ambient light plus diffuse light should be less than
  3492.           or equal to 1.0.  The program accepts any values, but may produce
  3493.           strange results.
  3494.  
  3495.      -    When using ripples, don't make the ripples too deep or you may get
  3496.           strange results (the dreaded "digital zits"!).
  3497.  
  3498.      -    Wood textures usually look better when they are scaled to different
  3499.           values in x, y, and z, and then rotated to a different angle.
  3500.  
  3501.      -    You can sort of dither a colour by placing a floating point number
  3502.           into the texture record:
  3503.  
  3504.           TEXTURE
  3505.                0.05
  3506.           END_TEXTURE
  3507.  
  3508.           This adds a small random value to the intensity of the diffuse
  3509.           light on the object.  Don't make the number too big or you may get
  3510.           strange results.  You generally won't want to use this if you are
  3511.           rendering frames for animations, as this "dithering" is random.
  3512.  
  3513.           Better results can be obtained, however, by doing proper dithering
  3514.           in a post-processor.
  3515.  
  3516.      -    You can compensate for non-square aspect ratios on the monitors by
  3517.           making the RIGHT vector in the VIEWPOINT longer or shorter.  A good
  3518.           value for the Amiga is about 1.333.  This seems ok for IBM's too at
  3519.           320x200 resolution.  If your spheres and circles aren't round, try
  3520.           varying it.
  3521.  
  3522.      -    If you are importing images from other systems, you may find that
  3523.           the shapes are backwards (left-to-right inverted) and no rotation
  3524.           can make them right.  All you have to do is negate the terms in the
  3525.           RIGHT vector of the viewpoint to flip the camera left-to-right (use
  3526.           the "right-hand" coordinate system).
  3527.  
  3528.      -    By making the DIRECTION vector in the VIEWPOINT longer, you can
  3529.           achieve the effect of a tele-photo lens.
  3530.  
  3531.      -    When rendering on the Amiga, use a resolution of 320 by 400 to
  3532.           create a full sized HAM picture.
  3533.  
  3534.  
  3535.  
  3536. 13) Compiling the Code
  3537.  
  3538. If you want to compile the source code on a supported platform, do the
  3539. following:
  3540.  
  3541.     1) Copy or rename the file called <system>conf.h to config.h
  3542.          eg.  rename amigaconf.h config.h
  3543.  
  3544.     2) Copy or rename the appropriate make file to "makefile"
  3545.          eg.  rename amigamake makefile
  3546.  
  3547.     3) Edit the makefile to make sure all compiler options are set up
  3548.          properly for your system.
  3549.  
  3550.     4) Type "make"
  3551.  
  3552.  
  3553.  
  3554.  
  3555. 14) Porting to Different Platforms
  3556.  
  3557. I've taken great pains to make DKBTrace as portable as possible.  So far, it's
  3558. working out fairly well.  For the most part, the core of the raytracer will
  3559. compile with any decent C compiler.
  3560.  
  3561. If you want to port the raytracer to another system, please try to modify the
  3562. core of the raytracer as little as possible.  Each system will have its own
  3563. makefile, config file, and C file.  The config file is included by all of the
  3564. raytrace modules and can be used to perform special #defines for that system.
  3565. The C file should contain all system-specific code.  It must implement the
  3566. following functions:
  3567.  
  3568.    void display_init ();    /* Open the graphics device and initialize it */
  3569.    void display_close();    /* Close the graphics device                  */
  3570.    void display_finished(); /* Perform any operations required after      */
  3571.                             /* finishing the rendering but before quitting*/
  3572.    void display_plot (x, y, Red, Green, Blue)
  3573.                             /* Display the specified colour at point x,y  */
  3574.  
  3575.  
  3576. In your config file, you may customize the following things:
  3577.  
  3578.    #define FILE_NAME_LENGTH    (default 150)
  3579.    #define DBL_FORMAT_STRING   (the string to use to read a double)
  3580.    #define DEFAULT_OUTPUT_FORMAT ('d', 'r' or 't' - default output file format)
  3581.    #define TEST_ABORT          (the operation to perform while tracing to see
  3582.                                 if we should abort the trace.)
  3583.    #define RED_RAW_FILE_EXTENSION
  3584.    #define GREEN_RAW_FILE_EXTENSION
  3585.    #define BLUE_RAW_FILE_EXTENSION
  3586.                                (the default extensions for the +fr mode)
  3587.  
  3588.    #define STARTUP_DKB_TRACE   (the code to call immediately after starting
  3589.                                 the main program. - useful if you don't have
  3590.                                 a command-line interface)
  3591.  
  3592.    #define PARAMS(x)           ("(x)" if you have prototypes, "()" otherwise)
  3593.  
  3594.  
  3595.  
  3596. 15) References
  3597.  
  3598. I'm always asked about good books on raytracing and graphics in general.
  3599. This section address that issue by listing several good books or periodicals
  3600. that you should be able to locate in your local computer book store or your
  3601. local university library.
  3602.  
  3603.     "An Introduction to Raytracing"
  3604.     Andrew S. Glassner (editor)
  3605.     Academic Press
  3606.     1989
  3607.  
  3608.     "Image Synthesis:  Theory and Practice"
  3609.     Nadia Magnenat-Thalman and Daniel Thalmann
  3610.     Springer-Verlag
  3611.     1987
  3612.  
  3613.     "The RenderMan Companion"
  3614.     Steve Upstill
  3615.     Addison Wesley
  3616.     1989
  3617.  
  3618.     "Graphics Gems"
  3619.     Andrew S. Glassner (editor)
  3620.     Academic Press
  3621.     1990
  3622.  
  3623.     "Fundamentals of Interactive Computer Graphics"
  3624.     J. D. Foley and A. Van Dam
  3625.     Addison-Wesley
  3626.     1983
  3627.  
  3628.     "Computer Graphics:  Principles and Practice (2nd Ed.)"
  3629.     J. D. Foley, A. van Dam, J. F. Hughes
  3630.     Addison-Wesley,
  3631.     1990
  3632.  
  3633.     "Computers, Pattern, Chaos, and Beauty"
  3634.     Clifford Pickover
  3635.     St. Martin's Press
  3636.  
  3637.     "SIGGRAPH Conference Proceedings"
  3638.     Association for Computing Machinery
  3639.     Special Interest Group on Computer Graphics
  3640.  
  3641.     "IEEE Computer Graphics and Applications"
  3642.     The Computer Society
  3643.     10662, Los Vaqueros Circle
  3644.     Los Alimitos, CA 90720
  3645.  
  3646.     "The CRC Handbook of Mathematical Curves and Surfaces"
  3647.     David von Seggern
  3648.     CRC Press
  3649.     1990
  3650.  
  3651.     "The CRC Handbook of Standard Mathematical Tables"
  3652.     CRC Press
  3653.     The Beginning of Time
  3654.  
  3655.  
  3656. 16) Concluding Remarks
  3657.  
  3658. It seems that in any project like this, as soon as you fix some bugs, some
  3659. more appear.  I expect that the new features I provided in this release will
  3660. cause some problems somewhere.  There's only so much you can do to get all the
  3661. bugs out.  For the next little while, I intend to keep the program stable
  3662. feature-wise and just tackle major bugs.  Hopefully things will stablize this
  3663. way (and I can take a much needed breather).
  3664.  
  3665. Thanks go out to Alexander Enzmann for generously providing the code for the
  3666. QUARTIC surface algorithms, and for his assistance in implementing it and
  3667. for helping squash a couple of other bugs.
  3668.  
  3669. I would like to thank all the people who used versions 2.01 and 2.04 and
  3670. provided useful comments and helpful suggestions.  The program has been much
  3671. improved with your help.
  3672.  
  3673. I would also like to thank my beta testers for all the help, bug reports,
  3674. suggestions, comments, and time spent.  I'd like to say a special thank-you to
  3675. Aaron Collins who has fielded many of the questions on the raytracer and has
  3676. been invaluable in debugging, testing, and generally improving the program.
  3677. Thanks guys. 
  3678.  
  3679. David Buck
  3680.  
  3681.