Render 3D graphics in Mathematica using Pov-ray

Mathematica can produce beautiful 3D plots, but sometimes we want more realistic looking plots such as the plots produced by ray tracing softwares. Since Mathematica support exporting varies 3d format, we can use this ability to export the 3d plots and render in other ray tracing softwares.

Here is a simple wrapper (download at the end of this post) that can export and render 3d graphics in Pov-ray, and then connect the results back into the notebook. The usage is simple, just call the function with a 3d plot and the path to the povray executable. Here are some examples:

Get["PovrayRender.m"]
p = SphericalPlot3D[
 1 + 2 Cos[2 \[Theta]], {\[Theta], 0, Pi}, {\[Phi], 0, 2 Pi}, 
 Mesh -> None, PlotPoints -> 80];
povrayRender[p, "/Applications/PovrayCommandLineMac/Povray37UnofficialMacCmd"]
Snip20140727_6

 

p = ParametricPlot3D[{{4 + (3 + Cos[v]) Sin[u], 
 4 + (3 + Cos[v]) Cos[u], 4 + Sin[v]}, {8 + (3 + Cos[v]) Cos[u], 
 3 + Sin[v], 4 + (3 + Cos[v]) Sin[u]}}, {u, 0, 2 Pi}, {v, 0, 2 Pi},
 PlotStyle -> {Red, Green}, PlotPoints -> 80, Mesh -> None];
povrayRender[p, "/Applications/PovrayCommandLineMac/Povray37UnofficialMacCmd"] 

 

Snip20140727_3

 

p = ContourPlot3D[(x^2 + (9/4) y^2 + z^2 - 1)^3 - 
 x^2 z^3 - (9/80) y^2 z^3 == 0, {x, -1.5, 1.5}, {y, -1.5, 
 1.5}, {z, -1.5, 1.5}, PlotPoints -> {100, 40, 40}, Mesh -> None, 
 ContourStyle -> Red];
povrayRender[p, "/Applications/PovrayCommandLineMac/Povray37UnofficialMacCmd"] 

 

Snip20140727_8

p = ListPointPlot3D[
 4 Table[Sin[i] Cos[j], {i, -5, 5, .25}, {j, -5, 5, .25}], 
 ColorFunction -> "Rainbow"];
povrayRender[p, "/Applications/PovrayCommandLineMac/Povray37UnofficialMacCmd"] 

 

Snip20140727_10

p = ParametricPlot3D[{(2 + Cos[v]) Cos[u], (2 + Cos[v]) Sin[u], 
 Sin[v]}, {u, 0, 2 Pi}, {v, 0, 2 Pi}, Mesh -> 25, 
 MeshShading -> {{Red, Yellow}, {Pink, Orange}}, PlotPoints -> 100];
povrayRender[p, "/Applications/PovrayCommandLineMac/Povray37UnofficialMacCmd"] 
Snip20140727_11

The package can be downloaded here