GemRay, GemFrame, and GemFlick
Users' Guide
Version 1.4, June, 1993
by
Robert W. Strickland
Copyright © 1992, 1993, 2001 Robert W. Strickland
HTML version January 22, 20001
All rights Reserved
Introduction
GemRay, GemFrame, and GemFlick are computer programs that make and display images of faceted gemstones under a variety of simulated lighting conditions. GemRay and kin evaluate facet designs made using the GemCad program. GemRay, GemFrame, and GemFlick run on IBM PC-Compatibles with VGA graphics adapters. A minimum of 80486DX processor is recommended.
GemRay constructs an image of a stone with the technique of raytracing. Raytracing is the process of rendering an image of a stone by following the path of individual light rays through the stone. GemRay actually follows light rays backwards from a single point (the viewer's eye) into the stone and then out of the stone and, with a bit of luck, back to a light source. So, you might ask, Why not mimic nature and start at the light source instead of the viewer's eye? The answer is because of the amount of computation involved. Most light rays that leave the light source miss the stone entirely. Also, most of the rays that do hit the stone miss the viewer's eye. By starting at the eye and moving backwards, only the light rays that actually hit the eye are considered.
When you run GemRay, it will make three images of the stone under three lighting models. Here is an example of what your screen will look like after GemRay finishes raytracing a round brilliant in quartz (R.I.=1.54) with a pavilion main angle of 41.5° and a crown main angle of 26°.
| RANDOM | COS | ISO |
GemRay computes and plots the three images simultaneously. They represent the same stone in the same orientation but under three different lighting models. Obviously, the random lighting model provides a better feel for the scintillation and reflection patterns, while the COS and ISO lighting models give a more quantitative evaluation of brightness. Why do the three pictures look so different? The answer is because of the distribution of light sources in the different lighting models. Let's consider these differences in detail.
The random lighting model has a mottled pattern of light and dark areas. Pretend you are under the center of a hemispherical dome, as inside a planetarium. The stone is at the center of the hemisphere with its girdle parallel to the base of the hemisphere. You are facing the floor and looking down on the stone. For the random lighting model, the following pattern is projected onto the dome.

Random Lighting Model
The outside edge of the circular pattern hits the rim of the dome. This smooth, high-contrast pattern can highlight light rays that come from slightly different directions. This feature allows you to see subtle reflection patterns.
In the second lighting model, called the COS model, the light varies with the cosine of the angle of inclination of the light ray. It is brightest directly above the stone and black on the horizon (light rays that enter the side of the crown parallel to the table). Again, imagine yourself under the dome. For the COS lighting model, the following pattern is projected onto the dome.

COS (Cosine) Lighting Model
In the third lighting model, called the ISO model, the light is uniform in all directions. It is as if the hemisphere surrounding the stone is uniformly lit. These three lighting models taken together give much more information than any one of them alone. The Random model is best for getting a qualitative feel for the scintillation and reflection patterns. The difference between the COS and ISO lighting models give a feel for where the light is coming from that returns to the viewer. If the images under the COS and ISO models are nearly the same, much of the light is coming from high in the sky. If the image under the COS model appears much darker than the image under the ISO model, much of the light is came from low in the sky.
No matter what lighting model GemRay uses, any rays that would have had to enter the pavilion to exit the crown toward the viewer are lost. This is somewhat like mounting the stone in a bezel instead of prongs. Since most mountings allow some light into the pavilion, this model is pessimistic.
GemRay makes a single set of images per run. There is a companion program called GemFrame that makes a sequence of images for either varying the tilt angle or pavilion depth and/or crown height. If the tilt angle is varied, the resulting files can be played back with the Gemflick program. GemFlick plays back a series of images from GemRay making an animated loop.
Running GemRay
When you first run GemRay, it will print a version number and copyright notice.
This is GemRay 1.4
Copyright (c) 1992, 1993 Robert W. Strickland
All rights reserved.
Next, GemRay will ask you a series of questions. All of these questions have reasonable defaults, so you can just answer most of them by pressing the Enter key. First, GemRay asks for the name of the design. It wants you to type in the the name of a file written by GemCad with its Save (s) command.
Enter name of GemCad design file (Enter for list):
If you wish, you may type in the name of the file. If you just press the Enter key, GemRay will bring up a file picker just as in GemCad. You can change which file is highlighted by using the cursor keys or the mouse. Use the Enter key or a mouse button to select the highlighted file. See the GemCad 4.0 Manual to find out how to change directories and how to change the drive or wildcard (file specification).
Next, GemRay will ask you for three file names. These are GemRay's output files that will contain the images of the design under three lighting models. GemRay will construct default file names by changing the extension on the GemCad file name to RAY, COS, or ISO. If you don't want GemRay to save the COS or ISO models, enter n in place of the file name.
Random light image output file name (xxxxx default)?
COS light image output file name (xxxxx default, n for none)?
ISO light image output file name (xxxxx default, n for none)?
Next, GemRay will ask you for a file name for its output ray vector file.
Exit ray vector output file name (xxxxx default, n for none)?
This output file will contain the direction of each light ray that entered the stone, bounced around, and returned toward the viewer. This file is a binary file and is for future use. One such use will be to quickly compute the response to different lighting models. Another might be to make reflection patterns as in Long's & Steele's programs. I welcome your suggestions for alternative lighting models.
Next, GemRay will ask for the height of the image in pixels.
Number of pixels tall (xxxxx default)?
The running time will go as the square of the number of pixels. If you enter anything larger than 640/3 = 213 pixels, a portion of the ISO light model image will be cut off. (The VGA screen resolution is 640 by 480 pixels.)
Next, GemRay will ask you for the refractive index of the stone.
Refractive index (xxxxx default)?
If you just press the Enter key, GemRay will use the refractive index saved with the GemCad file (as set with the Index of Refraction (I) command).
GemRay can also tilt the stone. It will ask you for the tilt angles.
X-axis tilt angle (xxxxx default)?
Y-axis tilt angle (xxxxx default)?
If you imagine that you are holding the stone level with your eye looking perpendicular to the table, a positive x-axis tilt means that the top of the stone is tilted away from the viewer, and a positive y-axis tilt means that the right side of the stone is tilted away from the viewer.
GemRay can also tangent ratio scale the the pavilion, crown, or both. Tangent ratio scaling raises or lowers all of the angles on one side of the stone without changing how the stone looks from the top. To use this feature, you type in the old angle of one of the facets and then type in its new angle. (To use this effectively, you must already know the angle you want to change, either by making a note while you are running GemCad or from the faceting diagram.) GemRay will ask you about the pavilion first and then the crown. If you just press the Enter key without entering an angle, GemRay will not perform the scaling. Tangent ratio scaling is performed before any tilting.
Next, GemRay will ask you if the stone is concave.
Concave stone with vee-groove facets (default: no)?
GemCad is ordinarily limited to convex stones. One GemCad user has managed to subvert GemCad into making a file of a design with vee-grooves on the pavilion by a convoluted process involving a commercial 3D CAD program and custom translation software. Such designs can be raytraced with GemRay. On ordinary convex designs, the only effect is to slow down GemRay greatly.
Finally, GemRay will ask you if all the above information is correct. If your answer begins with y, GemRay will switch to the graphics mode and start drawing the stone. If your answer begins with n, GemRay will go back through the above questions again. The second time around however, the first set of answers you typed in are the defaults.
When GemRay draws the image of the stone, it will draw the stone with all three lighting models, regardles of whether or not you requested the images to be saved to disk. When GemRay finishes the raytracing and the stone is completely drawn, GemRay will continue to display the pictures of the stone until you press a key. After GemRay goes back to text mode, it prints the average brightness under the COS and ISO lighting models. The COS brightness will always be less than the ISO brightness. If the two are nearly equal, that means that light rays returning to the viewer originate roughly parallel to the line of sight to the stone. If the two are quite different, much of the light returning to the viewer originates from rays low in the sky or near the rim of the dome (asuming that the viewer is looking straight down on the stone with the sky above). Here is an example of the Tribble design under the three lighting models.

| RANDOM | COS | ISO |
GemRay makes a file called GEMRAY.LOG. Each time it runs it adds a line to this file. If GEMRAY.LOG does not exist, it is created. The purpose of this file is to record brightness values and the corresponding tilt angles and tangent ratio parameters. Here is an example of GEMRAY.LOG after one raytracing.
OLD NEW OLD NEW TILT TILT REFR COS ISO NUM GEMCAD RAND LT
PAV PAV CRN CRN X Y INDX BRT BRT PXL FILE FILE
0.0 0.0 0.0 0.0 0 0 1.54 57.5 72.4 120 STONE.GEM STONE.RAY
The log file is also particularly useful when using the GemFrame program to run GemRay in batch-mode.
Running GemFrame
GemFrame runs GemRay repeatedly in batch-mode. It has two main purposes. The first is to make tilt animations to be played back by GemFlick. The second purpose is to have GemRay vary the angles of a design in a systematic way to determine the optimum angles to maximize brightness. GemFrame asks the same basic sequence of questions as GemRay. GemFrame uses the GemRay program to do the raytracing, so the executible file GEMRAY.EXE must be in the DOS search PATH.
One of the questions GemFrame asks is
Make tilt movie (no for tangent ratio scaling, default is yes)?
Depending on your answer to this question, GemFrame will either make a tilt movie or do tangent ratio scaling. If you anser yes to this question, GemFrame will make a tilt movie.
To make a tilt movie you tell GemFrame the starting direction and ending direction. It will display a sort of a compass card that indicates tilt direction.
8 1 2 \ | / 7 - 0 - 3 / | \ 6 5 4
The numbers correspond to the tilt direction. Imagine the top view of the stone placed on top of the compass card. A direction of 1 means that the dop axis of the stone tilts toward the north. That is, the top of the stone will be tilted away from the viewer. A direction of 3 means that the axis of the stone tilts toward the east. That is, the right side of the stone is tilted away from the viewer. Fractional values are allowed. For instance, 1.5 corresponds to the direction northnortheast. The direction 0 means no tilt. GemFrame will ask you a starting direction and and ending direction. Next, GemFrame will ask you the maximum tilt angle and the increment.
How do you know what direction to tilt the stone? The best direction to tilt it depends on the symmetry of the stone. Let's say that the stone has 2-fold radial symmetry and mirror-image symmetry (such as an oval or emarald cut). A useful starting direction might be 1 and the ending direction 3. This would start the stone tilted toward the north by the maximum amount. The amount of tilt will then be reduced until the stone is not tilted (direction 0). Then it will then be progressively tilted toward the east until it is tilted by the maximum amount specified. On a square- or cushion-shaped stone, it's useful to start at 1 and end at 4. (By symmetry, the ISO and COS brightness plots for the 3, 5, and 7 directions are the same as the 1 direction for a design with a 4-fold radial symmetry.) If you give GemFrame two nonzero directions it always starts with the stone tilted the maximum amount toward the starting direction and then reduces the tilt angle until the stone is not tilted. It then progressively tilts the stone toward the ending direction.
The other major use for GemFrame is to allow you to vary the pavilion and/or crown angles in a systematic way to determine the optimum angles for maximum brightness. You do this by answering no to the tilt question. GemFrame will ask you for the old pavilion angle. This should be the angle of an existing pavilion facet that you have noted previously from GemCad or the faceting diagram. If you don't want to scale the pavilion, enter 0 for the old pavilion angle. If you enter a nonzero angle, GemFrame will ask for the new starting pavilion angle, ending angle, and angle step. GemFrame will then ask you the same series of questions for the crown.
When GemFrame steps through the angles, it will vary the crown angles the fastest. That is, it will start out at the starting pavilion angle and the starting crown angle. Next, it will increment the crown angle and leave the pavilion angle the same. It will step through the entire sequence of crown angles before incrementing the pavilion angle. If you are varying both pavilion and crown angles, plan ahead about the range of angles. Usually, the brightness is much more sensitive to the pavilion angle than the crown angle. Vary the pavilion angle in 1 degree increments and the crown in 3-5 degree increments. Beware of making the increments too fine. If you were to vary the pavilion and crown angles over a ten degree range in one degree increments each, that would result in 11x11=121 runs of GemRay and 121 files!
The output files that GemFrame makes have the name as the GemCad file with an extention starting with R. The last two characters of the extension are a two digit number. GemFrame will ask you the first number in the sequence, and each subsequent image will have its number incremented by one.
Now let's consider two examples: an angle analysis and a tilt analysis.

| 22/40 | 26/40 | 30/40 | 34/40 |

| 22/41.5 | 26/41.5 | 30/41.5 | 34/41.5 |

| 22/43 | 26/43 | 30/43 | 34/43 |

| 22/44.5 | 26/44.5 | 30/44.5 | 34/44.5 |
Brilliant in Quartz with Various Crown/Pavilion Angles
This is an angle analysis of a round brilliant in quartz that shows various combinations of crown and pavilion angles. Each row has a different pavilion angle, and each column has a different crown angle. The starting pavillion angle of 40° is below the critical angle of 40.5° for quartz. To produce these images, I ran GemFrame with the following input:
Make tilt movie (no for tangent ratio scaling, default is yes)? n
Tangent ratio scaling:
Old pavilion angle (0.0 default)? 41.5
New pavilion starting angle (41.5 default)? 40
New pavilion ending angle (41.5 default)? 44.5
Pavilion angle increment (1.0 default)? 1.5
Old crown angle (0.0 default)? 26
New crown starting angle (26.0 default)? 22
New crown ending angle (26.0 default)? 34
Crown angle increment (1.0 default)? 4

| 0 | 1 | 2 | 3 |

| 4 | 5 | 6 | 7 |

| 8 | 9 | 10 | 11 |

| 12 | 13 | 14 | 15 |
Brilliant in Quartz Tilted 0-15°
This is a tilt analysis of a round brilliant in quartz (R.I.=1.54) with a pavilion main angle of 41.5° and a crown main angle of 26°. This is with the Random lighting model. To make this tilt study, I typed in the following answers to GemFrame:
Starting tilt direction (1.0 default)? 0
Ending tilt direction (5.0 default)? 1
Maximum tilt angle (10.0) default? 15
Tilt angle increment (1.0) default? 1
The wedge-shaped dark area is the pavilion windowing as the stone is tilted.
Running GemFlick
GemFlick displays the images made by GemRay under the control of GemFrame. GemFlick can display still images or animations. When GemFlick is first run, it asks for the number of files. If you type in 1, GemFlick will display just one picture. Any other response tells GemFlick that you want to view an animation composed of files made by GemFrame. If GemFlick is to display just one image, it will bring up the file picker and show all files whose extensions start with R. After you pick one, it asks you for an expansion factor or number of pixels. It then displays the image and a grayscale palette in the upper-lefthand corner of the screen.
If GemFlick is to display a series of files, it brings up a list of all of the sets of files. Such a set of files have the same base name, same the first character of their extension in common, and numbers for the last two characters in their extension. When you pick the set of files, GemFlick will show all of the files in the set and ask you to pick the first file in the set. Then, GemFlick will ask you to pick the last file in the set. The numbers from the last two characters of the file name must be consecutive. (GemFrame automatically numbers the files sequentially.) GemFlick will next ask you for the expansion factor. The maximum expansion factor depends on how much conventional memory is available, how many files make up the animation, and how big the individual files are. The larger the image size, the slower the animation. You can also enter the image size in number of pixels instead of an expansion factor. GemFlick will then read the images from disk and display them in sequence, enlarging them according to the expansion factor. As it dispays each image on the screen, it saves a copy of the image in conventional memory. After all of the images are read in, it displays them sequentially to make the animation. It starts with the first image, steps through them in sequence to the last one, and then displays them in reverse order again. You can use the cursor keys to slow down or speed up the animation. GemFlick starts out at top speed. The animation is repeated until you press the Esc key.
I hope these somewhat sketchy instructions provide enough information to get you started experimenting with the programs.
Acknowledgments
I am grateful to Robert Long for his valuable suggestions on how to handle partial reflections on entry and exit. The pioneering work of Robert Long and Norman Steele in the mathematical modeling of gemcuts has contributed greatly to this work and to the education of the faceting community and improvement of faceting designs and diagrams.
I prepared this document with the Write word processor that comes with Microsoft Windows 3.1. The pictures are screen captures of a DOS session running in a window. (Windows must be in 386 Enhanced Mode to run a DOS session in a window. The Print Screen key will copy the screen to the Clipboard.) I cropped the images with Paintbrush. I fiddled with the order of colors in the color palette inside of GemRay and GemFlick so that the screen captures print with reasonable shades of gray on my HP DeskJet printer. I hope my choices work as well on other printers. Screen captures under Windows 3.0 will probably not have the shades of gray in the proper order.
GemRay Comand-Line Options
Answers to all of the questions that GemRay asks can be supplied on the DOS command line. This is useful when running GemRay from a batch file. This is also how the GemFrame program conveys your answers to GemRay. If you are not fond of the DOS command line or batch files, you need read no further.
The GemRay command line is given by the following. Optional parameters are shown in square brackets.
GEMRAY [options] [GEMFILE [RAYFILE [COSFILE [ISOFILE [VECFILE]]]]]
If you don't supply any options or filenames on the command line, GemRay will prompt for its input interactively. It prompts for all of the parameters settable with command line options below except for the eye position. If the you supply the GEMFILE name, GemRay runs in batch mode. This is so you can run GemRay repeatedly from a batch file. The command line options are:
-n NUM Make image NUM pixels (rays) tall. The default is 120.
-p OLDANG NEWANG
Multiply pavilion elevations by tan(NEWANG/tan(OLDANG), where the angles are in degrees. This only works properly for level girdles. The default is no tangent ratio scaling.
-c OLDANG NEWANG
Multiply crown elevations by tan(NEWANG/tan(OLDANG). The default is no tangent ratio scaling.
-i R Make refractive index R instead of that specified in the GemCad file.
-x D Tilt about x-axis D degrees. The default is no tilting.
-y D Tilt about y-axis D degrees. The default is no tilting.
-e Z
Position eye at Z stone radii above center of stone. The default is 200. For a 10 mm diameter stone this corresponds to a viewing distance of 1000 mm, or nearly parallel rays.
-g
Do not display VGA images while running. This is useful for running the program from a Windows text window. The default is to display VGA images.
-v
Allow for concave stones (with vee-grooved pavilions, for instance). Runs several times slower.
The option flag may either be the minus (-) or slash (/), and option characters may be in upper or lower case. Option flags and their parameters must be surrounded with spaces. All options must come before any file names.
The file names are:
GEMFILE Name of the input file containing the design (as made by GemCad's save command).
RAYFILE Name of the output file containing the image of what the stone will look like under the random lighting model. If omitted, GemCad will form the name by changing the extension of the GemCad file name to .RAY. If a file by the same name already exists, it will be overwritten silently.
COSFILE Name of the output file containing brightness image under the COS lighting model. If omitted, Gemcad will form the name by changing the suffix of the GemCad file name to .COS.
ISOFILE Name of the output file containing Long & Steele-style ISO brightness image. If omitted, Gemcad will form the name by changing the suffix of the GemCad file name to .ISO.
VECFILE Name of the exit-ray vector file. If omitted, Gemcad will form the name by changing the suffix of the GemCad file name to .VEC.
For any of the file names COSFILE, ISOFILE, or VECFILE, if a file by the same name already exits, it will be overwritten silently. An n in place of any of these file names will cause that file not to be written.