How to simulate a rainbow

This article describes how to model a rainbow using the non-sequential capabilities of OpticStudio. Non-Sequential Mode has the ability to model true color sources using several source color models.

Authored By Shinichi Nagata, Lensya Limited


Article Attachments


In OpticStudio's Non-Sequential Mode, a rainbow can be simulated in a few steps. By generating a black body source used in conjunction with user-defined coating, we will show how to model a rainbow in this article.

The files we use are attached to this article. 

System definition

Here is the simulated image of a rainbow.

primary rainbow

In the detector image above, you can see a “primary rainbow” which is the brighter rainbow on the bottom, and a “secondary rainbow”, the dimmer rainbow on the top. The darkness between these two bows is the so called the “dark Alexander’s Band”.

As you can see, the secondary rainbow is dark and its color order from red to purple is in the inverse order.

The displayed field angle is ±16 degrees horizontally and ±9 degrees vertically.

The layout for this model is below. It is set to color rays by segments. In other words, the rays are a different color after each refraction and reflection.

layout     layout

The parallel incidents rays are drawn in blue lines, which represent the light from the sun, and the rays refract as they enter the sphere, which represents the spherical raindrop; rays traveling inside of the raindrop are plotted with green lines. As you can see, most of the rays directly emerge from the raindrop as displayed in red lines. However, some rays entering the upper part of the raindrop reflect at the back of the drop with a Fresnel reflection of 2%, as drawn in brown lines, and they leave the drop close to the bottom, as shown in the yellow line which refracts at the exit. This makes the primary rainbow and the brighter section under it.

In addition, there are some rays entering at the bottom part of the raindrop which reflect twice at the back of the drop. The reflected rays exit the drop on the upper part, as drawn in the purple and create the secondary rainbow and the brighter section above it. Because both of the reflections are Fresnel reflections, the secondary rainbow only has 2% of energy in comparison to the primary. There is a caustic line in the angle of the primary and secondary rainbows and hence the rainbows are in vivid color. Although there are reflected rays under the primary and above the secondary rainbows, all colors are mixed so that no individual colors can be observed. Because there are no reflected rays between the angles of the primary and the secondary rainbows, the dark band is created.

Modeling a rainbow

We will now model a rainbow. First, in order to model a raindrop, we use a spherical object with a radius of 0.1 mm and water as the material. For the source, we use a “Source Radial” with the X & Y half width of -0.1 mm (negative signs make it circular.) The distribution angle of the source is the same as the apparent angular radius of the sun, which is 0.25 degrees. We then set the source’s spectrum as shown in the object properties dialog below:

black body spectrum

For the source color , we use a black body spectrum with a temperature of 6000 K (the temperature of the sun). The wavelengths are from 0.4 to 0.7 microns with 100 discrete wavelengths in between.

We use a “Detector Color” which displays the real color based on the spectral sensitivity of the human eye. We use radiant intensity as the data shown so that we can reproduce a condition that the observer is watching many raindrops from a far distance. Thus, it is unnecessary to model multiple raindrops.

If we are to model only a rainbow, the above three objects are sufficient. However, that will create a rainbow in the dark sky. So in this article, we will add a “blue sky”. We use a standard surface to model the blue sky and we add Gaussian Scattering on its surface as shown in the green box below. The material for the object is “mirror”.


To reproduce the blueness of the sky we need blue reflected light, so we create a coating called BREF as defined below.


This coating will give you the following reflection versus wavelength:

reflection vs wavelength

Shorter wavelengths have higher intensity reflection, so the reflected light will be blue in color. This reflection versus wavelength is not the same as the actual air scattering properties; it is simplified to mimic the blue sky.

Once we define all of the necessary objects above, may perform a ray trace. Make sure to check the boxes for “split rays” and “scatter rays” when you trace. The number of analysis rays is 50 million so it will probably take a few minutes to complete.



Was this article helpful?
3 out of 3 found this helpful



Please sign in to leave a comment.