home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 1995 January / pcw-0195.iso / polyray / polyray.doc < prev    next >
Text File  |  1994-12-31  |  203KB  |  4,862 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.                                Polyray v1.7
  26.                     (c) 1991-1994 Alexander R. Enzmann
  27.                                17 March 1994
  28.                             All Rights Reserved
  29.  
  30.      1 Introduction & Shareware Information                   1
  31.      1.1 Acknowledgments and Other Legal Stuff                2
  32.      1.2 Useful tools                                         3
  33.      1.2.1 Animation Utilities                                3
  34.      1.2.2 Modellers                                          4
  35.      1.2.3 Miscellaneous Programs                             4
  36.      1.2.4 Other Raytracers                                   5
  37.      1.2.5 References                                         5
  38.      1.3 Contents of this document                            6
  39.      1.4 Quick demo                                           6
  40.      1.5 Command Line Options                                 8
  41.      1.6 Initialization File                                  9
  42.      1.7 Rendering Options                                    10
  43.      1.7.1 Raytracing                                         10
  44.      1.7.1.1 Antialiasing                                     11
  45.      1.7.1.2 Focal Blur                                       12
  46.      1.7.1.3 Bounding Slabs                                   12
  47.      1.7.1.4 Shading Quality Flags                            13
  48.      1.7.2 Scan Conversion                                    14
  49.      1.7.3 Wireframe                                          15
  50.      1.7.4 Depth Files                                        15
  51.      1.7.5 Raw Triangles                                      16
  52.      1.8 Display Options (IBM format only)                    16
  53.      2  Detailed description of the Polyray input format      17
  54.      2.1 Expressions                                          18
  55.      2.1.1 Numeric expressions                                18
  56.      2.1.2 Vector Expressions                                 19
  57.      2.1.3 Arrays                                             20
  58.      2.1.4 Conditional Expressions                            22
  59.      2.1.5 Run-Time expressions                               22
  60.      2.1.6 Named Expressions                                  23
  61.      2.1.6.1 Static variables                                 24
  62.      2.1.6.2 Lazy Evaluation                                  25
  63.      2.2 Definition of the viewpoint                          26
  64.      2.3 Objects/Surfaces                                     28
  65.      2.3.1 Object Modifiers                                   28
  66.      2.3.1.1 Position and Orientation Modifiers               29
  67.      2.3.1.1.1 Translation                                    29
  68.      2.3.1.1.2 Rotation                                       29
  69.      2.3.1.1.3 Scaling                                        29
  70.      2.3.1.1.4 Shear                                          30
  71.      2.3.1.1.5 Displace                                       30
  72.      2.3.1.1.6 UV Bounds                                      31
  73.      2.3.1.2 Bounding box                                     31
  74.      2.3.1.3 Subdivision of Primitives                        32
  75.      2.3.1.4 Shading Flags                                    32
  76.      2.3.2 Primitives                                         33
  77.      2.3.2.1 Bezier patches                                   33
  78.      2.3.2.2 Blob                                             34
  79.      2.3.2.3 Box                                              35
  80.      2.3.2.4 Cone                                             36
  81.      2.3.2.5 Cylinder                                         36
  82.      2.3.2.6 Disc                                             36
  83.      2.3.2.7 Glyphs (TrueType fonts)                          37
  84.      2.3.2.8 Implicit Surface                                 38
  85.      2.3.2.9 Height Field                                     39
  86.      2.3.2.9.1 File Based Height Fields                       40
  87.      2.3.2.9.1.1 8 Bit Format                                 40
  88.      2.3.2.9.1.2 16 Bit Format                                40
  89.      2.3.2.9.1.3 24 Bit Format                                41
  90.      2.3.2.9.1.4 32 Bit Format                                42
  91.      2.3.2.9.2 Implicit Height Fields                         42
  92.      2.3.2.10 Lathe surfaces                                  43
  93.      2.3.2.11 NURBS                                           44
  94.      2.3.2.12 Parabola                                        45
  95.      2.3.2.13 Parametric surface                              46
  96.      2.3.2.14 Polygon                                         46
  97.      2.3.2.15 Polynomial surface                              47
  98.      2.3.2.16 Spheres                                         48
  99.      2.3.2.17 Sweep surface                                   48
  100.      2.3.2.18 Torus                                           49
  101.      2.3.2.19 Triangular patches                              50
  102.      2.3.3 Constructive Solid Geometry (CSG)                  50
  103.      2.3.4 Gridded objects                                    51
  104.      2.3.5 Particle Systems                                   53
  105.      2.4 Color and lighting                                   54
  106.      2.4.1 Light sources                                      55
  107.      2.4.1.1 Positional Lights                                55
  108.      2.4.1.2 Spot Lights                                      55
  109.      2.4.1.3 Directional lights                               56
  110.      2.4.1.4 Textured lights                                  56
  111.      2.4.1.4.1 Area Lights                                    56
  112.      2.4.1.5 Depth Mapped Lights                              57
  113.      2.4.2 Background color                                   57
  114.      2.4.2.1 Global Haze (fog)                                59
  115.      2.4.3 Textures                                           59
  116.      2.4.3.1 Procedural Textures                              59
  117.      2.4.3.1.1 Standard Shading Model                         60
  118.      2.4.3.1.1.1 Ambient light                                61
  119.      2.4.3.1.1.2 Diffuse light                                61
  120.      2.4.3.1.1.3 Specular highlights                          62
  121.      2.4.3.1.1.4 Reflected light                              62
  122.      2.4.3.1.1.5 Transmitted light                            62
  123.      2.4.3.1.1.6 Microfacet distribution                      63
  124.      2.4.3.1.2 Checker                                        63
  125.      2.4.3.1.3 Hexagon                                        64
  126.      2.4.3.1.4 Noise surfaces                                 64
  127.      2.4.3.2 Functional Textures                              67
  128.      2.4.3.2.1 Color maps                                     68
  129.      2.4.3.2.1.1 Using CMAPPER                                69
  130.      2.4.3.2.2 Image maps                                     69
  131.      2.4.3.2.3 Bumpmaps                                       71
  132.      2.4.3.3 Indexed Textures and Texture Maps                72
  133.      2.4.3.4 Layered Textures                                 73
  134.      2.4.3.5 Summed Textures                                  74
  135.      2.5 Comments                                             74
  136.      2.6 Animation support                                    74
  137.      2.7 Conditional processing                               75
  138.      2.8 Include files                                        76
  139.      2.9 File flush                                           76
  140.      2.10 System calls                                        76
  141.      3 File formats                                           77
  142.      3.1 Output files                                         77
  143.      4 Outstanding Issues                                     77
  144.      4.1 To do list                                           77
  145.      4.2 Known Bugs                                           77
  146.      5 Revision History                                       78
  147.  
  148.                                                                            1
  149.      1 Introduction & Shareware Information
  150.  
  151.      The program Polyray is a rendering program for producing scenes of 3D
  152.      shapes and surfaces.  The means of description range from standard
  153.      primitives like box, sphere, etc. to 3 variable polynomial expression,
  154.      and finally (and slowest of all) surfaces containing transcendental
  155.      functions like sin, cos, log.  The files associated with Polyray are
  156.      distributed in three pieces: the executable, a collection of document
  157.      files, and a collection of data files.
  158.  
  159.      Version 1.5 and later of Polyray are Shareware.  If you enjoy this
  160.      program, use it frequently, and can afford to pay a registration fee,
  161.      then send $35 to:
  162.  
  163.           Alexander Enzmann
  164.           20 Clinton St.
  165.           Woburn, Ma 01801
  166.           USA
  167.  
  168.      Please include your name and mailing address.
  169.  
  170.      If you formally register this program, you will receive free the next
  171.      release of Polyray, when it occurs.  In addition you will be
  172.      contributing to my ability to purchase software tools to make Polyray
  173.      a better program.  If you don't register this program, don't feel bad
  174.      - I'm poor too - but you also shouldn't expect as prompt a response to
  175.      questions or bugs.  Consider it guilt-free Shareware.  Note that all
  176.      of the sample files in PLYDAT are Public Domain, you may use them
  177.      freely.
  178.  
  179.      It is assumed that you are familiar with files compressed with PKZIP
  180.      (version 2.04 is required) and setting the PATH variable to make an
  181.      executable visible to DOS.  If you aren't, then get some help from
  182.      someone who has used ZIP and is familiar with configuring a DOS
  183.      system.
  184.  
  185.      The data files are ASCII text, the output image file format supported
  186.      is Targa.  Input images (for texturing, height fields, etc.) may be:
  187.      Targa (all variants defined in the Truevision spec), GIF (both 87a and
  188.      89a should work), or JPEG (JFIF format).  The Targa format is
  189.      supported by many image processing programs so if you need to
  190.      translate between Targa and something else it is quite simple.  The
  191.      utility CJPEG, which converts from Targa to JPEG has been included in
  192.      the utility archive.  Polyray is case sensitive, so the following ways
  193.      of writing foo are all considered different: Foo, FOO, and foo.  For
  194.      an abbreviated list of Polyray's syntax, see the file quickref.txt.
  195.  
  196.      Polyray supports a number of VESA compliant display modes from the
  197.      standard 320x200 VGA mode through to 24 bits at high resolution.  If
  198.      you don't have a VESA compliant graphics board you will either be
  199.      limited to standard VGA or you will need to find a VESA driver for
  200.      your board.
  201.  
  202.      The executable requires IBM PC compatible with at least a 386 and 387,
  203.  
  204.                                                                            2
  205.      and a minimum of 2 Mbytes of RAM to run.  Other memory models will be
  206.      made available if enough requests are made.  The distributed
  207.      executable uses a DOS extender in order to grab as much memory as is
  208.      available.  It has been successfully run with both HIMEM.SYS, and
  209.      386MAX.SYS.  Under Windows it will run in a DOS box, however if you
  210.      use the graphics display it will need to be run full screen.
  211.  
  212.      There have been a number of problems reported of conflicts between the
  213.      DOS extender used in Polyray and memory managers.  These all involve
  214.      DOS 6.0 or later.  In general the conflict results in an error message
  215.      along the lines of:
  216.  
  217.         Previously loaded software is neither VCPI or DPMI compliant
  218.  
  219.      If you see this message, or one like it, you may need to disable EMS
  220.      handling from you CONFIG.SYS file.  A typical change is:
  221.  
  222.         EMM386 NOEMS
  223.  
  224.      For some people, just running Polyray in a DOS box under Windows is
  225.      sufficient to eliminate memory manager problems.  As a first step in
  226.      resolving this type of problem, try setting up a CONFIG.SYS and
  227.      AUTOEXEC.BAT with as few entries as possible.
  228.  
  229.      I'm interested in any comments/bug reports.  I can be reached via
  230.      email by:
  231.  
  232.      Compuserve as: Alexander Enzmann 70323,2461
  233.  
  234.      Internet as:   xander@mitre.org
  235.  
  236.  
  237.      1.1 Acknowledgments and Other Legal Stuff
  238.  
  239.      There is no warranty, explicit or implied, of the suitability of this
  240.      software for any purpose.  This software is provided as is, and the
  241.      user of this software assumes the entire risk as to its quality,
  242.      accuracy, and for any damages resulting from the use of this software.
  243.  
  244.      No part of this package may be included as part of a commercial
  245.      package without explicit written permission.
  246.  
  247.      This original code for this program was based on the mtv ray-tracer,
  248.      written (and placed in the public domain) by Mark VandeWettering.
  249.  
  250.      This software is based in part on the work of the Independent JPEG
  251.      Group.
  252.  
  253.      The Graphics Interchange Format(c) is the copyright property of
  254.      Compuserve Incorporated.  The service marks Graphics Interchange
  255.      Format(sm), and GIF(sm) are owned by Compuserve Incorporated.
  256.  
  257.      Many thanks go to David Mason for his numerous comments and
  258.      suggestions (and for adding a new feature to DTA every time I needed
  259.  
  260.                                                                            3
  261.      to test something).  Thanks also to the Cafe Pamplona in Cambridge Ma.
  262.      for providing a place to get heavily caffinated and rap about ray-
  263.      tracing and image processing for hours at a time.
  264.  
  265.      Kudos go to Jeff Bowermaster, Alfonso Hermida, and Dan Richardson for
  266.      extensive beta testing of Polyray and their many suggestions for
  267.      improvements.  Additionally, many thanks to the folks that let me
  268.      include some of their scenes in the data archive: Jeff Bowermaster,
  269.      Dan Farmer, and Will Wagner.
  270.  
  271.  
  272.      1.2 Useful tools
  273.  
  274.      There are several types of tools that you will want to have to work
  275.      with this program (in relative order of importance):
  276.  
  277.         o An ASCII text editor for preparing and modifying input files.
  278.  
  279.         o A picture viewer for viewing images.
  280.  
  281.         o An image processing program for translation between Targa and
  282.           some other format.
  283.  
  284.         o An animation generator that will take a series of Targa images
  285.           and produce an animation file.
  286.  
  287.         o An animation viewer for playing an animation on the screen.
  288.  
  289.      There are a number of tools out there that can be used in conjunction
  290.      with Polyray.  I've somewhat arbitrarily divided them into categories,
  291.      with no particular order of importance.  I'm pretty sure all of the
  292.      following are available from Compuserve in either the GRAPHDEV or
  293.      GRAPHSUP forums.
  294.  
  295.      1.2.1 Animation Utilities
  296.  
  297.      Many of the features in Polyray are specifically to support the
  298.      generation of multiple frames.  Once the frames are generated,
  299.      additional tools are necessary to format and play the resulting
  300.      animation.  Top picks in this area are:
  301.  
  302.         o DTA      (David Mason)
  303.         o DFV      (David Mason)
  304.         o PLAY     (Trilobyte)
  305.  
  306.      Dave's Targa Animator (DTA) may be the only tool you need for creating
  307.      FLI/FLCs from images, converting images between formats, compositing
  308.      images, etc.  For building animations with Polyray, all you need is
  309.      DTA and a FLI/FLC player.
  310.  
  311.      DFV and PLAY80 do a single thing.  They play FLI/FLC animations on a
  312.      VGA or SVGA screen.  Either one will do the job for 8 bit FLI and FLC
  313.      animations.  However, DFV can handle a few formats that aren't
  314.      supported by PLAY (in particular the 16 and 24 bit animation formats
  315.  
  316.                                                                            4
  317.      produced by DTA).
  318.  
  319.      1.2.2 Modellers
  320.  
  321.      There are a couple of really good Shareware modellers out there.  Both
  322.      of them allow the creation of objects in native form (rather than as
  323.      hundreds of polygons), and provide fast, interactive, development of
  324.      scenes using wireframe displays.  The modellers are:
  325.  
  326.         o POV-CAD      (Alphonso Hermida)
  327.         o Moray        (Lutz Kretzschmar)
  328.  
  329.      POV-CAD, written by Alfonso Hermida is a graphical modeling program
  330.      with both Windows and DOS versions.  POV-CAD allows you to quickly
  331.      build models through point and click in a wireframe environment.  Both
  332.      Polyray and POV-Ray data files can be generated.
  333.  
  334.      Actually, Moray is a modeller for POV-Ray, but it is mentioned here
  335.      since it is a very good Shareware modeller.  Perhaps if enough people
  336.      ask Lutz to add Polyray support...
  337.  
  338.      1.2.3 Miscellaneous Programs
  339.  
  340.         o CTDS         (Truman Brown)
  341.         o RAW2POV      (Steve Anger)
  342.         o 3DS2POV      (Steve Anger)
  343.         o SPD          (Eric Haines,
  344.                         updates by Eduard Schwan & Alexander Enzmann)
  345.  
  346.      CTDS is dot-to-dot for renderers.  By creating a file listing lots of
  347.      points and associated radii, this program will connect them together
  348.      using spheres and cones.  It can output to the native input of several
  349.      renderers, including: Polyray, POV-Ray, and Vivid.  This programs
  350.      really fun for creating abstract shapes.
  351.  
  352.      RAW2POV is a conversion program that takes ASCII files of triangle
  353.      vertices and creates an input for various renderers.  It can also
  354.      examine the triangles and calculate normals for the vertices, giving a
  355.      very smooth looking object when rendered.  This is a must have utility
  356.      if you are going to be converting polygonal objects into a form that
  357.      can be used by Polyray.
  358.  
  359.      3DS2POV converts model files built by the costly 3DS modeller/renderer
  360.      into the native input of various renderers.  Really nice to have if
  361.      you are getting models in 3DS format or if you are fortunate to have
  362.      3DS yourself.
  363.  
  364.      SPD is a library of C code originally developed to benchmark various
  365.      renderers.  Similar in nature to OORT (described below), it allows you
  366.      to write short C programs that will generate scene files for a number
  367.      of different renderers.  Currently supported are: Polyray, POV-Ray,
  368.      Vivid, Rayshade, Rend386, RTrace, NFF, and QRT.  There are also
  369.      routines for displaying the models in wireframe (have to be tuned for
  370.      individual compilers and platforms).  New output modes and rendering
  371.  
  372.                                                                            5
  373.      formats are still being added.
  374.  
  375.  
  376.      1.2.4 Other Raytracers
  377.  
  378.      If you want to explore the world of raytracers, below is a list of
  379.      what I consider the best of the Shareware/Freeware world.  (No flame
  380.      wars please, these are just ones I happen to have and like.)  Each has
  381.      it's own strengths and weaknesses.  Overall, you will learn something
  382.      from working with each one of them.
  383.  
  384.         o POV-Ray      (The POV-Ray Team)
  385.         o Vivid        (Stephen Coy)
  386.         o Rayshade     (Craig Kolb)
  387.         o OORT         (Nicholas Wilt)
  388.  
  389.      POV-Ray is the camel that you let warm it's nose in your tent.  It's
  390.      starting to really dominate the scene.  It's strengths are in a broad
  391.      set of features together with a huge level of support.  The authors
  392.      are available on Compuserve (Graphdev) to answer questions, there are
  393.      an astonishing number of utilities, and the source code is available
  394.      for porting it to different platforms.
  395.  
  396.      For a really fast raytracer, Vivid can't be beat.  It's DOS based
  397.      only, but the registered version comes with a DOS extender for those
  398.      really huge scene files.  Shape primitives are somewhat limited, but
  399.      the texturing capabilities and camera lens features are very strong.
  400.  
  401.      Rayshade is an old standard for the UNIX workstation crowd.  It has
  402.      just about all of the shapes you would want, texturing approximately
  403.      on a par with POV-Ray, and an interesting gridded optimization
  404.      technique.  It doesn't do graphics, and it's really slow if you don't
  405.      manually tune the optimization. On the plus side it has a long
  406.      background of people using it and will compile on just about anything
  407.      (source code is available).
  408.  
  409.      A real newcomer, OORT is a whole bunch of C++ code (classes, objects,
  410.      whatever) for creating and then rendering scenes.  No native input
  411.      language yet (other than minimal NFF support), so you really need a
  412.      C++ compiler to use it.  (This is likely to change as Nicholas is
  413.      really energetic and seems to want to throw just about everything into
  414.      OORT.)
  415.  
  416.      1.2.5 References
  417.  
  418.      Over the last year or so there have been several books published that
  419.      describe ways to use Polyray.  Although these books were written about
  420.      v1.6a, almost all of the content is still valid for v1.7.  The
  421.      differences are pretty well described in section 5.  Other differences
  422.      are buried here and there in this document.  (I don't remember what
  423.      they all are, so I won't try to list them.)
  424.  
  425.      Of the books published, the three that really dig into using Polyray
  426.      for various tasks, from modeling to animations are:
  427.  
  428.                                                                            6
  429.  
  430.         Making Movies on Your PC
  431.         David Mason & Alexander Enzmann
  432.         Waite Group Press, 1993
  433.         ISBN 1-878739-41-7
  434.  
  435.         Adventures in Ray Tracing
  436.         Alphonso Hermida
  437.         Que, 1993
  438.         ISBN 1-56529-555-2
  439.  
  440.         Animation How-To CD
  441.         Jeff Bowermaster
  442.         Waite Group Press, 1994
  443.         ISBN 1-878739-54-9
  444.  
  445.      There's good stuff in each of these books, so it's not unreasonable to
  446.      actually get all of them.  (I don't get royalties from any of them, so
  447.      this is a reasonably shameless plug.)
  448.  
  449.  
  450.      1.3 Contents of this document
  451.  
  452.      This document describes the input format and capabilities of the
  453.      Polyray ray-tracing program.  The following features are supported:
  454.  
  455.         o Viewpoint (camera) characteristics,
  456.         o Positional (point), directional (spotlight) light sources, and
  457.           functional (textured) lights.
  458.         o Background color,
  459.         o Shape primitives:
  460.               Bezier patch, blob, box, cone, cylinder, disc, glyph,
  461.               implicit function, height field, lathe surface, NURBS,
  462.               parabola, parametric function, polygon, polynomial
  463.               function, sphere, sweep surface, torus, triangular patches
  464.         o Animation support,
  465.         o Conditional processing,
  466.         o Include files,
  467.         o Named values and objects.
  468.         o Constructive Solid Geometry (CSG)
  469.         o Grids of objects
  470.         o User definable (functional) textures
  471.         o Initialization file for default values
  472.  
  473.  
  474.      1.4 Quick demo
  475.  
  476.      This section describes one of the simplest possible data files: a
  477.      single sphere and a single light source.  In what follows anything
  478.      following a double slash, // is a comment and is ignored by Polyray.
  479.      The data file is the following indented lines.  You can either use the
  480.      file sphere.pi in the data archive, or copy these declarations into a
  481.      new file.
  482.  
  483.  
  484.                                                                            7
  485.         // We start by setting up the camera.  This is where the eye is
  486.         // located, and describes how wide a field of view will be used,
  487.         // and the resolution (# of pixels wide and high) of the resulting
  488.         // image.
  489.         viewpoint {
  490.            from <0,0,-8>        // The location of the eye
  491.            at <0,0,0>           // The point that we are looking at
  492.            up <0,1,0>           // The direction that will be up
  493.            angle 45             // The vertical field of view
  494.            resolution 160, 160  // The image will be 160x160 pixels
  495.            }
  496.  
  497.         // Next define the color of the background.  This is the color
  498.         // that is used for any pixel that isn't part of an object.  In
  499.         // this file it will color the image around the sphere.
  500.         background skyblue
  501.  
  502.         // Next is a light source.  This is a point light source a little
  503.         // above, to the left, and behind the eye.
  504.         light <-10,3, -20>
  505.  
  506.         // The following declaration is a texture that will be applied
  507.         // to the sphere.  It will be red at every point but where the
  508.         // light is reflecting directly towards the eye - at that point
  509.         // there will be a bright white spot.
  510.         define shiny_red
  511.         texture {
  512.            surface {
  513.               color red
  514.               ambient 0.2         // Always a little red in the sphere
  515.               diffuse 0.6         // Where the light is hitting the
  516.                                   // sphere, the color of the sphere
  517.                                   // will be a little brighter.
  518.               specular white, 0.5 // There will be a white highlight.
  519.               microfacet Cook 5   // The white highlight drops to half
  520.                                   // its intensity at an angle of 5
  521.                                   // degrees.
  522.               }
  523.            }
  524.  
  525.         // Finally we declare the sphere.  It sits right at the origin,
  526.         // and has a radius of two.  Following the declaration of the
  527.         // sphere, we associate the texture declared above.
  528.         object {
  529.            sphere <0, 0, 0>, 2
  530.            shiny_red
  531.            }
  532.  
  533.      Now that we have a data file, lets render it and show it on the
  534.      screen.  First of all we can look at a wireframe representation of the
  535.      file.  Enter the following commands (DOS prompts are in capitals).
  536.  
  537.         C> polyray sphere.pi -r 2 -V 1 -W
  538.  
  539.  
  540.                                                                            8
  541.      An outline of the sphere will be drawn on the screen, press any key to
  542.      get back to DOS.  Next lets do a raytrace.  Enter the following:
  543.  
  544.         C> polyray sphere.pi -V 1
  545.  
  546.      The sphere will be drawn a line at a time, when it is done you will be
  547.      returned to DOS
  548.  
  549.      The output image will be the default output file, out.tga.  You can
  550.      view it directly with VPIC or CSHOW (although VPIC will not have the
  551.      full range of colors that were generated by the raytrace).  If you
  552.      have PICLAB, then the following commands will load the image, map its
  553.      colors into a spectrum that matches the colors in the image, then will
  554.      display it.
  555.  
  556.         C:> piclab
  557.         > tload out
  558.         > makepal
  559.         > map
  560.         > show
  561.  
  562.      hit any key to get back to PICLAB's command line
  563.  
  564.         > quit
  565.         C:>
  566.  
  567.      You should see a greatly improved image quality over the display that
  568.      is shown during tracing.
  569.  
  570.      Now that you have seen a simple image, you have two options: go render
  571.      some or all of the files in the data archive, PLYDAT, or continue
  572.      reading the documents.  For those of you that prefer immediately
  573.      getting started, there are a series of DOS batch files that pretty
  574.      well automate the rendering of the sample scenes.  (When you unzip the
  575.      data files, remember to use the -d switch so that all the
  576.      subdirectories will be installed properly.)  The sample scenes in
  577.      PLYDAT will render on a 33Mhz 486 in less than a day.  The animation
  578.      examples will take an additional 4-5 days (and chew up quite a few
  579.      megabytes of disk space).
  580.  
  581.  
  582.      1.5 Command Line Options
  583.  
  584.      A number of operations can be manipulated through values in an
  585.      initialization file, within the data file, or from the command line
  586.      (processed in that order, with the last read having the highest
  587.      precedence).  The command line values will be displayed if no
  588.      arguments are given to Polyray.
  589.  
  590.      The values that can be specified at the command line, with a brief
  591.      description of their meaning are:
  592.  
  593.         -a n           Antialiasing (0=none, 1=filter, 2-4=adaptive)
  594.         -b pixels      Set the maximum number of pixels that will be
  595.  
  596.                                                                            9
  597.                        calculated between file flushes
  598.         -B             Flush the output file every scan line
  599.         -d             Output the image as a depth map
  600.         -o filename    The output file name (if not specified is out.tga)
  601.         -p bits/pixel  Set the number of bits per pixel in the output file
  602.                        (must be one of 8, 16, 24, 32)
  603.         -P pallette    Which pallette option to use in 8 bit display modes
  604.                        [0=grey, 1=666, 2=884]
  605.         -Q             Abort if any key is hit during trace
  606.         -q flags       Turn on/off various global shading options
  607.         -r renderer    Which rendering method: [0=raytrace, 1=scan convert,
  608.                        2=wireframe, 3=raw tri, 4=u/v tri]
  609.         -R             Resume an interrupted trace.
  610.         -S samples     # of samples per pixel when performing focal blur
  611.         -t status_vals Status display type [0=none, 1=totals, 2=line,
  612.                        3=pixel].
  613.         -T threshold   Threshold to start adaptive antialiasing
  614.         -u             Write the output file in uncompressed form
  615.         -v             Trace from bottom to top
  616.         -V mode        Use VGA display while tracing [0=none,1-5=8 bit,
  617.                        6-10=15 bit, 11-15=24 bit]
  618.         -W             Wait for key before clearing display
  619.         -x columns     Set the x resolution
  620.         -y lines       Set the y resolution
  621.         -z start_line  Start a trace at a specified line
  622.  
  623.      If no arguments are given then Polyray will give a brief description
  624.      of the command line options.
  625.  
  626.  
  627.      1.6 Initialization File
  628.  
  629.      The first operation carried out by Polyray is to read the
  630.      initialization file polyray.ini.  This file can be used to tune a
  631.      number of the default variables used during rendering.  It must appear
  632.      in the current directory.  It doesn't have to exist, it is typically
  633.      used as a convenience to eliminate retyping command line parameters.
  634.  
  635.      Each entry in the initialization file must appear on a separate line,
  636.      and have the form:
  637.  
  638.      default_name   default_value
  639.  
  640.      The names are text.  The values are numeric for some names, and text
  641.      for others.  The allowed names and values are:
  642.  
  643.         abort_test        true/false/on/off
  644.         alias_threshold   [threshold to start adaptive antialiasing]
  645.         antialias         none/filter/adaptive1/adaptive2
  646.         display           none/vga1-vga5/hicolor1-hicolor5/
  647.                           truecolor1-truecolor5
  648.         max_level         [max depth of recursion]
  649.         max_samples       [# samples for focal blur]
  650.         optimizer         none/slabs
  651.  
  652.                                                                            10
  653.         pixel_size        [8, 16, 24, 32]
  654.         pixel_encoding    none/rle
  655.         renderer          ray_trace/scan_convert/wire_frame/
  656.                           raw_triangles/uv_triangles
  657.         shade_flags       [default/bit mask of flags, (see section
  658.                            1.7.1.4)]
  659.         shadow_tolerance  [minimum distance for blocking objects]
  660.         status            none/totals/line/pixel
  661.         warnings          on/off
  662.  
  663.      A typical example of polyray.ini would be:
  664.  
  665.         abort_test        on
  666.         alias_threshold   0.05
  667.         antialias         adaptive
  668.         display           vga
  669.         max_samples       8
  670.         pixel_size        24
  671.         status            line
  672.  
  673.      If no initialization file exists, then Polyray will use the following
  674.      default values:
  675.  
  676.         abort_test        on
  677.         alias_threshold   0.2
  678.         antialias         none
  679.         display           none
  680.         max_level         5
  681.         max_samples       4
  682.         optimizer         slabs
  683.         pixel_size        16
  684.         pixel_encoding    rle
  685.         renderer          ray_trace
  686.         shade_flags       default
  687.         shadow_tolerance  0.001
  688.         status            none
  689.         warnings          on
  690.  
  691.  
  692.      1.7 Rendering Options
  693.  
  694.      Polyray supports four very distinct means of rendering scenes:
  695.      raytracing, polygon scan conversion, wireframe, and raw triangle
  696.      output.  Raytracing is often a very time consuming process, however
  697.      the highest quality of images can be produced this way.  Scan
  698.      conversion is a very memory intensive method, but produces a good
  699.      quality image quickly.  Wireframe gives a very rough view of the scene
  700.      in the fastest possible time.  (Note that there is no output file when
  701.      wireframe is used.)  Raw triangle output produces an ASCII file of
  702.      triangles describing the scene.
  703.  
  704.  
  705.      1.7.1 Raytracing
  706.  
  707.  
  708.                                                                            11
  709.      Raytracing is a very compute intensive process, but is the method of
  710.      choice for a final image.  The quality of the images that can be
  711.      produced is entirely a function of how long you want to wait for
  712.      results.  There are certain options that allow you to adjust how you
  713.      want to make tradeoffs between: quality, speed, and memory
  714.      requirements.
  715.  
  716.      The basic operation in raytracing is that of shooting a ray from the
  717.      eye, through a pixel, and finally hitting an object.  For each type of
  718.      primitive there is specialized code that helps determine if a ray has
  719.      hit that primitive.  The standard way that Polyray generates an image
  720.      is to use one ray per pixel and to test that ray against all of the
  721.      objects in the data file.  Antialiasing or focal blur will result in
  722.      more than one ray per pixel, increasing rendering time.
  723.  
  724.  
  725.      1.7.1.1 Antialiasing
  726.  
  727.      The representation of rays is as a 1 dimensional line.  On the other
  728.      hand pixels and objects have a definite size.  This can lead to a
  729.      problem known as aliasing, where a ray may not intersect an object
  730.      because the object only partially overlaps a pixel, or the pixel
  731.      should have color contributed by several objects that overlap it, none
  732.      of which completely fills the pixel. Aliasing often shows up as a
  733.      staircase effect on the edges of objects.
  734.  
  735.      Polyray offers a couple of ways to reduce aliasing: by filtering or by
  736.      adaptive oversampling.  Filtering smoothes the output image by
  737.      averaging the color values of neighboring pixels to the pixel being
  738.      rendered.  Oversampling is performed by adding extra rays around the
  739.      original one.  By averaging the result of all of the rays that are
  740.      shot through a single pixel, aliasing problems can be greatly reduced.
  741.  
  742.      The filtering process adds little overhead to the rendering process,
  743.      however the resolution of the image is degraded by the averaging
  744.      process.  It simply averages the colors found at the four corners of a
  745.      pixel.
  746.  
  747.      Adaptive antialiasing starts by sending a ray through the four corners
  748.      of a pixel.  If there is a sufficient contrast between the corners
  749.      then Polyray will fire five more rays within the pixel.  This results
  750.      in four subpixels.  Each level of adaptive antialiasing repeats this
  751.      procedure.  If adaptive1 is used in polyray.ini, or -a 2 from the
  752.      command line, then the antialiasing stops after a single subdivision.
  753.      If adaptive2 is used then each subpixel is checked and if the corners
  754.      are sufficiently different then it will be divided again.
  755.  
  756.      The two initialization (and command line) variables that will affect
  757.      the performance of adaptive antialiasing are alias_threshold and
  758.      max_samples.  The first is a measure of how different a pixel must be
  759.      with respect to its neighbors before antialiasing will kick in.  If a
  760.      pixel has the value: <r1, g1, b1>, and it's neighbor has the value
  761.      <r2, g2, b2> (RGB values between 0 and 1 inclusive), then the distance
  762.      between the two colors is:
  763.  
  764.                                                                            12
  765.  
  766.      dist = sqrt((r1 - r2)^2 + (b1 - b2)^2 + (g1 - g2)^2)
  767.  
  768.      This is the standard Pythagorean formula for values specified in RGB.
  769.      If dist is greater than the value of alias_threshold, then extra rays
  770.      will be fired through the pixel in order to determine an averaged
  771.      color for that pixel.
  772.  
  773.  
  774.      1.7.1.2 Focal Blur
  775.  
  776.      The default viewpoint declaration is a pinhole camera model.  All
  777.      objects are in sharp focus, no matter how near or far they are.  By
  778.      adjusting the aperture and focal_distance parameters it is possible to
  779.      simulate a real world camera.  Objects close to the focal distance
  780.      will be in focus and those closer or farther will be blurred.  Three
  781.      parameters affect the blur: aperture, focal_distance, and max_samples.
  782.  
  783.      Adjusting the size of aperture allows you to adjust how much of the
  784.      scene is in focus.  Adjusting focal_distance gives you control over
  785.      what part of the scene is in focus.  If focal_distance isn't set,
  786.      Polyray will set it so that the point defined by the 'at' declaration
  787.      is in focus.  The declaration max_samples allows you to fine tune how
  788.      smooth the final image appears.  If you use a large value for
  789.      aperture, you will probably need to increase max_samples as well to
  790.      avoid a grainy appearance in the image.
  791.  
  792.      Also note that focal blur and adaptive antialiasing interact with each
  793.      other.  Polyray attempts to distribute the focal blur rays into the
  794.      antialiasing rays, however there will be more rays cast than would
  795.      have been using either method alone.  It's best to leave the
  796.      antialiasing off and the value of max_samples small until producing
  797.      the final image.
  798.  
  799.      1.7.1.3 Bounding Slabs
  800.  
  801.      For scenes with large numbers of small objects, there are optimization
  802.      tricks that can take advantage of the distribution of the objects.  An
  803.      easy one to implement, and one that often results in huge time savings
  804.      are bounding slabs. The basic idea of a bounding slab is to sort all
  805.      objects along a particular direction.  Once this sorting step has been
  806.      performed, then during rendering the ray can be quickly checked
  807.      against a slab (which can represent many objects rather than just one)
  808.      to see if intersection tests need to be made on the contents of the
  809.      slab.
  810.  
  811.      The most important caveats with Polyray's implementation of bounding
  812.      slabs are:
  813.  
  814.         o Scenes with only a few large objects will derive little speed
  815.           benefits.
  816.         o If there is a lot of overlap of the positions of the objects in
  817.           the scene, then there will be little advantage to the slabs.
  818.         o If the direction of the slabs does not correspond to a direction
  819.  
  820.                                                                            13
  821.           that easily sorts objects, then there will be little speed
  822.           gained.
  823.  
  824.      However, for data files that are generated by another program, the
  825.      requirements for effective use of bounding slabs are often met.  For
  826.      example, most of the data files generated by the SPD programs will be
  827.      rendered orders of magnitude faster with bounding slabs than without.
  828.  
  829.      Slabs are turned on by default.  To turn them off either use the
  830.      command line flag, -O 0, or add the line, optimizer none, to
  831.      polyray.ini.
  832.  
  833.  
  834.      1.7.1.4 Shading Quality Flags
  835.  
  836.      By specifying a series of bits, various shading options can be turned
  837.      on and off.  The value of each flag, as well as the meaning are:
  838.  
  839.          1   Shadow_Check      Shadows will be generated
  840.          2   Reflect_Check     Reflectivity will be tested
  841.          4   Transmit_Check    Check for refraction
  842.          8   Two_Sides         If on, highlighting will be performed
  843.                                on both sides of a surface.
  844.         16   UV_Check          Calculate the uv-coordinates of each point
  845.         32   Cast_Shadow       Determines if an object can cast a shadow
  846.  
  847.      The default settings of these flags are:
  848.  
  849.         raytracing        Shadow_Check + Reflect_Check + Transmit_Check +
  850.                           UV_Check  (= 23)
  851.         scan conversion   Two_Sides (=  8)
  852.         wireframe         Not applicable
  853.         raw triangles     Not applicable
  854.  
  855.      Note that the flag, cast_shadow, is only meaningful for declarations
  856.      of shading flags for an object, not for the renderer.  See section
  857.      2.3.1.4 for more information.  If you want to turn off shadows in a
  858.      raytrace, then you would leave out the shadow_check flag (conversely
  859.      if you wanted shadows in scan conversion you would add it).
  860.  
  861.      The assumption made is that during raytracing the highest quality is
  862.      desired, and consequently every shading test is made.  The assumption
  863.      for scan conversion is that you are trying to render quickly, and
  864.      hence most of the complex shading options are turned  off.  In some
  865.      images the quality will be improved if you
  866.  
  867.      If any of the three flags Shadow_Check, Reflect_Check, or
  868.      Transmit_Check are explicitly set and scan conversion is used to
  869.      render the scene, then at every pixel that is displayed, a recursive
  870.      call to the raytracer will be made to determine the correct shading.
  871.      Note that due to the faceted nature of objects during scan conversion,
  872.      shadowing, and especially refraction can get messed up during scan
  873.      conversion.
  874.  
  875.  
  876.                                                                            14
  877.      For example if you want to do a scan conversion that contains shadows,
  878.      you would use the following:
  879.  
  880.         polyray xxx.pi -r 1 -q 1
  881.  
  882.      or if you wanted to do raytracing with no shadows, reflection turned
  883.      on, transparency turned off, and with diffuse and specular shading
  884.      performed for both sides of surfaces you would use options 2 and 8:
  885.  
  886.         polyray xxx.pi -q 10
  887.  
  888.      Note: texturing cannot be turned off.
  889.  
  890.  
  891.      1.7.2 Scan Conversion
  892.  
  893.      In order to support a quicker render of images, Polyray can render
  894.      most primitives as a series of polygons.  Each polygon is scan
  895.      converted using a Z-Buffer for depth information, and a S-Buffer for
  896.      color information.
  897.  
  898.      The scan conversion process does not by default provide support for:
  899.      shadows, reflectivity, or transparency.  It is possible to instruct
  900.      Polyray to use raytracing to perform these shading operations through
  901.      the use of either the global shade flags or by setting shade flags for
  902.      a specific object.  An alternative method for quickly testing shadows
  903.      involves using depth mapped lights (see section 2.4.1.5).  Reflections
  904.      can be simulated with a multipass approach where an image map or
  905.      environment map is calculated and then applied to the reflective
  906.      object.
  907.  
  908.      The memory requirements for performing scan conversion can be quite
  909.      substantial.  You need at least as much memory as is required for
  910.      raytracing, plus at least 7 bytes per pixel for the final image.  In
  911.      order to correctly keep track of depth and color - 4 bytes are used
  912.      for the depth of each pixel in the Z-Buffer (32 bit floating point
  913.      number), and 3 bytes are used for each pixel in the S-Buffer (1 byte
  914.      each for red, green, and blue).
  915.  
  916.      During scan conversion, the number of polygons used to cover the
  917.      surface of a primitive is controlled using the keywords u_steps, and
  918.      v_steps (or combined with uv_steps).  These two values control how
  919.      many steps around and along the surface of the object values are
  920.      generated to create polygons (see section 2.3.1.1.6).  The higher the
  921.      number of steps, the smoother the final appearance.  Note however that
  922.      if the object is very small then there is little reason to use a fine
  923.      mesh - hand tuning is sometimes required to get the best balance
  924.      between speed and appearance.
  925.  
  926.      Generating isosurfaces for blobs, polynomial functions and implicit
  927.      functions, followed by polygonalization of the surfaces is performed
  928.      using a marching cubes algorithm.  Currently the value of u_steps
  929.      determines the number of slices along the x-axis, the value of v_steps
  930.      controls the number of slices along the y-axis, and the value of
  931.  
  932.                                                                            15
  933.      w_steps controls the number of slices along the z-axis.  Future
  934.      versions may introduce a third value to allow independent control of y
  935.      and z.
  936.  
  937.      Note that running Polyray in a Windows DOS box is a way to increase
  938.      the memory available for performing scan conversion.  Polyray will
  939.      take advantage of the virtual memory capabilities of Windows, allowing
  940.      for larger image to be rendered.
  941.  
  942.      Also note that there are images that render slower in scan conversion
  943.      and wireframe that raytracing!  These are typically those files that
  944.      contain large numbers of spheres and cones such as data files
  945.      generated by CTDS or large gridded objects.  The scan conversion
  946.      process generates every possible part of each object, whereas the
  947.      raytracer is able to sort the objects an only display the visible
  948.      parts of the surfaces.  If you run into this situation, a speedup
  949.      trick you can use is to set the values of uv_steps very low for the
  950.      small objects (e.g., uv_steps 6, 4 for spheres).
  951.  
  952.  
  953.      1.7.3 Wireframe
  954.  
  955.      In most cases the fastest way to display a model is by showing a
  956.      wireframe representation.  Polyray supports this as a variant of the
  957.      scan conversion process.  When drawing a wireframe image only the
  958.      edges of the polygons that are generated as part of scan conversion
  959.      are drawn onto the screen.  A big problem with wireframe
  960.      representations is that CSG operations are not performed.  If you use
  961.      CSG intersection, difference, or clipping, you may see a lot of stuff
  962.      that will not appear in the final image.
  963.  
  964.  
  965.      1.7.4 Depth Files
  966.  
  967.      Instead of creating an image, it is possible to instruct Polyray to
  968.      create a file that contains depth information.  Each pixel in the
  969.      resulting Targa will contain the distance from the eye to the first
  970.      surface that is hit.  The format of the files is identical to the
  971.      formats used by height fields (see 2.3.2.9.1).
  972.  
  973.      For example, to create a 24 bit depth file, the following command
  974.      could be used:
  975.  
  976.         polyray sphere.pi -p 24 -d
  977.  
  978.      Polyray will disable any antialiasing when creating depth files(it is
  979.      inappropriate to average depths).
  980.  
  981.      There are three common applications for depth files: shadow maps (see
  982.      Depth Lights, 2.4.1.5), height fields, and creating Random Dot
  983.      Stereograms (RDS).
  984.  
  985.      RDS images are an interesting way to create a 3D picture that doesn't
  986.      require special glasses.  The program RDSGEN (available in the
  987.  
  988.                                                                            16
  989.      GRAPHDEV forum on Compuserve) will accept Polyrays 24 bit depth format
  990.      and create an RDS image.
  991.  
  992.  
  993.      1.7.5 Raw Triangles
  994.  
  995.      A somewhat odd addition to the image output formats for Polyray is the
  996.      generation of raw triangle information.  What happens is very similar
  997.      to the scan conversion process, but rather than draw polygons, Polyray
  998.      will write a text description of the polygons (after splitting them
  999.      into triangles).  The final output is a (usually long) list of lines,
  1000.      each line describing a single smooth triangle.  The format of the
  1001.      output is one of the following:
  1002.  
  1003.         x1 y1 z1 x2 y2 z2 x3 y3 z3
  1004.      or
  1005.         x1 y1 z1 x2 y2 z2 x3 y3 z3 nx1 ny1 nz1 nx2 ny2 nz2 nx3 ny3 nz3
  1006.         u1 v1 u2 v2 u3 v3
  1007.  
  1008.      If the output is raw triangles then only the three vertices are
  1009.      printed.  If uv_triangles are being created, then the normal
  1010.      information for each of the vertices follows the vertices and the u/v
  1011.      values follow them.  The actual u/v values are specific to the type of
  1012.      object being generated.
  1013.  
  1014.      Currently I don't have any applications for this output, but the first
  1015.      form is identical to the input format of the program RAW2POV. The
  1016.      intent of this feature is to provide a way to build models in polygon
  1017.      form for conversion to the input format of another renderer.
  1018.  
  1019.      For example, to produce raw triangle output describing a sphere, and
  1020.      dump it to a file you could use the command:
  1021.  
  1022.         polyray sphere.pi -r 3 > sphere.tri
  1023.  
  1024.      For full vertex, normal, and uv information, use the following
  1025.      command:
  1026.  
  1027.         polyray sphere.pi -r 4 > uvsphere.tri
  1028.  
  1029.      Nothing is drawn on screen while the raw triangles are generated, so
  1030.      typically you would turn off the graphics display (-V 0) when using
  1031.      this option.
  1032.  
  1033.  
  1034.      1.8 Display Options (IBM format only)
  1035.  
  1036.      Polyray supports 15 distinct VESA display modes.  The table below
  1037.      lists the modes, the command line value to use with '-V x', and the
  1038.      entry in the file polyray.ini to set a default video mode.
  1039.  
  1040.            Resolution   Colors    Command Line   Initialization name
  1041.      ---------------------------------------------------------------
  1042.                N/A       none        -V 0        none
  1043.  
  1044.                                                                            17
  1045.  
  1046.            320x200        256        -V 1        vga/vga1
  1047.            640x480        256        -V 2        vga2
  1048.            800x600        256        -V 3        vga3
  1049.           1024x768        256        -V 4        vga4
  1050.          1280x1024        256        -V 5        vga5
  1051.  
  1052.            320x200        32K        -V 6        hicolor/hicolor1
  1053.            640x480        32K        -V 7        hicolor2
  1054.            800x600        32K        -V 8        hicolor3
  1055.           1024x768        32K        -V 9        hicolor4
  1056.          1280x1024        32K        -V 10       hicolor5
  1057.  
  1058.            320x200        16M        -V 11       truecolor1
  1059.            640x480        16M        -V 12       truecolor2
  1060.            800x600        16M        -V 13       truecolor3
  1061.           1024x768        16M        -V 14       truecolor4
  1062.          1280x1024        16M        -V 15       truecolor5
  1063.  
  1064.      It is pretty unlikely you have a board that will do all of the
  1065.      resolutions listed above.  For that reason, Polyray will check to see
  1066.      if the requested mode is possible on your board.  If not, another mode
  1067.      will be selected.  The first priority is to find a mode with the same
  1068.      # of bits per pixel (even if the screen resolution is lower).  The
  1069.      second priority is to drop to the next lower # of bits per pixel,
  1070.      starting at the highest resolution possible.
  1071.  
  1072.      Setting the default display mode in polyray.ini is done by inserting a
  1073.      line of the form:
  1074.  
  1075.         display hicolor1
  1076.  
  1077.      To override a display mode from the command line you would do
  1078.      something
  1079.      like:
  1080.  
  1081.         C> polyray sphere.pi -V 12
  1082.  
  1083.      Note that using the line status display will mess up some of the
  1084.      higher graphics modes.  If this bothers you, use the flag -t 1 to
  1085.      limit statistics to only startup and totals (or -t 0 for no
  1086.      statistics).
  1087.  
  1088.  
  1089.      2  Detailed description of the Polyray input format:
  1090.  
  1091.      An input file describes the basic components of an image:
  1092.  
  1093.         o A viewpoint that characterizes where the eye is, where it is
  1094.           looking and what its orientation is.
  1095.         o Objects, their shape, placement, and orientation.
  1096.         o Light sources, their placement and color.
  1097.  
  1098.      Beyond the fundamentals, there are many components that exist as a
  1099.  
  1100.                                                                            18
  1101.      convenience such as definable expressions and textures.  This section
  1102.      of the document describes in detail the syntax of all of the
  1103.      components of an input file
  1104.  
  1105.  
  1106.      2.1 Expressions
  1107.  
  1108.      There are six basic types of expressions that are used in Polyray:
  1109.  
  1110.         o float:  Floating point expression (e.g., 0.5, 2 * sin(1.33)).
  1111.                   These are used at any point a floating point value is
  1112.                   needed, such as the radius of a sphere or the amount of
  1113.                   contribution of a part of the lighting model.
  1114.         o vector: Vector valued expression  (e.g., <0, 1, 0>, red,
  1115.                   12 * <2, sin(x), 17> + P).  Used for color expressions,
  1116.                   describing positions, describing orientations, etc.
  1117.         o arrays: Lists of expressions (e.g., [0, 1, 17, 42],
  1118.                   [<0,1,0>, <2*sin(theta), 42, -4>, 2*<3, 7, 2>])
  1119.         o cexper: Conditional expression (e.g., x < 42).
  1120.         o string: Strings used for file names or systems calls
  1121.         o images: A Targa, GIF, or JPEG image.
  1122.  
  1123.      The following sections describe the syntax for each of these types of
  1124.      expressions, as well as how to define variables in terms of
  1125.      expressions.  See also the description of color maps, image maps (from
  1126.      which you can retrieve color or vector values), indexed maps, and
  1127.      height maps.
  1128.  
  1129.  
  1130.      2.1.1 Numeric expressions
  1131.  
  1132.      In most places where a number can be used (i.e. scale values, angles,
  1133.      RGB components, etc.) a simple floating point expression (float) may
  1134.      be used.  These expressions can contain any of the following terms:
  1135.  
  1136.         -0.1, 5e-3, ab, ...     A floating point number or defined value
  1137.         '(' float ')'           Parenthesised expression
  1138.         float ^ float           Exponentiation, same as pow(x, y)
  1139.         float * float           Multiplication
  1140.         float / float           Division
  1141.         float + float           Addition
  1142.         float - float           Subtraction
  1143.         -float                  Unary minus
  1144.         acos(float)             Arccosine, (radians for all trig functions)
  1145.         asin(float)             Arcsin
  1146.         atan(float)             Arctangent
  1147.         atan2(float,float)      Angle from x-axis to the point (x, y)
  1148.         ceil(float)             Ceiling function
  1149.         cos(float)              Cosine
  1150.         cosh(float)             Hyperbolic cosine
  1151.         degrees(float)          Converts radians to degrees
  1152.         exp(float)              e^x, standard exponential function
  1153.         fabs(float)             Absolute value
  1154.         floor(float)            Floor function
  1155.  
  1156.                                                                            19
  1157.         fmod(float,float)       Modulus function for floating point values
  1158.         heightmap(image,vector) Height of an pixel in an image
  1159.         indexed(image,vector)   Index of an pixel in an image
  1160.         legendre(l,m,n)         Legendre function
  1161.         ln(float)               Natural logarithm
  1162.         log(float)              Logarithm base 10
  1163.         min(float,float)        Minimum of the two arguments
  1164.         max(float,float)        Maximum of the two arguments
  1165.         noise(vector)
  1166.         noise(vector,float)     Solid texturing (noise) function.  If the
  1167.                                 second argument is given, it is used as the
  1168.                                 number of octaves (repetitions) of the 3D
  1169.                                 noise function.
  1170.         noise(vector,vector)    Second arg provides more flexible operation
  1171.                                 using: <pos scale, noise scale, octaves>
  1172.         pow(float,float)        Exponentiation (x^y)
  1173.         radians(float)          Converts degrees to radians
  1174.         sawtooth(float)         Sawtooth function (range is 0 - 1)
  1175.         sin(float)              Sine
  1176.         sinh(float)             Hyperbolic sine
  1177.         sqrt(float)             Square root
  1178.         tan(float)              Tangent
  1179.         tanh(float)             Hyperbolic tangent
  1180.         visible(vector,vector)  Returns 1 if second point visible from
  1181.                                 first.
  1182.         vector[i]               Extract component i from a vector (0<=i<=3)
  1183.         vector . vector         Dot product of two vectors
  1184.         |float|                 Absolute value (same as fabs)
  1185.         |vector|                Length of a vector
  1186.  
  1187.  
  1188.      2.1.2 Vector Expressions
  1189.  
  1190.      In most places where a vector can be used (i.e. color values, rotation
  1191.      angles, locations, ...), a vector expression is allowed.  The
  1192.      expressions can contain any of the following terms:
  1193.  
  1194.  
  1195.         vector + vector         Addition
  1196.         vector - vector         Subtraction
  1197.         vector * vector         Cross product
  1198.         vector * float          Scaling of a vector by a scalar
  1199.         float  * vector         Scaling of a vector by a scalar
  1200.         vector / float          Inverse scaling of a vector by a scalar
  1201.         brownian(vector,vector) Makes a random displacement of the first
  1202.                                 point by an amount proportional to the
  1203.                                 components of the second point
  1204.         brownian(vector)        Random displacement of up to 0.1
  1205.         color_wheel(x, y, z)    RGB color wheel using x and z (y ignored),
  1206.                                 the color returned is based on <x, z>
  1207.                                 using the chart below:
  1208.  
  1209.                                          Z-Axis
  1210.                                             ^
  1211.  
  1212.                                                                            20
  1213.                                             |
  1214.                                             |
  1215.                                       Green   Yellow
  1216.                                           \   /
  1217.                                            \ /
  1218.                                   Cyan ---- * ---- Red  -----> X-Axis
  1219.                                            / \
  1220.                                           /   \
  1221.                                        Blue   Magenta
  1222.  
  1223.                                 Intermediate colors are generated by
  1224.                                 interpolation.
  1225.  
  1226.         dnoise(vector)
  1227.         dnoise(vector,float)    Returns a vector (gradient) based on the
  1228.                                 location given in the first argument.  If
  1229.                                 the second argument is given, it is used as
  1230.                                 the number of octaves (repetitions) of the
  1231.                                 3D noise function
  1232.         dnoise(vector,vector)   Second arg provides more flexible operation
  1233.                                 using: <pos scale, noise scale, octaves>
  1234.         planar_imagemap(image, vector [, rflag])
  1235.         cylindrical_imagemap(image, vector [, rflag])
  1236.         spherical_imagemap(image, vector [, rflag])
  1237.         environment_map(vector, environment)
  1238.                                 Image map lookup functions.  If the third
  1239.                                 argument is given, then the image will be
  1240.                                 tiled, otherwise black is used outside the
  1241.                                 bounds of the image.  Note: for planar
  1242.                                 image maps only the x and z coordinates of
  1243.                                 the second argument are used.
  1244.         rotate(vector,vector)   Rotate the point specified in the first
  1245.                                 argument by the angles specified in the
  1246.                                 second argument (angles in degrees).
  1247.         rotate(vector,vector,   Rotate the point specified in the first
  1248.                float)           argument about the axis specified in
  1249.                                 the second argument by the angle given
  1250.                                 in the third argument
  1251.         reflect(vector,vector)  Reflect the first vector about the second
  1252.                                 vector (particularly useful in environment
  1253.                                 maps)
  1254.         trace(vector,vector)    Color resulting from tracing a ray from the
  1255.                                 the point given as the first argument in
  1256.                                 the direction given by the second argument.
  1257.  
  1258.  
  1259.      2.1.3 Arrays
  1260.  
  1261.      Arrays are a way to represent data in a convenient list form.  A good
  1262.      use for arrays is to hold a number of locations for polygon vertices
  1263.      or as locations for objects in successive frames of an animation.
  1264.  
  1265.      As an example, a way to define a tetrahedron (4 sided solid) is to
  1266.      define its vertices, and which vertices make up its faces.  By using
  1267.  
  1268.                                                                            21
  1269.      this information in an object declaration, we can make a tetrahedron
  1270.      out of polygons very easily.
  1271.  
  1272.         define tetrahedron_faces
  1273.            [<0, 1, 2>, <0, 2, 3>, <0, 3, 1>, <1, 3, 2>]
  1274.  
  1275.         define tetrahedron_vertices
  1276.            [<0, 0, sqrt(3)>,
  1277.             <0, (2*sqrt(2)*sqrt(3))/3, -sqrt(3)/3>,
  1278.             <-sqrt(2), -(sqrt(2)*sqrt(3))/3, -sqrt(3)/3>,
  1279.             <sqrt(2), -(sqrt(2)*sqrt(3))/3, -sqrt(3)/3>]
  1280.  
  1281.         define tcf tetrahedron_faces
  1282.         define tcv tetrahedron_vertices
  1283.         define tetrahedron
  1284.         object {
  1285.          object { polygon 3,tcv[tcf[0][0]],tcv[tcf[0][1]],tcv[tcf[0][2]]} +
  1286.          object { polygon 3,tcv[tcf[1][0]],tcv[tcf[1][1]],tcv[tcf[1][2]]} +
  1287.          object { polygon 3,tcv[tcf[2][0]],tcv[tcf[2][1]],tcv[tcf[2][2]]} +
  1288.          object { polygon 3,tcv[tcf[3][0]],tcv[tcf[3][1]],tcv[tcf[3][2]]}
  1289.          }
  1290.  
  1291.  
  1292.      What happened in the object declaration is that each polygon grabbed a
  1293.      series of vertex indices from the array tetrahedron_faces, then used
  1294.      that index to grab the actual location in space of that vertex.
  1295.  
  1296.      Another example is to use an array to store a series of view
  1297.      directions so that we can use animation to generate a series of very
  1298.      distinct renders of the same scene (the following example is how the
  1299.      views for an environment map are generated):
  1300.  
  1301.         define location <0, 0, 0>
  1302.         define at_vecs [<1, 0, 0>, <-1, 0, 0>, < 0, 1, 0>, < 0,-1, 0>,
  1303.                         < 0, 0,-1>, < 0, 0, 1>]
  1304.         define up_vecs [< 0, 1, 0>, < 0, 1, 0>, < 0, 0, 1>, < 0, 0,-1>,
  1305.                         < 0, 1, 0>, < 0, 1, 0>]
  1306.  
  1307.         // Generate six frames
  1308.         start_frame 0
  1309.         end_frame 5
  1310.  
  1311.         // Each frame generates the view in a specific direction.  The
  1312.         // vectors stored in the arrays at_vecs, and up_vecs turn the
  1313.         // camera in such a way as to generate image maps correct for using
  1314.         // in an environment map.
  1315.         viewpoint {
  1316.            from location
  1317.            at location + at_vecs[frame]
  1318.            up up_vecs[frame]
  1319.            ...
  1320.            }
  1321.  
  1322.      Sample files: plyhdrn.pi, environ.pi
  1323.  
  1324.                                                                            22
  1325.  
  1326.  
  1327.      2.1.4 Conditional Expressions
  1328.  
  1329.      Conditional expressions are used in one of two places: conditional
  1330.      processing of declarations (see section 2.7) or conditional value
  1331.      functions.
  1332.  
  1333.      cexper has one of the following forms:
  1334.  
  1335.         !cexper
  1336.         cexper && cexper
  1337.         cexper || cexper
  1338.         float < float
  1339.         float <= float
  1340.         float > float
  1341.         float >= float
  1342.  
  1343.      A use of conditional expressions is to define a texture based on other
  1344.      expressions, the format of this expression is:
  1345.  
  1346.         (cexper ? true_value : false_value)
  1347.  
  1348.      Where true_value/false_value can be either floating point or vector
  1349.      values.  This type of expression is taken directly from the equivalent
  1350.      in the C language.  An example of how this is used (from the file
  1351.      spot1.pi) is:
  1352.  
  1353.         special surface {
  1354.            color white
  1355.            ambient (visible(W, throw_offset) == 0
  1356.                     ? 0
  1357.                     : (P[0] < 1 ? 1
  1358.                       : (P[0] > throw_length ? 0
  1359.                          : (throw_length - P[0]) / throw_length)))
  1360.            transmission (visible(W, throw_offset) == 1
  1361.                          ? (P[0] < 1 ? 0
  1362.                             : (P[0] > throw_length ? 1
  1363.                                : P[0] / throw_length))
  1364.                          : 1), 1
  1365.            }
  1366.  
  1367.      In this case conditional statements are used to determine the surface
  1368.      characteristics of a cone defining the boundary of a spotlight.  The
  1369.      amount of ambient light is modified with distance from the apex of the
  1370.      cone, the visibility of the cone is modified based on both distance
  1371.      and on a determination if the cone is behind an object with respect to
  1372.      the source of the light.
  1373.  
  1374.  
  1375.      2.1.5 Run-Time expressions
  1376.  
  1377.      There are a few expressions that only have meaning during the
  1378.      rendering process:
  1379.  
  1380.                                                                            23
  1381.  
  1382.         I       Direction of the ray that struck the object
  1383.         P       Point of intersection in object coordinates
  1384.         N       Normal to the point of intersection in world
  1385.                 coordinates
  1386.         W       Point of intersection in world coordinates
  1387.         U       The u/v/w coordinate of the intersection point
  1388.         x,y,z   Components of the point in object coordinates
  1389.         u,v,w   Components of the uv-coordinate of the point
  1390.  
  1391.      These expressions describe the interaction of a ray and an object.  To
  1392.      use them effectively, you need to understand the distinction between
  1393.      world coordinates, object coordinates, and u/v coordinates.  Object
  1394.      coordinates describe a point or a direction with respect to an object
  1395.      as it was originally defined.  World coordinates describe the same
  1396.      point after it has been rotated/scaled/translated.  u/v coordinates
  1397.      describe the point in a way natural to a particular object type (e.g.,
  1398.      latitude and longitude for a sphere).  Typically texturing is done in
  1399.      either object coordinates or u/v coordinates so that as the object is
  1400.      moved around the texture will move with it.  On the other hand shading
  1401.      is done in world coordinates.
  1402.  
  1403.      The variables u, v, and w are specific to each surface type and in
  1404.      general are the natural mapping for the surface (e.g., latitude and
  1405.      longitude on a sphere)  In general u varies from 0 to 1 as you go
  1406.      around an object and v varies from 0 to one as you go from the bottom
  1407.      to the top of an object.  These variables can be used in a couple of
  1408.      ways, to tell Polyray to only render portions of a surface within
  1409.      certain uv bounds, or they can be used as arguments to expressions in
  1410.      textures or displacement functions.
  1411.  
  1412.      Not all primitives set meaningful values for u and v, those that do
  1413.      are:
  1414.  
  1415.         bezier, cone, cylinder, disc, height fields, NURB, parabola,
  1416.         parametric, sphere, torus, patch
  1417.  
  1418.      Other surface types will simply have u=x, v=y, w=z.  An intersection
  1419.      with a gridded object will use the u/v coordinates of the object
  1420.      within the grid.
  1421.  
  1422.      See the file uvtst.pi in the data archives for an example of using uv
  1423.      bounds on objects.  The file spikes.pi demonstrates using uv as
  1424.      variables in a displacement surface.  The file bezier1.pi demonstrates
  1425.      using uv as variables to stretch an image over the surface of a bezier
  1426.      patch.
  1427.  
  1428.      The meanings of some of these variables are slightly different when
  1429.      creating particle systems (see 2.3.5), or when coloring the background
  1430.      of an image (see 2.4.2)
  1431.  
  1432.  
  1433.      2.1.6 Named Expressions
  1434.  
  1435.  
  1436.                                                                            24
  1437.      A major convenience for creating input files is the ability to create
  1438.      named definitions of surface models, object definitions, vectors, etc.
  1439.      The way a value is defined takes one of the following forms:
  1440.  
  1441.         define token expression          float, vector, array, cexper
  1442.         define token "str..."            string expression
  1443.         define token object { ... }
  1444.         define token surface { ... }
  1445.         define token texture { ... }
  1446.         define token transform { ... }   Each entry may be one of
  1447.                                          scale/translate/rotate/shear
  1448.         define token particle { ... }
  1449.  
  1450.      Objects, surfaces, and textures can either be instantiated as-is by
  1451.      using the token name alone, or it can be instantiated and modified:
  1452.  
  1453.         token,
  1454.      or
  1455.         token { ... modifiers ... },
  1456.  
  1457.      Polyray keeps track of what type of entity the token represents and
  1458.      will parse the expressions accordingly.
  1459.  
  1460.      Note: It is not possible to have two types of entities referred to by
  1461.      the same name.  If a name is reused, then a warning will be printed,
  1462.      and all references to that name will use the new definition from that
  1463.      point on.
  1464.  
  1465.  
  1466.      2.1.6.1 Static variables
  1467.  
  1468.      Static variables are a way to retain variable values (expressions,
  1469.      objects, textures, ...) from frame to frame of an animation.  Instead
  1470.      of the normal declaration of a variable:
  1471.  
  1472.         define xyz 32 * frame
  1473.  
  1474.      you would do something like this:
  1475.  
  1476.         if (frame == start_frame)
  1477.            static define xyz 42
  1478.         else
  1479.            static define xyz (xyz + 0.1)
  1480.  
  1481.      The big differences between a static define and a define are that the
  1482.      static variable will be retained from frame to frame, and the static
  1483.      variable actually replaces any previous definitions rather than simply
  1484.      overloading them.
  1485.  
  1486.      The static variables have an additional use beyond simple arithmetic
  1487.      on variables.  By defining something that takes a lot of processing at
  1488.      parse time (like height fields and large image maps), you can make
  1489.      them static in the first frame and simply instantiate them every frame
  1490.      after that.
  1491.  
  1492.                                                                            25
  1493.  
  1494.      One example of this would be to spin a complex height field, if you
  1495.      have to create it every frame, there is a long wait while Polyray
  1496.      generates the field.  The following declarations would be a better
  1497.      way:
  1498.  
  1499.         if (frame == start_frame)
  1500.            static define sinsf
  1501.               object {
  1502.                  smooth_height_fn 128, 128, -2, 2, -2, 2,
  1503.                                   0.25 * sin(18.85 * x * z + theta_offset)
  1504.                  shiny_red
  1505.                  }
  1506.         ...
  1507.         sinsf { rotate <0, 6*frame, 0> }
  1508.         ...
  1509.  
  1510.      Several examples of how static variables can be used are found in the
  1511.      animation directory in the data file archive.  Two that make extensive
  1512.      use of static variables are movsph.pi, which bounces several spherical
  1513.      blob components around inside a box, and cannon.pi which points a
  1514.      cannon in several directions, firing balls once it is pointed.
  1515.  
  1516.      Warning:  A texture inside a static object should ONLY be static
  1517.      itself.  The reason is that between frames, every non-static thing is
  1518.      deallocated.  If you have things inside a static object that point to
  1519.      a deallocated pointer, you will most certainly crash the program.
  1520.      Sorry, but detecting these things would be too hard and reallocating
  1521.      all the memory would take up too much space.
  1522.  
  1523.  
  1524.      2.1.6.2 Lazy Evaluation
  1525.  
  1526.      Normally, Polyray tries to reduce the amount of time and space
  1527.      necessary for evaluating and storing variables and expressions.  For
  1528.      example, if you had the following definition of x:
  1529.  
  1530.         define x 2 * 3
  1531.  
  1532.      Polyray would store 6 rather than the entire expression.  This can
  1533.      cause problems in certain circumstances if Polyray decides to reduce
  1534.      the expression too soon.  The problem is most notable in particle
  1535.      systems since the expression that is used in it's declaration is used
  1536.      for the life of the particle system.  An example of the problem would
  1537.      be a declaration like:
  1538.  
  1539.         define t (frame - start_frame) / (end_frame - start_frame)
  1540.  
  1541.      When Polyray encounters this it will store a value for t that is
  1542.      between 0 (for the first frame) and 1 (for the last frame).  This
  1543.      great, up until you declare a particle system with something like:
  1544.  
  1545.         if (frame == start_frame)
  1546.            define partx
  1547.  
  1548.                                                                            26
  1549.            particle {
  1550.               ...
  1551.               death (t > 0.5 ? 1 : 0)
  1552.               }
  1553.  
  1554.      Clearly the intent here is that the particles created by this system
  1555.      will die halfway through the animation (t > 0.5).  This won't happen,
  1556.      since Polyray will evaluate the value of t at the time that partx is
  1557.      declared, and store the expression (0 > 0.5 ? 1 : 0), which then
  1558.      reduces to 0.  This means the particle will never die.
  1559.  
  1560.      To avoid this difficulty, the keyword noeval can be added to a
  1561.      definition to force Polyray to postpone evaluation.  The declaration
  1562.      of t would now be:
  1563.  
  1564.         define noeval t (frame - start_frame) / (end_frame - start_frame)
  1565.  
  1566.      When partx is declared, the entire expression is now used and the
  1567.      particles will die at the appropriate time.  Note that noeval is
  1568.      always the last keyword in a definition, and it works correctly with
  1569.      static definitions as well as normal ones.
  1570.  
  1571.      Sample file: part6.pi
  1572.  
  1573.  
  1574.      2.2 Definition of the viewpoint
  1575.  
  1576.      The viewpoint and its associated components define the position and
  1577.      orientation the view will be generated from.
  1578.  
  1579.      The format of the declaration is:
  1580.  
  1581.          viewpoint {
  1582.             from vector
  1583.             at vector
  1584.             up vector
  1585.             angle float
  1586.             hither float
  1587.             resolution float, float
  1588.             aspect float
  1589.             yon float
  1590.             max_trace_depth float
  1591.             aperture float
  1592.             max_samples float
  1593.             focal_distance float
  1594.             image_format float
  1595.             pixel_encoding float
  1596.             pixelsize float
  1597.             antialias float
  1598.             antialias_threshold float
  1599.             }
  1600.  
  1601.      All of the entries in the viewpoint declaration are optional and have
  1602.      reasonable default values (see below).  The order of the entries
  1603.  
  1604.                                                                            27
  1605.      defining the viewpoint is not important, unless you redefine some
  1606.      field. (In which case the last is used.)
  1607.  
  1608.      The parameters are:
  1609.  
  1610.         aspect               The ratio of width to height. (Default: 1.0.)
  1611.         at                   The center of the image, in  world
  1612.                              coordinates. (Default: <0, 0, 0>)
  1613.         angle                The field of view (in degrees), from the
  1614.                              center of the top row to the center of the
  1615.                              bottom row. (Default: 45)
  1616.         from                 The location of the eye. (Default: <0, 0, -1>)
  1617.         hither               Distance to front of view pyramid.  Any
  1618.                              intersection closer  than this value will be
  1619.                              ignored. (Default: 1.0e-3)
  1620.         resolution           Number of columns and rows in the image.
  1621.                              (Default: 256x256)
  1622.         up                   Which direction is up (Default: <0, 1, 0>)
  1623.         yon                  Distance to back of view pyramid.  Any
  1624.                              intersection beyond this distance will be
  1625.                              ignored. (Default: 1.0e5)
  1626.         max_trace_depth      This allows you to tailor the amount of
  1627.                              recursion allowed for scenes with reflection
  1628.                              and/or transparency. (Default: 5)
  1629.         aperture             If larger than 0, then extra rays are shot
  1630.                              (controlled by max_samples) to produce a
  1631.                              blurred image. Good values are between 0.1
  1632.                              and 0.5. (Default: 0)
  1633.         max_samples          Number of rays/pixel when performing focal
  1634.                              blur (Default: 4)
  1635.         focal_distance       Distance from the eye to the point that things
  1636.                              are in focus, this defaults to the distance
  1637.                              between from and at.
  1638.         image_format         If 0 then normal image, if 1 then depth image
  1639.         pixel_encoding       If 0 then uncompressed, if 1 then image is RLE
  1640.         pixelsize            Number of bits/pixel in image (Default: 16)
  1641.         antialias            Level of antialiasing to use (Default: 0)
  1642.         antialias_threshold  Threshold to start antialiasing
  1643.                              (Default: 0.01)
  1644.  
  1645.      The view vectors will be coerced so that they are perpendicular to the
  1646.      vector from the eye (from) to the point of interest (at).
  1647.  
  1648.      A typical declaration is:
  1649.  
  1650.         viewpoint {
  1651.            from <0, 5, -5>
  1652.            at   <0, 0,  0>
  1653.            up   <0, 1,  0>
  1654.            angle 30
  1655.            resolution 320, 160
  1656.            aspect 2
  1657.            }
  1658.  
  1659.  
  1660.                                                                            28
  1661.      In this declaration the eye is five units behind the origin, five
  1662.      units above the x-z plane and is looking at the origin.  The up
  1663.      direction is aligned with the y-axis, the field of view is 30 degrees
  1664.      and the output file will default to 320x160 pixels.
  1665.  
  1666.      In this example it is assumed that pixels are square, and hence the
  1667.      aspect ratio is set to width/height.  If you were generating an image
  1668.      for a screen that has pixels half as wide as they are high then the
  1669.      aspect ratio would be set to one.
  1670.  
  1671.      Note that you can change from left handed coordinates (the default for
  1672.      Polyray) to right handed by using a negative aspect ratio (e.g.,
  1673.      aspect -4/3).
  1674.  
  1675.  
  1676.      2.3 Objects/Surfaces
  1677.  
  1678.      In order to make pictures, the light has to hit something.  Polyray
  1679.      supports several primitive objects.  The following sections give the
  1680.      syntax for describing the primitives, as well as how more complex
  1681.      primitives can be built from simple ones.
  1682.  
  1683.      An object declaration is how polyray associates a surface with its
  1684.      lighting characteristics, and its orientation.  This declaration
  1685.      includes one of the primitive shapes (sphere, polygon, ...), and
  1686.      optionally: a texture declaration (set to a matte white if none is
  1687.      defined), orientation declarations, or a bounding box declaration.
  1688.  
  1689.      The format the declaration is:
  1690.  
  1691.         object {
  1692.            shape_declaration
  1693.            [texture_declaration]
  1694.            [translate/rotate/scale declarations]
  1695.            [subdivision declarations]
  1696.            [displacement declaration]
  1697.            [shading flag declaration]
  1698.            [bounding box declaration]
  1699.            [u/v bounds declaration]
  1700.            }
  1701.  
  1702.      The following sub-sections describe the format of the individual parts
  1703.      of an object declaration.  (Note:  The shape declaration MUST be first
  1704.      in the declaration, as any operations that follow have to have data to
  1705.      work on.)
  1706.  
  1707.      2.3.1 Object Modifiers
  1708.  
  1709.      Object modifiers are statements within an object declaration that are
  1710.      used to move and/or change the shape of the object.
  1711.  
  1712.      The declarations are processed in the order they appear in the
  1713.      declaration, so if you want to resize and object before moving it, you
  1714.      need to put the scale statement before the translation statement.  The
  1715.  
  1716.                                                                            29
  1717.      exception to this are displacement and u/v bounds.  These act on the
  1718.      underlying shape and are applied prior to any other object modifiers,
  1719.      regardless of where they appear in the object declaration.
  1720.  
  1721.      2.3.1.1 Position and Orientation Modifiers
  1722.  
  1723.      The position, orientation, and size of an object can be modified
  1724.      through one of four linear transformations: translation, rotation,
  1725.      scaling, and shear.  Other modifications that can be made to the hape
  1726.      are displacement and u/v bounding.
  1727.  
  1728.  
  1729.      2.3.1.1.1 Translation
  1730.  
  1731.      Translation moves the position of an object by the number of units
  1732.      specified in the associated vector.  The format of the declaration is:
  1733.  
  1734.         translate <xt, yt, zt>
  1735.  
  1736.  
  1737.      2.3.1.1.2 Rotation
  1738.  
  1739.      Rotation revolves the position of an object about the x, y, and z axes
  1740.      (in that order).  The amount of rotation is specified in degrees for
  1741.      each of the axes.  The direction of rotations follows a left-handed
  1742.      convention: if the thumb of your left hand points along the positive
  1743.      direction of an axis, then the direction your fingers curl is the
  1744.      positive direction of rotation.  (A negative aspect ratio in the
  1745.      viewpoint flips everything around to a right handed system.)
  1746.  
  1747.      The format of the declaration is:
  1748.  
  1749.         rotate <xr, yr, zr>
  1750.  
  1751.      For example the declaration:
  1752.  
  1753.         rotate <30, 0, 20>
  1754.  
  1755.      will rotate the object by 30 degrees about the x axis, followed by 20
  1756.      degrees about the z axis.
  1757.  
  1758.      Remember: Left Handed Rotations.
  1759.  
  1760.  
  1761.      2.3.1.1.3 Scaling
  1762.  
  1763.      Scaling alters the size of an object by a given amount with respect to
  1764.      each of the coordinate axes.  The format of the declaration is:
  1765.  
  1766.         scale <xs, ys, zs>
  1767.  
  1768.      Note that using 0 for any of the components of a scale is a bad idea.
  1769.      It may result in a division by zero in Polyray, causing a program
  1770.      crash.  Use a small number like 1.0e-5 to flatten things.  Usually you
  1771.  
  1772.                                                                            30
  1773.      will just want to use 1 for components that don't need scaling.
  1774.  
  1775.  
  1776.      2.3.1.1.4 Shear
  1777.  
  1778.      A less frequently used, but occasionally useful transformation is
  1779.      linear shear.  Shear scales along one axis by an amount that is
  1780.      proportional to the location on another axis.  The format of the
  1781.      declaration is:
  1782.  
  1783.         shear yx, zx, xy, zy, xz, yz
  1784.  
  1785.      Typically only one or two of the components will be non-zero, for
  1786.      example the declaration:
  1787.  
  1788.         shear 0, 0, 1, 0, 0, 0
  1789.  
  1790.      will shear an object more and more to the right as y gets larger and
  1791.      larger.  The order of the letters in the declaration is descriptive,
  1792.      shear ... ab, ... means shear along direction a by the amount ab times
  1793.      the position b.
  1794.  
  1795.      This declaration should probably be split into three: one that
  1796.      associates shear in x with the y and z values, one that associates
  1797.      shear in y with x and z values, and one that associates shear in z
  1798.      with x and y values.
  1799.  
  1800.      You might want to look at the file xander.pi - this uses shear on
  1801.      boxes to make diagonally slanted parts of letters.
  1802.  
  1803.  
  1804.      2.3.1.1.5 Displace
  1805.  
  1806.      The displacement operation causes a modification of the shape of an
  1807.      object as it is being rendered.  The amount and direction of the
  1808.      displacement are specified by the statement:
  1809.  
  1810.         displace vector
  1811.      or
  1812.         displace float
  1813.  
  1814.  
  1815.      If a vector expression is given, then Polyray will displace each
  1816.      vertex in the surface by the vector.  If a floating point expression
  1817.      is given, then Polyray will displace the surface along the direction
  1818.      of the normal, by the amount given in the expression.
  1819.  
  1820.      For effective results, the value of u_steps and v_steps should be set
  1821.      fairly high.  Polyray subdivides the surface, then performs the
  1822.      displacement.  If there are too few subdivisions of the surface then
  1823.      the result will be a very coarse looking object.
  1824.  
  1825.      An example of an object that has a displacement is shown below.  The
  1826.      displacement in the outer object is applied to each of the two spheres
  1827.  
  1828.                                                                            31
  1829.      within.
  1830.  
  1831.      object {
  1832.         object {
  1833.            sphere <0,-1.5, 0>, 2
  1834.            u_steps 32
  1835.            v_steps 64
  1836.            shiny_red
  1837.            }
  1838.         + object {
  1839.            sphere <0, 1.5, 0>, 2
  1840.            u_steps 32
  1841.            v_steps 64
  1842.            shiny_blue
  1843.            translate <0, -1.5, 0>
  1844.            rotate <-20, 0, 30>
  1845.            translate <0, 2.25, 0>
  1846.            }
  1847.         displace 0.5 * sin(5*y)
  1848.         }
  1849.  
  1850.      Sample Files:  disp2.pi, disp3.pi, legen.pi, spikes.pi
  1851.  
  1852.  
  1853.      2.3.1.1.6 UV Bounds
  1854.  
  1855.      By adjusting the value of the u/v bounds, it is possible to only
  1856.      render a selected portion of a surface.  The format of the declaration
  1857.      is:
  1858.  
  1859.         uv_bounds low_u, high_u, low_v, high_v
  1860.  
  1861.      For example, the following declaration will result in a wedge shaped
  1862.      portion of a sphere:
  1863.  
  1864.         object {
  1865.            sphere <-2, 2, 0>, 1
  1866.            uv_bounds 0.3, 1.0, 0.0, 0.8
  1867.            }
  1868.  
  1869.      The same effect could be achieved through the use of CSG with one or
  1870.      more clipping planes.  For most purposes (e.g., creating a hemisphere
  1871.      by setting u_low to 0.5) the uv_bounds will easier to create and
  1872.      faster to render.
  1873.  
  1874.      Sample File: uvtst.pi
  1875.  
  1876.  
  1877.      2.3.1.2 Bounding box
  1878.  
  1879.      In order to speed up the process of determining if a ray intersects an
  1880.      object and in order to define good bounds for surfaces such as
  1881.      polynomials and implicit surfaces, a bounding box can be specified.  A
  1882.      short example of how it is used to define bounds of a polynomial:
  1883.  
  1884.                                                                            32
  1885.  
  1886.         define r0 3
  1887.         define r1 1
  1888.         define torus_expression (x^2 + y^2 + z^2 - (r0^2 + r1^2))^2 -
  1889.                                 4 * r0^2 * (r1^2 - z^2)
  1890.         object {
  1891.            polynomial torus_expression
  1892.            shiny_red
  1893.            bounding_box <-(r0+r1), -(r0+r1), -r1>,
  1894.                         < (r0+r1),  (r0+r1),  r1>
  1895.            }
  1896.  
  1897.      The test for intersecting a ray against a box is much faster than
  1898.      performing the test for the polynomial equation.  In addition the box
  1899.      helps the scan conversion process determine where to look for the
  1900.      surface of the torus.
  1901.  
  1902.  
  1903.      2.3.1.3 Subdivision of Primitives
  1904.  
  1905.      The amount of subdivision of a primitive that is performed before it
  1906.      is displayed as polygons is tunable.  These declarations are used for
  1907.      scan conversion of object, when creating displacement surfaces, and to
  1908.      determine the quality of an implicit function.  The declarations are:
  1909.  
  1910.         u_steps n
  1911.         v_steps m
  1912.         w_steps l
  1913.         uv_steps n, m
  1914.         uv_steps n, m, l
  1915.  
  1916.      Where u generally refers to the number of steps around the primitive
  1917.      (the number of steps around the equator of a sphere for example).  The
  1918.      parameter v refers to the number of steps along the primitive
  1919.      (latitudes on a sphere). Cone and cylinder primitives only require 1
  1920.      step along v, but for smoothness may require many steps in u.
  1921.  
  1922.      For blobs, polynomials, and implicit surfaces, the u_steps component
  1923.      defines how many subdivisions along the x-axis, the v_steps component
  1924.      defines how many subdivisions along the y-axis, and the w_steps
  1925.      component defines how many subdivision along the z-axis.
  1926.  
  1927.  
  1928.      2.3.1.4 Shading Flags
  1929.  
  1930.      It is possible to tune the shading that will be performed for each
  1931.      object.  The values of each bit in the flag has the same meaning as
  1932.      that given for  global shading in section 1.7.1.4:
  1933.  
  1934.         1   Shadow_Check     Shadows will be generated on the object
  1935.         2   Reflect_Check    Reflectivity will be tested
  1936.         4   Transmit_Check   Check for refraction
  1937.         8   Two_Sides        If on, highlighting will be performed
  1938.                              on both sides of a surface.
  1939.  
  1940.                                                                            33
  1941.         16  UV_Check         If on then u/v coordinates are calculated
  1942.         32  Cast_Shadow      If off then the object doesn't cast a shadow
  1943.  
  1944.      By default, all objects have the following flags set: Shadow_Check,
  1945.      Reflect_Chect, Transmit_Check, UV_Check, and Cast_Shadow.  The two
  1946.      sides check is normally off.
  1947.  
  1948.      The declaration has the form:
  1949.  
  1950.         shading_flags xx
  1951.  
  1952.      For example, if the value 50 (32 + 16 + 2) is used for xx above, then
  1953.      this object can be reflective and will cast shadows, however there
  1954.      will be no tests for transparency, there will be no shading of the
  1955.      back sides of surfaces, and there will be no shadows on the surface.
  1956.  
  1957.      Note: the shading flag only affects the object in which the
  1958.      declaration is made.  This means that if you want the shading values
  1959.      affected for all parts if a CSG object, then you will need a
  1960.      declaration in every component.
  1961.  
  1962.  
  1963.      2.3.2 Primitives
  1964.  
  1965.      Primitives are the lowest level of shape description.  Typically a
  1966.      scene will contain many primitives, appearing either individually or
  1967.      as aggregates using either Constructive Solid Geometry (CSG)
  1968.      operations or gridded objects.
  1969.  
  1970.      Descriptions of each of the primitive shapes supported by Polyray, as
  1971.      well as references to data files that demonstrate them are given in
  1972.      the following subsections.  Following the description of the
  1973.      primitives are descriptions of how CSG and grids can be built.
  1974.  
  1975.  
  1976.      2.3.2.1 Bezier patches
  1977.  
  1978.      A Bezier patch is a form of bicubic patch that interpolates its
  1979.      control vertices.  The patch is defined in terms of a 4x4 array of
  1980.      control vertices, as well as several tuning values.
  1981.  
  1982.      The format of the declaration is:
  1983.  
  1984.         bezier subdivision_type, flatness_value,
  1985.                u_subdivisions, v_subdivision,
  1986.                [ 16 comma-separated vertices, i.e.
  1987.                   <x0, y0, z0>, <x1, y1, z1>, ..., <x15, y15, z15> ]
  1988.  
  1989.      The subdivision_type and flatness_value are no longer used by Polyray.
  1990.      They are retained in the declaration for backwards compatibility.
  1991.  
  1992.      The number of levels of subdivision of the patch, in each direction,
  1993.      is controlled by either the u_subdivisions and v_subdivisions given in
  1994.      the bezier shape declaration or by the value of uv_steps (see section
  1995.  
  1996.                                                                            34
  1997.      2.3.1.3) if given later in the object declaration.  The more
  1998.      subdivisions allowed, the smoother the approximation to the patch,
  1999.      however storage and processing time go up.
  2000.  
  2001.      An example of a bezier patch is:
  2002.  
  2003.         object {
  2004.            bezier 2, 0.05, 3, 3,
  2005.               <0, 0, 2>, <1, 0, 0>, <2, 0, 0>, <3, 0,-2>,
  2006.               <0, 1, 0>, <1, 1, 0>, <2, 1, 0>, <3, 1, 0>,
  2007.               <0, 2, 0>, <1, 2, 0>, <2, 2, 0>, <3, 2, 0>,
  2008.               <0, 3, 2>, <1, 3, 0>, <2, 3, 0>, <3, 3,-2>
  2009.         uv_steps 8, 8
  2010.         rotate <30, -70, 0>
  2011.         shiny_red
  2012.         }
  2013.  
  2014.      Sample files: bezier0.pi, teapot.pi, teapot.inc
  2015.  
  2016.  
  2017.      2.3.2.2 Blob
  2018.  
  2019.      A blob describes a smooth potential field around one or more
  2020.      spherical, cylindrical, or planar components.
  2021.  
  2022.      The format of the declaration is:
  2023.  
  2024.         blob threshold:
  2025.            blob_component1
  2026.            [, blob_component2 ]
  2027.            [, etc. for each component ]
  2028.  
  2029.      The threshold is the minimum potential value that will be considered
  2030.      when examining the interaction of the various components of the blob.
  2031.      Each blob component one of two forms:
  2032.  
  2033.         sphere <x, y, z>, strength, radius
  2034.         cylinder <x0, y0, z0>, <x1, y1, z1>, strength, radius
  2035.         plane <nx, ny, nz>, d, strength, dist
  2036.         torus <x, y, z>, <dx, dy, dz>, major, strength, minor
  2037.  
  2038.      The strength component describes how strong the potential field is
  2039.      around the center of the component, the radius component describes the
  2040.      maximum distance at which the component will interact with other
  2041.      components.  For a spherical blob component the vector <x,y,z> gives
  2042.      the center of the potential field around the component.  For a
  2043.      cylindrical blob component the vector <x0, y0, z0> defines one end of
  2044.      the axis of a cylinder, the vector <x1, y1, z1> defines the other end
  2045.      of the axis of a cylinder.  A planar blob component is defined by the
  2046.      standard plane equation with <nx, ny, nz> defining the normal and 'd'
  2047.      defining the distance of the plane from the origin along the normal.
  2048.  
  2049.      Note: The ends of a cylindrical blob component are given hemispherical
  2050.      caps.
  2051.  
  2052.                                                                            35
  2053.  
  2054.      Note: toroidal blob components won't render correctly in raytracing.
  2055.      The numerical precision of a PC is insufficient.  It will work
  2056.      correctly in scan conversion or raw triangle output.
  2057.  
  2058.      Note: The colon and the commas in the declaration really are
  2059.      important.
  2060.  
  2061.  
  2062.      An example of a blob is:
  2063.  
  2064.      object {
  2065.            blob 0.5:
  2066.               cylinder <0,  0, 0>, <5, 0, 0>, 1, 0.7,
  2067.               cylinder <1, -3, 0>, <3, 2, 0>, 1, 1.4,
  2068.               sphere <3, -0.8, 0>, 1, 1,
  2069.               sphere <4,  0.5, 0>, 1, 1,
  2070.               sphere <1,  1,   0>, 1, 1,
  2071.               sphere <1,  1.5, 0>, 1, 1,
  2072.               sphere <1,  2.7, 0>, 1, 1
  2073.  
  2074.            shiny_red
  2075.         }
  2076.  
  2077.      Note: since a blob is essentially a collection of 4th order
  2078.      polynomials, it is possible to specify which quartic root solver to
  2079.      use.  See section 2.3.2.15, for a description of the root_solver
  2080.      statement.
  2081.  
  2082.      Sample files: blob.pi, tblob.pi
  2083.  
  2084.  
  2085.      2.3.2.3 Box
  2086.  
  2087.      A box is rectangular solid that has its edges aligned with the x, y,
  2088.      and z axes.  it is defined in terms of two diagonally opposite
  2089.      corners.  The alignment can be changed by rotations after the shape
  2090.      declaration.
  2091.  
  2092.      The format of the declaration is:
  2093.  
  2094.         box <x0, y0, z0>, <x1, y1, z1>
  2095.  
  2096.      Usually the convention is that the first point is the front-lower-left
  2097.      point and the second is the back-upper-right point.  The following
  2098.      declaration is four boxes stacked on top of each other:
  2099.  
  2100.         define pyramid
  2101.         object {
  2102.              object { box <-1, 3, -1>, <1, 4, 1> }
  2103.            + object { box <-2, 2, -2>, <2, 3, 2> }
  2104.            + object { box <-3, 1, -3>, <3, 2, 3> }
  2105.            + object { box <-4, 0, -4>, <4, 1, 4> }
  2106.            matte_blue
  2107.  
  2108.                                                                            36
  2109.            }
  2110.  
  2111.      Sample file: boxes.pi
  2112.  
  2113.  
  2114.      2.3.2.4 Cone
  2115.  
  2116.      A cone is defined in terms of a base point, an apex point, and the
  2117.      radii at those two points.  Note that cones are not closed (you must
  2118.      use discs to cap them).
  2119.  
  2120.      The format of the declaration is:
  2121.  
  2122.         cone <x0, y0, z0>, r0, <x1, y1, z1>, r1
  2123.  
  2124.      An example declaration of a cone is:
  2125.  
  2126.           object {
  2127.              cone <0, 0, 0>, 4, <4, 0, 0>, 0
  2128.              shiny_red
  2129.              }
  2130.  
  2131.      Sample file: cone.pi
  2132.  
  2133.      2.3.2.5 Cylinder
  2134.  
  2135.      A cylinder is defined in terms of a bottom point, a top point, and its
  2136.      radius.  Note that cylinders are not closed.
  2137.  
  2138.      The format of the declaration is:
  2139.  
  2140.         cylinder <x0, y0, z0>, <x1, y1, z1>, r
  2141.  
  2142.      An example of a cylinder is:
  2143.  
  2144.         object {
  2145.            cylinder <-3, -2, 0>, <0, 1, 3>, 0.5
  2146.            shiny_red
  2147.            }
  2148.  
  2149.      Sample file: cylinder.pi
  2150.  
  2151.  
  2152.      2.3.2.6 Disc
  2153.  
  2154.      A disc is defined in terms of a center a normal and either a radius,
  2155.      or using an inner radius and an outer radius.  If only one radius is
  2156.      given, then the disc has the appearance of a (very) flat coin.  If two
  2157.      radii are given, then the disc takes the shape of an annulus (washer)
  2158.      where the disc extends from the first radius to the second radius.
  2159.      Typical uses for discs are as caps for cones and cylinders, or as
  2160.      ground planes (using a really big radius).
  2161.  
  2162.      The format of the declaration is:
  2163.  
  2164.                                                                            37
  2165.  
  2166.         disc <cx, cy, cz>, <nx, ny, nz>, r
  2167.      or
  2168.         disc <cx, cy, cz>, <nx, ny, nz>, ir, or
  2169.  
  2170.      The center vector <cx,cy,cz> defines where the center of the disc is
  2171.      located, the normal vector <nx,ny,nz> defines the direction that is
  2172.      perpendicular to the disc.  i.e. a disc having the center <0,0,0> and
  2173.      the normal <0,1,0> would put the disc in the x-z plane with the y-axis
  2174.      coming straight out of the center.
  2175.  
  2176.      An example of a disc is:
  2177.  
  2178.         object {
  2179.            disc <0, 2, 0>, <0, 1, 0>, 3
  2180.            rotate <-30, 20, 0>
  2181.            shiny_red
  2182.            }
  2183.  
  2184.      Note: a disc is infinitely thin.  If you look at it edge-on it will
  2185.      disappear.
  2186.  
  2187.      Sample file: disc.pi
  2188.  
  2189.  
  2190.      2.3.2.7 Glyphs (TrueType fonts)
  2191.  
  2192.      The glyph primitive creates shapes similar to the sweep primitive.
  2193.      The big difference is that straight line and curved line segments may
  2194.      appear in the same contour.  Additionally, the glyph can be made from
  2195.      several contours with exterior ones defining the outsides of the shape
  2196.      and interior ones defining holes within the glyph.
  2197.  
  2198.      Typically the glyph primitive will be used in conjunction with the
  2199.      utility TTFX (described below) to translate TrueType font information
  2200.      into Polyray glyph information.
  2201.  
  2202.      The following declaration creates a box with a square hole cut out of
  2203.      it.
  2204.  
  2205.         object {
  2206.            glyph 2
  2207.               contour 4,
  2208.                  <0, 0>, <4, 0>, <4, 4>, <0, 4>
  2209.               contour 4,
  2210.                  <1, 1>, <1, 3>, <3, 3>, <3, 1>
  2211.            texture { shiny { color red reflection 0.2 } }
  2212.            translate <-2, 0, 0>
  2213.            }
  2214.  
  2215.      The default placement of glyph coordinates is in the x-y plane and the
  2216.      glyph has a depth of one in z (starting at z=0 and going to z=1).  To
  2217.      change the depth, just use something like: scale <1, 1, 0.2>.
  2218.  
  2219.  
  2220.                                                                            38
  2221.      Each entry in a contour is a 2D point.  If a non-zero z component is
  2222.      added then the point is assumed to be an off-curve point and will
  2223.      create a curved segment within the contour.  For example, the
  2224.      following declaration makes a somewhat star shaped contour with sharp
  2225.      corners for the inner parts of the star and rounded curves for the
  2226.      outer parts of the star:
  2227.  
  2228.         object {
  2229.            glyph 1 contour 14,
  2230.              <r0*cos( 1*dt),r0*sin( 1*dt)>,<r1*cos( 2*dt),r1*sin( 2*dt),1>,
  2231.              <r0*cos( 3*dt),r0*sin( 3*dt)>,<r1*cos( 4*dt),r1*sin( 4*dt),1>,
  2232.              <r0*cos( 5*dt),r0*sin( 5*dt)>,<r1*cos( 6*dt),r1*sin( 6*dt),1>,
  2233.              <r0*cos( 7*dt),r0*sin( 7*dt)>,<r1*cos( 8*dt),r1*sin( 8*dt),1>,
  2234.              <r0*cos( 9*dt),r0*sin( 9*dt)>,<r1*cos(10*dt),r1*sin(10*dt),1>,
  2235.              <r0*cos(11*dt),r0*sin(11*dt)>,<r1*cos(12*dt),r1*sin(12*dt),1>,
  2236.              <r0*cos(13*dt),r0*sin(13*dt)>,<r1*cos(14*dt),r1*sin(14*dt),1>
  2237.            }
  2238.  
  2239.      The program TTFX.EXE has been included to help with the conversion of
  2240.      TrueType fonts from their .TTF format (typically found in the
  2241.      /WINDOWS/SYSTEM directory) into the sort of declaration that Polyray
  2242.      can understand.  For example,
  2243.  
  2244.         ttfx \windows\system\times.ttf Foo > temp.pi
  2245.      or,
  2246.         ttfx \windows\system\times.ttf Foo 0.2 > temp.pi
  2247.  
  2248.      By default, the characters in the string being converted (the word Foo
  2249.      above) are packed right next to each other.  If a number follows the
  2250.      text string, then the characters are separated by that amount.  A
  2251.      spacing of 0.2 has worked pretty well for the fonts I've tried.
  2252.  
  2253.      If you then add the following line to the top of temp.pi (leaving
  2254.      everything else like viewpoint to their defaults)
  2255.  
  2256.         light <0, 100, -100>
  2257.  
  2258.      and render it with
  2259.  
  2260.         polyray temp.pi -r 1
  2261.  
  2262.      you will get a nice rendered image of the word Foo.
  2263.  
  2264.      Note that the combination of TTFX, Polyray raw triangle output, and
  2265.      RAW2POV is a way you can create TrueType characters for use in a
  2266.      number of renderers.
  2267.  
  2268.      Sample files: timestst.pi, glyph1.pi, glyph2.pi, glyph3.pi, wingtst.pi
  2269.  
  2270.  
  2271.      2.3.2.8 Implicit Surface
  2272.  
  2273.      The format of the declaration is:
  2274.  
  2275.  
  2276.                                                                            39
  2277.         function f(x,y,z)
  2278.  
  2279.      The function f(x,y,z) may be any expression composed of the variables:
  2280.      x, y, z, a numerical value (e.g., 0.5), the operators: +, -, *, /, ^,
  2281.      and any Polyray supported function.  The code is not particularly
  2282.      fast, nor is it totally accurate, however the capability to ray-trace
  2283.      such a wide class of functions by a SW program is (I believe) unique
  2284.      to Polyray.
  2285.  
  2286.  
  2287.      The following object is taken from sombrero.pi and is a surface that
  2288.      looks very much like diminishing ripples on the surface of water.
  2289.  
  2290.         define a_const 1.0
  2291.         define b_const 2.0
  2292.         define c_const 3.0
  2293.         define two_pi_a 2.0 * 3.14159265358 * a_const
  2294.  
  2295.         // Define a diminishing cosine surface (sombrero)
  2296.         object {
  2297.            function y - c_const * cos(two_pi_a * sqrt(x^2 + z^2)) *
  2298.                                   exp(-b_const * sqrt(x^2 + z^2))
  2299.            matte_red
  2300.            bounding_box <-4, -4, -4>, <4, 4, 4>
  2301.            }
  2302.  
  2303.      Rendering the following object will show all the places within a
  2304.      sphere where the solid noise function takes on the value 0.5.
  2305.  
  2306.         object {
  2307.            object {
  2308.               function noise(3*P) - 0.5
  2309.               u_steps 64
  2310.               v_steps 64
  2311.               w_steps 64
  2312.               Lapis_Lazuli
  2313.               bounding_box <-2, -2, -2>, <2, 2, 2>
  2314.               }
  2315.            & object { sphere <0, 0, 0>, 2 }
  2316.            rotate <-10, 20, 0>
  2317.            }
  2318.  
  2319.      It is quite important to have the bounding box declaration within the
  2320.      object where the function is declared.  If that isn't there, Polyray
  2321.      will be unable to determine where to look for intersections with the
  2322.      surface.  (The bounding box of an implicit function defaults to <-1, -
  2323.      1, -1>, <1, 1, 1>.)
  2324.  
  2325.      Sample files: noisefn.pi, sinsurf.pi, sectorl.pi, sombrero.pi,
  2326.                    superq.pi, zonal.pi
  2327.  
  2328.  
  2329.      2.3.2.9 Height Field
  2330.  
  2331.  
  2332.                                                                            40
  2333.      There are two ways that height fields can be specified, either by
  2334.      using data stored in a Targa file, or using an implicit function of
  2335.      the form y = f(x, z).
  2336.  
  2337.      The default orientation of a height field is that the entire field
  2338.      lies in the square 0 <= x <= 1, 0 <= z <= 1.  File based height fields
  2339.      are always in this orientation, implicit height fields can optionally
  2340.      be defined over a different area of the x-z plane.  The height value
  2341.      is used for y.
  2342.  
  2343.  
  2344.      2.3.2.9.1 File Based Height Fields
  2345.  
  2346.      Height fields data can be read from any Targa, GIF, or JPEG format
  2347.      file.  A GIF image will be treated as an 8 bit format image as
  2348.      described below.  Any color information in the GIF file is ignored.
  2349.  
  2350.      Note that if you use JPEG images, a grayscale JPEG will be treated as
  2351.      an 8 bit format and a color JPEG will be treated as a 24 bit format
  2352.      height field.  Due to the lossy nature of JPEG, it is extremely
  2353.      unlikely that a color JPEG will be useful as a height field.  It is
  2354.      possible that reasonable results can be obtained using grayscale JPEG
  2355.      images as height fields (no guarantees).
  2356.  
  2357.      By using smooth_ in front of the declaration, an extra step is
  2358.      performed that calculates normals to the height field at every point
  2359.      within the field.  The result of this is a greatly smoothed
  2360.      appearance, at the expense of around three times as much memory being
  2361.      used.
  2362.  
  2363.      The format of the declaration is:
  2364.  
  2365.         height_field "filename"
  2366.         smooth_height_field "filename"
  2367.  
  2368.      The sample program wake.c generates a Targa file that simulates the
  2369.      wake behind a boat.
  2370.  
  2371.      Sample files: wake.pi, spiral.pi, islands.pi
  2372.  
  2373.  
  2374.      2.3.2.9.1.1 8 Bit Format
  2375.  
  2376.      Each pixel in the file is represented by a single byte.  The value of
  2377.      the byte is used as an integer height between -127 and 128.
  2378.  
  2379.  
  2380.      2.3.2.9.1.2 16 Bit Format
  2381.  
  2382.      Each pixel in the file is represented by two bytes, low then high.
  2383.      The high component defines the integer component of the height, the
  2384.      low component holds the fractional part scaled by 255. The entire
  2385.      value is offset by 128 to compensate for the unsigned nature of the
  2386.      storage bytes.  As an example the values  high = 140, low = 37 would
  2387.  
  2388.                                                                            41
  2389.      be translated to the height:
  2390.  
  2391.         (140 + 37 / 256) - 128 = 12.144
  2392.  
  2393.      similarly if you are generating a Targa file to use in Polyray, given
  2394.      a height, add 128 to the height, extract the integer component, then
  2395.      extract the scaled fractional component.  The following code fragment
  2396.      shows a way of generating the low and high bytes from a floating point
  2397.      number.
  2398.  
  2399.               unsigned char low, high;
  2400.               float height;
  2401.               FILE *height_file;
  2402.  
  2403.               ...
  2404.  
  2405.               height += 128.0;
  2406.               high = (unsigned char)height;
  2407.               height -= (float)high;
  2408.               low = (unsigned char)(256.0 * height);
  2409.               fputc(low, height_file);
  2410.               fputc(high, height_file);
  2411.  
  2412.  
  2413.      2.3.2.9.1.3 24 Bit Format
  2414.  
  2415.      The red component defines the integer component of the height, the
  2416.      green component holds the fractional part scaled by 255, the blue
  2417.      component is ignored.  The entire value is offset by 128 to compensate
  2418.      for the unsigned nature of the RGB  values.  As an example the values
  2419.      r = 140, g = 37, and b = 0 would be translated to the height:
  2420.  
  2421.         (140 + 37 / 256) - 128 = 12.144
  2422.  
  2423.      similarly if you are generating a Targa file to use in Polyray, given
  2424.      a height, add 128 to the height, extract the integer component, then
  2425.      extract the scaled fractional component.  The following code fragment
  2426.      shows
  2427.      a way of generating the RGB components from a floating point number.
  2428.  
  2429.               unsigned char r, g, b;
  2430.               float height;
  2431.               FILE *height_file;
  2432.  
  2433.               ...
  2434.  
  2435.               height += 128.0;
  2436.               r = (unsigned char)height;
  2437.               height -= (float)r;
  2438.               g = (unsigned char)(256.0 * height);
  2439.               b = 0;
  2440.               fputc(b, height_file);
  2441.               fputc(g, height_file);
  2442.               fputc(r, height_file);
  2443.  
  2444.                                                                            42
  2445.  
  2446.  
  2447.      2.3.2.9.1.4 32 Bit Format
  2448.  
  2449.      The four bytes of the 32 bit Targa image are used to hold the four
  2450.      bytes of a floating point number.  The format of the floating point
  2451.      number is machine specific, and the order of the four bytes in the
  2452.      image correspond exactly to the order of the four bytes of the
  2453.      floating number when it is in memory.
  2454.  
  2455.      For example, the following code shows how to take a floating point
  2456.      number and store it to a file in the format that Polyray will expect.
  2457.      You will also need to write the Targa header, etc.
  2458.  
  2459.         unsigned char *byteptr;
  2460.         float depth;
  2461.         FILE *ofile;
  2462.  
  2463.         ... calculations for depth ...
  2464.  
  2465.         /* Store a floating point number as a 32 bit color- this is
  2466.            obviously a machine specific result for the floating point
  2467.            number that is stored.  There is also an assumption here
  2468.            that a float type is exactly 4 bytes and that the
  2469.            size of an unsigned char is exactly 1 byte. */
  2470.         byteptr = (unsigned char *)&depth;
  2471.         fputc(byteptr[0], ofile);
  2472.         fputc(byteptr[1], ofile);
  2473.         fputc(byteptr[2], ofile);
  2474.         fputc(byteptr[3], ofile);
  2475.  
  2476.         ...
  2477.  
  2478.  
  2479.      2.3.2.9.2 Implicit Height Fields
  2480.  
  2481.      Another way to define height fields is by evaluating a mathematical
  2482.      function over a grid.  Given a function y = f(x, z), Polyray will
  2483.      evaluate the function over a specified area and generate a height
  2484.      field based on the function.  This method can be used to generate
  2485.      images of many sorts of functions that are not easily represented by
  2486.      collections of simpler primitives.
  2487.  
  2488.      The valid formats of the declaration are:
  2489.  
  2490.         height_fn xsize, zsize, minx, maxx, minz, maxz, expression
  2491.         height_fn xsize, zsize, expression
  2492.         smooth_height_fn xsize, zsize, minx, maxx, minz, maxz, expression
  2493.         smooth_height_fn xsize, zsize, expression
  2494.  
  2495.      If the four values minx, maxx, minz, and maxz are not defined then the
  2496.      default square 0 <= x <= 1, 0 <= z <= 1 will be used.
  2497.  
  2498.      For example,
  2499.  
  2500.                                                                            43
  2501.  
  2502.         // Define constants for the sombrero function
  2503.         define a_const 1.0
  2504.         define b_const 2.0
  2505.         define c_const 3.0
  2506.         define two_pi_a 2.0 * 3.14159265358 * a_const
  2507.  
  2508.         // Define a diminishing cosine surface (sombrero)
  2509.         object {
  2510.            height_fn 80, 80, -4, 4, -4, 4,
  2511.               c_const * cos(two_pi_a * sqrt(x^2 + z^2)) *
  2512.                         exp(-b_const * sqrt(x^2 + z^2))
  2513.            shiny_red
  2514.            }
  2515.  
  2516.      will build a height field 80x80, covering the area from -4 <= x <= 4,
  2517.      and -4 <= z <= 4.
  2518.  
  2519.      Compare the run-time performance and visual quality of the sombrero
  2520.      function as defined in sombfn.pi with the sombrero function as defined
  2521.      in sombrero.pi.  The former uses a height field representation and
  2522.      renders quite fast.  The latter uses a very general function
  2523.      representation and gives smoother but very slow results.
  2524.  
  2525.      Sample file: sombfn.pi, sinfn.pi
  2526.  
  2527.  
  2528.      2.3.2.10 Lathe surfaces
  2529.  
  2530.      A lathe surface is a polygon that has been revolved about the y-axis.
  2531.      This surface allows you to build objects that are symmetric about an
  2532.      axis, simply by defining 2D points.
  2533.  
  2534.      The format of the declaration is:
  2535.  
  2536.          lathe type, direction, total_vertices,
  2537.             <vert1.x,vert1.y,vert1.z>
  2538.             [, <vert2.x, vert2.y, vert2.z>]
  2539.             [, etc. for total_vertices vertices]
  2540.  
  2541.      The value of type is either 1, or 2.  If the value is 1, then the
  2542.      surface will simply revolve the line segments.  If the value is 2,
  2543.      then the surface will be represented by a spline that approximates the
  2544.      line segments that were given.  A lathe surface of type 2 is a very
  2545.      good way to smooth off corners in a set of line segments.
  2546.  
  2547.      The value of the vector direction is used to change the orientation of
  2548.      the lathe.  For a lathe surface that goes straight up and down the y-
  2549.      axis, use <0, 1, 0> for direction.  For a lathe surface that lies on
  2550.      the x-axis, you would use <1, 0, 0> for the direction.
  2551.  
  2552.      Sample file: lathe1.pi, lathe2.pi, lathe3.pi
  2553.  
  2554.      Note that CSG will really only work correctly if you close the lathe -
  2555.  
  2556.                                                                            44
  2557.      that is either make the end point of the lathe the same as the start
  2558.      point, or make the x-value of the start and end points equal zero.
  2559.      Lathes, unlike polygons are not automatically closed by Polyray.
  2560.  
  2561.      Note: since a splined lathe surface (type = 2) is a 4th order
  2562.      polynomial, it is possible to specify which quartic root solver to
  2563.      use.  See section 2.3.2.15 for a description of the root_solver
  2564.      statement.
  2565.  
  2566.  
  2567.      2.3.2.11 NURBS
  2568.  
  2569.      Polyray supports the general patch type, Non-Uniform Rational B-
  2570.      Splines (NURBS).  All that is described here is how they are declared
  2571.      and used in Polyray.  For further background and details on NURBS,
  2572.      refer to the literature.
  2573.  
  2574.      They are declared with the following syntax:
  2575.  
  2576.         nurb u_order, u_points, v_order, v_points,
  2577.              u_knots, v_knots, uv_mesh
  2578.      or
  2579.         nurb u_order, u_points, v_order, v_points, uv_mesh
  2580.  
  2581.      Where each part of the declaration has the following format and
  2582.      definition,
  2583.  
  2584.         Name        Format      Definition
  2585.         u_order     integer     One more than the power of the spline in
  2586.                                 the u direction.  (If u_order = 4, then it
  2587.                                 will be a cubic patch.)
  2588.         u_points    integer     The number of vertices in each row of the
  2589.                                 patch mesh
  2590.         v_order     integer     One more than the power of the spline
  2591.                                 in v direction.
  2592.         v_points    integer     The number of rows in the patch mesh
  2593.         u_knots     [...]       Knot values in the u direction
  2594.         v_knots     [...]       Knot values in the v direction
  2595.         uv_mesh     [[...]      An array of arrays of vertices.  Each
  2596.                                 vertex may have either three or four
  2597.                      [...]]     components.  If the fourth component is
  2598.                                 set then the spline will be rational.
  2599.                                 If the vertex has only three components
  2600.                                 then the homogenous (fourth) component is
  2601.                                 assumed to be one. The homogenous
  2602.                                 component must be greater than 0.
  2603.  
  2604.      For example, the following is a complete declaration of a NURB patch
  2605.  
  2606.         object {
  2607.          nurb 4, 6, 4, 5,
  2608.               [0, 0, 0, 0, 1.5, 1.5, 3, 3, 3, 3], // Non-uniform knots
  2609.               [0, 0, 0, 0, 1, 2, 2, 2, 2],        // Uniform open knots
  2610.             [[<0,0,0>, <1,0, 3>, <2,0,-3>,     <3,0, 3>, <4,0,0>],
  2611.  
  2612.                                                                            45
  2613.              [<0,1,0>, <1,1, 0>, <2,1, 0>,     <3,1, 0>, <4,1,0>],
  2614.              [<0,2,0>, <1,2, 0>, <2,2, 5,2>,   <3,2, 0>, <4,2,0>],
  2615.              [<0,3,0>, <1,3, 0>, <2,3, 5,0.5>, <3,3, 0>, <4,3,0>],
  2616.              [<0,4,0>, <1,4, 0>, <2,4, 0>,     <3,4, 0>, <4,4,0>],
  2617.              [<0,5,0>, <1,5,-3>, <2,5, 3>,     <3,5,-3>, <4,5,0>]]
  2618.            translate <-2, -2.5, 0>
  2619.            rotate <-90, -30, 0>
  2620.            uv_steps 32, 32
  2621.            shiny_red
  2622.            }
  2623.  
  2624.      The preceeding patch was both non-uniform and rational.  If you don't
  2625.      want to bother declaring the knot vector you can simply omit it.  This
  2626.      will result in a open uniform B-Spline patch.  Most of the time the
  2627.      non-uniform knot vectors are unnecessary and can be safely omitted.
  2628.      The preceeding declaration with uniform knot vectors, and non-rational
  2629.      vertices could then be declared as:
  2630.  
  2631.         object {
  2632.            nurb 4, 6, 4, 5,
  2633.             [[< 0, 0, 0>, < 1, 0, 3>, < 2, 0,-3>, < 3, 0, 3>, < 4, 0, 0>],
  2634.              [< 0, 1, 0>, < 1, 1, 0>, < 2, 1, 0>, < 3, 1, 0>, < 4, 1, 0>],
  2635.              [< 0, 2, 0>, < 1, 2, 0>, < 2, 2, 5>, < 3, 2, 0>, < 4, 2, 0>],
  2636.              [< 0, 3, 0>, < 1, 3, 0>, < 2, 3, 5>, < 3, 3, 0>, < 4, 3, 0>],
  2637.              [< 0, 4, 0>, < 1, 4, 0>, < 2, 4, 0>, < 3, 4, 0>, < 4, 4, 0>],
  2638.              [< 0, 5, 0>, < 1, 5,-3>, < 2, 5, 3>, < 3, 5,-3>, < 4, 5, 0>]]
  2639.            translate <-2, -2.5, 0>
  2640.            rotate <-90, -30, 0>
  2641.            uv_steps 32, 32
  2642.            shiny_red
  2643.            }
  2644.  
  2645.      Note that internally NURBS are stored as triangles.  This can result
  2646.      in a high memory usage for a finely diced NURB (uv_steps large).
  2647.  
  2648.      Sample files: nurb0.pi, nurb1.pi
  2649.  
  2650.  
  2651.      2.3.2.12 Parabola
  2652.  
  2653.      A parabola is defined in terms of a bottom point, a top point, and its
  2654.      radius at the top.
  2655.  
  2656.      The format of the declaration is:
  2657.  
  2658.         parabola <x0, y0, z0>, <x1, y1, z1>, r
  2659.  
  2660.      The vector <x0,y0,z0> defines the top of the parabola - the part that
  2661.      comes to a point.  The vector <x1,y1,z1> defines the bottom of the
  2662.      parabola, the width of the parabola at this point is r.
  2663.  
  2664.      An example of a parabola declaration is:
  2665.  
  2666.         object {
  2667.  
  2668.                                                                            46
  2669.            parabola <0, 6, 0>, <0, 0, 0>, 3
  2670.            translate <16, 0, 16>
  2671.            steel_blue
  2672.            }
  2673.  
  2674.      This is sort of like a salt shaker shape with a rounded top and the
  2675.      base on the x-z plane.
  2676.  
  2677.  
  2678.      2.3.2.13 Parametric surface
  2679.  
  2680.      A parametric surface allows the creation of surfaces as a mesh of
  2681.      triangles.  By defining the vertices of the mesh in terms of functions
  2682.      of u and v, Polyray will automatically create the entire surface.  The
  2683.      smoothness of the surface is determined by the number of steps allowed
  2684.      for u and v.
  2685.  
  2686.      The mesh defaults to 0 <= u <= 1, and 0 <= v <= 1.  By explicitly
  2687.      defining the uv_bounds for the surface it is possible to create only
  2688.      the desired parts of the surface.
  2689.  
  2690.      The format of the declaration is:
  2691.  
  2692.         parametric <fx(u,v), fy(u,v), fz(u,v)>
  2693.  
  2694.      For example, the following declarations could be used to create a
  2695.      torus:
  2696.  
  2697.         define r0 1.25
  2698.         define r1 0.5
  2699.  
  2700.         define torux (r0 + r1 * cos(v)) * cos(u)
  2701.         define toruy (r0 + r1 * cos(v)) * sin(u)
  2702.         define toruz r1 * sin(v)
  2703.  
  2704.         object {
  2705.            parametric <torux,toruy,toruz>
  2706.            rotate <-20, 0, 0>
  2707.            shiny_red
  2708.            uv_bounds 0, 2*pi, 0, 2*pi
  2709.            uv_steps 16, 8
  2710.            }
  2711.  
  2712.  
  2713.      2.3.2.14 Polygon
  2714.  
  2715.      Although polygons are not very interesting mathematically, there are
  2716.      many sorts of objects that are much easier to represent with polygons.
  2717.      Polyray assumes that all polygons are closed and automatically adds a
  2718.      side from the last vertex to the first vertex.
  2719.  
  2720.      The format of the declaration is:
  2721.  
  2722.          polygon total_vertices,
  2723.  
  2724.                                                                            47
  2725.             <vert1.x,vert1.y,vert1.z>
  2726.             [, <vert2.x, vert2.y, vert2.z>]
  2727.             [, etc. for total_vertices vertices]
  2728.  
  2729.      As with the sphere, note the comma separating each vertex of the
  2730.      polygon.
  2731.  
  2732.      I use polygons as a floor in a lot of images.  They are a little
  2733.      slower than the corresponding plane, but for scan conversion they are
  2734.      a lot easier to handle.  An example of a checkered floor made from a
  2735.      polygon is:
  2736.  
  2737.         object {
  2738.            polygon 4, <-20,0,-20>, <-20,0,20>, <20,0,20>, <20,0,-20>
  2739.            texture {
  2740.               checker matte_white, matte_black
  2741.               translate <0, -0.1, 0>
  2742.               scale <2, 1, 2>
  2743.               }
  2744.            }
  2745.  
  2746.      Sample file: polygon.pi
  2747.  
  2748.  
  2749.      2.3.2.15 Polynomial surface
  2750.  
  2751.      The format of the declaration is:
  2752.  
  2753.         polynomial f(x,y,z)
  2754.  
  2755.      The function f(x,y,z) must be a simple polynomial, i.e. x^2+y^2+z^2-
  2756.      1.0 is the definition of a sphere of radius 1 centered at (0,0,0).
  2757.  
  2758.      For quartic (4th order) equations, there are three ways that Polyray
  2759.      can use to solve for roots.  By specifying which one is desired, it is
  2760.      possible to tune for quality or speed.  The method of Ferrari is the
  2761.      fastest, but also the most numerically unstable.  By default the
  2762.      method of Vieta is used.  Sturm sequences (which are the slowest)
  2763.      should be used where the highest quality is desired.
  2764.  
  2765.      The declaration of which root solver to use takes one of the forms:
  2766.  
  2767.         root_solver Ferrari
  2768.         root_solver Vieta
  2769.         root_solver Sturm
  2770.  
  2771.      (Capitalization is important - these are proper nouns after all.)
  2772.  
  2773.      Note: due to unavoidable numerical inaccuracies, not all polynomial
  2774.      surfaces will render correctly from all directions.
  2775.  
  2776.      The following example, taken from devil.pi defines a quartic
  2777.      polynomial.  The use of the CSG clipping object is to trim
  2778.      uninteresting parts of the surface.  The bounding box declaration
  2779.  
  2780.                                                                            48
  2781.      helps the scan conversion routines figure out where to look for the
  2782.      surface.
  2783.  
  2784.         // Variant of a devil's curve in 3-space.  This figure has a top
  2785.         // and bottom part that are very similar to a hyperboloid of one
  2786.         // sheet, however the central region is pinched in the middle
  2787.         // leaving two teardrop shaped holes.
  2788.         object {
  2789.            object { polynomial x^4 + 2*x^2*z^2 - 0.36*x^2 - y^4 +
  2790.                                0.25*y^2 + z^4
  2791.                     root_solver Ferrari }
  2792.            & object { box <-2, -2, -0.5>, <2, 2, 0.5> }
  2793.            bounding_box <-2, -2, -0.5>, <2, 2, 0.5>
  2794.            rotate <10, 20, 0>
  2795.            translate <0, 3, -10>
  2796.            shiny_red
  2797.            }
  2798.  
  2799.      Note: as the order of the polynomial goes up, the numerical accuracy
  2800.      required to render the surface correctly also goes up.  One problem
  2801.      that starts to rear its ugly head starting at around 3rd to 4th order
  2802.      equations is a problem with determining shadows correctly.  The result
  2803.      is black spots on the surface.  You can ease this problem to a certain
  2804.      extent by making the value of shadow_tolerance larger.  For 4th and
  2805.      higher equations, you will want to use a value of at least 0.05,
  2806.      rather than the default 0.001.
  2807.  
  2808.      Sample file: torus.pi, many others
  2809.  
  2810.      2.3.2.16 Spheres
  2811.  
  2812.      Spheres are the simplest 3D object to render and a sphere primitive
  2813.      enjoys a speed advantage over most other primitives.
  2814.  
  2815.      The format of the declaration is:
  2816.  
  2817.          sphere <center.x, center.y, center.z>, radius
  2818.  
  2819.      Note the comma after the center vector, it really is necessary.
  2820.  
  2821.      My basic benchmark file is a single sphere, illuminated by a single
  2822.      light.  The definition of the sphere is:
  2823.  
  2824.         object {
  2825.            sphere <0, 0, 0>, 2
  2826.            shiny_red
  2827.            }
  2828.  
  2829.      Sample file: sphere.pi
  2830.  
  2831.      2.3.2.17 Sweep surface
  2832.  
  2833.      A sweep surface, also referred to as an extruded surface, is a polygon
  2834.      that has been swept along a given direction.  It can be used to make
  2835.  
  2836.                                                                            49
  2837.      multi-sided beams, or to create ribbon-like objects.
  2838.  
  2839.      The format of the declaration is:
  2840.  
  2841.          sweep type, direction, total_vertices,
  2842.             <vert1.x,vert1.y,vert1.z>
  2843.             [, <vert2.x, vert2.y, vert2.z>]
  2844.             [, etc. for total_vertices vertices]
  2845.  
  2846.      The value of type is either 1, or 2.  If the value is 1, then the
  2847.      surface will be a set of connected squares.  If the value is 2, then
  2848.      the surface will be represented by a spline that approximates the line
  2849.      segments that were given.
  2850.  
  2851.      The value of the vector direction is used to change the orientation of
  2852.      the sweep.  For a sweep surface that is extruded straight up and down
  2853.      the y-axis, use <0, 1, 0> for direction.  The size of the vector
  2854.      direction will also affect the amount of extrusion (e.g., if
  2855.      |direction| = 2, then the extrusion will be two units in that
  2856.      direction).
  2857.  
  2858.      An example of a sweep surface is:
  2859.  
  2860.         // Sweep made from connected quadratic splines.
  2861.         object {
  2862.            sweep 2, <0, 2, 0>, 16,
  2863.               <0, 0>, <0, 1>, <-1, 1>, <-1, -1>, <2, -1>, <2, 3>,
  2864.               <-4, 3>, <-4, -4>, <4, -4>, <4, -11>, <-2, -11>,
  2865.               <-2, -7>, <2, -7>, <2, -9>, <0, -9>, <0, -8>
  2866.            translate <0, 0, -4>
  2867.            scale <1, 0.5, 1>
  2868.            rotate <0,-45, 0>
  2869.            translate <10, 0, -18>
  2870.            shiny_yellow
  2871.            }
  2872.  
  2873.  
  2874.      Sample file: sweep1.pi, sweep2.pi
  2875.  
  2876.      Note: CSG will really only work correctly if you close the sweep -
  2877.      that is make the end point of the sweep the same as the start point.
  2878.      Sweeps, unlike polygons are not automatically closed by Polyray.
  2879.  
  2880.      See the description of glyphs for a more general swept surface.
  2881.  
  2882.  
  2883.      2.3.2.18 Torus
  2884.  
  2885.      The torus primitive is a doughnut shaped surface that is defined by a
  2886.      center point, the distance from the center point to the middle of the
  2887.      ring of the doughnut, the radius of the ring of the doughnut, and the
  2888.      orientation of the surface.
  2889.  
  2890.      The format of the declaration is:
  2891.  
  2892.                                                                            50
  2893.  
  2894.          torus r0, r1, <center.x, center.y, center.z>,
  2895.                        <dir.x, dir.y, dir.z>
  2896.  
  2897.  
  2898.      As an example, a torus that has major radius 1, minor radius 0.4, and
  2899.      is oriented so that the ring lies in the x-z plane would be declared
  2900.      as:
  2901.  
  2902.         object {
  2903.            torus 1, 0.4, <0, 0, 0>, <0, 1, 0>
  2904.            shiny_red
  2905.            }
  2906.  
  2907.      Note: since a torus is a 4th order polynomial, it is possible to
  2908.      specify which quartic root solver to use.  See section 2.3.2.15 for a
  2909.      description of the root_solver statement.
  2910.  
  2911.      Sample file: torus.pi
  2912.  
  2913.      2.3.2.19 Triangular patches
  2914.  
  2915.      A triangular patch is defined by a set of vertices and their normals.
  2916.      When calculating shading information for a triangular patch, the
  2917.      normal information is used to interpolate the final normal from the
  2918.      intersection point to produce a smooth shaded triangle.
  2919.  
  2920.      The format of the declaration is:
  2921.  
  2922.          patch <x0,y0,z0>, <nx0,ny0,nz0>,  [UV u0, v0,]
  2923.                <x1,y1,z1>, <nx1,ny1,nz1>,  [UV u1, v1,]
  2924.                <x2,y2,z2>, <nx2,ny2,nz2> [, UV u2, v2]
  2925.  
  2926.      The vertices and normals are required for each of the three corners of
  2927.      the patch.  The u/v coordinates are optional.  If they are omitted,
  2928.      then they will be set to the following values:
  2929.  
  2930.         u0 = 0, v0 = 0
  2931.         u1 = 1, v1 = 0
  2932.         u2 = 0, v1 = 1
  2933.  
  2934.      Smooth patch data is usually generated as the output of another
  2935.      program.
  2936.  
  2937.      2.3.3 Constructive Solid Geometry (CSG)
  2938.  
  2939.      Objects can be defined in terms of the union, intersection, and
  2940.      inverse of other objects.  The operations and the symbols used are:
  2941.  
  2942.         csgexper + csgexper  - Union
  2943.         csgexper * csgexper  - Intersection
  2944.         csgexper - csgexper  - Difference
  2945.         csgexper & csgexper  - Clip the first object by the second
  2946.         ~csgexper            - Inverse
  2947.  
  2948.                                                                            51
  2949.         (csgexper)           - Parenthesised expression
  2950.  
  2951.      Note that intersection and difference require a clear inside and
  2952.      outside.  Not all primitives have well defined sides.  Those that do
  2953.      are:
  2954.  
  2955.         Spheres, Boxes, Glyphs, Polynomials, Blobs, Tori, and Functions.
  2956.  
  2957.      Other surfaces that do not always have a clear inside/outside, but
  2958.      work reasonably well in CSG intersections are:
  2959.  
  2960.         Cylinders, Cones, Discs, Height Fields, Lathes, Parabola, Polygons,
  2961.         and Sweeps.
  2962.  
  2963.      Using Cylinders, Cones, and Parabolas works correctly, but the open
  2964.      ends of these surfaces will also be open in the resulting CSG.  To
  2965.      close them off you can use a disc shape.
  2966.  
  2967.      Using Discs, and Polygons in a CSG is really the same as doing a CSG
  2968.      with the plane that they lie in.  If fact, a large disc is an
  2969.      excellent choice for clipping or intersecting an object, as the
  2970.      inside/outside test is very fast.
  2971.  
  2972.      Lathes, and Sweeps use Jordan's rule to determine if a point is
  2973.      inside.  This means that given a test point, if a line from that point
  2974.      to infinity crosses the surface an odd number of times, then the point
  2975.      is inside.  The net result is that if the lathe (or sweep) is not
  2976.      closed, then you may get odd results in a CSG intersection (or
  2977.      difference).
  2978.  
  2979.      CSG involving height fields only works within the bounds of the field.
  2980.  
  2981.      As an example, the following object is a sphere of radius 1 with a
  2982.      hole of radius 0.5 through the middle:
  2983.  
  2984.         define cylinder_z object { cylinder <0,0,-1.1>, <0,0,1.1>, 0.5 }
  2985.         define unit_sphere object { sphere <0, 0, 0>, 1 }
  2986.  
  2987.         // Define a CSG shape by deleting a cylinder from a sphere
  2988.         object {
  2989.            unit_sphere - cylinder_z
  2990.            shiny_red
  2991.            }
  2992.  
  2993.      Sample files: csg1.pi, csg2.pi, csg3.pi, roman.pi, lens.pi,
  2994.      polytope.pi
  2995.  
  2996.  
  2997.      2.3.4 Gridded objects
  2998.  
  2999.      A gridded object is a way to compactly represent a rectangular
  3000.      arrangement of objects by using an image map.  Each object is placed
  3001.      within a 1x1 cube that has its lower left corner at the location <i,
  3002.      0, j> and its upper right corner at <i+1, 1, j+1>.  The color index of
  3003.  
  3004.                                                                            52
  3005.      each pixel in the image map is used to determine which of a set of
  3006.      objects will be placed at the corresponding position in space.
  3007.  
  3008.      The gridded object is much faster to render than the corresponding
  3009.      layout of objects.  The major drawback is that every object must be
  3010.      scaled and translated to completely fit into a 1x1x1 cube that has
  3011.      corners at <0,0,0> and <1,1,1>.
  3012.  
  3013.      The size of the entire grid is determined by the number of pixels in
  3014.      the image.  A 16x32 image would go from 0 to 16 along the x-axis and
  3015.      the last row would range from 0 to 16 at 31 units in z out from the x-
  3016.      axis.
  3017.  
  3018.      The format of the declaration is:
  3019.  
  3020.         gridded "image.tga",
  3021.            object1
  3022.            object2
  3023.            object3
  3024.            ...
  3025.  
  3026.      An example of how a gridded object is declared is:
  3027.  
  3028.         define tiny_sphere object { sphere <0.5, 0.4, 0.5>, 0.4 }
  3029.         define pointy_cone object { cone <0.5, 0.5, 0.5>, 0.4,
  3030.                                          <0.5, 1, 0.5>, 0 }
  3031.  
  3032.         object {
  3033.            gridded "grdimg0.tga",
  3034.               tiny_sphere { shiny_coral }
  3035.               tiny_sphere { shiny_red }
  3036.               pointy_cone { shiny_green }
  3037.            translate <-10, 0, -10>
  3038.            rotate <0, 210, 0>
  3039.            }
  3040.  
  3041.      In the image grdimg0.tga, there are a total of 3 colors used, every
  3042.      pixel that uses color index 0 will generate a shiny coral colored
  3043.      sphere, every pixel that uses index  will generate a red sphere, every
  3044.      pixel that uses index 2 will generate a green cone, and every other
  3045.      color index used in the image will leave the corresponding space
  3046.      empty.
  3047.  
  3048.      The normal image format for a gridded object is either grayscale or
  3049.      color mapped.  To determine which object will be used, the value of
  3050.      the pixel itself in the grayscale image and the color index is used in
  3051.      the mapped image.  If a 16 bit Targa is used, then the second byte of
  3052.      the color is used.  If a 24 bit Targa is used, then the value of the
  3053.      red component is used.  This limits the # of objects for all images to
  3054.      256.
  3055.  
  3056.      A color JPEG is treated the same as a 24 bit Targa (unlikely to be
  3057.      useful, due to the lossy nature of JPEG).
  3058.  
  3059.  
  3060.                                                                            53
  3061.      Sample files: grid0.pi, river.pi
  3062.  
  3063.  
  3064.      2.3.5 Particle Systems
  3065.  
  3066.      There are two distinct pieces of information that are used by Polyray
  3067.      to do particles.  The first is a particle declaration, this is the
  3068.      particle generator. The second is the particle itself.  It is
  3069.      important to retain the distinction, you generally only want to have
  3070.      one particle generator, but you may want that generator to produce
  3071.      many particles.
  3072.  
  3073.      The form of the declaration for a particle generator is:
  3074.  
  3075.         particle {
  3076.            object "name"
  3077.            position vector
  3078.            velocity vector
  3079.            acceleration vector
  3080.            birth float
  3081.            death float
  3082.            count float
  3083.            avoid float
  3084.            }
  3085.  
  3086.      The wrapper for the particle must be the name of an object appearing
  3087.      in a define statement.  If there isn't an object with that name,
  3088.      Polyray will write an error message and abort.  Everything else is
  3089.      optional, but if you don't set either the velocity or acceleration
  3090.      then the object will just sit at the origin.
  3091.  
  3092.      The default values for each component are:
  3093.  
  3094.         position     - <0, 0, 0>
  3095.         velocity     - <0, 0, 0>
  3096.         acceleration - <0, 0, 0>
  3097.         birth        - frame == start_frame
  3098.         death        - false (never dies)
  3099.         count        - 1
  3100.         avoid        - false (doesn't bounce)
  3101.  
  3102.      As an example, the following declaration makes a starburst of 50
  3103.      spheres.  Note the conditional before the particle declaration.  You
  3104.      almost always want to do this, otherwise you will create a new
  3105.      particle generator at every frame of the animation. Since the default
  3106.      birth condition is to generate particles only on the first frame, the
  3107.      only side effect here would be to suck up more memory every frame to
  3108.      retain the particle generator definition.
  3109.  
  3110.         frame_time 0.05
  3111.  
  3112.         define gravity -1
  3113.  
  3114.         // Star burst
  3115.  
  3116.                                                                            54
  3117.         if (frame == start_frame)
  3118.         particle {
  3119.            position <0, 5, 0>
  3120.            velocity brownian(<0, 0, 0>, <1, 1, 1>)
  3121.            acceleration gravity
  3122.            object "bsphere"
  3123.            count 50
  3124.            }
  3125.  
  3126.      The value in the velocity declaration generates a random vector that
  3127.      ranges from <-1, -1, -1> to <1, 1, 1>.  Each particle of the 50 is
  3128.      given a different initial velocity, which is what gives the bursting
  3129.      effect.
  3130.  
  3131.      An additional declaration, frame_time xx, has been added specifically
  3132.      for tuning particle animations.  This declaration determines how much
  3133.      time passes for every frame.  Each particle starts with an age of 0,
  3134.      after each frame it's age is incremented by the value xx in the
  3135.      frame_time declaration.  Additionally the position and velocity of the
  3136.      particle is updated after every frame according to the formula:
  3137.  
  3138.         V = V + frame_time * A
  3139.         P = P + frame_time * V
  3140.  
  3141.      The status of a particle is set by making use of some of the standard
  3142.      Polyray variables.  The names and meanings are:
  3143.  
  3144.         P   - Current location of the particle as a vector
  3145.         x   - X location of the particle (or P[0])
  3146.         y   - Y location of the particle (or P[1])
  3147.         z   - Z location of the particle (or P[2])
  3148.         I   - Current velocity of the particle as a vector
  3149.         u   - Age of the particle (frame_time * elapsed frames since birth)
  3150.  
  3151.      These values are used in two situations, when checking the death
  3152.      condition of a particle and when calculating the acceleration of the
  3153.      particle.
  3154.  
  3155.      If an avoid statement is given then before every frame the position of
  3156.      the particle is checked to see if it hits any objects in the scene
  3157.      (non-particle objects).  If so, then the particle will bounce off the
  3158.      object.
  3159.  
  3160.      Note: see section 1.6.1.2 for information on lazy evaluation of
  3161.      expressions.  This is necessary for some particle systems to behave
  3162.      correctly.
  3163.  
  3164.      Sample files: part1.pi, part2.pi, part3.pi, part6.pi
  3165.  
  3166.  
  3167.      2.4 Color and lighting
  3168.  
  3169.      The color space used in polyray is RGB, with values of each component
  3170.      specified as a value from 0 -> 1.  The way the color and shading of
  3171.  
  3172.                                                                            55
  3173.      surfaces is specified is described in the following sections.
  3174.  
  3175.      RGB colors are defined as either a three component vector, such as
  3176.      <0.6, 0.196078, 0.8>, or as one of the X11R3 named colors (which for
  3177.      the value given is DarkOrchid).  One of these days when I feel like
  3178.      typing and not thinking (or if I find them on line), I'll put in the
  3179.      X11R4 colors.
  3180.  
  3181.      The coloring of objects is determined by the interaction of lights,
  3182.      the shape of the surface it is striking, and the characteristics of
  3183.      the surface itself.
  3184.  
  3185.  
  3186.      2.4.1 Light sources
  3187.  
  3188.      Light sources are one of: simple positional light sources, spot
  3189.      lights, or textured lights.  None of these lights have any physical
  3190.      size.  The lights do not appear in the scene, only the effects of the
  3191.      lights.
  3192.  
  3193.      2.4.1.1 Positional Lights
  3194.  
  3195.      A positional light is defined by its RGB color and its XYZ position.
  3196.  
  3197.      The formats of the declaration are:
  3198.  
  3199.          light color, location
  3200.          light location
  3201.  
  3202.      The second declaration will use white as the color.
  3203.  
  3204.      2.4.1.2 Spot Lights
  3205.  
  3206.      The formats of the declaration are:
  3207.  
  3208.          spot_light color, location, pointed_at, Tightness, Angle, Falloff
  3209.          spot_light location, pointed_at
  3210.  
  3211.      The vector location defines the position of the spot light, the vector
  3212.      pointed_at defines the point at which the spot light is directed.  The
  3213.      optional components are:
  3214.  
  3215.         color        - The color of the spotlight
  3216.         Tightness    - The power function used to determine the shape of
  3217.                        the hot spot
  3218.         Angle        - The angle (in degrees) of the full effect of the
  3219.                        spot light
  3220.         Falloff      - A larger angle at which the amount of light falls
  3221.                        to nothing
  3222.  
  3223.      A sample declaration is:
  3224.  
  3225.         spot_light white, <10,10,0>, <3,0,0>, 3, 5, 20
  3226.  
  3227.  
  3228.                                                                            56
  3229.      Sample file: spot0.pi
  3230.  
  3231.  
  3232.      2.4.1.3 Directional lights
  3233.  
  3234.      The directional light means just that - light coming from some
  3235.      direction.
  3236.  
  3237.         directional_light color, direction
  3238.         directional_light direction
  3239.  
  3240.      An example would be: directional_light <2, 3, -4>, giving a white
  3241.      light coming from the right, above, and behind the origin.
  3242.  
  3243.  
  3244.      2.4.1.4 Textured lights
  3245.  
  3246.      Textured lights are an enhancement of point lights that add: a
  3247.      function (including image maps) to describe the intensity & color of
  3248.      the light in each direction, transformations, and size.  The format of
  3249.      the declaration is:
  3250.  
  3251.         textured_light {
  3252.            color float
  3253.            [sphere center, radius]
  3254.            [translate/rotate/scale]
  3255.            }
  3256.  
  3257.      Any color expression is allowed for the textured light, and is
  3258.      evaluated at run time.
  3259.  
  3260.      A rotating slide projector light from the data file ilight.pi is shown
  3261.      below:
  3262.  
  3263.         define block_environ
  3264.         environment("one.tga", "two.tga", "three.tga",
  3265.                     "four.tga", "five.tga", "six.tga")
  3266.         textured_light {
  3267.            color environment_map(P, block_environ)
  3268.            rotate <frame*6, frame*3, 0>
  3269.            translate <0, 2, 0>
  3270.            }
  3271.  
  3272.      Sample files: environ.pi, ilight.pi
  3273.  
  3274.  
  3275.      2.4.1.4.1 Area Lights
  3276.  
  3277.      By adding a sphere declaration to a textured_light, it is turned into
  3278.      an area light.  The current implementation is a bit rough for long and
  3279.      narrow shadows, but in general gives very good results.  A typical
  3280.      declaration of an area light is:
  3281.  
  3282.         textured_light {
  3283.  
  3284.                                                                            57
  3285.            color white
  3286.            sphere <8, 10, 0>, 1
  3287.            }
  3288.  
  3289.  
  3290.      Sample file: spoty.pi
  3291.  
  3292.  
  3293.      2.4.1.5 Depth Mapped Lights
  3294.  
  3295.      Depth mapped lights are very similar to spotlights, in the sense that
  3296.      they point from one location and at another location.  The primary use
  3297.      for this light type is for doing shadowing in scan converted scenes.
  3298.      The format of their declaration is:
  3299.  
  3300.         depthmapped_light {
  3301.            [ angle float ]
  3302.            [ aspect float ]
  3303.            [ at vector ]
  3304.            [ color expression ]
  3305.            [ depth "depthfile.tga" ]
  3306.            [ from vector ]
  3307.            [ hither float ]
  3308.            [ up vector ]
  3309.            }
  3310.  
  3311.      You may notice that the format of the declaration is very similar to
  3312.      the viewpoint declaration.  This is intentional, as you will usually
  3313.      generate the depth information for depthfile.tga as the output of a
  3314.      run of Polyray. To support output of depth information, a new
  3315.      statements was added to the viewpoint declaration, image_format.
  3316.  
  3317.      A viewpoint declaration that will output a depth file would have the
  3318.      form:
  3319.  
  3320.         viewpoint {
  3321.            from [ location of depth mapped light ]
  3322.            at   [ location the light is pointed at ]
  3323.  
  3324.            image_format 1
  3325.            }
  3326.  
  3327.      Where the final statement tells Polyray to output depth information
  3328.      instead of color information.  Note that if the value in the
  3329.      image_format statement is 0, then normal rendering will occur.
  3330.  
  3331.      If a hither declaration is used, then the value given is used as a
  3332.      bias to help prevent self shadowing.  The default value for this bias
  3333.      is the value of shadow_tolerance in polyray.ini.
  3334.  
  3335.      Sample File: room1.pi, depmap.pi
  3336.  
  3337.  
  3338.      2.4.2 Background color
  3339.  
  3340.                                                                            58
  3341.  
  3342.      The background color is the one used if the current ray does not
  3343.      strike any objects.  The color can be any vector expression, although
  3344.      is usually a simple RGB color value.
  3345.  
  3346.      The format of the declaration is:
  3347.  
  3348.          background <R,G,B>
  3349.       or
  3350.          background color
  3351.  
  3352.      If no background color is set black will be used.
  3353.  
  3354.      An interesting trick that can be performed with the background is to
  3355.      use an image map as the background color (it is also a way to
  3356.      translate from one Targa format to another).  The way this can be done
  3357.      is:
  3358.  
  3359.      background planar_imagemap(image("test1.tga", P)
  3360.  
  3361.      The background also affects the opacity channel in 16 and 32 bit Targa
  3362.      output images.  If any background contributes directly to the pixel
  3363.      (not as a result of reflection or refraction), then the attribute bit
  3364.      is cleared in a 16 bit color and the attribute byte is set to the
  3365.      percentage of the pixel that was covered by the background in a 32 bit
  3366.      color.
  3367.  
  3368.      In order to extend the flexibility of the background, the meanings of
  3369.      various runtime variables are set uniquely.
  3370.  
  3371.         u,x - How far across the output image (from 0 at left to 1 at
  3372.               right)
  3373.         v,z - How far down the output image (from 0 at bottom to 1 at top)
  3374.         W   - <0,0,0>
  3375.         P   - Same as <x, 0, z>
  3376.         N   - Direction of the current ray
  3377.         I   - <0,0,0>
  3378.         U   - Same as <u, v, w>
  3379.         w   - Level of recursion (0 for eye rays, higher for reflected
  3380.               and refracted rays)
  3381.  
  3382.      As an example, suppose you wanted to have an image appear in the
  3383.      background, but you didn't want to have the image appear in any
  3384.      reflections.  Then you could define the background with the following
  3385.      expression:
  3386.  
  3387.         background (w == 0 ? planar_imagemap(img1, P) : black)
  3388.  
  3389.      If you wanted to have one image in the background, and another that
  3390.      appears in reflections (or refracted rays), then you could use the
  3391.      following expression:
  3392.  
  3393.         background (w == 0 ? planar_imagemap(img1, P)
  3394.                            : spherical_imagemap(img2, N))
  3395.  
  3396.                                                                            59
  3397.  
  3398.      The previous background expression fits img1 exactly into the output
  3399.      imgae and maps img2 completely around the entire scene.  This might be
  3400.      useful if you have a map of stars that you want to appear in
  3401.      reflections, but still want to have an image as the background.
  3402.  
  3403.  
  3404.      2.4.2.1 Global Haze (fog)
  3405.  
  3406.      The global haze is a color that is added based on how far the ray
  3407.      traveled before hitting the surface.  The format of the expression is:
  3408.  
  3409.         haze coeff, starting_distance, color
  3410.  
  3411.      The color you use should almost always be the same as the background
  3412.      color. The only time it would be different is if you are trying to put
  3413.      haze into a valley, with a clear sky above (this is a tough trick, but
  3414.      looks nice).  A  example would be:
  3415.  
  3416.         haze 0.8, 3, midnight_blue
  3417.  
  3418.      The value of the coeff ranges from 0 to 1, with values closer to 0
  3419.      causing the haze to thicken, and values closer to 1 causing the haze
  3420.      to thin out.  I know it seems backwards, but it is working and I don't
  3421.      want to break anything.
  3422.  
  3423.  
  3424.      2.4.3 Textures
  3425.  
  3426.      Polyray supports a few simple procedural textures: a standard shading
  3427.      model, a checker texture, a hexagon texture, and a general purpose (3D
  3428.      noise based) texture.  In addition, a very flexible (although slower)
  3429.      functional texture is supported.  Individual textures can be combined
  3430.      in various ways to create new ones.  Texture types that help to
  3431.      combine other textures include: layered textures, indexed textures,
  3432.      and summed textures.  (See section 2.4.3.3 through 2.4.3.5).
  3433.  
  3434.      The general syntax of a texture is:
  3435.  
  3436.         texture { [texture declaration] }
  3437.      or
  3438.         texture_sym
  3439.  
  3440.      Where texture_sym is a previously defined texture declaration.
  3441.  
  3442.  
  3443.      2.4.3.1 Procedural Textures
  3444.  
  3445.      Procedural textures (i.e. checker, matte_white, shiny_red, ...) are
  3446.      ones that are completely defined at the time the data file is read.
  3447.      Textures that are evaluated during rendering are described in section
  3448.      2.4.3.2.
  3449.  
  3450.  
  3451.  
  3452.                                                                            60
  3453.      2.4.3.1.1 Standard Shading Model
  3454.  
  3455.      Unlike many other ray-tracers, surfaces in Polyray not have a single
  3456.      color that is used for all of the components of the shading model.
  3457.      Instead a number of characteristics of the surface must be defined
  3458.      (with a matte white being the default).
  3459.  
  3460.      A surface declaration has the form:
  3461.  
  3462.           surface {
  3463.              [ surface definitions ]
  3464.              }
  3465.  
  3466.      For example, the following declaration is a red surface with a white
  3467.      highlight, corresponding to the often seen plastic texture:
  3468.  
  3469.         define shiny_red
  3470.         texture {
  3471.            surface {
  3472.               ambient red, 0.2
  3473.               diffuse red, 0.6
  3474.               specular white, 0.8
  3475.               microfacet Reitz 10
  3476.               }
  3477.            }
  3478.  
  3479.      The allowed surface characteristics that can be defined are:
  3480.  
  3481.         color                - Color if not given in another component
  3482.         ambient              - Light given off by the surface
  3483.         diffuse              - Light reflected in all directions
  3484.         specular             - Amount and color of specular highlights
  3485.         reflection           - Reflectivity of the surface
  3486.         transmission         - Amount and color of refracted light
  3487.         microfacet           - Specular lighting model (see below)
  3488.  
  3489.      The lighting equation used is (in somewhat simplified terms):
  3490.  
  3491.         L = ambient + diffuse + specular + reflected + transmitted, or
  3492.  
  3493.         L = Ka + Kd * (l1 + l2 + ...) + Ks * (l1 + l2 + ...) + Kr + Kt
  3494.  
  3495.      Where l1, l2, ... are the lights, Ka is the ambient term, Kd is the
  3496.      diffuse term, Ks is the specular term, Kr is the reflective term, and
  3497.      Kt it the transmitted (refractive) term. Each of these terms has a
  3498.      scale value and a filter value (the filter defaults to white/clear if
  3499.      unspecified).
  3500.  
  3501.      See the file colors.inc for a number of declarations of surface
  3502.      characteristics, including: mirror, glass, shiny, and matte.
  3503.  
  3504.      For lots of detail on lighting models, and the theory behind how color
  3505.      is used in computer generated images, run (don't walk) down to your
  3506.      local computer bookstore and get:
  3507.  
  3508.                                                                            61
  3509.  
  3510.            Illumination and Color in Computer Generated Imagery
  3511.            Roy Hall, 1989
  3512.            Springer Verlag
  3513.  
  3514.      Source code in the back of that book was the inspiration for the
  3515.      microfacet distribution models implemented for Polyray.
  3516.  
  3517.      Note that you don't really have to specify all of the color components
  3518.      if you don't want to.  If the color of a particular part of the
  3519.      surface declaration is not defined, then the value of the color
  3520.      component will be examined to see if it was declared.  If so, then
  3521.      that color will be used as the filter.  As an example, the declaration
  3522.      above could also be written as:
  3523.  
  3524.         define shiny_red
  3525.         texture {
  3526.            surface {
  3527.               color red
  3528.               ambient 0.2
  3529.               diffuse 0.6
  3530.               specular white, 0.8
  3531.               microfacet Reitz 10
  3532.               }
  3533.            }
  3534.  
  3535.  
  3536.      2.4.3.1.1.1 Ambient light
  3537.  
  3538.      Ambient lighting is the light given off by the surface itself.  This
  3539.      will be a constant amount, independent of any lights that may be in
  3540.      the scene.
  3541.  
  3542.      The format of the declaration is:
  3543.  
  3544.          ambient color, scale
  3545.          ambient scale
  3546.  
  3547.      As always, color indicates either an RGB triple like <1.0,0.7,0.9>, or
  3548.      a named color.  scale gives the amount of contribution that ambient
  3549.      gives to the overall amount light coming from the pixel.  The scale
  3550.      values should lie in the range 0.0 -> 1.0
  3551.  
  3552.  
  3553.      2.4.3.1.1.2 Diffuse light
  3554.  
  3555.      Diffuse lighting is the light given off by the surface under
  3556.      stimulation by a light source.  The intensity of the diffuse light is
  3557.      directly proportional to the angle of the surface with respect to the
  3558.      light.
  3559.  
  3560.      The format of the declaration is:
  3561.  
  3562.          diffuse color, scale
  3563.  
  3564.                                                                            62
  3565.          diffuse scale
  3566.  
  3567.      The only information used for diffuse calculations is the angle of
  3568.      incidence of the light on the surface.
  3569.  
  3570.  
  3571.      2.4.3.1.1.3 Specular highlights
  3572.  
  3573.      The format of the declaration is:
  3574.  
  3575.         specular color, scale
  3576.         specular scale
  3577.  
  3578.      The means of calculating specular highlights is by default the Phong
  3579.      model.  Other models are selected through the Microfacet distribution
  3580.      declaration.
  3581.  
  3582.  
  3583.      2.4.3.1.1.4 Reflected light
  3584.  
  3585.      Reflected light is the color of whatever lies in the reflected
  3586.      direction as calculated by the relationship of the view angle and the
  3587.      normal to the surface.
  3588.  
  3589.      The format of the declaration is:
  3590.  
  3591.         reflection scale
  3592.         reflection color, scale
  3593.  
  3594.      Typically, only the scale factor is included in the reflection
  3595.      declaration, this corresponds to all colors being reflected with
  3596.      intensity proportional to the scale.  A color filter is allowed in the
  3597.      reflection definition, and this allows the modification of the color
  3598.      being reflected (I'm not sure if this is useful, but I included it
  3599.      anyway).
  3600.  
  3601.  
  3602.      2.4.3.1.1.5 Transmitted light
  3603.  
  3604.      Transmitted light is the color of whatever lies in the refracted
  3605.      direction as calculated by the relationship of the view angle, the
  3606.      normal to the surface, and the index of refraction of the material.
  3607.  
  3608.      The format of the declaration is:
  3609.  
  3610.         transmit scale, ior
  3611.         transmit color, scale, ior
  3612.  
  3613.      Typically, only the scale factor is included in the transmitted
  3614.      declaration, this corresponds to all colors being transmitted with
  3615.      intensity proportional to the scale.  A color filter is allowed in the
  3616.      transmitted definition, and this allows the modification of the color
  3617.      being transmitted by making the transmission filter different from the
  3618.      color of the surface itself.
  3619.  
  3620.                                                                            63
  3621.  
  3622.      It is possible to have surfaces with colors very different than the
  3623.      one closest to the eye become apparent.  (See gsphere.pi for an
  3624.      example, a red sphere is in the foreground, a green sphere and a blue
  3625.      sphere behind.  The specular highlights of the red sphere go to
  3626.      yellow, and blue light is transmitted through the red sphere.)
  3627.  
  3628.      A more complex file is lens.pi in which two convex lenses are lined up
  3629.      in front of the viewer.  The magnified view of part of a grid of
  3630.      colored balls is very apparent in the front lens.
  3631.  
  3632.  
  3633.      2.4.3.1.1.6 Microfacet distribution
  3634.  
  3635.      The microfacet distribution is a function that determines how the
  3636.      specular highlighting is calculated for an object.
  3637.  
  3638.      The format of the declaration is:
  3639.  
  3640.         microfacet Distribution_name falloff_angle
  3641.         microfacet falloff_angle
  3642.  
  3643.      The distribution name is one of: Blinn, Cook, Gaussian, Phong, Reitz.
  3644.      The falloff angle is the angle at which the specular highlight falls
  3645.      to 50% of its maximum intensity.  (The smaller the falloff angle, the
  3646.      sharper the highlight.)  If a microfacet name is not given, then the
  3647.      Phong model is
  3648.      used.
  3649.  
  3650.      The falloff angle must be specified in degrees, with values in the
  3651.      range 0 to 45.  The falloff angle corresponds to the roughness of the
  3652.      surface, the smaller the angle, the smoother the surface.
  3653.  
  3654.      Note: as stated before, look at the book by Hall.  I have found
  3655.      falloff values of 5-10 degrees to give nice tight highlights.  Using
  3656.      falloff angle may seem a bit backwards from other raytracers, which
  3657.      typically use the power of a cosine function to define highlight size.
  3658.      When using a power value, the higher the power, the smaller the
  3659.      highlight.  Using angles seems a little tidier since the smaller the
  3660.      angle, the smaller the highlight.
  3661.  
  3662.      2.4.3.1.2 Checker
  3663.  
  3664.      the checker texture has the form:
  3665.  
  3666.         texture {
  3667.            checker texture1, texture2
  3668.            }
  3669.  
  3670.      where texture1 and texture2 are texture declarations (or texture
  3671.      constants).
  3672.  
  3673.      A standard sort of checkered plane can be defined with the following:
  3674.  
  3675.  
  3676.                                                                            64
  3677.         // Define a matte red surface
  3678.         define matte_red
  3679.         texture {
  3680.            surface {
  3681.               ambient red, 0.1
  3682.               diffuse red, 0.5
  3683.               }
  3684.            }
  3685.  
  3686.         // Define a matte blue surface
  3687.         define matte_blue
  3688.         texture {
  3689.            surface {
  3690.               ambient blue, 0.2
  3691.               diffuse blue, 0.8
  3692.               }
  3693.            }
  3694.  
  3695.         // Define a plane that has red and blue checkers
  3696.         object {
  3697.            disc <0, 0.01, 0>, <0, 1, 0>, 5000
  3698.            texture {
  3699.               checker matte_red, matte_blue
  3700.               }
  3701.            }
  3702.  
  3703.      For a sample file, look at spot0.pi.  This file has a sphere with a
  3704.      red/blue checker, and a plane with a black/white checker.
  3705.  
  3706.  
  3707.      2.4.3.1.3 Hexagon
  3708.  
  3709.      the hexagon texture is oriented in the x-z plane, and has the form:
  3710.  
  3711.         texture {
  3712.            hexagon texture1, texture2, texture3
  3713.            }
  3714.  
  3715.      This texture produces a honeycomb tiling of the three textures in the
  3716.      declaration.  Remember that this tiling is with respect to the x-z
  3717.      plane, if you want it on a vertical wall you will need to rotate the
  3718.      texture.
  3719.  
  3720.      2.4.3.1.4 Noise surfaces
  3721.  
  3722.      The complexity and speed of rendering of the noise surface type lies
  3723.      between the standard shading model and the special surfaces described
  3724.      below.  It is an attempt to capture a large number of the standard 3D
  3725.      texturing operations in a single declaration.
  3726.  
  3727.      A noise surface declaration has the form:
  3728.  
  3729.           texture {
  3730.              noise surface {
  3731.  
  3732.                                                                            65
  3733.                 [ noise surface definition ]
  3734.                 }
  3735.              }
  3736.  
  3737.      The allowed surface characteristics that can be defined are:
  3738.  
  3739.         color <r, g, b>          - Basic surface color (used if the noise
  3740.                                    function generates a value not contained
  3741.                                    in the color map)
  3742.         ambient scale            - Amount of ambient contribution
  3743.         diffuse scale            - Diffuse contribution
  3744.         specular color, scale    - Amount and color of specular highlights,
  3745.                                    if the color is not given then the body
  3746.                                    color will be used.
  3747.         reflection               - Reflectivity of the surface
  3748.         transmission scale, ior  - Amount of refracted light
  3749.         microfacet kind angle    - Specular lighting model (see the
  3750.                                    description of a standard surface)
  3751.  
  3752.         color_map(map_entries)   - Define the color map (see following
  3753.                                    section on color map definitions for
  3754.                                    further details)
  3755.         bump_scale float         - How much the bumps affect the normal
  3756.         frequency float          - Affects the wavelength of ripples and
  3757.                                    waves
  3758.         phase float              - Affects the phase of ripples and waves
  3759.         lookup_fn index          - Selects a predefined lookup function
  3760.         normal_fn index          - Selects a predefined normal modifier
  3761.         octaves float            - Number of octaves of noise to use
  3762.         position_fn index        - How the intersection point is used in
  3763.                                    the generation of a noise texture
  3764.         position_scale float     - Amount of contribution of the position
  3765.                                    value to the overall texture
  3766.         turbulence float         - Amount of contribution of the noise to
  3767.                                    overall texture.
  3768.  
  3769.      The way the final color of the texture is decided is by calculating a
  3770.      floating point value using the following general formula:
  3771.  
  3772.         index = lookup_fn(position_scale * position_fn +
  3773.                           turbulence * noise3d(P, octaves))
  3774.  
  3775.      The index value that is calculated is then used to lookup a color from
  3776.      the color map.  This final color is used for the ambient, diffuse,
  3777.      reflection and transmission filters.  The functions that are currently
  3778.      available, with their corresponding indices are:
  3779.  
  3780.      Position functions:
  3781.         Index       Effect
  3782.             1        x value in the object coordinate system
  3783.             2        x value in the world coordinate system
  3784.             3        Distance from the z axis
  3785.             4        Distance from the origin
  3786.             5        Angle from the x-axis (in the x-z plane, from 0 to 1)
  3787.  
  3788.                                                                            66
  3789.          default:    0.0
  3790.  
  3791.      Lookup functions:
  3792.         Index       Effect
  3793.             1        sawtooth function, result from 0 -> 1
  3794.             2        sin function, result from 0->1
  3795.             3        ramp function, result from 0->1
  3796.          default:    no modification made
  3797.  
  3798.      Definitions of these function numbers that make sense are:
  3799.  
  3800.      define position_plain       0
  3801.      define position_objectx     1
  3802.      define position_worldx      2
  3803.      define position_cylindrical 3
  3804.      define position_spherical   4
  3805.      define position_radial      5
  3806.  
  3807.      define lookup_plain    0
  3808.      define lookup_sawtooth 1
  3809.      define lookup_sin      2
  3810.      define lookup_ramp     3
  3811.  
  3812.      An example of a texture defined this way is a simple white marble:
  3813.  
  3814.         define white_marble_texture
  3815.         texture {
  3816.            noise surface {
  3817.               color white
  3818.               position_fn position_objectx
  3819.               lookup_fn lookup_sawtooth
  3820.               octaves 3
  3821.               turbulence 3
  3822.               ambient 0.2
  3823.               diffuse 0.8
  3824.               specular 0.3
  3825.               microfacet Reitz 5
  3826.               color_map(
  3827.                  [0.0, 0.8, <1, 1, 1>, <0.6, 0.6, 0.6>]
  3828.                  [0.8, 1.0, <0.6, 0.6, 0.6>, <0.1, 0.1, 0.1>])
  3829.               }
  3830.            }
  3831.  
  3832.      In addition to coloration, the bumpiness of the surface can be
  3833.      affected by selecting a function to modify the normal.  The currently
  3834.      supported normal modifier functions are:
  3835.  
  3836.         Index       Effect
  3837.             1        Make random bumps in the surface
  3838.             2        Add ripples to the surface
  3839.             3        Give the surface a dented appearance
  3840.          default:    no change
  3841.  
  3842.      Definitions that make sense are:
  3843.  
  3844.                                                                            67
  3845.  
  3846.      define default_normal 0
  3847.      define bump_normal    1
  3848.      define ripple_normal  2
  3849.      define dented_normal  3
  3850.  
  3851.      See also the file texture.txt for a little more explanation.
  3852.  
  3853.  
  3854.      2.4.3.2 Functional Textures
  3855.  
  3856.      The most general and flexible texture type is the functional texture.
  3857.      These textures are evaluated at run-time based on the expressions
  3858.      given for the components of the lighting model.  The general syntax
  3859.      for a surface using a functional texture is:
  3860.  
  3861.         special surface {
  3862.            [ surface declaration ]
  3863.            }
  3864.  
  3865.      In addition to the components usually defined in a surface
  3866.      declaration, it is possible to define a function that deflects the
  3867.      normal, and a function that modifies the intersection point prior to
  3868.      texturing.  The format of the two declarations are:
  3869.  
  3870.         position vector
  3871.         normal vector
  3872.  
  3873.      An example of how a functional texture can be defined is:
  3874.  
  3875.         define sin_color_offset (sin(3.14 * fmod(x*y*z,1) + otheta)+1)/2
  3876.         define sin_color <sin_color_offset, 0, 1 - sin_color_offset>
  3877.  
  3878.         define xyz_sin_texture
  3879.         texture {
  3880.            special surface {
  3881.               color sin_color
  3882.               ambient 0.2
  3883.               diffuse 0.7
  3884.               specular white, 0.2
  3885.               microfacet Reitz 10
  3886.               }
  3887.            }
  3888.  
  3889.      In this example, the color of the surface is defined based on the
  3890.      location of the intersection point using the vector defined as
  3891.      sin_color.  Note that sin_color uses yet another definition.
  3892.  
  3893.      The position declaration is useful to achieve the effect of
  3894.      turbulence.  By adding a solid noise to the position, it is possible
  3895.      to add swirl to a basic texture.  For example:
  3896.  
  3897.  
  3898.         define white_marble
  3899.  
  3900.                                                                            68
  3901.         texture {
  3902.            special shiny {
  3903.               color white_marble_map[sawtooth(x)]
  3904.               position P + dnoise(P, 3)
  3905.               }
  3906.  
  3907.      This will create a basic white marble (which would have very straight,
  3908.      even bands of color), and by adding dnoise, swirls the colors around.
  3909.  
  3910.      The normal declaration is used to add some bumpyness to the surface.
  3911.      The bumps can be created with a statement as simple as:
  3912.  
  3913.         normal N + (dnoise(P) - <0.5, 0.5, 0.5>)
  3914.  
  3915.      The value <0.5,0.5,0.5> is subtracted from the dnoise function since
  3916.      dnoise only returns positive values in each component.
  3917.  
  3918.      Note: if the color component has any alpha in it (as the result of a
  3919.      lookup from a color map or from an image) then that alpha value will
  3920.      be used as the scale for the transmit statement.
  3921.  
  3922.      Sample files: cossph.pi, cwheel.pi.
  3923.  
  3924.  
  3925.      2.4.3.2.1 Color maps
  3926.  
  3927.      Color maps are generally used in noise textures and functional
  3928.      textures.  They are a way of representing a spectrum of colors that
  3929.      blend from one into another.  Each color is represented as RGB, with
  3930.      an optional alpha (transparency) value.  The format of the declaration
  3931.      is:
  3932.  
  3933.         color_map([low0, high0, <r0, g0, b0>, a0, <r1, g1, b1>, a1]
  3934.                   [low1, high1, <r2, g2, b2>, a2, <r3, g3, b3>, a3]
  3935.                   ...
  3936.                   [lowx, highx, <rx, gx, bx>, ax, <ry, gy, by>, ay])
  3937.  
  3938.      Note that there are no commas between entries in the color map even
  3939.      though commas are required within each entry.  (This is a holdover to
  3940.      retain compatibility with earlier versions of Polyray.)  If you don't
  3941.      need any transparency in the color map, then the following declaration
  3942.      could be used:
  3943.  
  3944.         color_map([low0, high0, <r0, g0, b0>, <r1, g1, b1>]
  3945.                   [low1, high1, <r2, g2, b2>, <r3, g3, b3>]
  3946.                   ...
  3947.                   [lowx, highx, <rx, gx, bx>, <ry, gy, by>])
  3948.  
  3949.      In this case, the alpha is set to 0 for all colors created by the
  3950.      color map.  Note that it is possible to mix colors with and without
  3951.      alpha value.
  3952.  
  3953.      Note: If there is an alpha value in the color map, then the amount of
  3954.      alpha is used as the scale for the transmit component of the surface.
  3955.  
  3956.                                                                            69
  3957.      To turn off this automatic transparency, use transmit 0.
  3958.  
  3959.  
  3960.      2.4.3.2.1.1 Using CMAPPER
  3961.  
  3962.      A good way to build color maps for layered textures is with
  3963.      ColorMapper,
  3964.  
  3965.             Written by : SoftTronics, Lutz + Kretzschmar
  3966.  
  3967.      This is available as CMAP.ZIP in the forum Graphdev on Compuserve.
  3968.      This program allows you to build color maps with varying colors and
  3969.      transparency values.  The output of this program does have to be
  3970.      massaged a little bit to make it into a color map as Polyray
  3971.      understands it.  In order to help with this process an IBM executable,
  3972.      makemap.exe has been included.  To use this little program, you follow
  3973.      these steps:
  3974.  
  3975.         1) run CMAPPER to create a color map in the standard output (not
  3976.            the POV-Ray output format).
  3977.  
  3978.         2) run makemap on that file, giving a name for the new Polyray
  3979.            color map definition
  3980.  
  3981.         3) Add this definition to your Polyray data file.
  3982.  
  3983.      If you saved your map as foo.map, and you wanted to add this color map
  3984.      to the Polyray data file foo.inc, with the name of foox_map, you would
  3985.      then run makemap the following way:
  3986.  
  3987.         makemap foo.map foox_map >> foo.inc
  3988.  
  3989.      This makes the translation from CMAPPER format to Polyray format, and
  3990.      appends the output as, define foox_map color_map(...), to the file
  3991.      foo.inc.
  3992.  
  3993.      2.4.3.2.2 Image maps
  3994.  
  3995.      Projecting an image onto a surface is one of the most common texturing
  3996.      techniques.  There are four types of projection supported: planar,
  3997.      cylindrical, spherical, and environment.  Input files for use as image
  3998.      maps may be any valid Targa, GIF, or JPEG image.
  3999.  
  4000.      The declaration of an image map is:
  4001.  
  4002.         image("imfile.tga")
  4003.  
  4004.      Typically, an image will be associated with a variable through a
  4005.      definition such as:
  4006.  
  4007.         define myimage image("imfile.tga")
  4008.  
  4009.      The image is projected onto a shape by means of a projection.  The
  4010.      four types of projection are declared by:
  4011.  
  4012.                                                                            70
  4013.  
  4014.         planar_imagemap(image, coordinate [, repeat]),
  4015.         cylindrical_imagemap(image, coordinate [, repeat]),
  4016.         spherical_imagemap(image, coordinate)
  4017.         environment_map(coordinate,
  4018.                         environment("img1.tga", "img2.tga", "img3.tga",
  4019.                                     "img4.tga", "img5.tga", "img6.tga"))
  4020.  
  4021.      The planar projection maps the entire raster image into the
  4022.      coordinates 0 <= x <= 1, 0 <= z <= 1.  The vector value given as
  4023.      coordinate is used to select a color by multiplying the x value by the
  4024.      number of columns, and the z value by the number of rows.  The color
  4025.      appearing at that position in the raster will then be returned as the
  4026.      result.  If a repeat value is given then entire surface, repeating
  4027.      between every integer Value of x and/or z.
  4028.  
  4029.      The planar image map is also used for wrapping images based on u/v
  4030.      coordinates.  By using the vector <u, 0, v>, the planar image map will
  4031.      automatically wrap the image around surfaces that have natural u/v
  4032.      coordinates (such as sphere, cylinder, torus, etc.).
  4033.  
  4034.      The cylindrical projection wraps the image about a cylinder that has
  4035.      one end at the origin and the other at <0, 1, 0>.  If a repeat value
  4036.      is given, then the image will be repeated along the y-axis, if none is
  4037.      given, then any part of the object that is not covered by the image
  4038.      will be given the color of pixel (0, 0).
  4039.  
  4040.      The spherical projection wraps the image about an origin centered
  4041.      sphere.  The top and bottom seam are folded into the north and south
  4042.      poles respectively.  The left and right edges are brought together on
  4043.      the positive x axis.
  4044.  
  4045.      The environment map wraps six images around a point.  This method is a
  4046.      standard way to fake reflections by wrapping the images that would be
  4047.      seen from a point inside an object around the object.  A sample of
  4048.      this technique can be seen by rendering room1.pi (which generates the
  4049.      images) followed by rendering room0.pi (which wraps the images around
  4050.      a sphere).
  4051.  
  4052.      Following are a couple of examples of objects and textures that make
  4053.      use of image maps:
  4054.  
  4055.         define hivolt_image image("hivolt.tga")
  4056.         define hivolt_tex
  4057.         texture {
  4058.            special surface {
  4059.               color cylindrical_imagemap(hivolt_image, P, 1)
  4060.               ambient 0.9
  4061.               diffuse 0.1
  4062.               }
  4063.            scale <1, 2, 1>
  4064.            translate <0, -1, 0>
  4065.            }
  4066.         object { cylinder <0, -1, 0>, <0, 1, 0>, 3 hivolt_tex }
  4067.  
  4068.                                                                            71
  4069.  
  4070.      and
  4071.  
  4072.         define disc_image image("test.tga")
  4073.         define disc_tex
  4074.         texture {
  4075.            special surface {
  4076.               color planar_imagemap(disc_image, P)
  4077.               ambient 0.9
  4078.               diffuse 0.1
  4079.               }
  4080.            translate <-0.5, 0, -0.5>
  4081.            scale <7*4/3, 1, 7>
  4082.            rotate <90, 0, 0>
  4083.            }
  4084.         object {
  4085.            disc <0, 0, 0>, <0, 0, 1>, 6
  4086.            u_steps 10
  4087.            disc_tex
  4088.            }
  4089.  
  4090.      Note: If there is an alpha/opacity value in the image map, then the
  4091.      amount of opacity is used as the scale for the transmit component of
  4092.      the surface.  To turn off this automatic transparency, use transmit 0.
  4093.  
  4094.      Sample files: map0.pi, map1.pi, map2.pi
  4095.  
  4096.      2.4.3.2.3 Bumpmaps
  4097.  
  4098.      Bumpmaps are declared using the same sort of projections as image maps
  4099.      (excepting environment maps).  The following are the valid
  4100.      declarations of bump maps:
  4101.  
  4102.         planar_bumpmap(image, coordinate [, bump size]),
  4103.         cylindrical_bumpmap(image, coordinate [, bump size]),
  4104.         spherical_bumpmap(image, coordinate [, bump size])
  4105.  
  4106.  
  4107.      Instead of an optional repeat argument, bumpmaps have an optional bump
  4108.      size argument.  If this argument is left out, then the bump size is
  4109.      set to one.  Note that negative bump values are allowed and cause the
  4110.      bumps to appear to project the other way.
  4111.  
  4112.      Any Targa image can be used, but for best results greyscale or color
  4113.      mapped images are best.  The following declarations show how a bump
  4114.      map can be applied to objects:
  4115.  
  4116.         include "colors.inc"
  4117.  
  4118.         define tile_bumps image("tile1.tga")
  4119.  
  4120.         define bumpmap_red1
  4121.         texture {
  4122.            special shiny {
  4123.  
  4124.                                                                            72
  4125.               color red
  4126.               normal planar_bumpmap(tile_bumps, <8*u, 0, 6*v>, 1)
  4127.               }
  4128.            }
  4129.         object {
  4130.              object { torus 2, 0.75, <0, -1.25, 0>, <0, 1, 0> }
  4131.            + object { cone <0, -2, 0>, 1, <0, 3, 0>, 0 }
  4132.            + object { sphere <2, 0, 4>, 2 }
  4133.            bumpmap_red1
  4134.            }
  4135.  
  4136.      The bumpmap is declared using u/v coordinates so that it will follow
  4137.      the natural coordinates of the object.  This ensures that it wraps
  4138.      properly around the torus, cone, and sphere in the example above.
  4139.      There is an automatic wrapping of bump maps, so there will be 8 tiles
  4140.      in the u direction and 6 tiles in the v direction of each object.
  4141.  
  4142.      Sample file:
  4143.  
  4144.  
  4145.      2.4.3.3 Indexed Textures and Texture Maps
  4146.  
  4147.      A texture map is declared in a manner similar to color maps.  There is
  4148.      a list of value pairs and texture pairs, for example:
  4149.  
  4150.         define index_tex_map
  4151.            texture_map([-2, 0, red_blue_check, bumpy_green],
  4152.                        [0, 2, bumpy_green, reflective_blue])
  4153.  
  4154.      Note that for texture maps there is a required comma separating each
  4155.      of the entries.
  4156.  
  4157.      These texture maps are complimentary to the indexed texture (see
  4158.      below).  Two typical uses of indexed textures are to use solid
  4159.      texturing functions to select (and optionally blend) between complete
  4160.      textures rather than just colors, and to use image maps as a way to
  4161.      map textures to a surface.
  4162.  
  4163.      For example, using the texture map above on a sphere can be done
  4164.      accomplished with the following:
  4165.  
  4166.      object {
  4167.         sphere <0, 0, 0>, 2
  4168.         texture { indexed x, index_tex_map }
  4169.         }
  4170.  
  4171.      The indexed texture uses a lookup function (in example above a simple
  4172.      gradient along the x axis) to select from the texture map that
  4173.      follows.  See the data file indexed1.pi for the complete example.
  4174.  
  4175.      As an example of using an image map to place textures on a surface,
  4176.      the following example uses several textures, selected by the color
  4177.      values in an image map.  The function indexed_map returns the color
  4178.      index value from a color mapped image (or uses the red channel in a
  4179.  
  4180.                                                                            73
  4181.      raw image).  The example below is equivalent to creating a material
  4182.      map in the POV-Ray raytracer.
  4183.  
  4184.         object {
  4185.            sphere <0, 0, 0>, 1
  4186.            texture {
  4187.               indexed indexed_map(image("txmap.tga"), <x, 0, y>, 1),
  4188.                       texture_map([1, 1, mirror, mirror],
  4189.                                   [2, 2, bright_pink, bright_pink],
  4190.                                   [3, 3, Jade, Jade])
  4191.               translate <-0.5, -0.5, 0> // center image
  4192.               }
  4193.            }
  4194.  
  4195.      In this example, the image is oriented in the x-y plane and centered
  4196.      on the origin.  The only difference between a indexed_map and a
  4197.      planar_imagemap is that the first (indexed_map) returns the index of
  4198.      the color in the image and the second returns the color itself.  Note
  4199.      that the texture map shown above has holes in it (between the integer
  4200.      values), however this isn't a problem as the indexed_map function will
  4201.      only produce integers.
  4202.  
  4203.  
  4204.      2.4.3.4 Layered Textures
  4205.  
  4206.      Layered textures allow you to stack multiple textures on top of each
  4207.      other.  If a part of the texture is not completely opaque (non-zero
  4208.      alpha), then the layers below will show through.  For example, the
  4209.      following texture creates a texture with a marble outer layer and a
  4210.      mirrored bottom layer and applies it to a sphere:
  4211.  
  4212.         include "colors.inc"
  4213.  
  4214.         define marble_alpha_map
  4215.            color_map([0.0, 0.2, white, 0,   white, 0]
  4216.                      [0.2, 0.5, white, 0,   black, 0.2]
  4217.                      [0.6, 1.0, black, 0.2, black, 1])
  4218.  
  4219.         define mirror_veined_marble
  4220.         texture {
  4221.            layered
  4222.               texture {
  4223.                  special shiny { color marble_alpha_map[marble_fn] }
  4224.                  },
  4225.               mirror
  4226.            }
  4227.  
  4228.         object {
  4229.            sphere <0, 0, 0>, 2
  4230.            mirror_veined_marble
  4231.            }
  4232.  
  4233.      Sample files: Stone1-Stone24, layer1.pi, layer2.pi
  4234.  
  4235.  
  4236.                                                                            74
  4237.  
  4238.      2.4.3.5 Summed Textures
  4239.  
  4240.      Summed textures simply add weighted amounts of a number of textures
  4241.      together to make the final color.  The syntax is:
  4242.  
  4243.         texture {
  4244.            summed f1, tex1, f2, tex2, ...
  4245.            }
  4246.  
  4247.      The expressions f1, f2, ... are numeric expressions.  The expressions
  4248.      tex1, ... are textures.
  4249.  
  4250.      Sample file: blobtx.pi
  4251.  
  4252.  
  4253.      2.5 Comments
  4254.  
  4255.      Comments follow the standard C/C++ formats.  Multiple line comments
  4256.      are enclosed by /* ... */ and single line comments are preceeded by
  4257.      //.
  4258.  
  4259.      Single line comments are allowed and have the following format:
  4260.  
  4261.         // [ any text to end of the line ]
  4262.  
  4263.      As soon as the two characters // are detected, the rest of the line is
  4264.      considered a comment.
  4265.  
  4266.      2.6 Animation support
  4267.  
  4268.      An animation is generated by rendering a series of frames, numbered
  4269.      from 0 to some total value.  The declarations in Polyray that support
  4270.      the generation of multiple Targa images are:
  4271.  
  4272.         total_frames val     - The total number of frames in the animation
  4273.         start_frame val      - The value of the first frame to be rendered
  4274.         end_frame val        - The last frame to be rendered
  4275.         frame_time val       - Duration of each frame (for particles)
  4276.         outfile "name"       - Polyray appends the frame number to 'name'
  4277.         outfile name           in order to generate distinct Targa files.
  4278.  
  4279.      The values of total_frames, start_frame, and end_frame, as well as the
  4280.      value of the current frame, frame, are usable in arithmetic
  4281.      expressions in the input file.  Note that these statements should
  4282.      appear before the use of: total_frames, start_frame, end_frame, or
  4283.      frame as a part of an expression.  Typically I put the declarations
  4284.      right at the top of the file.
  4285.  
  4286.      WARNING: if the string given for outfile is longer than 5 characters,
  4287.      the three digit frame number that is appended will be truncated by
  4288.      DOS.  Make sure this string is short enough or you will end up
  4289.      overwriting image files.
  4290.  
  4291.  
  4292.                                                                            75
  4293.      Sample files: whirl.pi, plane.pi, squish.pi, many others
  4294.  
  4295.  
  4296.      2.7 Conditional processing
  4297.  
  4298.      In support of animation generation (and also because I sometimes like
  4299.      to toggle attributes of objects), polyray supports limited conditional
  4300.      processing.  The syntax for this is:
  4301.  
  4302.         if (cexper) {
  4303.            [object/light/... declarations]
  4304.            }
  4305.         else {
  4306.            [other object/light/... declarations]
  4307.            }
  4308.  
  4309.      The sample file rsphere.pi shows how it can be used to modify the
  4310.      color characteristics of a moving sphere.
  4311.  
  4312.      The use of conditional statements is limited to the top level of the
  4313.      data file.  You cannot put a conditional within an object or texture
  4314.      declaration. i.e.
  4315.  
  4316.         object {
  4317.            if (foo == 42) {
  4318.               sphere <0, 0, 0>, 4
  4319.               }
  4320.            else {
  4321.               disc <0, 0, 0>, <0, 1, 0>, 4
  4322.               }
  4323.            }
  4324.  
  4325.      is not a valid use of an if statement, whereas:
  4326.  
  4327.         if (foo == 42) {
  4328.            object {
  4329.               sphere <0, 0, 0>, 4
  4330.               }
  4331.            }
  4332.         else {
  4333.            object {
  4334.               disc <0, 0, 0>, <0, 1, 0>, 4
  4335.               }
  4336.            }
  4337.      or
  4338.         if (foo == 42)
  4339.            object { sphere <0, 0, 0>, 4 }
  4340.         else if (foo = 12) {
  4341.            object { torus 3.0, 1.0, <0, 0, 0>, <0, 1, 0> }
  4342.            object { cylinder <0, -1, 0>, <0, 1, 0>, 0.5 }
  4343.            }
  4344.         else
  4345.            object { disc <0, 0, 0>, <0, 1, 0>, 4 }
  4346.  
  4347.  
  4348.                                                                            76
  4349.      are valid.
  4350.  
  4351.      Note: the curly brackets { } are required if there are multiple
  4352.      statements within the conditional, and not required if there is a
  4353.      single statement.
  4354.  
  4355.      2.8 Include files
  4356.  
  4357.      In order to allow breaking an input file into several files (as well
  4358.      as supporting the use of library files), it is possible to direct
  4359.      polyray to process another file.  The syntax is:
  4360.  
  4361.         include "filename"
  4362.  
  4363.      Beware that trying to use #include ... will fail.
  4364.  
  4365.      2.9 File flush
  4366.  
  4367.      Due to unforeseen occurrences, like power outages, or roommates that
  4368.      hit the reset button so they can do word processing, it is possible to
  4369.      specify how often the output file will be flushed to disk.  The
  4370.      default is to wait until the entire file has been written before a
  4371.      flush (which is a little quicker but you lose everything if a crash
  4372.      occurs).
  4373.  
  4374.      The format of the declaration is:
  4375.  
  4376.         file_flush xxx
  4377.  
  4378.      The number xxx indicates the maximum number of pixels that will be
  4379.      written before a file flush will occur.  This value can be as low as 1
  4380.      - this will force a flush after every pixel (only for the very
  4381.      paranoid).
  4382.  
  4383.  
  4384.      2.10 System calls
  4385.  
  4386.      The system call allows you to invoke an external program from within
  4387.      Polyray.  This is useful if you have a program that will generate new
  4388.      data for every frame of an animation.  By using system, you can invoke
  4389.      the external program for every frame of the program, and possibly pass
  4390.      it the frame number so that it will know the specific data to
  4391.      generate.
  4392.  
  4393.      The format of the declaration is:
  4394.  
  4395.         system(arg1, ..., argn)
  4396.  
  4397.      The arguments are concatenated together (no spaces added) and then
  4398.      passed to the system to execute.  Any numeric or string variable is
  4399.      allowed for an argument.  The number of arguments isn't limited,
  4400.      however the total number of characters in the final string must be
  4401.      less than 255.
  4402.  
  4403.  
  4404.                                                                            77
  4405.      One possible use for the system call is to use DTA to extract a
  4406.      particular frame of an animation for use in an image map.  By
  4407.      incrementing the frame number that is retrieved, you can embed an
  4408.      animation into your own animation.
  4409.  
  4410.  
  4411.      3 File formats
  4412.  
  4413.      3.1 Output files
  4414.  
  4415.      Currently the output file formats are 8, 16, 24, and 32 bit
  4416.      uncompressed and RLE compressed Targa.  If no output file is defined
  4417.      with the '-o' command line option, the file out.tga will be used.  The
  4418.      command line option -u specifies that no compression should be used on
  4419.      the output file.
  4420.  
  4421.      The default output format is an RLE compressed 16 bit color format.
  4422.      This format holds 5 bits for each of red, green, and blue.  If you
  4423.      have the hardware to display more than 32K colors then set the command
  4424.      line switches (i.e. -p 24 or -p 32) or set the defaults in the
  4425.      polyray.ini (i.e. pixelsize 24 or pixelsize 32) to generate 24 or 32
  4426.      bit Targa files.
  4427.  
  4428.      4 Outstanding Issues
  4429.  
  4430.      Polyray will probably never be done.  And in this respect, the next
  4431.      two sections list some things that are planned for the future, as well
  4432.      as things that should already have been fixed.
  4433.  
  4434.      4.1 To do list
  4435.  
  4436.         Add defined color_maps to noise surfaces.  Currently you have to
  4437.         put the entire color map into the noise surface declaration.
  4438.  
  4439.         Parameterised objects and textures.  This will occur in the next
  4440.         major release of Polyray, due to the extreme structural changes
  4441.         required.
  4442.  
  4443.         User definable positioning of display elements, in particular
  4444.         placement of the image as it is drawn, and placement of the status
  4445.         display during the trace.
  4446.  
  4447.         Appending .pi to input file names that do not have an extension.
  4448.  
  4449.         Use of environment variables to find polyray.ini and standard
  4450.         include ciles.
  4451.  
  4452.         Trim curves for NURBS
  4453.  
  4454.      4.2 Known Bugs
  4455.  
  4456.      It is possible to specify surface components that have no meaning for
  4457.      the type of surface that is being declared (e.g., octaves in a special
  4458.      surface).
  4459.  
  4460.                                                                            78
  4461.  
  4462.      The initialization file polyray.ini has to be in the current
  4463.      directory.
  4464.  
  4465.      Shading in scan conversion doesn't always match that from raytracing.
  4466.      Not much can be done about this other than increasing the values of
  4467.      u_steps and v_steps.
  4468.  
  4469.      Refraction does not appear to be correct when the ray passes through
  4470.      several overlapping transparent objects. Works fine if the ior is 1.0,
  4471.      or if there is only 1 object intersected by the ray.  The cure is to
  4472.      use clipping or u/v bounds to remove the overlapping pieces.
  4473.  
  4474.      5 Revision History
  4475.  
  4476.      Version 1.7
  4477.      Released: 17 March 1994
  4478.  
  4479.       o  Antialiasing improved.  Levels of detail are now given rather
  4480.          than numbers of random samples.  Additionally, the uniform
  4481.          subdivision provides consistency across across frames of
  4482.          an animation.
  4483.  
  4484.           o  Added parametric surfaces.  Now possible to define a mesh
  4485.              object (surface) where each point in the mesh is a function
  4486.              of u and v.
  4487.  
  4488.           o  Added bump maps
  4489.  
  4490.           o  Added noeval to definitions to cure a particle system bug
  4491.  
  4492.           o  Added support for GIF and JPEG images in textures, etc.
  4493.  
  4494.           o  Added support for system calls in 386 version.  Can now
  4495.              call an external program from within Polyray.
  4496.  
  4497.           o  The default shading flags for raytracing is now set to:
  4498.                 SHADOW_CHECK + REFLECT_CHECK + TRANSMIT_CHECK +
  4499.                 UV_CHECK + CAST_SHADOW
  4500.              The difference is that it is no longer assumed that surfaces
  4501.              should be lit on both sides (normal correction), this boosts
  4502.              rendering speed at the cost of funny shading once in a while.
  4503.              UV_CHECK was added to allow turning off checking of u/v bounds
  4504.              on objects (also a speedup).
  4505.  
  4506.           o  Changed u_steps, v_steps back to the way it was in v1.5.  Now
  4507.              for all objects it is uniformly subdivided by exactly the
  4508.              value of u_steps/v_steps.
  4509.  
  4510.           o  Significantly enhanced the function object.  Polyray will
  4511.              now accept any predefined function as part of the function
  4512.              definition.
  4513.  
  4514.           o  Added NURBS objects.  (Sorry, no trim curves yet.)
  4515.  
  4516.           o  Displacement functions are now possible on CSG objects.  They
  4517.              also work in raytracing now (although you may need to really
  4518.              boost the u_steps and v_steps values to get good results).
  4519.  
  4520.  
  4521.                                                                            79
  4522.           o  Now supports /* ... */ comments (C style).  No you can't nest
  4523.              them.  You can nest the single line // comments within them.
  4524.  
  4525.           o  Internal modifications made that should result in less memory
  4526.              usage by objects.  Your mileage may vary.
  4527.  
  4528.           o  Modified numeric input to allow numbers like 1., .1
  4529.  
  4530.           o  Fixed up bug in polygon tracing that caused them to drop out
  4531.              if they were oriented in just the right way.
  4532.  
  4533.           o  Added a second raw triangle output format - only outputs the
  4534.              vertex coordinates.  This makes it more compatible with
  4535.              RAW2POV. Previous style with normals and u/v still available.
  4536.  
  4537.           o  Removed BSP tree bounding.  It wasn't any faster than slabs
  4538.              and locked up every once in a while.
  4539.  
  4540.           o  Added a glyph object to support TrueType style extruded
  4541.              surfaces. Glyphs are always closed at the top and bottom, they
  4542.              may have both straight and curved sides in the same shape.  A
  4543.              program to extract TrueType information and write into Polyray
  4544.              glyph format is included with the data file archive.
  4545.  
  4546.           o  Support for simple particle systems.  Can define birth and
  4547.              death conditions, # of objects to generate, and ability to
  4548.              bounce off other objects.
  4549.  
  4550.           o  Added many more VESA display modes.  There are now 5 SVGA 256
  4551.              color modes, 5 Hicolor modes, and 5 truecolor modes supported.
  4552.              If your board doesn't support a selected mode, Polyray tries a
  4553.              lower res one having the same # of bytes per pixel.
  4554.  
  4555.      Version 1.6a (Crud, stuff was still broken...)
  4556.      Released: 23 April 1993
  4557.  
  4558.           o  Problems in writing Targa images!  Uncompressed/RLE was being
  4559.              set improperly in the image file.
  4560.  
  4561.           o  Allocation/Deallocation of static variables had some problems.
  4562.              Mostly fixed, however: DONT use a non-static texture in a
  4563.              static object.
  4564.  
  4565.           o  Added some code to special surface to make use of an alpha
  4566.              value in a color map.  If you use, color xxx_map[foo_fn], it
  4567.              will grab the alpha value and use it for the transmission
  4568.              scale. (This overrides any transmission scale you might put
  4569.              in later, so beware.)
  4570.  
  4571.      Version 1.6 (beta)
  4572.      Released:
  4573.  
  4574.           o  Added opacity values to 16 and 32 bit Targa output.  Just a
  4575.              single bit in the 16 bit files.  In the 32 bit files the extra
  4576.  
  4577.                                                                            80
  4578.              channel holds the percentage of the background that
  4579.              contributed to the pixel.
  4580.  
  4581.           o  Added static (last from frame to frame) variables
  4582.  
  4583.           o  Added indexed and summed textures.
  4584.  
  4585.           o  Added RLE compressed 8 bit Targa files.
  4586.  
  4587.           o  Added VESA Hicolor display in 640x480 (still a bit buggy).
  4588.              Don't use anything but '-t 0' or '-t 1' for status displays or
  4589.              the screen will go wierd after about 50 lines.
  4590.  
  4591.           o  Added texture maps (similar to color maps), indexed image
  4592.              files (for use with texture maps)
  4593.  
  4594.           o  Added output of raw triangle information.  Render type 3 will
  4595.              render the image as triangles, in ASCII form.  Each line of
  4596.              the output has the form: v1 v2 v3 n1 n2 n3 uv1 uv2 uv3.
  4597.              Where vx is a 3D vertex, nx is the normal at the corresponding
  4598.              vertex, and uv1 is a pair of u,v values for each vertex.
  4599.              (This means there are 24 floating point values per line.)
  4600.  
  4601.           o  Fixed bug involving conditional include files.  If an include
  4602.              directive was inside a conditional, the file was read
  4603.              regardless of the value of the conditional.
  4604.  
  4605.           o  Smoothed out Bezier surfaces.  A patch (smooth) triangle is
  4606.              now used instead of a flat one when performing final
  4607.              intersection tests.
  4608.  
  4609.           o  Fixed view bug in scan conversion - if the direction of view
  4610.              was along the y-axis & the up was along the z-axis, the image
  4611.              came out upside down.
  4612.  
  4613.           o  Added displacement to scan converted surfaces
  4614.  
  4615.           o  Added u-v mapping to most primitives.  The variables u and v
  4616.              work in all expressions.  This is especially useful for image
  4617.              mapping.
  4618.  
  4619.           o  Added u-v limits to several primitives.  This allows for
  4620.              creation of sections of a primitive.
  4621.  
  4622.           o  Changed scan conversion to be adaptive to the on-screen pixel
  4623.              size. Unless limited by u_steps or v_steps, the subdivision of
  4624.              a primitive continues until a polygon about the size of a
  4625.              pixel is created.  This is then drawn.  The biggest drawback
  4626.              is the appearance of cracks when the adaptive subdivision is
  4627.              different for adjacent parts of a surface.
  4628.  
  4629.           o  Changed the meaning of u_steps and v_steps for most
  4630.              primitives. They now mean the number of binary subdivisions
  4631.              that are performed rather than the number of steps.  Therefore
  4632.  
  4633.                                                                            81
  4634.              u_steps 4 in this version is equivalent to u_steps 16 in
  4635.              previous versions. (Unaffected primitives: blobs, sweeps,
  4636.              lathes. These still work the old way.)
  4637.  
  4638.           o  Fixed dot product of vectors in expressions.
  4639.  
  4640.           o  Added Legendre polynomials as an expression.  Pretty cool for
  4641.              doing spherical harmonics.
  4642.  
  4643.           o  Added depth mapped lights.  Useful if you need to do shadows
  4644.              of things that can only be scan converted (like displacement
  4645.              surfaces).
  4646.  
  4647.           o  Fixed problems with using a torus in CSG.  (Only appeared in
  4648.              some versions of v1.5)
  4649.  
  4650.      Version 1.5
  4651.      (not released)
  4652.  
  4653.           o Buggy SVGA support removed.  Only standard VGA mode (320x200)
  4654.             supported.
  4655.  
  4656.           o Gridded objects added.
  4657.  
  4658.           o Arrays added
  4659.  
  4660.           o Components of CSG objects are now properly sorted by bounding
  4661.             slabs
  4662.  
  4663.           o User defined bounding slabs removed.  Polyray will always use
  4664.             bounding slabs aligned with the x, y, and z-axes.
  4665.  
  4666.           o Clipping and bounding objects removed.  Clipping is now
  4667.             performed in CSG, bounding is specified using a bounding_box
  4668.             declaration.
  4669.  
  4670.           o Added wireframe display mode.
  4671.  
  4672.           o Added planar blob types.  (Also added toroidal blob types, but
  4673.             they only appear in scan conversion images due to the extreme
  4674.             numerical precision needed to raytrace them.)
  4675.  
  4676.           o Added smooth height fields.
  4677.  
  4678.           o Fixed shading bug involving transparent objects & multiple
  4679.             light sources.
  4680.  
  4681.           o Fixed diffuse lighting from colored lights.
  4682.  
  4683.           o Changed RLE Targa output so that line boundaries are not
  4684.             crossed.
  4685.  
  4686.      Version 1.4
  4687.      Released: 11 April 1992
  4688.  
  4689.                                                                            82
  4690.  
  4691.           o Support for many SVGA boards at 640x480 resolution in 256
  4692.             colors.  See documentation for the -V flag. (Note: SVGA
  4693.             displays only work on the 286 versions.)
  4694.  
  4695.           o Changed the way the status output is managed.  Now requires a
  4696.             number following the -t flag.  Note that line and pixel status
  4697.             will screw up SVGA displays - drawing goes to the wrong place
  4698.             starting around line 100.  If using SVGA display then either
  4699.             use no status, or totals.
  4700.  
  4701.           o Added cylindrical blob components.  Changed the syntax for
  4702.             blobs to accommodate the new type.
  4703.  
  4704.           o Added lathe surfaces made from either line segments or
  4705.             quadratic splines.
  4706.  
  4707.           o Added sweep surfaces made from quadratic splines.
  4708.  
  4709.           o Height field syntax changed slightly.  Non-square height fields
  4710.             now handled correctly.
  4711.  
  4712.           o Added adaptive antialiasing.
  4713.  
  4714.           o Squashed bug in shading routines that affected almost all
  4715.             primitives. This bug was most noticeable for objects that were
  4716.             scaled using different values for x, y, and z.
  4717.  
  4718.           o Added transparency values to color maps.
  4719.  
  4720.           o Added new keywords to the file polyray.ini: shadow_tolerance,
  4721.             antialias, alias_threshold, max_samples.  Lines that begin with
  4722.             // in polyray.ini are now treated as comments.
  4723.  
  4724.           o Short document called texture.txt is now included in
  4725.             PLYDOC.  This describes in a little more detail how to go
  4726.             about developing solid textures using Polyray.
  4727.  
  4728.           o Added command line argument -z start_line.  This allows the
  4729.             user to start a trace somewhere in the middle of an image.
  4730.             Note that an image that was started this way cannot be
  4731.             correctly resumed & completed.  (You may be able to use image
  4732.             cut and paste utilities though.)
  4733.  
  4734.      Version 1.3
  4735.      (not released)
  4736.  
  4737.           o Added support for scan converting implicit functions and
  4738.             polynomial surfaces using the marching cubes algorithm.  This
  4739.             technique can be slow, and is restricted to objects that have
  4740.             user defined bounding shapes, but now Polyray is able to scan
  4741.             convert any primitive.
  4742.  
  4743.           o A global shading flag has been added in order to selectively
  4744.  
  4745.                                                                            83
  4746.             turn on/off some of the more time consuming shading options.
  4747.             This option will also allow for the use of raytracing as a way
  4748.             of determining shadows, reflectivity, and transparency during
  4749.             scan conversion.
  4750.  
  4751.           o Added new keywords to the file polyray.ini: pixel_size,
  4752.             pixel_encoding, shade_flags.
  4753.  
  4754.           o Improved refraction code to (mostly) handle transparent
  4755.             surfaces that are defined by CSG intersection.
  4756.  
  4757.           o Fixed discoloring of shadows that receive some light through a
  4758.             transparent object.
  4759.  
  4760.           o Jittered antialiasing was not being called when the option was
  4761.             selected, this has been fixed.
  4762.  
  4763.           o Fixed parsing of blobs and polygons that had large numbers of
  4764.             entries. Previously the parser would fail after 50-60 elements
  4765.             in a blob and the same number of vertices of a polygon.
  4766.  
  4767.           o In keeping with the format used by POV-Ray and Vivid, comments
  4768.             may now start with // as well as #.  The use of the pound
  4769.             symbol for comments may be phased out in future versions.
  4770.  
  4771.      Version 1.2
  4772.      Released: 16 February 1992
  4773.  
  4774.           o Scan conversion of many primitives, using Z-Buffer techniques.
  4775.  
  4776.           o New primitives: sweep surface, torus
  4777.  
  4778.           o Support for the standard 320x200 VGA display in 256 colors.
  4779.  
  4780.           o An initialization file, polyray.ini, is read before
  4781.             processing.  This allows greater flexibility in tuning many
  4782.             of the default values used by Polyray.
  4783.  
  4784.           o User defined bounding slabs added.  This greatly improves speed
  4785.             of rendering on data files with many small objects.
  4786.  
  4787.           o Noise surface added.
  4788.  
  4789.           o Symbol table routines completely reworked.  Improved speed for
  4790.             data files containing many definitions.
  4791.  
  4792.           o Bug in the texturing of height fields corrected.
  4793.  
  4794.      Version 1.1
  4795.      (not released)
  4796.  
  4797.           o Added parabola primitive
  4798.  
  4799.           o Dithering of rays, and objects
  4800.  
  4801.                                                                            84
  4802.  
  4803.           o Blob code improved, shading corrected, intersection code is
  4804.             faster and returns fewer incorrect results.
  4805.  
  4806.      Version 1.0
  4807.      Released: 27 December 1991
  4808.  
  4809.           o Several changes in input syntax were made, the most notable
  4810.             result being that commas are required in many more places.  The
  4811.             reason for this is that due to the very flexible nature of
  4812.             expressions possible, a certain amount of syntactic sugar is
  4813.             required to remove ambiguities from the parser.
  4814.  
  4815.           o Several new primitives were added: boxes, cones, cylinders,
  4816.             discs, height fields, and Bezier patches.
  4817.  
  4818.           o A new way of doing textures was added - each component of the
  4819.             lighting model can be specified by an implicit function that is
  4820.             evaluated at run time.  Using this feature leads to slower
  4821.             textures, however because the textures are defined in the data
  4822.             file instead of within Polyray, development of mathematical
  4823.             texturing can be developed without making alterations to
  4824.             Polyray.
  4825.  
  4826.           o File flush commands in the data file and at the command line
  4827.             were added.
  4828.  
  4829.           o Several new Targa variants were added.
  4830.  
  4831.           o Image mapping added.
  4832.  
  4833.           o Numerous bug fixes have occurred.
  4834.  
  4835.      Version 0.3 (beta)
  4836.      Released: 14 October 1991
  4837.  
  4838.           o This release added Constructive Solid Geometry, functional
  4839.             surfaces defined in terms of transcendental functions, a
  4840.             checker texture, and compressed Targa output.
  4841.  
  4842.           o Polyray no longer accepted a list of bounding/clipping objects,
  4843.             only a single object is allowed. since CSG can be used to
  4844.             define complex shapes, this is not a limitation, and even
  4845.             better makes for cleaner data files.
  4846.  
  4847.      Version 0.2 (beta)
  4848.      (not released)
  4849.  
  4850.           o This release added animation support, defined objects,
  4851.             arithmetic expression parsing, and blobs.
  4852.  
  4853.      Version 0.1 (beta)
  4854.      (not released)
  4855.  
  4856.  
  4857.                                                                            85
  4858.           o First incarnation of Polyray.  This version had code for
  4859.             polynomial equations and some of the basic surface types
  4860.             contained in mtv.
  4861.  
  4862.