home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 4 / Amiga Tools 4.iso / grafix / raytracing / raylab / docs / raylab.doc < prev   
Encoding:
Text File  |  1996-02-17  |  39.7 KB  |  1,137 lines

  1.  
  2.                                   R A Y L A B
  3.  
  4.                                   version 1.0
  5.                                      rev 1
  6.  
  7.                               Users Documentation
  8.  
  9.                         (c)1995-1996 by Marcus Geelnard
  10.  
  11.  
  12.  
  13.  
  14.                                Table of contents
  15.                                -----------------
  16.  
  17. 1     INTRODUCTION
  18.  
  19.   1.1  Intentions with RayLab
  20.  
  21.   1.2  What does RayLab do?
  22.  
  23. 2     FEATURES   
  24.  
  25.   2.1  Primitives
  26.  
  27.   2.2  Textures
  28.  
  29.   2.3  Transforms
  30.  
  31.   2.4  Antialiasing
  32.  
  33.   2.5  Display
  34.  
  35. 3     HOW TO CREATE 3D IMAGES WITH RAYLAB
  36.  
  37.   3.1  An example scene
  38.  
  39. 4     LANGUAGE REFERENCE
  40.  
  41.   4.1  Primitives
  42.     4.1.1  Sphere
  43.     4.1.2  Ellipsoid
  44.     4.1.3  Plane
  45.     4.1.4  Box
  46.     4.1.5  Triangle
  47.     4.1.6  Disc
  48.     4.1.7  Cylinder
  49.  
  50.   4.2  Lights
  51.  
  52.   4.3  Camera
  53.     4.3.1  Location
  54.     4.3.2  Viewpoint
  55.     4.3.3  Aspect
  56.  
  57.   4.4  Textures
  58.     4.4.1  Color
  59.     4.4.2  Colormap
  60.     4.4.3  Pattern
  61.       4.4.3.1  checker
  62.       4.4.3.2  circles
  63.       4.4.3.3  rings
  64.       4.4.3.4  spots
  65.       4.4.3.5  gradient
  66.       4.4.3.6  none
  67.     4.4.4  Reflect
  68.     4.4.5  Diffuse
  69.     4.4.6  Ambient
  70.     4.4.7  Phong
  71.     4.4.8  Phongsize
  72.     4.4.9  Default
  73.  
  74.   4.5  Deftexture
  75.  
  76.   4.6  Transform
  77.     4.6.1  Scale
  78.     4.6.2  Move
  79.     4.6.3  Rotate
  80.     4.6.4  None
  81.  
  82.   4.7  Deftransform
  83.  
  84.   4.8  Globals
  85.     4.8.1  Picwidth
  86.     4.8.2  Picheight
  87.     4.8.3  Backgroundcolor
  88.     4.8.4  Recdepth
  89.     4.8.5  Display
  90.     4.8.6  Antialiasrec
  91.     4.8.7  Antialiasthreshold
  92.  
  93.   4.9  Comments
  94.  
  95. 5     MISCELLANEOUS
  96.  
  97.   5.1  How to contact the author
  98.  
  99.   5.2  Legal stuff
  100.  
  101.   5.3  Past, present and the future
  102.  
  103.   5.4  Comments by the author
  104.  
  105.  
  106.  
  107. 1.  INTRODUCTION
  108. ================
  109.  
  110. 1.1 Intentions with RayLab
  111. --------------------------
  112.  
  113. My intention with RayLab was, first of all, to create a decent raytracer based
  114. on my newfound (rather limited) knowledge in linear algebra, as I took a course
  115. in that particular subject at the university. I also wanted to improve my
  116. skills in C-programming (this is my third 'real' C program). As it turned out
  117. it was not hard at all to create a working program, and after about a week of
  118. programming I could already produce good looking pictures with shades, reflect-
  119. ions, highlights, texture-patterns and several different shape primitives. A
  120. working (but primitive) description language had also been introduced success-
  121. fully at that time.
  122.  
  123. RayLab is rather slow as it is not really optimized in any way, and that is the
  124. way I intend to keep it. I am more interested in getting a working program
  125. with (more or less) powerful features than a sporting competitor to those other
  126. brilliant raytracers, developed by far more experienced persons than me. It may
  127. also be mentioned that I have not bothered to look up any information on ray-
  128. tracing in particular, as I am more interested in putting geometry theory into
  129. practice than to produce a commercial program. But feel free to enjoy it
  130. anyway!
  131.  
  132.  
  133. 1.2 What does RayLab do?
  134. ------------------------
  135.  
  136. RayLab is capable of producing realistic three-dimensional images using a tech-
  137. nique called 'raytracing'. What it basically means is that you place 3D objects
  138. in a space (room, world, scene or whatever you like to call it). Then you add
  139. some light-sources and a camera. What the raytracer does is to mathematically
  140. calculate what the picture would look like, if it was to be taken by a real
  141. camera. This is done by dividing the picture into small elements (pixels) and
  142. for each element, a ray (or beam) is casted, from the camera out into the
  143. three-dimensional space. If this ray 'hits' an abject, some steps are taken:
  144. 1) The color of the object is checked.
  145. 2) The light from different light-sources are checked, and also another ray
  146.    (from the point on the object to the light-source(s)) is casted to see if
  147.    any other objects block the light. This way shadows are produced.
  148. 3) If the object is reflective, a new ray will be casted to see if any other
  149.    objects are visible thorugh reflection of the first object.
  150. 4) If the object is transparent, a new ray will be produced which continues on
  151.    the other side of the surface of the object (this is not supported in RayLab
  152.    yet, unfortunately).
  153.  
  154. The information from all these calculations is used to set the color of the
  155. pixel in the picture. This procedure is repeated for every ray, including all
  156. 'camera-rays' and those produced by reflection and transparency. As you would
  157. probably guess, this requires a great deal of computation. On a normal personal
  158. computer calcualtion times of several hours are not too uncommon (a processor
  159. with good floating point performance is strongly recommended).
  160.  
  161.  
  162.  
  163. 2  FEATURES
  164. ===========
  165.  
  166. RayLab is a program that will probably be updated with new features every now
  167. and then, as I like experimenting with new effects, but for now we will have to
  168. settle for a rather limited set of features.
  169.  
  170.  
  171. 2.1  Primitives
  172. ---------------
  173.  
  174. Primitives are the basic shapes that make the building blocks of objects. Some
  175. raytracers are specialized at only handling objects built up from triangles
  176. (just as a 2D object can be built up from lines, a 3D object can be described
  177. by triangles, but only roughly), but RayLab handles several different shapes.
  178. Those are (at the moment): sphere (perfectly round), ellipsoid, plane (infinitly
  179. long and wide), box, triangle, disc and cylinder.
  180.  
  181.  
  182. 2.2  Textures
  183. -------------
  184.  
  185. As we all know, an object needs to have a surface texture. In RayLab this
  186. means a set of properties that describes the looks and feels of a surface. The
  187. different properties are: color (or set of color-shades), pattern, diffuse
  188. reflection (color intensity proportional to surrounding light-sources), high-
  189. light intensity and concentration, ambient light, and finally reflection.
  190. Important properties that have been 'left out' are transparency and refraction.
  191. This will certainly be implemented in the next major release of RayLab.
  192.  
  193.  
  194. 2.3  Transforms
  195. ---------------
  196.  
  197. In the common case, primitives and textures do not always match the object
  198. shape and look that you want. Therefor you may need to transform a shape and/or
  199. texture into what you need for your specific needs. For instance the box
  200. primitive is always aligned along the x-y-z-axises, which is not always conv-
  201. enient when you want to construct complex scenes. This is where the transform-
  202. ation facilities of RayLab come in handy; just apply a rotation to the box to
  203. make it fit into your scene. All primitives can be transformed in one of the
  204. following ways: scaling, movement (displacement) and rotation. This is also
  205. valid for all textures. Be warned though: transformation can consume very much
  206. computation power, especially rotation of primitives, so do not use it unless
  207. you need it (or have a monster computer).
  208.  
  209.  
  210. 2.4  Antialiasing
  211. -----------------
  212.  
  213. When you render a picture with a computer program such as RayLab, chanses are
  214. that the picture will look too 'jaggy'. This is because the pixels on the
  215. computer screen are square, and often visible to the eye. With antialiasing
  216. this rough look can be eliminated. The idea is to use several rays per pixel,
  217. and calculate the average color found by these rays. This method gives a very
  218. smooth and realistic appearance, but it also consumes more computation power.
  219.  
  220.  
  221. 2.5  Display
  222. ------------
  223.  
  224. One useful feature of RayLab is that it can display the output picture to your
  225. screen while rendering it. This is good for displaying previews. Currently only
  226. the Amiga version of RayLab has support for graphical displays, but I hope for
  227. more persons to develop display routines for different platforms.
  228.  
  229.  
  230.  
  231. 3  HOW TO CREATE 3D IMAGES WITH RAYLAB
  232. ======================================
  233.  
  234. To have RayLab create a picture for you, you first have to describe the pict-
  235. ure to it. This is done by setting up a 'scene', which can be created in any
  236. text-editor or word-processor that can save raw ascii files (Amiga: ced, ed,
  237. PC: edit, Unix: vi, emacs, nedit... etc.). The description is made in a special
  238. language, which will be described in detail in chapter 4. In the scene you will
  239. need to have at least one object and one light-source. You will probably want
  240. to set up a camera and a few parameters aswell (such as picture width and
  241. height).
  242.  
  243.  
  244. 3.1  An example scene
  245. ---------------------
  246.  
  247. To get to know a program or programming language, it is always wise to look at
  248. demonstration examples. So to get things started, here is an example of a
  249. complete scene description (detailed explanations will follow). This scene can
  250. also be found in the scenes directory, named 'demo1.rl':
  251.  
  252. ------------8X--------------------------------------------------------------
  253.  
  254. Globals:
  255.     picwidth 320               # Image dimensions: 320x240
  256.     picheight 240
  257.     backgroundcolor 0 0 0      # Red=0, green=0, blue=0 => black
  258. :end
  259.  
  260. Sphere:
  261.     centre  0 0 2              # Place the sphere in x=0, y=0, z=2
  262.     radius  2                  # ...and it will have a radius of 2 units
  263. :end
  264.  
  265. Light:
  266.     location 3 -8 4            # A light-source at x=3, y=-8, z=4
  267.     color    1 1 1             # Red=1.0, green=1.0, blue=1.0 => white
  268. :end
  269.  
  270. Camera:
  271.     location -1 -9 2           # Place the camera in x=-1, y=-9, z=2
  272.     viewpoint 0 0 2            # Look at x=0, y=0, z=2
  273. :end
  274.  
  275. ------------8X--------------------------------------------------------------
  276.  
  277. On the first line, the keyword 'Globals:' is found. This means that the next
  278. section will contain some information that is global to the whole scene. This
  279. section is ended by the keyword ':end' on line five. On the second line the
  280. picture width is declared by 'picwidth 320'. Next follows a comment, which is
  281. started by a '#' and ended by the end of the line. On the next line the picture
  282. height is declared. The fourth line says 'backgroundcolor 0 0 0', which means
  283. that the background color should be black. All colors in RayLab are described
  284. by their red, green and blue components, in that order, each component ranging
  285. from 0.0 (min) to 1.0 (max).
  286.  
  287. The next section describes a primitive. This primitive is a sphere with its
  288. centre in (0,0,2), and the radius 2. All points and vectors in RayLab are de-
  289. scribed by their x, y and z components, and are aligned to a right-hand system.
  290. This means that the x-axis pionts right, the y-axis away and the z-axis points
  291. upwards. The sphere is not given a texture, so it will use the default texture.
  292. The default texture is, if none else given, a non-reflective dull red surface.
  293.  
  294. The third section describes a light-source, which is located at (3,-8,4) and
  295. has the color white (all three components are set to their maximum value 1.0).
  296. The light-source casts its light all the way to the infinity in all directions.
  297.  
  298. Last, but not least, a camera is set up. The parameters location and viewpoint
  299. sort of speaks for themselves.
  300.  
  301. To finally render (compute) the picture which is described by this scene, you
  302. just have to call RayLab from your shell (cli, dos, or whatever) with the
  303. following syntax:
  304.  
  305.      raylab description-file picture-file
  306.  
  307. ...where description-file is the file that contains the descrition text (i.e.
  308. the example above), and the picture-file is the output image file, which will
  309. be saved in targa 24-bit format (.tga). To render the example above, type:
  310.                    raylab  scenes/demo1.rl demo1.tga
  311. That will produce a targa picture named 'demo1.tga'.
  312.  
  313.  
  314.  
  315. 4  LANGUAGE REFERENCE
  316. =====================
  317.  
  318. The description language that RayLab uses is very simple, although you may
  319. argue that it can look a bit dull (I agree). I have tried to make the interpr-
  320. eter as flexible as possible though to leave the layout to the user. This has
  321. been accomplished by the following means:
  322.  
  323. o  Keywords can be entered in any order.
  324. o  RayLab is totally case insensitive (SpHeRe: is the same thing as SPHERE:)
  325. o  RayLab does not differ between spaces, tabs and line-feeds (except when
  326.    you use comments), so indents, line-spaces etc. does not make a difference
  327.    to RayLab; e.g. you can write several keywords on one line.
  328. o  In many cases you can leave some keywords out. This will result in that
  329.    RayLab will use default settings for those keywords that are not specified.
  330.  
  331. A description is built up from several "sections", each section biginning with
  332. a keyword with a terminating colon (e.g. Box:), and ending with :end. Sections
  333. may also have sub-sections. For instance a primitive may have a texture speci-
  334. fication, which is also a section.
  335.  
  336.  
  337. 4.1  Primitives
  338. ---------------
  339.  
  340. As mentioned before, the so called primitvies are the actual shapes that you
  341. will use to build your scene. Each primitive is declared by creating a section
  342. that describes the primitive.
  343.  
  344.  
  345. 4.1.1  Sphere
  346.  
  347. The sphere primitive is a classic round shape, which is defined by its location
  348. in space (centre) and its radius. Example:
  349.  
  350. Sphere:
  351.     centre 0 0 3
  352.     radius 2
  353. :end
  354.  
  355. The default sphere has the radius 1.0 and has its centre at (0,0,0).
  356.  
  357.  
  358. 4.1.2  Ellipsoid
  359.  
  360. The ellipsoid is a more or less redundant shape, as it can be produced from a
  361. scaled sphere, but it was the first primitive introduced in RayLab and as such
  362. is kept due to nostalgic reasons. Unlike the sphere, the ellipsoid needs three
  363. values to describe the radius, one for each axis. Example:
  364.  
  365. Ellipsoid:
  366.     centre 0 0 3
  367.     radius 2 1.5 4
  368. :end
  369.  
  370. The default ellipsoid has the radius (1,1,1) and is located at (0,0,0).
  371.  
  372.  
  373. 4.1.3  Plane
  374.  
  375. A plane is an infinitely long and wide, totally flat surface. It is defined by
  376. its surface normal, which is orthogonal to the surface, and its offset along
  377. this normal. This example shows a plane which could be described as all points
  378. (x,y,z) which has x=-1 (regardless of y and z):
  379.  
  380. Plane:
  381.     normal 1 0 0
  382.     offset -1
  383. :end
  384.  
  385. The default plane has the surface normal (0,0,1) and offset 0.0, i.e. it
  386. stretches along the x and y axis.
  387.  
  388.  
  389. 4.1.4  Box
  390.  
  391. The box is simply a polyhedron with six sides, like a dice. It is described
  392. by two points in space. For instance, a cube with its eight courners:
  393. (0,0,0), (2,0,0), (2,2,0), (0,2,0), (0,0,2), (2,0,2), (2,2,2), (0,2,2),
  394. would look like this described to RayLab:
  395.  
  396. Box:
  397.     corners  0 0 0
  398.              2 2 2
  399. :end
  400.  
  401. Thus each side of the box is always parallel to two of the axises. To create
  402. a box with any alignment, you can simply transform it.
  403.  
  404. The default box is a box with the corners (0,0,0), (1,1,1).
  405.  
  406.  
  407. 4.1.5  Triangle
  408.  
  409. A triangle is defined by its three corners in space. Example:
  410.  
  411. Triangle:
  412.     corners  0 0 -1
  413.                  3 -2 4
  414.                  -5 -1 3
  415. :end
  416.  
  417. The default triangle has the corners (0,0,0), (1,1,1), (-1,1,1).
  418.  
  419.  
  420. 4.1.6  Disc
  421.  
  422. The disc is an infinitely thin surface, just like the plane. The difference
  423. between the plane and the disc, is that the disc has a radius, whereas the plane
  424. is infinitely long and wide. Thus the disc looks like a disc (he-he). The defin-
  425. ition of a disc requires three parameters: centre, normal and radius. Example:
  426.  
  427. Disc:
  428.         centre   2 -3 2
  429.         normal   1 -2 1
  430.         radius   1.5
  431. :end
  432.  
  433. The default disc has the following settings:
  434.         centre:  (0,0,0)
  435.         normal:  (0,0,1)
  436.         radius:  1
  437.  
  438.  
  439. 4.1.7  Cylinder
  440.  
  441. The cylinder is defined by its radius and its height, and it always has the z-
  442. axis as its centre axis. The ends of the cylinder are "closed" by two discs (all
  443. in the spirit of solid geometry). The centre of the first end is always (0,0,0),
  444. while the second end is located at (0,0,height). Just transform the cylinder to
  445. make it fit your needs. This example demonstrates a cylinder that lies along the
  446. x-axis, with its ends in (-3,0,0) and (3,0,0):
  447.  
  448. Cylinder:
  449.     radius 1.4
  450.     height 6
  451.     transform:
  452.         rotate 0 90 0
  453.         move -3 0 0
  454.     :end
  455. :end
  456.  
  457. The default cylinder has a radius of 1.0 and the height 1.0.
  458.  
  459.  
  460. 4.2  Lights
  461. -----------
  462.  
  463. Every scene needs at least one light-source. Light-sources in RayLab are s.c.
  464. point lights, which means that they cast their light in all directions, and
  465. they are infinitely small (you can not see them if you turn your camera to
  466. look at them). Light-sources can have different colors, and thereby also
  467. different intensities (a grey light-source does not give as much light as a
  468. white light-source does). A light-source is simply defined by a location and a
  469. color. Example:
  470.  
  471. Light:
  472.     location  -20 -30 40
  473.     color     1.0 0.0 0.0
  474. :end
  475.  
  476. This will place a red light-source at (-20,-30,40).
  477.  
  478. The default light-source is located at (10,-10,10), and has the color white.
  479.  
  480.  
  481. 4.3  Camera
  482. -----------
  483.  
  484. The camera is indeed a very important part of the scene. The camera does not
  485. have a shape, and will not be seen through a mirror or alike, but it can be
  486. manipulated to change the appearance of a picture drastically.
  487.  
  488.  
  489. 4.3.1  Location
  490.  
  491. The camera can be placed anywhere in space. This is given by the keyword
  492. location.
  493.  
  494. The default location is (0,-10,1).
  495.  
  496.  
  497. 4.3.2  Viewpoint
  498.  
  499. When the camera has been placed, it also needs to be directed to look at some
  500. point in space. In RayLab you only have to tell where to look at with the key-
  501. word viewpoint. The direction of the camera will be calculated automatically.
  502.  
  503. The default viewpoint is (0,0,0).
  504.  
  505.  
  506. 4.3.3  Aspect
  507.  
  508. The camera is also defined by its x:y:z aspect, which enables you to set the
  509. pixel-aspect of the output picture and the field of view of the camera. The x:y
  510. aspect should be the same as that of the output picture. E.g. a 640x480 picture
  511. has the aspect 4:3 if the pixels are to be completely square. If the picture is
  512. to be displayed on a screen with non-square pixels (e.g. an NTSC TV) you will
  513. have to change the x:y aspect to more sutible values. The aspect ratios does
  514. not have to be integer values in RayLab. The z-aspect is the 'depth' of the
  515. lens, and it is also proporional to the x and y aspect. With the z aspect you
  516. may change the field of view. This figure may be of some help:
  517.  
  518.                                       |--
  519.                                       |  --
  520.                                     Y |    --
  521.                                       |      --
  522.                               Z       |        |                    
  523.               +->  (+)- - - - - - - - - - +    |
  524.               |                       |        |
  525.               |                        --      |
  526.        Camera location                   --    |
  527.                                         X  --  |
  528.                                              --|
  529.  
  530. Larger values of the z aspect will give more tele-zoom, and smaller values will
  531. give wide-angle views.
  532.  
  533. Here is an example of a camera with extreme tele-zoom:
  534.  
  535. Camera:
  536.     location  0 -100 30            # We have to back off a bit due
  537.     viewpoint 0 0 0                # to the zooming
  538.     aspect    4 3 20
  539. :end    
  540.  
  541. The default aspect is 4:3:5, which gives quite a normal angle of view.
  542.  
  543.  
  544. 4.4  Textures
  545. -------------
  546.  
  547. A good surface texture will always make an object more interesting. To add or
  548. change a texture of a primitive, add a texture-section to the primitive declar-
  549. ation. Example:
  550.  
  551. Plane:
  552.     normal 0 0 1
  553.     offset -2
  554.     texture:
  555.         color 0.5 0.4 0.8
  556.         pattern spots
  557.         reflect 0.5 0.4 0.5
  558.         phong 0.6
  559.     :end
  560. :end
  561.  
  562. In the following sections all supported texture keywords will be described.
  563.  
  564.  
  565. 4.4.1  Color
  566.  
  567. In RayLab all primitives have an own color, which can be specified by the key-
  568. word color. Following the keyword there should be three decimal values specify-
  569. ing the red, green and blue components of the color. The values can range from
  570. 0.0 (0%) to 1.0 (100%).
  571.  
  572. The default color is 1.0 0.3 0.0, which is 100% red + 30% green.
  573.  
  574.  
  575. 4.4.2  Colormap
  576.  
  577. When you want to give an object surface a pattern (e.g. the rings of a piece of
  578. wood), it is not satisfying to only have one color for the object. Normally you
  579. want to have a set of colors, and smooth transitions between those colors. This
  580. is acomplished with a colormap. A colormap sort of creates a spectrum with
  581. different colors, just like the sky can have nice transitions between red and
  582. blue and maybe some other colors when the sun sets. A colormap can consist of a
  583. maximum of ten entries. Each entry is given a color, and a place in the map.
  584. This place is a value between 0.0 and 1.0. When you declare a colormap you also
  585. have to give the amount of entries by an integer value following the keyword
  586. colormap. Here is an example of a colormap with the colors of the rainbow:
  587.  
  588.     colormap 7                # This colormap contains seven entries
  589.         0.0   0.4 0.0 0.7     # The first entry (at 0.0) has the color 0 0 0.9
  590.         0.3   0.0 0.0 0.9
  591.         0.4   0.0 0.4 1.0
  592.         0.6   0.0 1.0 0.0
  593.         0.75  1.0 1.0 0.0
  594.         0.9   1.0 0.0 0.0
  595.         1.0   0.4 0.0 0.0     # The last entry (at 1.0) has the color 0.4 0 0
  596.  
  597. Note: All entries must be entered in ascending order with 0.0 first and 1.0
  598. last.
  599.  
  600. Actually, when a color is specified with the color keyword, a colormap with two
  601. entries is created; the first entry is 0.0, with the color which is specified
  602. after the color keyword, and the second entry is 1.0, with the color black.
  603. This is done so that a pattern will be visible even if only one color is speci-
  604. fied. This means that the default colormap has two entries: the first is red
  605. and the second is black.
  606.  
  607.  
  608. 4.4.3  Pattern
  609.  
  610. Patterns can significantly improve the appearance of an object. RayLab gives
  611. you a variety of patterns to chose from, and more are sure to come. A pattern
  612. will assign a value to each point of the object. This value ranges from 0.0 to
  613. 1.0 and is used as index to the colormap of the object. Now follows a descript-
  614. ion of the currently available patterns in RayLab. Experiment with them on
  615. different shapes to get to know how they work!
  616.  
  617.  
  618. 4.4.3.1  checker
  619.  
  620. Now this is a pattern we all want! A raytracer is not worth the name without
  621. this pattern. The checker pattern is simply an infinite amount of 1x1x1 cubes
  622. in 3D space. If applied to a plane it will look just like a chess-board, but if
  623. you apply it to a sphere it can look rather strange (try it, and you will see
  624. exactly how it works!). Each checker can have one of two colors, and the color
  625. is chosen from the colormap of the object. The first color is picked from the
  626. colormap with index 0.0, and the second will be picked with index 1.0. Here
  627. is an example of a blue and green checkered texture:
  628.  
  629.     texture:
  630.         pattern checker
  631.         colormap 2
  632.             0  0 0 1
  633.             1  0 1 0
  634.     :end
  635.  
  636.  
  637. 4.4.3.2  circles
  638.  
  639. Circles are like onion-rings. The colormap index is simply proportional to the
  640. distance from (0,0,0). Within one unit-distance the index-value changes from
  641. 0.0 to 1.0, then it goes back to 0.0 and increaces to 1.0 at two units, and
  642. then it starts over again...
  643.  
  644.  
  645. 4.4.3.3  rings
  646.  
  647. The rings pattern works like circles, but it only depends on the x-y coordi-
  648. nates. This means that it extend along the z-axis, and is very well suited for
  649. wooden textures.
  650.  
  651.  
  652. 4.4.3.4  spots
  653.  
  654. The spots pattern will simply produce spots on the surface of the object. The
  655. centre of the spot will get the color from the colormap at 0.0. The further
  656. away from the centre of the spot, the larger the colormap index. At the edge
  657. of the spot, and outside of the spot, the colormap index is 1.0.
  658.  
  659.  
  660. 4.4.3.5  gradient
  661.  
  662. This is probably the simplest pattern possible. The colormap index changes with
  663. the z-axis. It increases from 0.0 to 1.0 within one unit along the z-axis, then
  664. it starts over from 0.0 again...
  665.  
  666.  
  667. 4.4.3.6  none
  668.  
  669. Specifying a pattern with the identifyer none will give the object a mono-
  670. colored surface. The color will be picked from the colormap with index 0.0.
  671.  
  672. The default pattern is none.
  673.  
  674.  
  675. 4.4.4  Reflect
  676.  
  677. Reflection is one of the most interesting and powerful featurs of the ray-
  678. tracing technique compared to other forms of 3D rendering. In RayLab you can
  679. chose how much light an object should reflect. You can also decide what colors
  680. will be reflected. Here is an example of a reflection that reflects 70% of all
  681. light:
  682.  
  683.     reflect  0.7 0.7 0.7           # red=70%, green=70%, blue=70%
  684.  
  685. The default reflection is no reflection att all (0 0 0).
  686.  
  687.  
  688. 4.4.5  Diffuse
  689.  
  690. The diffuse keyword specifies how much of the light from the surrounding light-
  691. sources will affect the color intensity of the object. The diffuse intensity is
  692. specified by a decimal value ranging from 0.0 to 1.0. If a value of zero is
  693. given, the object will have the same color intensity on its lightened side as
  694. on its shadowed side. Normally, you would want a value between 0.5 and 1.0.
  695.  
  696. The default diffuse intensity is 0.8.
  697.  
  698.  
  699. 4.4.6  Ambient
  700.  
  701. If you look around in "the real world" you will see that even in the darkest
  702. shadows, objects are visible. This is due to the diffuse reflection from other
  703. surrounding objects. In a normal raytracer like RayLab, this is a very diffi-
  704. cult and power consuming task to produce. Instead this is simulated by the
  705. ambient effect, which will give the object a default light-intensity on every
  706. point of the surface. The ambient effect can also be used to create "glowing"
  707. objects. However, the ambient of one object will not affect any other objects.
  708. The keyword ambient is followed by a decimal value ranging from 0.0 to 1.0.
  709.  
  710. The default ambient is 0.2.
  711.  
  712.  
  713. 4.4.7  Phong
  714.  
  715. The phong keyword specifies how intense highlights from light-sources should
  716. be. Phong highlights have the same color as the light-source that it is prod-
  717. uced from, and is not proportional to the object color at all (a black object
  718. will have the same highlight color and intensity as a green object).
  719.  
  720. The default phong value is 0.3.
  721.  
  722.  
  723. 4.4.8  Phongsize
  724.  
  725. With phongsize you can specify the tighness of the phong highlight. The key-
  726. word is followed by a positive decimal value. Higher values give tighter spots.
  727. Theoretically the phongsize value can range from zero to the infinity, but in
  728. practice you would typically want a value larger than 1.0 (at least) and
  729. smaller than 100.
  730.  
  731. The default phongsize is 10.0.
  732.  
  733.  
  734. 4.4.9  Default
  735.  
  736. The keyword default can be placed in a texture section to initialize the
  737. texture with RayLabs hardcoded default settings.
  738.  
  739.  
  740. 4.5 Deftexture
  741. --------------
  742.  
  743. With a deftexture section, you can specify a default texture that will be
  744. applied to all the following objects in the scene description. Example:
  745.  
  746. Deftexture:
  747.     reflect  0.6 0.6 0.6
  748.     pattern  spots
  749.     colormap 4
  750.         0.0  1 0 0
  751.         0.7  1 0 0
  752.         0.8  0.2 0.2 0.2
  753.         1.0  0 0 0
  754. :end
  755.  
  756. At the end of the list of all objects that are to have the texture specified by
  757. deftexture, you will probably want to reinitiate the hardcoded default texture.
  758. Simply write:
  759.  
  760. Deftexture:
  761.     default
  762. :end
  763.  
  764.  
  765. 4.6 Transform
  766. -------------
  767.  
  768. When the shape of a primitve is too limited for your demands, chanses are that
  769. the transformation facilities of RayLab can help you. Transformations can
  770. change the shape, locaion and orientation of any primitive or texture. There
  771. are currently three possible transformations available in RayLab: scale, move
  772. and rotate. A transform section can contain a maximum of ten transformations,
  773. which are applied to the object or texture in the order they are entered in the
  774. description. A transform section is started with the transform keyword, and
  775. ended with ':end'. Here is an example:
  776.  
  777.     transform:
  778.         rotate 30 0 0         # rotate 30 degrees around the x-axis
  779.         scale  3 0.6 1        # scale 3*x, 0.6*y and 1*z
  780.         move   -3 0 4         # move the object -3*x +4*z from its current
  781.     :end                      #  location
  782.  
  783. Note that the following exaple will NOT do the same thing as the above:
  784.  
  785.     transform:
  786.         move   -3 0 4
  787.         rotate 30 0 0
  788.         scale  3 0.6 1
  789.     :end
  790.  
  791.  
  792. 4.6.1  Scale
  793.  
  794. Scaling an object means stretching or shrinking it along the x, y and z axis
  795. respectively. A scale value of 1.0 means no change. A value >1.0 means stretch-
  796. ing and a value <1.0 means shrinking. One value must be given for each dir-
  797. ection (i.e. three decimal values must follow the scale keyword). The scaling
  798. is always done relative to (0,0,0) in space, so if you scale a primitive that
  799. has an origin different from (0,0,0), it will also be moved.
  800.  
  801.  
  802. 4.6.2  Move
  803.  
  804. Moving an object means moving it from its current location to a location given
  805. by (current location) + (movement). Also here three decimal values must be
  806. given after the keyword.
  807.  
  808.  
  809. 4.6.3  Rotate
  810.  
  811. After the rotate keyword you must specify three angles (in degrees). They
  812. represent the rotation around each of the x, y and z axis, and the rotation is
  813. performed in that order (first x, then y and last z). To find out which way is
  814. the positive rotation, try this trick:  hold up your right hand in front of
  815. you, extend your thumb and curl the other fingers. Now, if you place your hand
  816. so that the thumb points in the positive direction of the axis that you want to
  817. rotate about, the four fingers will show the positive direction of rotation.
  818. Remember that RayLab uses a right hand system, so the orientation of the axises
  819. is as follows: the x-axis points right, the y-axis points "away", and the z-
  820. axis points up. An object or a texture is always rotated around (0,0,0) in
  821. space, so if you rotate a primitive that has an origin different from (0,0,0),
  822. it will also be moved.
  823.  
  824.  
  825. 4.6.4  None
  826.  
  827. The keyword none will clear a whole transform sequence.
  828.  
  829. The default transformation is no transformation.
  830.  
  831.  
  832. All transformations that can be done to an object, can also be done to a
  833. texture, independently. Often you may want to change the size or orientation
  834. of a pattern. To transform a texture, enter a transform section to the texture
  835. section. This example shows how you can make a pattern twice its original size:
  836.  
  837.     texture:
  838.         pattern checker
  839.         colormap 2
  840.             0  1 1 1
  841.             1  0 0 0
  842.         transform:
  843.             scale 2 2 2
  844.         :end
  845.     :end
  846.  
  847.  
  848. 4.7 Deftransform
  849. ----------------
  850.  
  851. With a deftransform section, you can specify a default transformation sequence
  852. that will be applied to all the following objects and textures in the scene
  853. description. Example:
  854.  
  855. Deftransform:
  856.     rotate 30 -45 17
  857.     move   10 0 -5
  858. :end
  859.  
  860. At the end of the list of all objects that are to be transformed with a def-
  861. transform, you need to withdraw the deftransform. Simply write:
  862.  
  863. Deftransform:
  864.     none
  865. :end
  866.  
  867.  
  868. 4.8  Globals
  869. ------------
  870.  
  871. In RayLab some interesting and useful parameters can be setup in a section
  872. called globals. 
  873.  
  874. 4.8.1  Picwidth
  875.  
  876. The keyword picwidth is followed by an integer value telling RayLab how many
  877. columns the output picture will have. For a 640x480 image this would be 640.
  878.  
  879. The default picture width is 200.
  880.  
  881.  
  882. 4.8.2  Picheight
  883.  
  884. Picheight specifies the amount of lines that the output image will consist of.
  885.  
  886. The default picture height is 150.
  887.  
  888.  
  889. 4.8.3  Backgroundcolor
  890.  
  891. You can specify a color that will be the background color of your scene. For
  892. instance this can be very useful if you make an outdoor scene where you want
  893. the sky to be blue; simply set the background color to blue. Backgroundcolor
  894. is followed by three decimal values ranging from 0.0 (0%) to 1.0 (100%), each
  895. value representing the red, green and blue components of the color, respect-
  896. ively, in that order. Example:
  897.  
  898.    bacgroundcolor 0.3 0.0 0.0       # Dark red sky
  899.  
  900. The default color is 0 0 0 (black).
  901.  
  902.  
  903. 4.8.4  Recdepth
  904.  
  905. The keyword recdepth is used to specify how many recursions RayLab is allowed
  906. to do for each camera-ray. A recursion-depth of 2 means that a ray will only
  907. 'bounce' one time through reflection, and a recursion-depth of 1 results in no
  908. reflection at all. Higher values means more realistic pictures, but also longer
  909. rendering-times if there are many reflective objects in the scene. Example:
  910.  
  911.     recdepth 4
  912.  
  913. The default recursion depth is 3.
  914.  
  915.  
  916. 4.8.5  Display
  917.  
  918. If you want to view a picture as it is being rendered, add the keyword display
  919. to your globals section. Following the keyword you must specify a display type.
  920. The display types are machine specific, so please consult the documentation for
  921. your specific platform for more information. The display type is an integer
  922. value. Example:
  923.  
  924.     display 1
  925.  
  926. Zero (0) means no display, which is the default.
  927.  
  928.  
  929. 4.8.6  Antialiasrec
  930.  
  931. This keyword turns on antialiasing, which can greatly improve the appearance of
  932. a scene. You must specify the recursion depth of the antialiasing, which is
  933. done with an integer value placed after the keyword. Example:
  934.  
  935.     antialiasrec 3
  936.  
  937. Zero (0) means no antialiasing, which is the default.
  938.  
  939. The recursion level can range from 0 (no antialiasing) to 4 (extremely heavy
  940. antialiasing). A value of 2 or 3 should be enought in most cases. Never use a
  941. recursion level of 1 though, as it is totally useless (it just blurs the
  942. picture, even turning antialiasing off looks better). For the different
  943. recursion levels, this is the maximum amount of rays that are traced for each
  944. pixel:
  945.  
  946.      Level:       Rays:
  947.        0            1
  948.        1            4
  949.        2            9
  950.        3           25
  951.        4           81
  952.  
  953. Well, RayLab uses a very intelligent adaptive method (meaning it does not have
  954. to trace more rays than really necessary), so in reality only one to six rays
  955. have to be traced per pixel if there are not too many edges and contours in the
  956. picture.
  957.  
  958.  
  959. 4.8.7  Antialiasthreshold
  960.  
  961. As mentioned, RayLab uses an adaptive method for antialiasing. This is achived
  962. by comparing the colors from the four corners of a square (this square is in
  963. reality a pixel from the picture). If the difference between the colors are not
  964. too big, it is assumed that this entire square has the same color (which is the
  965. average of the four colors). If the difference exceeds a certain value, the
  966. first square is divided into four new squares, which are checked in the same
  967. manner. With antialiasthreshold you can specify the threshold for how big the
  968. difference between the colors may be before another recursion takes place. The
  969. value specified after the keyword must be a decimal value ranging from 0.0 (all
  970. rays are casted as specified by the antialiasing recursion level) to 3.0 (no
  971. squares are subdivided). Example:
  972.  
  973.     antialiasthreshold 0.4
  974.  
  975. The color difference is calculated as the sum of the maximum red, green and
  976. blue differences. The default value is 0.3, which seems to be a very good
  977. value (you may raise this if you need faster rendering).
  978.  
  979.  
  980. 4.9  Comments
  981. -------------
  982.  
  983. In RayLab scene descritions you can put comments to clarify your work, both to
  984. yourself and others. A comment can be placed anywhere, except in the middle of
  985. or right after (no space, tab or newline between) a keyword or a number. Every
  986. comment is started by a comment identifyer and it is ended by the end of the
  987. line. The comment identifiers are   #  ;  and  *
  988.  
  989. Example:
  990.  
  991. Sphere:              # This is a sphere
  992.     centre  0 0 0    ; and it is placed in (0,0,0)
  993.     radius           ****** ok, here comes the radius:
  994.        2
  995. :end
  996.  
  997. As you see, it is fully possible to put a comment between the keyword and its
  998. parameter(s), although it does not look very nice.
  999.  
  1000.  
  1001.  
  1002. 5.  MISCELLANEOUS
  1003. =================
  1004.  
  1005. 5.1  How to contact the author
  1006. ------------------------------
  1007.  
  1008. I always like to get response from people who somehow come across my work, be
  1009. it good or be it bad. So if you have used RayLab, read the documentation or
  1010. heard about my latest assembler program for the C=64, please drop a mail in
  1011. my e-box:
  1012.  
  1013.  internet:     e4geeln@etek.chalmers.se
  1014.  
  1015. If you get any error-messages when compiling RayLab on your system, please let
  1016. me know as it would be nice to have it compile flawlessly on as many systems as
  1017. possible. Do not hesitate to report things like "strings.h not found..." (it
  1018. worked fine on my Amiga and at the university, but not at a friends PC with an
  1019. old Microsoft compiler. Now I know it should be string.h!!).
  1020.  
  1021. Any bug-reports etc. will ofcourse be warmly welcomed. If you do not have
  1022. access to internet, you can contact me by snail-mail:
  1023.  
  1024.   s-mail:     Marcus Geelnard
  1025.               Utbynasgatan 11
  1026.             S-415 06 Goteborg
  1027.               Sweden
  1028.  
  1029.  
  1030. 5.2  Legal stuff
  1031. ----------------
  1032.  
  1033. I have not yet decided exactly how I want RayLab to be released to the public,
  1034. but as I want to start distribution as soon as possible, I chosed to make the
  1035. restrictions a bit tight until I have made up my mind. Please let me know if
  1036. you have any preference/opinion about how RayLab should be treated legally.
  1037.  
  1038. Anyway, here are the rules:
  1039.  
  1040. o  RayLab is provided as is, and the author can not be held responsible for any
  1041.    system failure or data loss as a result, direct or indirect, of the use of
  1042.    RayLab. Use RayLab at your own risk.
  1043.  
  1044. o  RayLab is totally free! You should not pay a penny for the actual software,
  1045.    nor can anybody claim any money for RayLab (except for formal fees for
  1046.    storage media or transfer costs).
  1047.  
  1048. o  You may NOT change RayLab in part or in whole, and then redistribute it! The
  1049.    files and the contents of the files must remain as is, and they must all be
  1050.    there with their original names and in their original directory structures!
  1051.  
  1052. o  You may NOT use any part(s) of the RayLab sourcecode for your own product-
  1053.    ions, neither commercial nor noncommercial!
  1054.  
  1055. o  If you want to use RayLab or any pictures that are produced with RayLab for
  1056.    commercial purposes, you will have to have the permission to do so from the
  1057.    author of RayLab.
  1058.  
  1059. o  For noncommercial use of RayLab, such as a private art-gallery, you need no
  1060.    permission from the author of RayLab.
  1061.  
  1062. o  You may NOT spread your own compilation of RayLab without permission from
  1063.    the author of RayLab!
  1064.  
  1065. If you feel like breaking any of the above stated rules, e.g. if you want to
  1066. improve RayLab, try contacting me (the author of RayLab) first. I am not un-
  1067. reasonable, but I do like to have some control of my own software.
  1068.  
  1069.  
  1070. 5.3  Past, present and the future
  1071. ---------------------------------
  1072.  
  1073. Since the first release (1.0), these changes/additions have been made:
  1074.  
  1075. o  The disc primitive was added.
  1076. o  The cylinder primitve was added.
  1077. o  Anti-aliasing was added.
  1078. o  Display support for the Amiga was added.
  1079. o  A minor bug in the memory handling was detected and eliminated.
  1080. o  Some minor changes and improvements to the code have been made.
  1081.  
  1082. Right now RayLab is in a premeture stage, where I expect to find many bugs, and
  1083. lots of things remain to be improved and implemented.
  1084.  
  1085. Things that will most certainly be implemented in RayLab in a relatively near
  1086. future (?):
  1087.  
  1088. o  Transparency and refraction.
  1089. o  More patterns.
  1090. o  Better description language, especially more abstractions and better
  1091.    handling of faulty descriptions.
  1092.  
  1093. Things that I would like to implement in RayLab, but I don't know when, or even
  1094. if, it will be:
  1095.  
  1096. o  Focus blur.
  1097. o  Pattern distortion for more realistic appearance.
  1098. o  Surface normal modifiers, like bumpiness and waves.
  1099. o  Animation support, which will probably consist of a good expression handler
  1100.    and some useful mathematical functions like sin(x), sqrt(x), log(x) etc.
  1101. o  Motion blur (based on the animation support).
  1102.  
  1103. Any further suggestions are ofcourse welcome...
  1104.  
  1105.  
  1106. 5.4  Comments by the author
  1107. ---------------------------
  1108.  
  1109. I admit that RayLab was influenced by other raytracers that I have used (POV-
  1110. Ray, Imagine and Rayshade), but that is mostly due to my finding parts of those
  1111. raytracers very natural. I did, however, start from scratch when I developed
  1112. RayLab, and the only thing I have looked at from other source codes (so far)
  1113. is the C-language itself (I am still a beginner). The combination of RayLab
  1114. beeing one of my first C-programs, and me not having any experience in ray-
  1115. tracing techniques (except for the actual usage of other raytracers) is one
  1116. reason why RayLab is quite slow, and also I guess the source code itself looks
  1117. rather nasty (? still better than assembler though).
  1118.  
  1119. And then we have the description language... It is very primitive and not very
  1120. fault-tolerant right now, but I do have major plans (hrrm) for future improve-
  1121. ments.
  1122.  
  1123. You may wonder what the START/END keywords under the cylinder declaration are
  1124. doing (in 'getworld.c'). Well, my primary intention with the cylinder was to
  1125. have it declared by its both ends in space and its radius, but as for now I had
  1126. to settle for a simpler solution. The discs at the ends of the cylinder are
  1127. actually correct in respect to the START/END statements, but the cylinder body
  1128. is not, so it will look rather peculiar if you define ends that do not lay along
  1129. the z-axis, I guess.
  1130.  
  1131. Many of the things that are declared in a globals section should be possible to
  1132. declare right at the command line when calling RayLab, but so far I have not
  1133. decided how the parameters should look (and I AM lazy!).
  1134.  
  1135. Pheew! This documentation got a bit larger than expected... This program was
  1136. intended to be a simple personal hack, not a commercial raytracer!
  1137.