Automating Radiance renders with Python
Today’s session focused on automating the rendering process of Radiance using python. It involved creating a bunch of randomly positioned & sized red spheres with a couple of lights before calling Radiance for the render scene.
The final script can be obtained here. Below is a little bit of modifications applied to randomize the color of the spheres. However, glow , in the script below does not seem to have a major impact as compared to light even when maxrad value is modified. I was hoping the to get some glowing effect from the main light emitter.
#================================================================================
# Imports
#================================================================================
import os
import random
#================================================================================
# Functions
#================================================================================
#Function to write a glowing object
def write_material_light(rad_file, name, rgb_e, maxrad):
rad_file.write("# glow material\n")
rad_file.write("void glow " + name + "\n")
rad_file.write("0\n")
rad_file.write("0\n")
rad_file.write("4 " +
str(rgb_e[0])+ " " +
str(rgb_e[1]) + " " +
str(rgb_e[2]) + " " +
str(maxrad) + "\n\n")
def write_material_plastic(rad_file, name, rgb, spec, rough):
rad_file.write("# Plastic material\n")
rad_file.write("void plastic " + name + "\n")
rad_file.write("0\n")
rad_file.write("0\n")
rad_file.write("5 " +
str(rgb[0])+ " " +
str(rgb[1]) + " " +
str(rgb[2]) + " " +
str(spec) + " " +
str(rough) + "\n\n")
def write_surf_sphere(rad_file, name, material, position, radius):
rad_file.write("# Sphere \n")
rad_file.write(material + " sphere " + name + "\n")
rad_file.write("0\n")
rad_file.write("0\n")
rad_file.write("4 " +
str(position[0])+ " " +
str(position[1]) + " " +
str(position[2]) + " " +
str(radius) + "\n\n")
#================================================================================
# Main script
#================================================================================
#Create the scene file
rad_file_1 = open("D:/Pythontest/radiance/spheres/scene.rad", "w")
#Specify lights colour
write_material_light (rad_file_1, "mat_light_1", (100, 80, 80), 200)
#Randomize spheres colour
for i in range(10):
rgb = (random.random() / 11.0, random.random() /11.0, random.random() /11.0)
spec = random.random() /100.0
rough = random.random() /100.0
write_material_plastic( rad_file_1, "mat_red_"+str(i), rgb, spec, rough)
#Create main light
for i in range(1):
position = (random.random() * 5, random.random() * 5, random.random() * 5)
radius = random.random()
write_surf_sphere(rad_file_1, "light_"+str(i), "mat_light_1", position, radius)
#Create background lights
for i in range(200):
position = (random.random() * 5, random.random() * 5, random.random() * 5)
radius = random.random()/2000.0
write_surf_sphere(rad_file_1, "light_"+str(i), "mat_light_1", position, radius)
#Create the spheres
for i in range(5):
position = (random.random() * 5, random.random() * 5, random.random() * 5)
radius = random.random()
write_surf_sphere(rad_file_1, "ball_"+str(i), "mat_red_"+str(i), position, radius)
rad_file_1.close()
#Run radiance using rad
rif_file_1 = open("D:/Pythontest/radiance/spheres/scene.rif", "w")
rif_file_1.write("ZONE = E 0 5 0 5 0 5\n")
rif_file_1.write("EXPOSURE = +1\n")
rif_file_1.write("RESOLUTION = 1400 900 1200\n")
rif_file_1.write("QUALITY = HIGH\n")
rif_file_1.write("PENUMBRAS = TRUE\n")
rif_file_1.write("DETAIL = HIGH\n")
rif_file_1.write("VARIABILITY = LOW\n")
rif_file_1.write("scene = D:/Pythontest/radiance/spheres/scene.rad\n")
rif_file_1.close()
os.system("C:/Radiance/bin/rad D:/Pythontest/radiance/spheres/scene.rif")



