Skip to content

Instantly share code, notes, and snippets.

@sariths
Created October 11, 2017 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sariths/f16147efc83376c1f9c11c2f5ad24a20 to your computer and use it in GitHub Desktop.
Save sariths/f16147efc83376c1f9c11c2f5ad24a20 to your computer and use it in GitHub Desktop.
Create colorful tregenza sky patches.
# coding=utf-8
import os
import random
import glob
def renderTregenzaPatches(outputPath='tregenzaPatch.hdr',imgResolution=200,reinhartMF=1,cleanUp=True):
"""
:param outputPath: A filepath where the created image should be written to. Defaults to tregenzaPatch.hdr in the same
directory that the script is being run in.
:param imgResolution: Resolution of the generated fish eye image. Defaults to 200 pixels.
:param reinhartMF: Sky resolution. Specify a value between 1 to 6. In Windows, only 1 is likely to work.
:param cleanUp: Set this to True to delete all the files that were created during the process.
:return:
"""
viewDefinition="-vth -x {res} -y {res} -vd 0 0 1 -vv 180 -vh 180 -vp 0 0 0 -vu 0 -1 0".format(res=imgResolution)
skyGlow="""
#@rfluxmtx u=+Y h=u
void glow groundglow 0 0 4 1 1 1 0
groundglow source ground 0 0 4 0 0 -1 180
#@rfluxmtx u=+Y h=r{MF}
void glow skyglow 0 0 4 1 1 1 0
skyglow source skydome 0 0 4 0 0 1 180
""".format(MF=reinhartMF)
with open('skyDome.rad','w') as skyDome:
skyDome.write(skyGlow)
cmd = """vwrays -ff {view} | rfluxmtx -ffc -n 16 -x {res} -y {res} -ld- -ab 1 -o skyTregenza%04d.hdr - skyDome.rad"""\
.format(view=viewDefinition,res=imgResolution)
os.system(cmd)
cleanUpList = ['skyDome.rad']
Patches=144*reinhartMF*reinhartMF+1+1
genskyvecHeader=["#?RADIANCE"]
genskyvecHeader.append("genskyvec -m %s"%reinhartMF)
genskyvecHeader.append("NROWS=%s"%Patches)
genskyvecHeader.append("NCOLS=1")
genskyvecHeader.append("NCOMP=3")
genskyvecHeader.append("FORMAT=ascii\n")
genskyvecHeader.append("\n")
genskyvecHeader="\n".join(genskyvecHeader)
for val in xrange(Patches):
genskyvecHeader+="%.8f\t%.8f\t%.8f\n"%(random.random(),random.random(),random.random())
with open('sky.vec','wb') as skyVec:
skyVec.write(genskyvecHeader)
os.system('dctimestep skyTregenza%04d.hdr sky.vec > {}'.format(outputPath))
cleanUpList.append('sky.vec')
cleanUpList.extend(glob.glob("skyTregenza*.hdr"))
if cleanUp:
for files in cleanUpList:
os.remove(files)
return outputPath
renderTregenzaPatches('tregenzaPatches.hdr',imgResolution=600)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment