home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / paint / m / qrt / QRTdocs / Discuss < prev    next >
Encoding:
Text File  |  1989-05-23  |  10.9 KB  |  224 lines

  1.    This document discusses:
  2.  
  3.      The transmission of light in the QRT world
  4.      Removing sections from a planar object
  5.  
  6.  
  7. Transmission of light
  8. =====================
  9.  
  10.    Transmission of light through surfaces now works, allowing one to model
  11. glass surfaces. Some additions to and changes from the original grammar were
  12. necessary to provide the desired functionality. A new keyword, "DENSITY",
  13. has been added, and the function of the old "TRANS" keyword has been
  14. changed. Also, a "THRESHOLD" parameter has been added to the default
  15. structure. Since transmission is a complex operation, this entire Addendum
  16. will discuss aspects of modeling glass surfaces.
  17.  
  18. The DENSITY keyword
  19. ~~~~~~~~~~~~~~~~~~~
  20.  
  21.    It was my previous intent that the TRANS keyword would specify the
  22. percent transmission of light though the surface. After thinking a little
  23. more about the nature of light transmission, it was clear that this wasn't
  24. adequate. The amount of light transmitted depends not only on a fixed
  25. coefficient of the surface, but on the thickness of the surface. For
  26. example, a hollow glass sphere will appear darker (transmit less light) near
  27. the edges, where the glass is thickest. To account for this effect, the
  28. "DENSITY" keyword was added. Density specifies what percentage of
  29. transmitted light will be removed per unit distance travelled though the
  30. object. For example, the following density attribute would remove 2 percent
  31. of all light per unit distance:
  32.  
  33.    DENSITY = (.02, .02, .02);
  34.  
  35.    If a sphere, at its widest point, was 10 units thick, 20 percent of the
  36. light would be removed. Near the edge of the sphere, less light would be
  37. removed.
  38.  
  39.    Since density is a function of distance, the same density factor will
  40. have different effects on objects of different sizes. To remove the same
  41. percentage of light from an object half as thick, double the density factor.
  42.  
  43. Shadows from Transparent Surfaces
  44. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  45.  
  46.    The old "TRANS" keyword still exists, but it performs a different
  47. function. It does not affect the appearance of the object, but rather, the
  48. attenuation of light passed through the surface. QRT knows how glass
  49. surfaces bend light, and so it can model the magnifying effects of looking
  50. through curved glass, etc. But for computing shadows, it cannot properly
  51. bend the light from lamps. This means that you can model lenses that the
  52. observer looks through, but not lenses used to focus light. In order to
  53. provide some attenuation effects, use "TRANS" to tell QRT how much light is
  54. passed through the surface. This information is ONLY used for computing
  55. shadows. For example, blue glass should cast a blue shadow. Use something
  56. similar to:
  57.  
  58.    TRANS = (0, 0, .7)
  59.  
  60. to cast a blue shadow (this lets 70 percent of the blue light pass). Note
  61. that by using strange combinations of DENSITY and TRANS, you can model
  62. illogical objects which appear, for example, blue, but cast a red shadow.
  63. These shadows will be entirely of one intensity, and will not vary with the
  64. thickness of the glass.
  65.  
  66. Using MIRROR with Transparent surfaces
  67. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  68.  
  69.    Glass surfaces not only refract light, but also reflect a percentage of
  70. it. This means that to realistically model glass, the glass should reflect a
  71. small percentage of the light. Try starting with 20 to 25 percent
  72. reflection. Note that all glass objects reflect light from both the outside
  73. and the inside surfaces of the glass.
  74.  
  75. Index of Refraction
  76. ~~~~~~~~~~~~~~~~~~~
  77.  
  78.    The index of refraction for an object governs how much the light is bent
  79. upon entering or exiting the object. A higher index will bend the light
  80. more. The index of refraction of air is 1.00, and for glass is roughly 1.33.
  81. Some substances, such as diamond, have a higher index.
  82.  
  83. Modeling Hollow Objects
  84. ~~~~~~~~~~~~~~~~~~~~~~~
  85.  
  86.    When designing the QRT transmission routines, I wanted to be able to
  87. model both solid glass and hollow glass objects. To understand how this is
  88. done, it is necessary to understand a little about how QRT's transmission
  89. model works.
  90.  
  91.    A ray, after leaving the observer, has two states: either it is inside a
  92. glass object, or it is outside. The ray starts out outside. When it first
  93. encounters a glass surface, it is bent, and its state is toggled from
  94. OUTSIDE to INSIDE. It continues on until encountering another surface,
  95. whereupon it is bent again, and its state is once more toggled. This has
  96. several implications for modeling glass. The first is that ALL glass
  97. surfaces MUST have two sides - that is, once the ray enters the glass, there
  98. must be no way for it to exit without again passing through a surface. The
  99. second is that a ray must go from glass to air, or air to glass, but not
  100. from glass with index of refraction A to glass with index of refraction B;
  101. i.e, the two glass surfaces cannot touch each other, even though they may be
  102. placed very close together.
  103.  
  104.    As an example of how this works, consider a solid glass sphere. The ray
  105. encounters the sphere, and is bent (in this case, towards the normal
  106. vector). QRT now remembers that the ray is INSIDE a glass surface. The ray
  107. continues on until it hits the back side of the sphere, whereupon it is bent
  108. (away from the normal vector), and its state is toggled to OUTSIDE. In
  109. summary, the INSIDE/OUTSIDE flag tells QRT how to bend the ray.
  110.  
  111.    Consider now the case of a hollow glass sphere. This is modeled using two
  112. concentric spheres, one with a smaller radius. The ray will first hit the
  113. outside sphere, be bent, and have its state toggled to INSIDE. There are now
  114. two possible cases. First, the ray may miss the inside sphere, in which case
  115. the simulation proceeds as in the above paragraph. Second, it may hit the
  116. inside sphere. In this case, it is bent, and its state is toggled to
  117. OUTSIDE. The ray is now considered to be back in air, so that the inside
  118. sphere has modeled the hollow portion of the glass. In a similar manner, the
  119. ray reaches the other side of the inside sphere, enters the glass again, and
  120. finally leaves the outside sphere. Note that even though the inside sphere
  121. is thought of as the "air" in the center of the object, it MUST have the
  122. same index of refraction as the outside sphere. This is necessary so that
  123. QRT can correctly bend the light when it exits the glass.
  124.  
  125. Chromatic Aberration
  126. ~~~~~~~~~~~~~~~~~~~~
  127.  
  128.    In QRT, all rays, regardless of color, are refracted exactly the same.
  129. This is contrast to the real world, in which the amount the light is bent
  130. depends on its wavelength. This appears, so far as I can tell, to be a bug
  131. in the real world, and I saw no reason to include it in a ray tracer.
  132.  
  133. Threshold attribute
  134. ~~~~~~~~~~~~~~~~~~~
  135.  
  136.    A new keyword, THRESHOLD, has been added to the default structure. In
  137. previous versions of QRT, there was a mechanism for detecting infinite
  138. recursion provided that objects reflected less that 100 percent of the light
  139. reaching them. QRT stopped the recursion when the intensity of the light
  140. reached 1 percent of its original value. When transmission was added, I made
  141. this value adjustable. With glass objects, both surfaces reflect light, and
  142. if QRT waits until the 1 percent mark before stopping recursion, the time
  143. necessary to complete the image is greatly increased with little or no
  144. increase in image quality. The default is now 10 percent, and is changeable
  145. as follows:
  146.  
  147.    DEFAULT ( threshold = .05
  148.            )
  149.  
  150.    This would stop recursion when the intensity reaches 5 percent of the
  151. original value. An added effect is that if the objects surface reflects (or
  152. transmits) less than the threshold amount of light, the reflection or
  153. transmission will be ignored completely.
  154.  
  155. Affect of Glass on Speed
  156. ~~~~~~~~~~~~~~~~~~~~~~~~
  157.  
  158.    Unfortunately, the presence of any glass objects will slow the ray tracer
  159. down. This effect may range from barely noticeable, for few, small objects
  160. to excruciatingly miserably slow, for many, large objects. Sorry, there is
  161. nothing I can do to speed it up - the 68000 simply won't go any faster. The
  162. reason for the  slowdown is that for every ray/glass surface intersection,
  163. TWO additional rays must be sent out (as opposed to one, for reflection).
  164. And remember, each ray intersects a glass object twice: once on the way in,
  165. and once on the way out. Also, the two generated rays may intersect the
  166. glass, as well. You can see how this process could get very slow.
  167.  
  168. Notes, etc.
  169. ~~~~~~~~~~~
  170.  
  171.    Watch for control characters in the QRT input file. I had accidentally
  172. imbedded an invisible control character in a file I was working on, and the
  173. QRT parser refused to parse the file. After closely checking the file, I
  174. began to look for a bug in the parser code. Finally, I discovered the
  175. control character, but only after spending 1 hour checking the parser code.
  176. The QRT parser will generate a SYNTAX ERROR, CODE 207 upon encountering any
  177. special characters in the input file.
  178.  
  179.    Since transmission involves heavy recursion, don't forget to set the
  180. default stack size to something larger than the default 4000 bytes. A stack
  181. size of 40000 to 50000 bytes seems safe for most images.
  182.  
  183.  
  184. The REMOVE command
  185. ==================
  186.  
  187.    The 'REMOVE' command was added to allow sections of a planar primitive to
  188. be removed. This makes it much easier to create flat objects that are not
  189. shaped like QRT's planar primitives. For example, I had a QRT input file
  190. which created the image of a grand piano. The top of the piano, because of
  191. its complex shape, initially was created from 11 planar primitives. Now, it
  192. is only  1 PARALLELOGRAM primitive, and a section of the parallelogram is
  193. removed to create the shape of a piano top.
  194.  
  195.    Before the REMOVE command can be used, a pattern must be created using
  196. any of QRT's pattern primitives (the piano uses a polygon). This pattern
  197. need not be given any surface characteristics - it simply defines the region
  198. to be removed from the planar primitive. The pattern is attached to the
  199. primitive in exactly the same way as a normal pattern, except that the
  200. REMOVE command is used instead of the PATTERN command:
  201.  
  202.    PARALLELOGRAM ( loc = (0, 0, 0)
  203.                    v1 = (10, 0, 0)
  204.                    v2 = (0, 0, 10)
  205.  
  206.                    diff = (1, 0, 0)
  207.                    remove = SECTION_TO_REMOVE
  208.                    pattern = ANY_PATTERN
  209.                  )
  210.  
  211.    This example shows that the PATTERN command can be used on the same
  212. primitive as the REMOVE command.
  213.  
  214.    Several things should be noted about the REMOVE command. First, the
  215. pattern defines the sections to remove, not the sections which will remain.
  216. In the piano example, the pattern mapped all of the parallelogram except the
  217. part that composed the actual piano top. Second, even though the remove
  218. command can be used with the curved surface primitives (SPHERE, QUADRATIC),
  219. the results will not be quite right. To use the sphere as an example, the
  220. front surface of the sphere would have the correct pattern removed from it,
  221. but the back surface of the sphere would  be completely gone. This is
  222. because the SPHERE intersect routine ignores completely the back surface of
  223. the sphere. I will probably fix this in a future version.
  224.