Thursday, 23 August 2012

IES lights in Blender Cycles

IES photometric luminaire files can now be rendered, with a bit of a workaround, in Cycles. Point lamps in Cycles can accept environment textures, and since Blender 2.63 these environment textures can be High Dynamic Range (HDR) images. The correct HDR representation of an IES described lamp can therefore be loaded as an environment texture onto a point lamp and rendered. It is important that the lamp is a point lamp as this ensures that the incoming light ray sees the correct pixel of the texture, providing the mapping is as desired. The node arrangement below (specifically the 270 deg in the x rotation dialogue of the mapping node) achieves a mapping where the light is pointing downwards (-ve Z).
The multiply nodes allow you to change the colour of the light.The limiation with this arrangement is that rotation of the lamp in Blender does not rotate the texture (because it's a point lamp) so the rotation has to be changed in the mapping node to match the lamp rotation. This limitation has been overcome, rather cleverly, by gexwing at Blenderartists. Gexwing's node arrangement can be found in this thread. I've had some problems with this node arrangement when doing gpu rendering though so your mileage may vary.

The last piece of the jigsaw is the generation of the HDR texture from an IES file. The bad news is is that this requires another renderer; Radiance. The good news is I've written a Python script to help with the process. Radiance needs to be installed on your system, or more specifically the binaries oconv, ies2rad, rpict, rcalc and pvalue must be in your system path, and the file must be in your library path. The binaries and scripts for multiple packages can be found here. The script, called, is available from the scripts page, but as it's only short I've included the code here:

import subprocess, glob
spheregeo = open('sphere.rad', "w")
spheremat = open('sphere.mat', "w")
spheregeo.write("sphere_plastic bubble ball\n     0\n     0\n     4  0 0 0 1")
spheremat.write("void plastic sphere_plastic\n     0\n     0\n     5  1 1 1 0 0.5")

filelistIES = glob.glob('*.IES')
filelisties = glob.glob('*.ies')
filelist = filelisties+filelistIES

for file in filelist:
    filebase = file.split(".")[-2]"ies2rad -i 0.001 -t default -o "+filebase+" "+file, shell=True)"oconv sphere.mat sphere.rad "+filebase+".rad > "+filebase+".oct", shell = True)"rpict -ab 0 -vta -vp 0.0 0 0 -vd 0 0 -1 -vu 0 1 0 -vh 360 -vv 360 -x 500 -y 500 "+filebase+".oct | pvalue -d -h -H | rcalc -e '$1=3.149*$1;$2=3.149*$2;$3=3.149*$3' | pvalue -r -H -h -d -y 500 +x 500 > "+filebase+".hdr", shell=True)

With your system terminal navigate to the directory containing the ies files you want to convert and if you have made the file executable simply type and hit enter. If it is not executable then type python Naturally you'll need Python installed on your system too. I am going to convert this into a Blender add-on too eventually, and the system Python installation will then no longer be required. The script may not work as is on Windows. If not try replacing single with double quotes, and vice-versa, in the long subprocess line. If it worked you should now have an HDR file for each IES file, and it is these HDR files that are loaded into the Environment Texture node with a mirror ball mapping.
The simple video below shows single and dupliverted IES lights in Cycles.

IES lights in Blender Cycles from Ryan Southall on Vimeo.

Creative Commons Licence
This work is licensed under a Creative Commons Attribution 3.0 Unported License.

No comments:

Post a Comment