Photorealistic Rendering Using Zemax and POV-Ray
This article describes photorealistic rendering and the rendering software POV-Ray. It provides and explains a macro written to render Zemax lens files in POV-Ray.
Authored By: Akash Arora
INTRODUCTION
Zemax has many features that allow the user to visualize an optical system they have designed. From simple two dimensional line drawings to more complex OpenGL shaded model layouts, there are numerous options for displaying a system. For many purposes, these types of illustrations and their level of detail will suffice. It may be desirable, however, to create very realistic images of an optical system using what is known as photorealistic rendering.
Photorealistic rendering refers to the process of rendering a scene by launching rays from a viewer onto a scene to determine what is actually visible in each pixel of the field of view. In this sense it is the opposite of what Zemax does: launch rays from sources/objects that are ultimately collected on detector/image planes for analysis. You can read more about photorealistic rendering using raytracing at http://en.wikipedia.org/wiki/Ray_tracing_(graphics).
Using this raytracing method, programs that employ photorealistic rendering can create strikingly realistic scenes of nearly any object(s). Below is one such scene created using the Persistence of Vision Raytracer (POV-Ray).

This image was released to the public domain. Read more about it at http://www.oyonale.com/modeles.php?page=40
The advantage of photorealistic rendering is clear: one can create images that are nearly indiscernible from reality. The main disadvantage is that very complicated scenes can take long times to render. The scene above took about 24 hours to render on a 4 CPU computer. Photorealistic rendering is, therefore, ideal for still images being used for presentation purposes.
POV-RAY
There are many photorealistic rendering programs available, both free and paid. One of the most widely used that is both free and open source is the Persistence of Vision Raytracer (POV-Ray). POV-Ray is maintained by a team of developers and supported by an active community of users. Their website is http://www.povray.org and there you can find the software download as well as community forums and works posted by other users.
Currently POV-Ray is available in both 32-bit and 64-bit versions. The current version (3.62) is not multi-threaded. The beta release currently available (v3.7) adds multi-CPU support to drastically improve rendering times. You can download POV-Ray from the following page: http://www.povray.org/download/. Zemax technical support cannot provide assistance on installing or using POV-Ray.
POV-Ray scenes are created using an ASCII text based language. These files are simply text files with a .POV extension. There are several key features of any POV-Ray scene file.
• A series of standard files that define common colors, textures, and materials are defined using “Include” files. These can also include predefined objects.
• The location and orientation of the camera. This sets up the field of view for which POV-Ray will render the scene.
• The lighting, which can be multiple sources with varying sizes and characteristics.
• The objects that compose a scene are defined and given material and finish properties.
In order to create scenes such as the one on the previous page, much more detail has to be added, however these are still the basic elements.
THE POV-RAY EXPORT MACRO
Creating simple geometric shapes, such as spheres or cubes, in POV-Ray is very simple and can easily be done by hand. Complicated objects that aren’t simply a collection of primitive shapes are more difficult to create by hand, but can be generated by certain programs. Most of the objects in the scene on the first page of this article were created using the Rhinoceros™ CAD program. This CAD package has a built-in POV-Ray export capability that allows quick conversion for photo-realistic rendering.
Zemax has a built-in CAD export routine that can be executed manually (Tools > Export) or by using the programming language (ZPL). The macro export capability is the basis for easily converting a Zemax lens design into a POV-Ray scene file. At the end of this article you will find a macro (POV-Ray Export.ZPL) that converts a Zemax model into a POV-Ray scene file, executes and renders the scene in POV-Ray, and finally displays the result in a Zemax window.
The POV-Ray script file (*.POV) Zemax creates will be saved in the same folder as the original lens file. The resulting rendered image will be saved in the {Zemax}\IMAFiles folder.
The macro works by individually exporting each element in the design to IGS format and then converting the IGS object to a list of triangles. The objects are created in POV-Ray using a mesh of smooth triangles. It is desirable to export optical elements individually in order to assign each object different properties; this is why the export routine is rather complex. The macro’s limitations in modeling various optical elements are the same as the CAD export tool. See Chp. 8 of the Zemax manual for more information on the CAD export tool.
Creating the objects in POV-Ray is the easy part of the process. The more difficult aspect is locating the camera and lighting to encompass all the objects and assigning material and finish properties such that all the objects look realistic. A selection of a POV-Ray script generated by Zemax is below to help explain the meaning of the different sections.

To properly locate the camera for any optical system, no matter how large or small, the macro essentially computes a bounding box around the objects. The camera is placed far enough back to see all the objects and points at the center of the objects. The user is prompted to enter a point of view: either right, left, top, bottom, front, back or quarter.

