The Persistence of Ignorance

Menu Home

Mesh Camera

POV-Ray 3.7 > beta 39, 2010 (184 K)

The "mesh camera" is a new type of camera which uses a mesh as a guide to trace the rays into the scene, using the normal at each face. It was recently introduced in the beta version, and I helped to test and develop it at the POV-Team request.

Basically, this new feature has two main usages for now: baking textures and creating custom cameras. To show what it can do and how it works, I prepared a little tutorial and some basic demo scenes, which are also bundled with the latest beta release.

As this feature has great potential for many different uses, I opened a whole new subsection for it, where I will add subpages for specific uses, with quick tutorials and demo scenes (for the moment, these possible uses are listed at the end as "untested ideas").


Let's start first with an introduction to the new camera syntax:
camera{ mesh_camera{ rays_per_pixel distribution_type MESH_OBJECT ... [smooth] } location [direction ] }

I hope you will forget that I didn't use proper syntax specification... anyhow, here is the explanation of each item in the above specification:


This parameter controls the number of rays that will be shot from each face on the mesh. Each distribution bellow allows different values, but minimum is always 1.


This parameter controls how pixels are assigned to faces:


One or more mesh or mesh2 object to be used as camera. These will be treated differently depending on the distribution method, as explained above.

Transformations on the meshes can be used here, and will reflect on the resulting image as it would be expected for a regular camera.


On this special camera, location doesn't really tells where the camera is placed (that information is on the mesh object itself), but is used to move the origin of the ray slightly off the face, along the normal of that face. The X and Y for location is not currently used, and the Z always refers to the normal of the face, rather than the real Z direction in the scene.


Again, this doesn't correspond to the real direction vector of the camera. It serves only to reverse the normal of all the faces, if necessary. As with location, only the Z component is used.


As I said above, this new feature has two main usages:


Texture baking:

It is surely the usage that is going to be the most popular, because it is something other packages already do, and because it can be very useful for some specific and well established applications. I showed on the demo the potential as a tool to accelerate POV-Ray renderings, specially for camera animation, but the basics will apply when baking for other purposes, like generating texture maps for external applications (modelling packages, architectural presentations, games, VR environments, etc...).

As it's expected, it only allows to bake meshes, so it will be only useful when your scene consists mostly on meshes. That's why the demo scene included on the zip uses only mesh objects created with Wings3D: two vases and a room with a window. All of them have uv maps, which are also necessary to bake the textures.

The idea is to set up a scene in a way that would allow for normal rendering while developing the scene, later will allow to bake all the textures (with lighting) to image files, and finally will allow the use the baked textures to render the scene in much shorter time. The benefits are multiple: you can enhance/change the textures with an external paint program and render again in seconds, or add slow features to the baked render, like micro-normals for blurred reflections, focal blur, or any other feature wich used on a direct render will be very slow.

To accomplish the baking step, I used the animation features so that each mesh can be baked with a different value of the clock. Then, with a little script, I launch all the baking renders with custom output file names. These will be used later on a final step, where the lights are off and the baked textures have all emission on the finish. The baking script also calls to a "tool scene" which mitigates the problem with visible seams on the UV maps.


Custom cameras:

Perhaps not as exciting for the general public as the baking usage, this alternative use has great potential for experimentation, and surely will be the source for many useful tools that will use it for the more varied effects.

For a start, my examples illustrate how to mimic a classic pinhole camera, and how to add some interesting effects, like vignetting or distortion. Other uses could include custom focal blur, simulating specific lenses (with one or more elements), etc...

The basic premise of this approach is to use a mesh as a camera, but without instantiating it into the scene, as it was done for baking. Consider a standard POV camera: it could be represented as a mesh, with one face per pixel, all faces being set in the same plane, with the normal of the faces pointing in the direction of the camera, with angles diverging from the camera location.

So, I started just with that... a simple mesh with image_width columns and image_height rows of triangles, with all the normals pointing into the scene in the correct way. Sounds simple, but it took me a while to figure out the maths to do it, and a bit more learning how to use the useful macros from In the end, I was so confused that my damaged brain decide to take a shortcut, and I was illuminated with the idea of using trace() to overcome all the mathematical difficulties.

Finally I ended up writing a set of macros to help creating and placing such camera meshes. Here are some quick informations about the macros:


Here is the description of the included demos and auxiliary files:

common files:

texture baking:

custom cameras:


I had a lot of weird ideas during last weeks, but these are the ones that where interesting enough for my brain to remember them. There are also some that were initially suggested by Chris Cason.

Texture baking:

Custom cameras:

This site uses CMS Made Simple
© 1996-2016 Jaime Vives Piqueres

Creative Commons License