Drawing Stars - acnelson12/PP4 GitHub Wiki

Stars can be drawn either as disks or more realistically using gradients. While drawing disks is relatively trivial, drawing realistic stars is a rather difficult mathematical challenge.

Mathematics of Star Images

Creating good models of star images is not a simple task. Although stars appear as points, the image (including the one formed on your retinas by your eyes) is affected by diffraction and scattering that occurs with the instruments used to create it. These are also responsible for things like lens flares. The mathematical models created for star images are called point spread functions or PSFs, and obtaining an understanding of multivariable calculus and differential equations is recommended before exploring this topic in detail. My own understanding is rather limited, so I will not try to explain them here.

http://adsabs.harvard.edu/abs/1971PASP...83..199K

http://www.stsci.edu/hst/acs/documents/isrs/isr0601.pdf

Development of Realistic Stars

Radial Gradients

The simplest way to improve realism in the drawing of stars is to use a radial gradient. Unfortunately, most gradient functions only work linearly, but a look at good-quality astronomy photo will quickly show that a much more complex model is needed. In its simplest form, the linear radial gradient results in stars that look like spheres; they don't seem to have radiance. The spherical appearance can be improved by setting many stops in the gradient, but this quickly becomes more complicated than it's worth.

Exponential Functions

In an email from Ernie Wright, the following method was recommended as a place to start:

intensity = exp( -pow( d, p )) + exp( -pow( d, p * 2 )) + exp( -pow( d, p * 3 ));

Variable d is the distance from the center, and p is a variable to control the rate the function falls to zero. The runtime of this is rather slow, so a lookup table indexed by values of d is generated by PP4.