Lightmapping
POV-Ray lightmapping helper
This Java tool helps preparing a basic structure of POV-Ray files and a batch script, which will allow to bake lightmaps from a POV-Ray scene. The scene, at least the part of it to be baked, has to be composed out of uv-mapped meshes, and converted to POV-Ray format using Poseray.
At first, this was going to be just a little tutorial illustrating a method I developed to generate lightmaps with POV-Ray, using the new mesh_camera feature in the latest version. I started by doing all the work manually, but as it was rather tedious with more than a few meshes, I created a PHP_CLI script which automated the process by creating the needed include files and a batch script.
I used PHP just because I’m accustomed to use it to write this kind of file I/O scripts, but it seemed an odd choice for a multiplatform distribution. After a little quest, I decided my best option was to use Java instead. A friend recommended Netbeans, so I installed it and started development… it seemed so easy to learn, that I decided to move the app from the command-line to a simple GUI, and in the process I’ve made it a bit more complete and practical (though there is still plenty of room to refine and enhance, or even redesign this tool).
General Description
A lightmap is an image which captures the effect of the lighting on the surface of a 3D object. The technique usually known as lightmap baking, consists on rendering images of the uv maps with a plain white texture, so the resulting maps can be used back to texture the meshes (this is done usually by just multipliying the lightmaps and the final pigments), making the light sources no longer necessary.
The more obvious applications are virtual reality and games, but it could be useful also just to make faster POV-Ray animations, or to render in minutes multiple views of a scene, or the same shot with different textures, etc…
The main drawback is that we lose color bleeding in radiosity, as the pigments are all white (tough the same procedure can be used to bake textured maps, just by using POV-Ray textures instead plain white pigments). Also, only the meshes on the scene can be baked, but other primitives can be used if they are going to be self-lighted or not visible.
The process I used assumes that our main purpose is to use POV-Ray as a radiosity-baking engine for externally modelled scenes, converted to POV-Ray format with Poseray. It will go as follows:
- Create the mesh-scene on your favorite modeler and export it to a format supported by Poseray.
- Load the exported file into Poseray, and export it to POV-Ray meshes.
- Run the Java tool on the Poseray export to generate the customized include files and batch script needed for the baking process.
- Fill the generated templates for lighting, camera and non-baked objects.
- Render the main scene generated to test the camera and lighting setup using regular rendering.
- When you are satisfied with the lighting, run the generated batch script to bake all the lightmaps.
- Use the generated main scene to test the baked lightmaps, this time without light sources.
- Import the lightmaps and meshes onto you preferred VR application, game engine, etc… or just use them with POV-Ray.
I explained these steps with more detail on the include README, so just go and download the archive.