These will provide default points of view that will suffice for many systems. If you need to modify the camera location for your particular system, simply change the location and/or look_at portions of the camera syntax block in the POV script. The camera will be placed at the coordinates given by location and will be pointed at the coordinates given by look_at.
camera {
location
look_at
}
Note: POV-Ray uses a left-handed coordinate system as opposed to Zemax’s right-handed coordinate system. In a left-handed coordinate system the positive y-axis points in the direction of the left thumb, the positive z-axis points in the direction of the left index finger, and the positive x-axis points in the direction of the left middle finger.
The lighting syntax places a circular emitter a sufficient distance above the system and points towards the center of the system. Another identical source is place above and to the left of the camera to give a realistic shine to the elements. The default light source and location are chosen to give sufficient illumination of the entire system. If you need to modify the lighting syntax, it is the light_source{ } block of code. The syntax is as follows:
light_source{ color rgb spotlight radius R point_at }
The first (X,Y,Z) coordinate is the location of the center of the light source. The color of the light emitted is given by a set of RGB values. The half-width of the source is given by the radius R. Lastly the source will be oriented to point at some (X,Y,Z) coordinates. POV-Ray supports many types of light sources; if you desire to change the type of light source, consult the POV-Ray documentation for the supported syntax.
The object materials and finish have been defined to give a realistic looking mirror, absorbing, or glass look. Currently, the macro will assign all mirror elements the mirror look, all absorbing elements will be colored black, and all other non-air objects are assigned a glass look. Future macro developments may bring more detailed material and finish assignments based upon the optical properties of the surfaces/objects defined in Zemax.
The object definitions constitute the majority of the POV-Ray script and consist of smooth triangles combined to create a mesh object. It is not recommended that you modify this portion of the script by hand because this will change the object’s shape.
Lastly, the sky_sphere{} syntax defines a background that has a gradient color. The color can be changed by redefining the default “White” and “NewMidnightBlue” syntax. The color must be one of numerous supported colors. See the POV-Ray documentation on “colors.inc” for a list of supported colors.
EXPORT EXAMPLE
Let’s look at a simple example to demonstrate the use of the POV-Ray macro. First, make sure the POV-Ray Export macro is saved in the {Zemax}\Macros folder.
Before you run the macro, you must be aware of a particular setting in POV-Ray that could cause the macro to fail. The macro executes and closes POV-Ray via a shell command. By default, POV-Ray only allows one instance of the program to run at a time. If this is not disabled and POV-Ray is already running, an error will be given that will prevent proper execution of the macro.
There are two solutions:
1) Exit POV-Ray before running the macro.
2) Uncheck the “Keep Single Instance” option in the POV-Ray options menu

Once you have taken one of the two steps listed above, open the “Double Gauss 5 degree field” sample file in the {Zemax}\Samples\Sequential\Objectives folder. Select the POV-Ray Export macro from the macros menu.
The macro initially prompts the user to enter the full path of the POV-Ray program. This allows Zemax to execute POV-Ray via a shell command. To determine the program location: right-click the POV-Ray icon on the desktop or in the Start menu, and select Properties.

You will then be presented with a dialog that contains the "Target" for the program. Copy this path into the macro input dialog.

The other piece of information the macro needs is a point of view. You must enter the point of view in lower case letters with the correct spelling. The dialog will continue popping up until one of the seven supported points of view is entered.
For this example, enter “quarter” into the input dialog.

These are the only inputs the user must provide. Zemax then generates a POV-Ray script and runs POV-Ray using a shell command. You will see the POV-Ray program open, render, and then close. POV-Ray saves a bitmap file to the {Zemax}\IMAFiles folder with the same name as the original lens file.
The macro then pauses for 5 seconds to ensure that POV-Ray has finished rendering and saving the bitmap file. Most systems will be rendered and saved in less than 5 seconds. If Zemax gives the following error message, it means that Zemax is looking for the bitmap file before POV-Ray has created it.

If this is happening, you will need to increase the pause time before Zemax attempts to load the bitmap. This can be easily done by modifying the pause time syntax a few lines before the end of the macro. Enter the number of milliseconds that you would like Zemax to pause.

After this pause, Zemax launches the JPG/BMP File Viewer (Analysis > Image Simulation) and loads the newly created bitmap. The default window dimensions are set by Zemax, not POV-Ray, so you may find it necessary to resize the viewer. Note that if the viewer is expanded to be larger than the native resolution of the bitmap, the image will look pixelated.
The POV-Ray rendering of the Double Gauss lens is below.

Keep in mind that the realism of the rendering depends heavily on the placement of the camera and lights. The macro uses a generic routine to locate the camera and lights. If the size of the elements in the frame is too big or small, change the location of the camera. If the reflections and appearance of the elements is not desirable, relocate the lights. In general the materials and finishes are realistic, so long as the lights are properly placed.
SUMMARY
Photorealistic rendering can be used to create very realistic images of any object scene. The POV-Ray export macro can be used to create a photorealistic rendering of nearly any Zemax lens design. The user only needs to specify the POV-Ray program location and the point of view from which they would like to view the system, and the macro will create and execute the POV-Ray script.