This post will cover many things that I have learned over the years using povray. The goal is to keep things simple and generate nice looking renders without too much complexity. I will also cover how to load simulation data for rendering.
When using radiosity I do not put in any extra light sources, povray describes this as Radiosity without conventional lighting. I find that this creates cleaner looking renders. In some cases where hard shadows are required or you want to have fine control over lighting you can add lights as needed.
I usually start with the flowing settings and tweak from there. For most scenes I use a brightness value of 2.0 or 2.5 as there are no extra lights. Tweaking gray_threshold can be useful if you have bright objects and are getting too much color bleed.
A more complete radiosity example looks like this:
Max Trace Level
max_trace_level is a global settings that controls how many bounces each ray experiences. Another way to think about it is that if you had 100 glass spheres in a line, setting the max_trace_level to 10 would not allow light to pass through all of the objects because the ray didn’t make it all of the way through and stopped after 10 layers.
Povray doesn’t come with default support for quaternions but several years ago Alain Ducharme wrote a very useful set of macros. The include file is here.
I usually don’t include the full quaternions.inc file, the following macros are generally enough
To use the macros:
There are two main ways to specify information in povray like the image resolution or antialiasing settings. The first way is through the command line or through an INI file. In either case, every option in povray has a command line version and an INI version.
Below is the .ini file that I usually use. Antialiasing is turned on, the image resolution is 1920x1080, images are rendered as .png (Output_File_Type=N) and saved to output_folder.
Then I call povray with povray +WT2 +KFI0 +KFF2000 test.ini, which will render from frame 0 to frame 2000 using 2 threads. Note that output file names are padded with zeros depending on the start and final frame numbers. For example povray +WT2 +KFI0 +KFF2000 test.ini will pad zeros so that the file name is 4 numbers long 0001.png … 0200.png … 1900.png etc.
If you want to specify the start and end frame numbers in the ini add the following lines
Subset of frames can also be rendered, this is useful if you want to render a set of frames but keep the numbering consistent in terms of zero padding. For example povray +WT2 +KFI0 +KFF2000 +SF100 +EF120 test.ini will render from frame 0100.png to 0120.png. Note that the number of zeros padded is based on the +KFF2000 or Final_Frame=2000 setting and not the +SF +EF or equivalently the Subset_Start_Frame Subset_End_Frame options. More details on options can be found here
Note that for all of these frame number related settings there exists a frame_number variable in PovRay that changes with each frame. I will cover this a little bit later.
File I/O is important if you want to load in a ton of simulation data without writing a custom pov file. This way the simulation data can be used in other postprocessing applications while still being able to visualize it.
Say we have the following data file stored as “simdata.txt”
We can open this file for reading and read the first three entries and then do something with it.
If we wanted to read multiple lines automatically we can do the following
We can also generate a filename from an integer, this will come in use in the next section when we can to render an animation. Here the concat function is used to build up the file name using the number and the file extension. More complicated strings can be gerenated depending on your needs.
In PovRay there is a frame_number variable that is incremented with each frame based on settings in the .ini or settings set from the command line.
In many cases writing a single .pov file that handles all of your rendering rather than creating a new pov file for each frame is really useful. If we combine the file I/O and the frame number together we can read in data that is specific to a frame and write our pov file so that it can make decisions based on the data that is has for that frame.
Rendering Generic Data
I typically organize my data so that I have some information on the type of object I am rendering. The following convention works pretty well for me:
The first three entries are the position, followed by the rotation as a quaternion, and then the velocity of the shape I want to render. The next piece of information is the type of shape I want to render
in practice this looks like the following:
What we want to do is to read up till the type information and based on the type, read the next set of data. The pov file to read something like this is as follows:
Rendering Dirt or Water
Here what we are trying to do is to render a set of spheres but each sphere has a different color based on a random seed. This is useful to create a “dirt” or textured water look.
First find a set of colors, I used the following palette. To render a set of spheres loaded in from a file using four colors we do the following
If we store velocity data from the simulation and load it in we can render it as a color, details here