home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Raytrace & Morphing / SOS-RAYTRACE.ISO / programm / raytrace / rayce27 / rayce.doc < prev    next >
Encoding:
Text File  |  1994-02-02  |  42.4 KB  |  1,539 lines

  1.     Rayce version 2.7
  2.  
  3.     A Raytracer
  4.  
  5.     by Han-Wen Nienhuys <hanwen@stack.urc.tue.nl>
  6.  
  7.     Rayce is based on Ray, a raytracer written by George Kyriazis
  8.  
  9.  
  10.  
  11. 0.99    LEGALESE
  12.  
  13. Rayce is Copyright 1993 Han-Wen Nienhuys.  Rayce is distributed under
  14. the terms of the GNU General Public License.  You can modify and
  15. redistribute Rayce under certain conditions.  It is distributed "as
  16. is", without warranties of any kind. See the file "copying" for
  17. details.  If you have not received a copy of the GNU General Public
  18. License along with this program, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21.  
  22.  
  23. 1.    INTRODUCTION
  24.  
  25. Rayce is a raytracer I've written to find out how raytracing works.
  26. It's written for purely educational purposes.  If you want to make
  27. neat pictures, use PoV or Vivid instead.  Oh, by the way,
  28. "educational" means "for my education", but you could use it in a CG
  29. class too.  It wouldn't make a very good example, though, I am
  30. afraid.
  31.  
  32. Still, Rayce has been expanded very much, and I plan to incorporate a
  33. lot of weird and new stuff into it.
  34.  
  35.  
  36. 2.    CREDITS
  37.  
  38.  
  39. These people have (knowingly or unknowingly) contributed to Rayce: 
  40.  
  41. George Kyriazis     <kyriazis@turing.cs.rpi.edu>
  42. Shawn McHorse         <Zaphod@fcircus.sat.tx.us>
  43. The PoV-team
  44. Mark VandeWettering     <markv@cs.uoregon.edu>
  45. Ben Trumbore
  46. David G Hook, Bernie Kirby and Peter McAree, <echidna@munnari.oz.au>
  47. Jochen Schwarze
  48. Harm Hanemaayer     <hhanemaa@cs.ruu.nl>
  49.  
  50.  
  51. Rayce is based on a very small raytracer by George Kyriazis.  You can
  52. still download this raytracer on wuarchive.wustl.edu, in the directory
  53. /pub/graphics/graphics/ray/gk/ as ray2*.shar.Z.  This raytracer was
  54. called Ray, I've changed the name to avoid confusion.  Besides, "ray"
  55. isn't a very original name for a raytracer, is it ?  (and "Raycer" was
  56. too obvious :-).
  57.  
  58. In developing, I have used Persistence of Vision, a great raytracer
  59. usually dubbed PoV, as a shining example. That's why it looks like PoV
  60. so much.
  61.  
  62. I would like to especially thank Shawn McHorse
  63. <Zaphod@fcircus.sat.tx.us> for valuable comments, bugfixes, the Rayce
  64. output in the SPD, DJGCC compile and the new shading code.
  65.  
  66. The color include, and the concave polygon code were taken from for
  67. Mark Vandewettering's MTV tracer. BTW. It looks an awful lot like the
  68. X11 color database.
  69.  
  70. Most of the auto bounding for primitives is from: Graphics Gems III,
  71. section VI.5, bounding_volumes.c, Ben Trumbore, "Rectangular Bounding
  72. Volumes for Popular Primitives"
  73.  
  74. The formulas from the surfs.inc were taken partly from PoV 2.0.
  75.  
  76. The sturm sequence code in solve.c was taken from the raytracer Art,
  77. part of the Vort package (it is almost identical to the code in
  78. Graphics Gems I), by David G Hook, Bernie Kirby and Peter McAree,
  79. reachable via <echidna@munnari.oz.au>
  80.  
  81. The random numbers are also from Vort.
  82.  
  83. The cubic and quartic solver was by Jochen Schwarze, and was taken
  84. from Graphics Gems I.
  85.  
  86. The gif reader was done by Harm Hanemaayer <hhanemaa@cs.ruu.nl>, and
  87. it was based on posting in rec.games.programmer in spring of 1993.
  88.  
  89.  
  90.  
  91. 3.    USAGE & OPTIONS
  92.  
  93. The syntax is simple:
  94.  
  95.   rayce [options]
  96.  
  97. If you don't give options, it will print a small usage screen.  You can
  98. use the following command line options:
  99.  
  100.   -o<file>
  101.  
  102. Specifies the output file (default: output.tga). The output format is
  103. 24 bit type 2 uncompressed Targa.
  104.  
  105.   -i<file>
  106.  
  107. Specifies the input file (default: input.r)
  108.  
  109.   -I#
  110.  
  111. Specifies the number of samples per pixel to use (default: use the number
  112. In the options{} block, and that's 1 by default)
  113.  
  114.   -c
  115.     
  116. Continue a previously aborted trace (default: don't continue)
  117.  
  118.   -x
  119.  
  120. Disable abort via keypress (default:  allow abort).  If you have
  121. compiled Rayce for a different computer than IBM PC, your check_abort()
  122. determines the abort condition. 
  123.  
  124. For Linux, this flag has nog effect.  Interrupting should be done by
  125. sending a SIGINT (pressing ^C, killing rayce, rebooting, etc.)
  126.  
  127.   -h#
  128.  
  129. Specify image height in pixels (default: 50)
  130.  
  131.   -w#
  132.  
  133. Specify image width in pixels (default: 50)
  134.  
  135.   -d#
  136.  
  137. Turn on debugging.  The number given is the sum of the debug flags you
  138. want to use:
  139.  
  140.     1    switch on debugging for tokenizer.
  141.     2    switch on debugging for parser (yydebug = 1)
  142.     4    switch on debugging for memory (doesn't work under
  143.         linux)
  144.     8    print the interior after parsing
  145.  
  146. This only works if rayce was compiled with -DDEBUG.
  147.  
  148. After a line has been finished, some statistics are printed, and after
  149. Rayce has finished tracing, more elaborate statistics are printed.
  150.  
  151.  
  152. 4.    INPUT
  153.  
  154. The input is based on PoV 1.0 and 2.0 format.  Below is an overview.
  155. If you want the details, check out rayparse.y, the yacc/bison file
  156. which implements the parser.  Ok. Fasten your seatbelts:
  157.  
  158.  
  159. 4.1. Basic stuff 
  160.  
  161. Comments are between /* and */, and after a //.  It is legal to nest
  162. the /* */.
  163.  
  164. A float is what you would expect it to be: 
  165.  
  166.     1.2     12e-1    .12e1
  167.  
  168. all specify the same number.
  169.  
  170. Additionally, you can use expressions for floats: 
  171.  
  172.     12/10
  173.     0.12*10 
  174.     1.0 + 0.2
  175.     1.2^2 - 0.14
  176.     - (- 1.2)
  177.     
  178. These expressions are all valid, and all specify 1.2.
  179.  
  180. You can make a vector out of three floats:
  181.  
  182.     <FEXP1, FEXP2, FEXP3>
  183.  
  184. FEXP1, FEXP2 and FEXP3 are floating point expressions. You can use
  185. expressions on vectors in the same manner as you can with floats: -, +
  186. do addition and substraction. Use * for scalar multiplies, ^ for a
  187. vector cross product. From now on, I will use <VECTOR>
  188. to denote a vector. Use
  189.     
  190.     (<VEXP1>, <VEXP2>)
  191.  
  192. for the improduct, a float expression. "x", "y" and "z" are the
  193. coordinate vectors: Example:
  194.  
  195.     <1, 2/3, 4 * (x , <2,0,0>) > 
  196.  
  197. should give <1, 0.6666, 8>. There is one other feature:
  198.     
  199.     <0.5>
  200.  
  201. will produce a vector <0.5,0.5,0.5>. Although this isn't custom in
  202. mathematics, it is very easy for specifying all kinds of shapes, eg.
  203. boxes, scaling factors, etc.
  204.  
  205. ! Please note that everywhere two adjacent floats or vectors should be
  206. ! separated by a comma.
  207.  
  208. Keywords should be in lowercase. Everything is case sensitive.
  209.  
  210. Colors work the PoV-way. For reasons of compatibility, an alpha part
  211. is allowed, but it will be ignored.
  212.  
  213. An extra feature is to convert colors from and to vectors. This makes
  214. adding and substracting colors easier.
  215.  
  216. Example:
  217.  
  218.     color red 0.5 green 0.1
  219.     color red 0.5 green 0.1 alpha 0.5
  220.     color rgb <0.5, 0.1, 0>
  221.     #declare testcol = color red 1.0 green 0.2 
  222.       color rgb 0.5 * <color testcol>
  223.  
  224. All give the same color.
  225.  
  226.  
  227. 4.2 Camera
  228.  
  229. Rayce has a simple pinhole camera, and it is lefthanded, similar to
  230. PoV's camera. This camera can't be distorted, though.
  231.  
  232. The viewpoint is specified by
  233.  
  234.     camera {
  235.       location <EYE>
  236.       sky <SKYVECTOR>
  237.       fov FOV
  238.       direction <DIRECTION>
  239.       aspect ASPRATIO
  240.       look_at <POINT>
  241.     }
  242.  
  243. EYE is the eye location.
  244.  
  245. <SKYVECTOR> is the analogon of the PoV sky vector.  Your pictures will
  246. have their the top of your screen aligned to <SKYVECTOR>
  247.  
  248. <DIRECTION> is the viewing direction. This is not used very often,
  249. since look_at is so much easier.
  250.  
  251. FOV specifies the vertical Field of View.
  252.  
  253. ASPRATIO is the aspect ratio of your picture (normal computer screens
  254. have aspect 4/3 = 1.333)
  255.  
  256. look_at points the camera to towards <POINT>, while preserving the
  257. direction vector length.
  258.  
  259. Hope you understand this... A camera can be scaled, rotated and
  260. translated.
  261.  
  262.  
  263. 4.3 Options
  264.  
  265. General options can be set from the opions block:
  266.  
  267.      options {
  268.       time START, STOP
  269.       background [<GRADIENT>] color BACKGROUNDCOLOR
  270.       depth DEPTH
  271.       iterations NUMBEROFFRAMES
  272.       tolerance TOL
  273.       antialias WIDTH
  274.       cutoff TRESHOLD
  275.     }
  276.  
  277. START and STOP specify the time interval in which the scene takes
  278. place: this is used with the speed<> vector from the object
  279. declaration.  <GRADIENT> specifies in which direction the gradient
  280. of the background color should be, and BACKGROUNDCOLOR is the color to
  281. use.  If you don't want the gradient coloring, then use
  282.  
  283.     background color BACKGROUNDCOLOR.
  284.  
  285. DEPTH is the maximum recursion depth.
  286.  
  287. NUMBEROFFRAMES is the number of eyerays per pixel.  If you want to use
  288. antialiasing, set iterations to a value greater than 1.  This should
  289. also be done if you want to use distributed raytracing (If you are not
  290. familiar with this technique read section 11 of this document)
  291.  
  292. TOL is the minimum intersection distance: any intersection that is
  293. closer than TOL to the ray origin is ignored.  By default it is 1e-5,
  294. and normally you could make it as small as 1e-10.  With certain shapes
  295. (notably high order surfaces, such as toruses), this needs to be
  296. bigger, otherwise numerical inaccuracies will find the intersection at
  297. x = t*dir + pos with t smaller than TOL.  These are the intersections
  298. that should have t = 0.  These intersections cause "phantom" shadows
  299. and digital zits.
  300.  
  301. If you want to do antialiasing, use "antialias WIDTH".  This makes
  302. Rayce do Monte Carlo anti aliasing: Rayce will sample the rays within
  303. WIDTH times the pixelsize, using a Gaussian distribution. If antialias
  304. is not give, Rayce will use 1-(1/samples) as the antialias width.
  305.  
  306. This should be done using a grid, I haven't implemented it (yet).
  307.  
  308. Adaptive depth control is done by specifying a cutoff THRESHOLD.  If a
  309. ray would contribute less than a TRESHOLD fraction of the color
  310. written to the output, then the ray is not traced.  This is called
  311. adaptive depth cutoff or adaptive depth control.
  312.  
  313.  
  314. 4.4    PRIMITIVE SHAPES
  315.  
  316. Rayce supports the following primitives:
  317.  
  318. 4.4.1. The sphere
  319.  
  320. a sphere specified this way:
  321.  
  322.     sphere { <CENTER>, RADIUS }
  323.  
  324. Here, CENTER is a vector, and RADIUS a float.  The sphere is a special
  325. kind of quadric, and it is about 60% faster, see speedtst.r for some
  326. info.
  327.  
  328. You might expect a better performance of the sphere in comparison to
  329. the quadric.  I guess, that's because I didn't use vector operations
  330. in quadric.c; instead I directly calculated the quadratic equation in
  331. t.  See quadric.c if you don't understand what I just typed.  (or you
  332. might just as well forget it :)
  333.  
  334.  
  335. 4.4.2. Polygon
  336.  
  337. You can make polygons in this way:
  338.  
  339.   polygon { <P1>, <P2>, ..  }
  340.  
  341. <P1>, <P2>,... are the vertices of the polygon.
  342.  
  343. Convex polygons will render a lot faster. 
  344.  
  345. 4.4.3. Quadric
  346.  
  347. A quadric shape is a curve, which is described in this way: it is a set
  348. Q, with
  349.  
  350.     Q = { (x,y,z) in R^3 | Phi(x,y,z) = 0 }
  351.  
  352. In which Phi is
  353.  
  354.     Phi(x,y,z) = ax^2 + by^2 + cz^2 + dxy + eyz + fzx +
  355.       gx + hy + iz + j = 0
  356.  
  357. or, more casually said: a quadric consists of points x,y,z for which
  358.  
  359.     ax^2 + by^2 + cz^2 + dxy + eyz + fzx + gx
  360.         + hy + iz + j = 0
  361.  
  362. If you'd take a = b = c =1, j = -1, and d,e,f, ..  = 0, Q forms a
  363. sphere, center in (0,0,0), and radius 1.  The quadric is specified in
  364. same fashion as in PoV:
  365.  
  366.     quadric { <COEFF1>, <COEFF2>, <COEFF>, CONST }
  367.  
  368. The coefficients (a,b,c) form <COEFF1>, (c,d,e) <COEFF2>, (f,g,h)
  369. <COEFF3>, all of which are vectors.  The constant j is CONST. You
  370. could also use an "algebraic" for specifying a quadric, but this is
  371. faster.
  372.  
  373.  
  374. 4.4.4. The Plane
  375.  
  376. The plane is a shape mathematically defined by
  377.  
  378.     P = { X in R^3 | X.n = a }
  379.  
  380. Here, X.n denotes the dot vector product of the normal n, and X.  In
  381. Rayce and PoV it is usually defined by
  382.  
  383.     plane { <NORMAL>, A }
  384.  
  385. NORMAL is the normalvector to the plane, and A the distance in which
  386. it is moved along the normalvector.  Note that the normal isn't
  387. normalised (which sounds quite funny if you read it aloud :-) The
  388. reason for this is that it isn't normalised in PoV either....  For the
  389. best results, always use a vector with length 1.
  390.  
  391.  
  392. 4.4.5. The Box
  393.  
  394. A box is CSG intersection of six planes. You should specify it
  395. using
  396.  
  397.     box { <POINT>, <OPPOSITE_POINT> }
  398.  
  399. both POINT and OPPOSITE_POINT are vectors which correspond to two
  400. opposite corners of the box you want Rayce to produce.  The box has
  401. it's planes along the X, Y and Z axis.  The order of the points
  402. doesn't matter, so
  403.  
  404.     box { <-1, 0, 0 >, <1, 1, 1> }
  405.  
  406. and
  407.  
  408.     box { <1, 0, 1>, <-1, 1, 0> }
  409.  
  410. should look the same.  A box can be transformed in the usual ways.
  411. Rotating it will slow down tracing a bit, though.
  412.  
  413.  
  414. 4.4.6. Light source
  415.  
  416. Lightsources are cause for diffuse and specular illumination, the
  417. things that make those nice shadows and highlights.  Use them in this
  418. way
  419.  
  420.     light_source {
  421.       <ORIGIN> color LIGHTCOLOR
  422.       [light_modifiers]
  423.      }
  424.  
  425. The ORIGIN and LIGHTCOLOR are mandatory parts; they tell Rayce the
  426. point from which point lightrays emanate and their color (actually,
  427. shadow rays are directed to the light_source, but you knew that,
  428. right?).  Light sources in Rayce cannot be seen,
  429. intersect_lightsource() always returns FALSE.
  430.  
  431. These are the allowed light_modifiers:
  432.  
  433. attenuation FALLOFFEXPONENT
  434. radius  RADIUS
  435.  
  436. If you're interested: the intensity I is calculated using
  437.  
  438.  
  439.     I = (1/r)^FALLOFFEXPONENT
  440.  
  441. Here r denotes the distance to the light source.
  442.  
  443. FALLOFFEXPONENT is the exponent to use for fading light: in real life,
  444. the intensity of light diminishes with the distance; the intensity is
  445. proportional to 1/r^2, so in real life the FALLOFFEXPONENT is 2.
  446. Light in Rayce will diminsh with 1/r^FALLOFFEXPONENT.  By default it
  447. is 0, i.e. the intensity does not depend on the distance from the
  448. light source.
  449.  
  450. Rayce can do penumbra (soft shadows) as well. Use RADIUS to specify
  451. the radius of a discshaped lightsource.
  452.  
  453.  
  454. 4.4.7. Triangle
  455.  
  456. A triangle is specified this way:
  457.  
  458.     triangle { <P1>, <P2>, <P3> }
  459.  
  460. P1, P2 and P3 are the points of the triangle, and the order in which
  461. the points are specified points does not matter.  No backface culling
  462. is done, and these are ordinary triangles, i.e.  no normal
  463. interpolation is done.
  464.  
  465.  
  466. 4.4.8. Smooth triangle.
  467.  
  468. A triangle with interpolated normal vectors is represented in this
  469. way:
  470.  
  471.     smooth_triangle { <P1>, <N1>, <P2>, <N2>, <P3>, <N3> }
  472.  
  473. <P?> are the the vertices, and <N?> the normals at these vertices.
  474.  
  475.  
  476. 4.4.9.  Torus
  477.  
  478. A torus is a shape that looks like a donut.  If you want to make a
  479. torus, then use:
  480.  
  481.     torus { MAJOR, MINOR }
  482.  
  483. MAJOR is the major radius, and MINOR is the minor radius.  The torus
  484. produced lies in the XZ plane, so you have to rotate it if you want
  485. another direction.  Technically speaking, a torus is a circle in the
  486. XZ plane with radius MINOR and center <MAJOR, 0, 0>, swept around the Z
  487. axis.
  488.  
  489. Don't try to use bounding shapes on toruses.  The torus is already
  490. enclosed in an intersection of a minimal bounding sphere and two
  491. planes.
  492.  
  493. A torus is a quartic surface.  Among others, this means that a torus
  494. can at most have 4 intersections with a ray.  For calculating these
  495. intersections, by default, a technique known as Ferrari's method is
  496. used.
  497.  
  498. Although this technique is relatively fast, it can give surface acne
  499. because of numerical inaccuracies.  This is sometimes called "digital
  500. zits", black dots -- try a zoomed in version of the papercl.r with
  501. tolerance 1e-5, and no "sturm" keywords.
  502.  
  503. If this happens to you, then try adding the keyword "sturm" after the
  504. definition.  A different method --Sturm sequences-- for calculating
  505. intersections will be used, which is slower, but more accurate.
  506. Alternatively you can set SHADOW_TOLERANCE (see OPTIONS) higher, eg
  507. 0.05. This won't make the calculations more exact, but it will take
  508. away most of the phantom shadows.
  509.  
  510.  
  511. 4.4.10. High order surfaces.
  512.  
  513. You can model arbitrary algebraic (polynomial) surfaces using Rayce.
  514. Anything is allowed, as long as the order is less than 12 (if you'd
  515. like more, then you'll have to recompile; change MAX_ORDER in ray.h to
  516. suit your needs).
  517.  
  518. The algebraic surface S is determined by a polynomial Phi. The surface
  519. is the set S for which
  520.  
  521.     S = { (x,y,z) | Phi(x,y,z) = 0 }
  522.  
  523. In Rayce you get such a surface by defining Phi(), or specifying 
  524.  
  525.    Psi(x,y,z) = Chi(x,y,z)
  526.  
  527. Which means that
  528.  
  529.    Phi = Psi - Chi.
  530.  
  531. so Phi is a polynomial in x,y and z. You can perform the following
  532. operations on x,y and z to form new polynomials:
  533.  
  534.     addition     x + y + 83
  535.     substraction    x - z - 83
  536.     exponentation    y ^ 4 
  537.     multiplication    5 * x * y
  538.     grouping    (x+y)^2
  539.  
  540. Notice that only floating point numbers are allowed, and no
  541. expressions. Example:
  542.  
  543.     $ 1 + 2 $    // ok, we're adding the polynomials 1 and 2
  544.     $ (x,y) $    // WRONG, (x,y) is a float-expression not a 
  545.             // float
  546.     $ 1*x   $    // ok
  547.     $ 1/2    $    // WRONG, you can't divide polynomials (not
  548.             // even 1 and 2
  549.  
  550. If you want to use expressions, then use declared floating point
  551. constants. Example:
  552.  
  553.     #declare R = 1.0
  554.     #declare r = R/2
  555.     #declare mytorus = algebraic { 
  556.       $ (x^2 + y^2 + z^2 + R^2 - r^2)^2 = 4*R*(x^2+y^2) $
  557.       closed
  558.     }
  559.  
  560. In the above, mytorus is declared a torus with minor radius 0.5, and
  561. major radius 1.0. The "closed" keyword is for speeding up
  562. inside/outside calculations, and the rootfinder is the ordinary
  563. Ferrari rootfinder.
  564.  
  565. Example:
  566.  
  567.     algebraic { $ x^4 + y^4 + z^4 -1 $ closed sturm }
  568.  
  569. should specify a closed finite surface (in this case a superquadric; a
  570. cube with rounded corners), and it is to be calculated using Sturm
  571. sequences.
  572.  
  573. Since an algebraic is stored in terms of operations,
  574.  
  575.     algebraic { $ (x-1)^2 + y^2 - 1 $ }
  576.  
  577. is calculated differently from
  578.  
  579.     algebraic { $ (x^2 -2*x + 1) + y^2 - 1 $ }
  580.  
  581. The latter requires more operations, thus it is more expensive. Try to
  582. make your formula as compact and efficient as possible.
  583.  
  584.  
  585. 4.4.12. Cylinder
  586.  
  587. You can make a cylinder between <P1> and <P2> having radius R by
  588. inserting
  589.  
  590.   cylinder  { <P1>, <P2>, R }
  591.  
  592. This isn't really a primitive. If Rayce encounters a cylinder
  593. definition in its input, then it is converted to an extrusion of a
  594. sphere with radius R.
  595.  
  596.  
  597. 4.4.13. Superquadric
  598.  
  599. A superquadric is a generalized sphere. A n-dimensional sphere is
  600. defined by
  601.  
  602.   || X || = 1                (p >= 1) X in R^n 
  603.  
  604. Here, || . || is the Euclidian norm: ||X|| = sqrt(x_1^2 + x_2 ^2 +
  605. .. + x_n^2).  This norm can be generalized to the p-norm defined by
  606.  
  607.   (|x_1|^p + |x_2|^p + ... + |x_n|^p)^(1/p) = 1
  608.     
  609. If we consider 3D space, then n = 3, and the p-norm is 
  610.  
  611.   ||X||_p = (|x|^p + |y|^p + |z|^p)^(1/p) 
  612.    
  613. So a sphere in the p-norm is 
  614.   
  615.   ||X||_p = 1
  616.  
  617. or 
  618.    
  619.   (|x|^p + |y|^p + |z|^p)^(1/p)  =  1
  620.  
  621. since 1^p = 1, this is equivalent to
  622.  
  623.   |x|^p + |y|^p + |z|^p = 1
  624.  
  625. if p is large, then this forms a cube, with faces parallel to the axes
  626. and rounded corners.
  627.  
  628. if p = 1, it's a cube with corners in <0,0,1>, <1,0,0>, <-1,0,0>
  629.  etc.
  630.  
  631. if p = 2, it's a sphere. 
  632.  
  633. This is how you define such a primitive in rayce:
  634.  
  635.   superq { <p> }
  636.  
  637. NB. If p < 1, then you still get a shape, but since it will then not be
  638. convex anymore, an intersection algorithm would be harder; It will
  639. probably not work, if you try
  640.  
  641.   superq { <0.5> }
  642.  
  643. You probably won't get a good render.
  644.  
  645. In rayce the previous is generalized. The algorithm for computing
  646. intersections with superquadrics works for arbitrary shapes
  647.  
  648.   C1(x) + C2(y) + C3(z) = 1
  649.  
  650. If C1,C2 and C3 are convex functions. So in rayce, you can also render
  651. elements from this class of shapes:
  652.  
  653.   |x|^p1 + |y|^p2 + |z|^p3 = 1
  654.  
  655. where p1, p2 and p3 are all greater than 1. This is how you specify it.
  656.  
  657.   superq { <p1, p2, p3> }
  658.  
  659. See superq.tex, an article on superquadrics, which should be included.
  660.  
  661.  
  662. 4.4.13. Discs
  663.  
  664. Discs are round shaped pieces of a flat planes, they could be
  665. simulated with a plane clipped by a sphere, but they have been put in
  666. on special request from Shawn McHorse.  Syntax:
  667.  
  668.      disc { <CENTER>, <NORMAL>, Rad }
  669.  
  670. The above is a simple disc
  671.  
  672.      disc { <CENTER>, <NORMAL>, Majrad, minrad }
  673.  
  674. This is a disc with a hole in the center.
  675.  
  676. 4.4.14. Transformations
  677.  
  678. * All primitives may transformed using scale<>, rotate<> and
  679. translate<>.
  680.  
  681. * Every shape can have it's own private texture.
  682.  
  683. * Every shape which has a proper inside and outside defined, can be
  684. inverted using "inverse" (see below).  
  685.  
  686.  
  687.  
  688. 4.5    NON-PRIMITIVE SHAPES
  689.  
  690.  
  691. 4.5.1. Union
  692.  
  693. Union is a CSG operation, it merges two shapes into one.  Syntax:
  694.  
  695.     union {
  696.       CSGSHAPE
  697.       [CSGSHAPE]
  698.       [CSGSHAPE]
  699.       [.. etc]
  700.       [inverse]
  701.     }
  702.  
  703. The "inverse" flips a shape inside out.  Check out the mathematics
  704. section below for details.
  705.  
  706. Note that Rayce has a real union.  That is, if you do
  707.  
  708.         union {
  709.         sphere { <0, 0, 0>, 1 }
  710.         sphere { <0, 0, 1>, 1 }
  711.       }
  712.  
  713. the interior walls are removed:  if you are standing in the the first
  714. sphere, facing the second sphere, you can actually look inside the
  715. second sphere.
  716.  
  717.  
  718. 4.5.2.  Intersection
  719.  
  720. Intersection is another CSG operation.  If you do an intersection of N
  721. shapes, then only points that are contained in all N shapes
  722. simultaneously, are part of the intersection.
  723.  
  724. Actually, you can only see the boundary of this intersection.  An
  725. intersection looks like this:
  726.  
  727.     intersection {
  728.       CSG_items
  729.     }
  730.  
  731. CSG_item is one the following shapes:
  732.  
  733.     sphere
  734.     quadric
  735.     plane
  736.     box
  737.     intersection
  738.     union
  739.     torus
  740.     algebraic
  741.     extrusion (make sure it's closed! )
  742.     cylinder (idem ditto)
  743.     superquadric
  744.  
  745.  
  746. or it is a 
  747.     
  748.     transformation
  749.     inverse statement
  750.     texture block
  751.  
  752.  
  753. [Mathematics follows, so don't read it, unless you are interested. :]
  754.  
  755. The shapes mentioned above are special, because their boundaries are
  756. special.
  757.  
  758.   [intermezzo]
  759.  
  760.   In mathematics, these boundaries are usually called "frontiers".
  761.   These are the points which can be reached from both a set and its
  762.   complement.  More exactly speaking, the frontier of a set S, usually
  763.   denoted by dS is the following:
  764.  
  765.   dS consists of points P, for which the following holds: For every P,
  766.   one can find a sequence a1,a2, ...  which converges to P, and lies
  767.   Entirely in S, and one can find another sequence b1, b2, ...  which
  768.   also converges to P, but lies completely outside S.
  769.  
  770.   More casually said:  one can reach a point of dS by walking via points
  771.   in S, and by walking via points outside of S.
  772.  
  773. [Back to the computers and the special boundaries.]
  774.  
  775. The above mentioned surfaces (sphere, quadric etc...)  have
  776. following properties:
  777.  
  778. I.  They divide the whole of 3D space into two distinct pieces (sets):
  779. an "inside" and an "outside".  Every point lies either inside or
  780. outside the shape.  Theoretically, a point could be on the frontier of
  781. the inside and outside, i.e.  on the surface itself.  Due to numerical
  782. inaccuracies and implementation, this will happen next to never.
  783.  
  784.  
  785.   [sideway]
  786.   [Of every ray tested agains a CSG, only
  787.  
  788.     origin + 2*tolerance * direction
  789.  
  790.   is tested for inside/outside.  So if you want to create quirky images,
  791.   make sure you have intersections with CSG parts at distances d with
  792.  
  793.     tolerance < d < 2*tolerance.
  794.  
  795.   (So be warned! :-)
  796.  
  797.   Some special primitives, like the torus or the sphere, don't need this
  798.   testing:  if a ray intersects the shape an even number of times, then
  799.   the rays origin lies outside the shape, if the ray has an odd number
  800.   of intersections, then it's origin is inside.
  801.   ]
  802.  
  803. II.  If you would walk along a ray, changing inside/outside of a shape
  804. happens if and only if the ray hits the surface.
  805.  
  806. Other CSG algorithms can also use triangles and rings for CSG, but this
  807. one cannot, because a triangle fails property II.
  808.  
  809. The inside/outside for various shapes is determined using the following
  810. criteria:
  811.  
  812.   Sphere:
  813.   The inside of a sphere are the points X with
  814.  
  815.       distance(X, center) < radius
  816.  
  817.  
  818.   Box:
  819.   For a box, the inside is collection of points (x,y,z) which satisfy
  820.  
  821.       MaxX < x < MaxX
  822.       MaxY < y < MaxY
  823.       MaxZ < z < MaxZ
  824.  
  825.  
  826.   Torus:
  827.   The inside of a torus (donut) is the part where the jelly usually resides.
  828.  
  829.   The above shapes all have finite insides.  In jargon, you'd say that
  830.   they are closed curves.  The plane is somewhat different:
  831.  
  832.   Plane:
  833.   The outside of a plane is the part which is on the "side of the normal".
  834.   Symbolically: X is inside the plane if
  835.  
  836.       X.n < a
  837.  
  838.   See the section on planes.  This means, that both the inside, and the
  839.   outside are infinite.
  840.  
  841.   Quadrics:
  842.   For a quadric, the inside are points (x,y,z) with
  843.  
  844.       Phi(x,y,z) < 0.
  845.  
  846.   see the section on quadrics.
  847.  
  848.   Algebraic:
  849.   An algebraic is specified by a polynomial p(x,y,z). A point is inside
  850.   if p(x,y,z) < 0.
  851.  
  852.   Intersection:
  853.   A point is inside a CSG intersection of shapes S1, S2, etc if and only
  854.   if the point is inside S1, and S2, and S3 and etc.
  855.  
  856.   Union: 
  857.   A point is contained in the inside of a CSG union of S1, S2,
  858.   etc.  if and only if the point is inside at least one of S1, S2, etc.
  859.  
  860. The "inverse" keyword flips a shape: the inside of
  861.  
  862.     B = shape { A inverse }
  863.  
  864. has all points which are outside of A, and the inside of B has all
  865. points which are outside of A.  Mathematically speaking, taking the
  866. inverse of a shape, is equivalent to taking the complement of the set,
  867. formed by a shape.
  868.  
  869. It is legal to transform CSGs.  In effect, you are then transforming all
  870. components of the CSG.
  871.  
  872.  
  873. 4.4.11. Extrusion
  874.  
  875. You can extrude surfaces with rayce: Say, you'd want to make a column
  876. for use in a roman temple. 
  877.  
  878.  
  879.   extrusion {
  880.     HEIGHT
  881.     shape { ... }
  882.   }
  883.  
  884. This takes a shape, and extends the intersection of the shape with the
  885. XY plane to the Z-direction. Your extrusion will have height HEIGHT.
  886. HEIGHT should be bigger than 0. For instance, if you have defined the
  887. projection of a cogwheel on the XY plane, then you could make a 3d object
  888. out of it by specifying 
  889.  
  890.   extrusion { 
  891.     1 intersection { cogwheel }
  892.   }
  893.  
  894. NB. This is not the same as Polyray's sweep. Polyray only extrudes
  895. polygonal objects.
  896.  
  897.  
  898.  
  899. 4.5.4 TRANSFORMATIONS
  900.  
  901. * You can transform a nonprimitive shape using translate<>, rotate<>,
  902. scale<>: the composite is transformed.  This means that it's bounding
  903. shape is transformed, and it's objects and composites are transformed.
  904.  
  905. * Translation, rotation and scaling will only affect a CSG as far as
  906. it has been specified. For more information, look at the definition of
  907. hexagon in shapes.inc.
  908.  
  909. * All nonprimitive shapes (composites, CSG) can have their own
  910. texture. In PoV, only objects contained in a composite could have a
  911. texture
  912.  
  913.  
  914. 4.6    TEXTURES
  915.  
  916. Rayce's textures have more freedom than PoV's: every surface
  917. characteristic can have it's own color.  Although this isn't
  918. realistic, it can give nice effects.  I haven't implemented procedural
  919. textures yet, so checker- or marbletextures are not possible. For now,
  920. use an imagemap.
  921.  
  922. Textures have the following syntax:
  923.  
  924.     texture {
  925.       [texture_modifiers]
  926.     }
  927.  
  928. A texture_modifier is one of the following:
  929.  
  930.     ambient AMBCOLOR
  931.  
  932. the ambient color. It defaults to black.
  933.  
  934.     diffuse DIFFCOLOR
  935.  
  936. diffuse color, black by default.
  937.  
  938.     specular SPECCOLOR
  939.  
  940. This is the specular color.  In PoV this is always White.  (NB I've
  941. just found out, that this is not the PoV specular, but that these are
  942. Phong highlights)
  943.  
  944.     reflection REFLCOLOR
  945.  
  946. makes the surface reflect an AMOUNT part of the light, and it uses a
  947. REFLCOLOR filter.  default:  no reflection.
  948.  
  949.     refraction REFRCOLOR
  950.  
  951. makes the surface refract a REFRCOLOR part of the light.  Default:
  952. black, no reflection.
  953.  
  954. You can also use
  955.  
  956.     specular AMOUNT
  957.  
  958. This scales the specular color by AMOUNT. The same can be done for the
  959. other colors:
  960.  
  961.     ambient AMOUNT
  962.     diffuse AMOUNT
  963.     reflection AMOUNT
  964.     refraction AMOUNT
  965.  
  966.  
  967.     roughness ROUGHNESS
  968.  
  969. This is PoV's roughness factor. It defaults to 0.0. (actually, PoV's
  970. 1/phong)
  971.  
  972.     ior IOR
  973.  
  974. Index of Refrection, default: 1.0
  975.  
  976.     refract_angle ANGLE
  977.  
  978. maximum deviation for refracted rays. This causes blurred refraction.
  979.  
  980.     reflect_angle ANGLE
  981.  
  982. maximum deviation for reflected rays. This causes blurred reflection.
  983.  
  984. For PoV compatibility you can also specify
  985.  
  986.     color COLOR
  987.  
  988. This sets all colors (refraction, reflection, diff, ambient, specular)
  989. to COLOR, and the intensities to the default values used by PoV.
  990. (ambient 0.2, diffuse 0.6 etc.) From then on, these work PoV
  991. compatible:
  992.  
  993.     You can also use
  994.  
  995.     specular AMOUNT
  996.  
  997. This scales the specular color by AMOUNT. The same can be done for the
  998. other colors:
  999.  
  1000.     specular AMOUNT
  1001.     ambient AMOUNT
  1002.     diffuse AMOUNT
  1003.     reflection AMOUNT
  1004.     refraction AMOUNT
  1005.  
  1006.  
  1007. You can specify an imagemap: this is the syntax:
  1008.  
  1009.     image_map { FILETYPE FILENAME [map_type TYPE] [uvswap] [uvrange
  1010.       UR, VR] [uvoffset UO, VO] [once] [interpolate INTTYPE] }
  1011.  
  1012. This maps the file FILENAME onto the shape.  FILETYPE is the type of
  1013. the image which is in FILENAME.  The following types for FILETYPE are supported: 
  1014.  
  1015.     "tga" for Targa 24 bit uncompressed type 2 (the same type Rayce outputs)
  1016.     "gif" for a standard gif file.
  1017.  
  1018. map_type tells how the image should be wrapped around the object.
  1019. TYPE is one the following:
  1020.  
  1021.       0    maps the image onto the XY plane
  1022.       1    maps the image onto sphere centered in (0,0,0)
  1023.       2    maps the image onto cylinder along the Z axis.
  1024.       3    maps the image onto a torus lying in the XZ plane,
  1025.       radius 1.0
  1026.  
  1027. uvswap swaps the u and v parameters.  This is identical to rotating the
  1028. bitmap 90 degrees.
  1029.  
  1030. uvrange scales the bitmap down by UR, VR, ie.
  1031.  
  1032.     image_map { "marijke.gif" map_type 3 uvrange 2 2 }
  1033.  
  1034. will cause "marijke.gif" to be shrunk, until it fits 4 times on a
  1035. torus (two times along the big equator, two times along the small one)
  1036.  
  1037. uvoffset translates the image by UO, VO.
  1038.  
  1039. if "once" is set, then the image can be seen only once.
  1040.  
  1041. If you specify "interpolate" then interpolation is turned on. For PoV
  1042. compatibity, the interpolations should be followed by a integer, 0 for
  1043. no interpolation (default), something else for interpolation. The
  1044. interpolation is bilinear, anything else is not supported.
  1045.  
  1046. The color of an imagemap at (x,y,z) in R^3 is computed as follows:
  1047.  
  1048.     1. First find u and v for the desired image.
  1049.     2. Swap u and v if uvswap is set.
  1050.     3. Scale: u = u*UR, v = v*VR
  1051.     4. Translate: u = u + UO, v = v + VO
  1052.     5. Determine color:    
  1053.       a. if (once) and not (0.0 <= u,v <= 1.0) then return black.
  1054.       b. Get color at (u,v) in the image. If interpolation is
  1055.          turned on, then interpolate colors, else round the u,v
  1056.          coordinates and use that coordinate
  1057.  
  1058.  
  1059. Textures can be scaled, rotated and translated.
  1060.  
  1061.  
  1062.  
  1063. 4.7 TEXTURE HIERARCHY
  1064.  
  1065. A texture block which contains the object's texture.  If an object
  1066. doesn't have a texture, then Rayce uses the texture of its father.
  1067. Objects in Rayce have a hierarchy.
  1068.  
  1069.  
  1070.     #declare C = union {
  1071.       A
  1072.       B
  1073.     }
  1074.     union { C }
  1075.  
  1076. In this example, A and B are children of C, and C is a child of the
  1077. whole scene.  If Rayce registers a hit with primitive A, then it first
  1078. looks at A's texture.  If A doesn't have a texture, Rayce checks C for
  1079. a texture.  If C doesn't have a texture, then the Rayce checks C's
  1080. daddy.  C's daddy is the whole scene, and the whole scene always has a
  1081. texture, the default texture.
  1082.  
  1083. You can change the texture by putting this in your input file:
  1084.  
  1085.     default = texture { TEXT }
  1086.  
  1087. This will make TEXT the default texture. Take a look at hier.r for an
  1088. example of hierarchic textures.
  1089.  
  1090.  
  1091. 4.8.1    OBJECTS
  1092.  
  1093. In Rayce, objects are specified in this manner:
  1094.  
  1095.     SHAPENAME {
  1096.       shape_body
  1097.     }
  1098.  
  1099. or
  1100.     
  1101.     object {
  1102.       SHAPENAME {
  1103.         shape_body
  1104.       }
  1105.        }
  1106.  
  1107.  
  1108. SHAPENAME is one of the nine allowed shapes, shape_body the statements
  1109. with info about the shape in it.  The difference between these two
  1110. ways of specifying is: you can use speed and bounding shapes with the
  1111. latter.
  1112.  
  1113.  
  1114. 4.8.2. COMPOSITES
  1115.  
  1116. Rayce supports composites as well.  A composite collects a bunch of
  1117. shapes, and treats them as one.  This makes transforming and handling
  1118. a lot easier. A composite's syntax is the same as PoV's:
  1119.  
  1120.     composite {
  1121.       [OBJECTs|COMPOSITEs]
  1122.     }
  1123.  
  1124. Example:
  1125.  
  1126.       composite { 
  1127.        box {  <-1,1,1>, <2,3,4> } 
  1128.        object { heike }
  1129.       composite { Dikkerd }
  1130.         }
  1131.  
  1132.  
  1133. 4.8.3 TRANSFORMATIONS
  1134.  
  1135. These transformations on objects and composites are legal:
  1136.  
  1137. *    texture { }
  1138.  
  1139. An object can have a texture. 
  1140.  
  1141. Example:
  1142.    
  1143.   object { 
  1144.     sphere { <0,0,0>, 1 } 
  1145.     texture { ambient color red 1.0 }
  1146.   }
  1147.  
  1148. This is equivalent to 
  1149.  
  1150.   sphere { 
  1151.     <0,0,0>, 1 
  1152.     texture { ambient color red 1.0 }
  1153.   }
  1154.  
  1155. *    translate <> , rotate<>, scale<>
  1156.  
  1157. Translation, rotation and scaling will only affect a CSG as far as it
  1158. has been specified. For more information, look at the definition of
  1159. hexagon in shapes.inc.
  1160.  
  1161. *    speed <VELOCITY>
  1162.  
  1163. This says the composite will have a speed.  This is implemented by
  1164. adding SPEEDVECTOR to the speed of each object in the composite.
  1165.  
  1166. Note that only the bounding shapes of the noncomposite objects ("the
  1167. leafs in the tree") are moved along. (this is why I actually find this
  1168. motion blur a pain the reet, because it makes all kinds of stuff extra
  1169. complicated). So be careful about your bounding shapes with moving
  1170. objects. For a nice and smooth picture, don't forget to turn the numer
  1171. of frames from the options {} block up.
  1172.  
  1173. Note: this motion blur is only linear. Implementing rotational blur is
  1174. very expensive, so I haven't done it.
  1175.  
  1176. Example:
  1177.  
  1178.   object { 
  1179.     sphere { <0,0,0>, 1 } 
  1180.     speed <0,0,1>
  1181.   }
  1182.  
  1183.   composite {
  1184.     composite { fubar }
  1185.     object { fubular }
  1186.     bounded_by { box  { <-1,-1,-1>,<1,1,1> } }
  1187.     speed <0,0,1>
  1188.   }
  1189.  
  1190. this is not allowed.
  1191.  
  1192.   sphere { 
  1193.     <0,0,0>, 1 
  1194.     speed <0,0,1>    // WRONG! syntax error
  1195.   }
  1196.  
  1197.  
  1198. *    bounded_by { BOUNDINGSHAPES }
  1199.  
  1200. This means that the composite is bounded by BOUNDINGSHAPE. A lot of
  1201. shapes, especially compound shapes, take up a lot of time. To speed
  1202. this up, you can specify bounding shapes: simple shapes that encompass
  1203. a much more complex shape. This bounding shape should be closed; my
  1204. suggestion is to use a sphere or a box, if possible.
  1205.  
  1206. If an object has bounding shapes, then all rays are first tested
  1207. against these shapes, in the order which they have been specified.  If
  1208. this intersection test fails, or closer intersections have been found
  1209. previously, then the object itself is not tested.
  1210.  
  1211. Example:
  1212.  
  1213.   object { 
  1214.     algebraic { $ x^4 + y^4 + z^4 - 1 $ }
  1215.     bounded_by { box  { <-1,-1,-1>,<1,1,1> } }
  1216.   }
  1217.   
  1218.   composite {
  1219.     composite { fubar }
  1220.     object { fubular }
  1221.     bounded_by { box  { <-1,-1,-1>,<1,1,1> } }
  1222.   }
  1223.  
  1224. This is not allowed:
  1225.  
  1226.   algebraic { 
  1227.     $ x^4 + y^4 + z^4 - 1 $ 
  1228.     bounded_by { box  { <-1,-1,-1>,<1,1,1> } }    // WRONG! syntax error
  1229.   }
  1230.  
  1231.  
  1232. *     clipped_by { CLIPPINGSHAPES }
  1233.  
  1234. The object is clipped by SHAPE. A clipping shape is the Procrustes in
  1235. raytracing: a clipping shape cuts of all parts of an object that stick
  1236. out of the CLIPPINGSHAPES. If you want to use a shape as bounding
  1237. shape and clipping shape simultaneously, then you must use 
  1238.  
  1239.   clipped_by { bounded_by }
  1240.  
  1241. Example:
  1242.  
  1243.   object { 
  1244.     quadric { Cylinder_X }    // now it's infinite
  1245.     clipped_by { 
  1246.     box <-1,-1,-1>, <1,1,1> 
  1247.     sphere { <0,0,0>, 100 } 
  1248.     } 
  1249.     // now it's a tube, and you can look inside.
  1250.   }
  1251.  
  1252.   composite {
  1253.     composite { fubar }
  1254.     object { fubular }
  1255.     bounded_by { box { <-1,-1,-1>,<1,1,1> } }
  1256.     clipped_by { bounded_by }
  1257.   }
  1258.  
  1259.  
  1260.  
  1261. 4.8    # COMMANDS
  1262.  
  1263. If your scene file says:
  1264.  
  1265.     #include "foobar.inc"
  1266.  
  1267. then the parser will act as if the contents of foobar.inc are in the
  1268. place of the #include.  The '#' is optional: since the PoV team hasn't
  1269. made it mandatory, all '#' s in the input are treated is whitespace:
  1270. they are ignored.  If a file is opened, '[' is shown, and an "operator
  1271. pacification indicator" (.)  is printed every 25 lines read, after a
  1272. file has been read ']' is printed.
  1273.  
  1274. If you use objects, cameras, etc. a lot, you should declare them for
  1275. the greater benefit of the human race:
  1276.  
  1277.     #declare foo = object { sphere { <0, 0, 9>, 1 }
  1278.  
  1279. means you can use
  1280.  
  1281.     object { foo }
  1282.  
  1283. instead of
  1284.  
  1285.     object { sphere { <0, 0, 9>, 1 }
  1286.  
  1287. These can be declared:
  1288.  
  1289.     any shape:     #declare foo = sphere { .. }
  1290.     camera:     #declare foo = camera { .. }
  1291.     color:      #declare foo = color red ....
  1292.     texture:    #declare foobar = texture { ... }
  1293.     vector expressions:
  1294.             #declare fub = <0, 1, 0>^<1,0,0>
  1295.     floating point expressions:
  1296.             #declare blab = 1.34/2
  1297.     image_maps:    #declare auk = image_map { .. }
  1298.  
  1299. You can expect Bad Things to happen if you try something like:
  1300.  
  1301.     #declare foo = object { sphere { bla } texture { foo } }
  1302.  
  1303. If you attempt to save memory, don't use declarations: they only cost
  1304. more memory during the parsing stage. Actually #define would have been
  1305. a better term, but I didn't invent the PoV syntax.
  1306.  
  1307.  
  1308. 5.    COMPILING RAYCE
  1309.  
  1310. You can compile Rayce yourself if you want; then you have to get the
  1311. sources to Rayce, which should be available from the same source
  1312. you've got this from. Refer to tech.doc, included with the sources.
  1313.  
  1314.  
  1315. 7.    ME
  1316.  
  1317. About the author: I am a student, as of today (Januari 15 '94) I am
  1318. 19, and I study applied mathematics at the Eindhoven University of
  1319. Technology, in the Netherlands.  I am in my second year, and I spend
  1320. too little time on my study. Oh well. Raytracing is my hobby. If I
  1321. am not spending my time behind my computer I also play the French horn
  1322. and the piano.
  1323.  
  1324. The following have been helpful in developing Rayce:
  1325.  
  1326.     - the sources to MTV, PoV, Rayshade, Vort, Ray, Graphics Gems 
  1327.  
  1328.     - The fractal.028 and PCGNet Raytracing echo community for
  1329.     making me happy with mail.
  1330.  
  1331.     - "Tutorial: Computer Graphics: Image Synthesis", Kenneth I
  1332.     Joy, a.o.  ISBN 0-8186-8854-4.
  1333.  
  1334.     - "Three Dimensional Computer Graphics", Alan Watt, Addison
  1335.     Wesley.  
  1336.  
  1337.     - "Advanced Rendering and Animation Techniques", Alan Watt &
  1338.     Mark Watt, Addison Wesley.
  1339.  
  1340.     - Linus Torvaldsen, for creating Linux, an excellent free Unix
  1341.     system for the 386/486 PCs. Try it! It's the best thing since
  1342.     sliced bread (The next best thing after linux being Rayce, of
  1343.     course! :)
  1344.  
  1345. If you want something implemented, or if you want to hack something
  1346. yourself: please contact me, so other people can benefit from it too.
  1347. I also appreciate any comment on the Rayce, its sources and its docs.
  1348.  
  1349. I hope that all mathematics were understandable, and that my English
  1350. doesn't show that I normally speak Dutch.
  1351.  
  1352. Send your compliments, beer, bugreports and daughters to:
  1353.  
  1354.     Han-Wen Nienhuys
  1355.     Dommelseweg 1A
  1356.     5581 VA Waalre
  1357.     The Netherlands
  1358.  
  1359. But email is preferred for the compliments and bugreports, of course:
  1360.  
  1361.     hanwen@stack.urc.tue.nl
  1362.  
  1363. If you can't find me there, then try my dad's account:
  1364.  
  1365.     wsadjw@urc.tue.nl
  1366.  
  1367. If you are connected to fidonet, then you can reach me at 
  1368.  
  1369.     2:284/102.27
  1370.  
  1371. My PCGNet address is
  1372.  
  1373.     9:580/203.56
  1374.  
  1375. You could also try post a message to fractal.028, a fidonet graphics
  1376. echo in Holland.  I will try to have the latest version of Rayce
  1377. available at
  1378.  
  1379.     Bennekom BBS: fido node 2:283/203, PCGNet 9:580/203, tel.
  1380.     31-8389-15331. (freqqing times: 07.30 to 01.00, local time)
  1381.  
  1382. Bennekom BBS supports V32bis and V42bis. I regularly read the PCGNet
  1383. raytracing echo, and I am subscribed to the DKB-L mailing list.
  1384.  
  1385.  
  1386. 8.    HISTORY AND TODO-list
  1387.  
  1388. See the file "history.doc".
  1389.  
  1390.  
  1391. 9.    SYNTAX
  1392.  
  1393. Use The Source, Luke!
  1394.  
  1395.  
  1396. 10.    BUGS
  1397.  
  1398. Yes.
  1399.  
  1400.  
  1401.  
  1402. But seriously :), I am not a big tester myself. It is very probable
  1403. that Rayce contains bugs. 
  1404.  
  1405. * Maybe you will see "assert failed file XXX.c, line XXX". These are
  1406. messages you shouldn't ever get to see, they show that some internal
  1407. consistency check failed. If you see this, then please mail a
  1408. bugreport to me.
  1409.  
  1410. (On the other hand, if it came from csg.c, you are probably not using
  1411. correct shapes. Make sure extrusions and cylinders are closed, and
  1412. use the "closed" keyword correctly)
  1413.  
  1414. * If Rayce crashes, that's obviously subversive behaviour of Rayce.
  1415. Especially if the crashes are violent, you should report them.
  1416.  
  1417. * If you find very subtle bugs, I am also very interested. On the
  1418. average, it takes me two new versions before I discover those kind of
  1419. errors. I should do more testing.  Yes. I know. But coding is so much
  1420. more fun.
  1421.  
  1422. Known bugs:
  1423.  
  1424.     - Some algebraics don't render correctly. This is probably
  1425. caused by the root finder, which was copied from Vort almost verbatim.
  1426. When I learn numerical methods (in a few months) I'll take another
  1427. look at it.
  1428.  
  1429.     - Some algebraics have singular points, where there is no
  1430. normal to the surface (the normal is <0,0,0> ). When this happens,
  1431. "NNV # XXX.c" is printed, with line number and the file where it
  1432. happened.
  1433.  
  1434.     - Some algebraics aren't fun calculate precisely. If you use
  1435. sturm sequences, you will sometimes see solve.c scream if you use the
  1436. runtime warnings turned on (-d4). This happens because the sturm code
  1437. first tries a fast way of calculating a root.
  1438.  
  1439. Check out the history.doc on resolved bugs, and stuff that needs to be
  1440. done.
  1441.  
  1442.  
  1443.  
  1444. 11.    DISTRIBUTED RAYTRACING.
  1445.  
  1446. Detailed information on what distributed ray tracing is can be found
  1447. in the paper by Cook, Porter and Carpenter: "Distributed Ray Tracing",
  1448. ACM Computer Graphics, Vol.18, Num.3, July 1984. [Note: this paper is
  1449. also included in "Image Synthesis"] 
  1450.  
  1451. [Note: what follows is a interpretation of what I think distributed
  1452. raytracing is, so no garantuee is made that it is correct. ]
  1453.  
  1454. Distributed raytracing is a process used to model "fuzzy" phenomena,
  1455. such as soft shadows, focal blur, motion blur, fuzzy reflections and
  1456. fuzzy refractions. In raytracing, refractions usually are crystal
  1457. clear, and and reflections look unrealistically crisp. The shadows
  1458. have sharp edges. Although this is good for generating nifty pictures,
  1459. it is not realistic. In the real life, shadows don't have these sharp
  1460. edges, and you cannot comb your hair using a teaspoon as a mirror.
  1461.  
  1462. Let's take a closer look at this spoon. The surface of this spoon is
  1463. scratched and bumped. Indeed, if you would look at the surface through
  1464. a microscope you'd see a pretty wobbly surface. So not all of the
  1465. light falling on the metallic surface will be reflected in the same
  1466. direction.
  1467.  
  1468. Since light works bidirectional, this also means that eyerays cast
  1469. onto the surface don't generate one single reflection ray, but a huge
  1470. number of "small" reflection rays, all in slightly different
  1471. directions.  The light of a reflection we're searching for is the sum
  1472. of all these tiny contributions from various directions.
  1473.  
  1474. Mathematically speaking: the intensity I of the incoming light at a
  1475. point P, is a function of the direction D from which the light is
  1476. coming, and of the location on the surface (P), so 
  1477.  
  1478.   I = I(D, P)
  1479.  
  1480. Because the surface is bumped, the light coming from a direction D
  1481. will be reflected in P for percentage dependent on: D, the
  1482. "theoretical" reflection direction R, and the surface normal N at P.
  1483. So the reflection r percentage is:
  1484.  
  1485.    r (D, N, R)
  1486.  
  1487. So what we will be seeing of a reflected light from a certain direction is
  1488.   
  1489.    r (D, N, R) * I (D)
  1490.  
  1491. And the total reflection is the sum of all these tiny bits:
  1492.  
  1493.           /
  1494.    total  =       |           I(D)*r(D,N,R) 
  1495.           /
  1496.             all directions D
  1497.  
  1498. Of course in practical situations, this mathematical descriptions
  1499. isn't gonna help us. However, we could aproximate the above integral
  1500. by carefully choosing a few (say 16) directions D, and summing all
  1501. contributions:
  1502.  
  1503.          
  1504.                   __         
  1505.    total = 1/16   \   I(D) * r(D,N,R)
  1506.          ~        /_
  1507.  
  1508.            some directions D
  1509.  
  1510.  
  1511.  
  1512. This is the process which is modeled via "distributed" raytracing:
  1513. instead of one, multiple reflection rays are spawned off the surface
  1514. of our spoon. In effect, we are taking discrete samples of the "real"
  1515. reflection I*r, which is a continuous function.
  1516.  
  1517. In rayce: penumbra, and fuzzy refraction is also modelled in this way.
  1518. There is one caveat: If we would spawn N rays at each intersection
  1519. point for determining the fuzzy reflection/refraction/shadow, then we
  1520. would be tracing O((3N)^depth) rays. If we'd have complex scenes,
  1521. rendering would take a really LONG time. So instead rayce shoots a
  1522. fixed number of eyerays. All these eyerays are sampled differently at
  1523. each intersection point (this is called multidimensional sampling.
  1524. Sounds good, huh? :-).
  1525.  
  1526. At present, the rays are sampled with a simple random function. This
  1527. will be changed in the future.
  1528.  
  1529. Of course, you could do the sampling with 1 eyeray only. But then the
  1530. blur won't be so good since Rayce evaluates the color of the ray with
  1531. only one try.  The more samples the better, but if you use a higher
  1532. resolution, then less samples per pixel suffice.
  1533.  
  1534. The refl_diffuse and refr_diffuse produce non-sharp reflections and
  1535. refractions.  The argument is in degrees.  Anything less than 15 or 20
  1536. is good, altough the closer to zero the better you can see it.
  1537.  
  1538.  
  1539.