HDR Pipeline Tools

I recently saw a very convincing presentation, which argued that CG lighting is dead. HDR capture of lighting environments can be can be done quickly and easily - provided you have the right tools. Unfortunatly those tools aren't always available, and the tools which are around aren't always HDR safe.

My obvious reaction was to write some code to do the job for myself. The INITIAL results are here - these are very much alpha quality, work in progress, but I wanted to get some of them out here for testing, to figure out which bits of the pipeline need more work.


The HDR Tools are currently available for FreeBSD and Linux.


Firstly we need some clean input images. I've got a Canon DSLR, and have had good results shooting in RAW (jpeg sucked for this application). Convert your RAW's to 16bit linear tiff using the command " dcraw -v -4 -T xxx.CRW". You might need to install dcraw - it handles all sorts of formats, so you should be good to go for most cameras (though I can't say how reliable the captures will be - the Canon worked nicely for me).

Now we need to merge a set of shots at different eposures into one HDR image. This is done by the "knit" program: "knit out.exr in1.tiff in2.tiff...". Your tiff files must be in the order of either increasing or decreasing expoure (but not mixed). Knit guesses the relative exposures, and writes out the HDR file. The maximum exposure step should be 3 stops. This seems to be reliable, but if you ind something that fails badly, then let me know.

As you've shot on a wide lens you've probably got some nasty distortion going in. Delens is an image warper which fixes this. Run "Delens srcImage.exr", and adjust it till it looks good. Then you can write out srcImage.UV.tiff which contains the mapp for that lens. Once thats done you can delens the image (or any other image taken with the same lens) using "batchDelens nextImage.exr srcImage.UV.tiff out.exr". If you want to you can reverse the operation using batchDelens -r to reapply the distortion of the original lens.

You probably need to do some retouching at this point. The problem is most paint packages aren't (or might not be) HDR safe. "Paint" is the worlds worst paint program - its slow, clunky and lacking features of any kind. Maybe I should have spend more than an hour writing it... It is however HDR friendly.

Once you've got some nice clean planar images, you're ready to stitch them together: "stitch out.exr srcImages...". You can have up to ten images. press C to move iamges around, and Z to zoom images. Once you're done 'w' saves the result. A quick trip back to "paint" to tidy the edges and you've got an HDR environment map!

The only remaining stage is some fancy blurring so that you can use blurred maps to produce non-specular reflections. You can do this using the preblur commaon. You can use the -r option to specifiy roughness (rather like the RenderMan specualr function/plastic shader) - use 1 for diffuse, and a smaller value for shiy surfaces. Default is 0.01. You can adjust the image size with -w and the image quality with -s (samples - default 40000). This does take some time as the correct sampling pattern is complex, but if you set a batch job running overnight to produce a selection of blurs you should have a working set of environment mapts the next morning.

If you're using the graphical tools, don't forget to set GAMMA to a sensible value (try export GAMMA=2 if you don't know any better, but check the gamma pages for tools and advice). Also DO NOT resize the windows. The code is too dumb to figure it out, and all sorts of stuff will break.

ALL of these tools are pretty limited - the plan is to get them out REAL quick 9most were written in a few hours - a day at most), so that there's a pipeline in place. Then we can start working on turning each of the tools into something REALLY usefull.

Ian Stephenson.
DCT Systems
NCCA, Bournemouth University