Here the first code to create a simple production lighting pipeline script.
Stay tuned!
import maya.cmds as cmds
import maya.mel as mel
import pymel.core as pm
ambientName = 'ambient'
flatDiffuseName = 'diffuseflat'
ambientOcclusionName = 'occlusion'
sssFront = 'sssfront'
sssBack = 'sssback'
colorVector = ['red','green','blue']
colors = [[1,0,0],[0,1,0],[0,0,1]]
lights = ['key','fill','rim','extraR','extraG','extraB']
overrideMTLName = 'SHD_overrideMTL'
def createOverrideMTL(name):
overrideMTL = mel.eval('shadingNode -asShader lambert')
cmds.sets(renderable=True, noSurfaceShader = True, empty = True, name = overrideMTL + 'SG')
cmds.connectAttr(overrideMTL + '.outColor', overrideMTL + 'SG.surfaceShader')
cmds.setAttr(overrideMTL + '.color',1,1,1)
cmds.rename(overrideMTL,name)
cmds.rename(overrideMTL + 'SG',name + 'SG')
def createCustomColorRenderPass(contmapMin):
mayaDir=mel.eval("getenv MAYA_LOCATION") + '/presets/attrPresets/renderPass/customColor.mel'
pm.shadingNode('renderPass',n=contmapMin, asRendering=1) #Create custom color pass
mel.eval('applyAttrPreset "'+contmapMin +'" "'+mayaDir + '" 1;')
cmds.setAttr(contmapMin+'.useTransparency',1)
cmds.setAttr(contmapMin+'.transparentAttenuation',1)
cmds.setAttr(contmapMin+'.numChannels',3)
cmds.setAttr(contmapMin+'.frameBufferType',2)
cmds.setAttr(contmapMin+'.colorProfile',3)
def createPasses():
numberOfPass = numberOfIdPasses()
createCustomColorRenderPass(ambientName)
createCustomColorRenderPass(flatDiffuseName)
createCustomColorRenderPass(ambientOcclusionName)
createCustomColorRenderPass(sssFront)
createCustomColorRenderPass(sssBack)
for j in range(0,int(numberOfPass)):
createCustomColorRenderPass('id0'+str(j+1))
def numberOfIdPasses():
result = cmds.promptDialog(
title='idPasses',
message='How many id passes? :',
button=['OK', 'Cancel'],
defaultButton='OK',
cancelButton='Cancel',
dismissString='Cancel')
if result == 'OK':
idNum = cmds.promptDialog(query=True, text=True)
return idNum
def fillBuffer(wtc):
wtcName=wtc
passName = wtc
nodes = cmd.ls(typ='writeToColorBuffer')
if nodes != None:
for node in nodes:
if node.count(wtcName):
try:
cmd.connectAttr(passName + '.message', node + '.renderPass')
except:
pass
def defineGlobals():
cmds.setAttr('defaultRenderGlobals.currentRenderer', 'mentalRay', type='string')
createPasses()
createCustomRenderPass('motionvector','2DMotionVector')
createCustomRenderPass('beauty','beauty')
cmds.setAttr('beauty.frameBufferType',2)
cmds.setAttr('beauty.numChannels',3)
createCustomRenderPass('matte','matte')
cmds.setAttr('matte.frameBufferType',2)
createOverrideMTL(overrideMTLName)
#globals adjustment
cmds.setAttr('defaultRenderGlobals.imageFormat', 3) #TIF
cmds.setAttr('defaultResolution.width',1024)
cmds.setAttr('defaultResolution.height',436)
cmds.setAttr('defaultRenderGlobals.colorProfileEnabled',1)
cmds.setAttr('defaultRenderGlobals.inputColorProfile',3) #sRGB
cmds.setAttr('defaultRenderGlobals.outputColorProfile',2) #Linear sRGB
# Adjust the frame extension name
cmds.setAttr('defaultRenderGlobals.outFormatControl',0)
cmds.setAttr('defaultRenderGlobals.animation',1)
cmds.setAttr('defaultRenderGlobals.putFrameBeforeExt',1)
cmds.setAttr('defaultRenderGlobals.extensionPadding',4)
# RGB 3x16 frame buffer
cmds.setAttr('miDefaultFramebuffer.datatype',17)
cmds.setAttr('mentalrayGlobals.exportMotionOffset',0)
cmds.setAttr('mentalrayGlobals.exportMotionOutput',0)
def deleteAll():
selectionType = ['renderLayer','renderPass']
cmds.editRenderLayerGlobals( currentRenderLayer = 'defaultRenderLayer')
for s in selectionType:
sel = cmds.ls(type = s)
cmds.delete(sel)
for l in lights:
cmds.select(l,add=True)
cmds.delete()
def getSelection():
sel = cmds.ls(sl = True)
return sel
def createCustomRenderPass(contmapMin,passType):
mayaDir=mel.eval("getenv MAYA_LOCATION") + '/presets/attrPresets/renderPass/'+ passType + '.mel'
pm.shadingNode('renderPass',n=contmapMin, asRendering=1) #Create custom pass
mel.eval('applyAttrPreset "'+contmapMin +'" "'+mayaDir + '" 1;')
def createLightRig():
for l in lights:
cmds.spotLight(n = l, ca = 80, rs = True)
cmds.sets(lights[0],lights[1],lights[2],n = 'basicLights')
cmds.sets(lights[3],lights[4],lights[5],n = 'extraLights')
cmds.select(cl = True)
def createObjectAttributeOverride(layerName, object, attribute, value):
cmds.editRenderLayerAdjustment(object + '.' + attribute, layer = layerName)
if attribute == 'color':
conn = cmds.listConnections(object + '.' + attribute)
cmds.disconnectAttr(str(conn[0]) + '.outColor',object + '.' + attribute)
cmds.setAttr(object + '.' + attribute,value[0],value[1],value[2])
else:
cmds.setAttr(object + '.' + attribute,value)
def createLightsAttributeOverride(layerName, object, attribute, value):
cmds.editRenderLayerAdjustment(object + '.' + attribute)
cmds.setAttr(object + '.' + attribute,value[0],value[1],value[2])
def addSelectionToLayer(layerName, selection):
cmds.editRenderLayerMembers(layerName,selection)
def addObjectToLayer():
selection = getSelection()
for l in layers:
layerName = layerN + l
addSelectionToLayer(layerName, selection)
#load from interface
name = 'lambert2'
sq = 'sq_001'
sh = 'sh_007'
type = 'chr'
layerN = sq + '_' + sh + '_' + type + '_'
layers = ['basic','lights','extraLights','shadows','extraShadows','ctcocclusion','ctcshadows','motion']
defineGlobals()
createLightRig()
#create all renderLayer
for i in layers:
layerName = layerN + i
cmds.createRenderLayer(makeCurrent=True, number = 1, noRecurse = True, name = layerName)
#putObject into renderLayer
sel = cmds.ls('basicLights')
layerName = layerN + layers[0]
addSelectionToLayer(layerName,sel)
layerName = layerN + layers[1]
addSelectionToLayer(layerName,sel)
layerName = layerN + layers[3]
addSelectionToLayer(layerName,sel)
sel = cmds.ls('extraLights')
layerName = layerN + layers[0]
addSelectionToLayer(layerName,sel)
layerName = layerN + layers[2]
addSelectionToLayer(layerName,sel)
layerName = layerN + layers[4]
addSelectionToLayer(layerName,sel)
#basic layer
layerName = layerN + layers[0]
cmds.editRenderLayerGlobals( currentRenderLayer = layerName)
cmds.editRenderLayerAdjustment('defaultRenderGlobals.imageFilePrefix')
cmds.setAttr('defaultRenderGlobals.imageFilePrefix','<RenderLayer>/<RenderPass>/<RenderPass>', type = 'string')
sel = cmds.ls(type = 'renderPass')
for s in sel:
if s != 'motionvector':
cmds.connectAttr(layerName + '.renderPass',s + '.owner')
#override light layer
layerName = layerN + layers[1]
cmds.editRenderLayerGlobals( currentRenderLayer = layerName)
cmds.editRenderLayerAdjustment('defaultRenderGlobals.imageFilePrefix')
cmds.setAttr('defaultRenderGlobals.imageFilePrefix','<RenderLayer>/' + layers[1], type = 'string')
for i in range(0,3):
createLightsAttributeOverride(layerName,lights[i],'color',colors[i])
createLightsAttributeOverride(layerName,lights[i],'shadowColor',(0,0,0))
cmds.connectAttr(overrideMTLName + 'SG.message', layerName + '.shadingGroupOverride')
#override extralight layer
layerName = layerN + layers[2]
cmds.editRenderLayerGlobals( currentRenderLayer = layerName)
cmds.editRenderLayerAdjustment('defaultRenderGlobals.imageFilePrefix')
cmds.setAttr('defaultRenderGlobals.imageFilePrefix','<RenderLayer>/' + layers[2], type = 'string')
for i in range(0,3):
createLightsAttributeOverride(layerName,lights[i+3],'color',colors[i])
createLightsAttributeOverride(layerName,lights[i+3],'shadowColor',(0,0,0))
cmds.connectAttr(overrideMTLName + 'SG.message', layerName + '.shadingGroupOverride')
#override shadow layer
layerName = layerN + layers[3]
cmds.editRenderLayerGlobals( currentRenderLayer = layerName)
cmds.editRenderLayerAdjustment('defaultRenderGlobals.imageFilePrefix')
cmds.setAttr('defaultRenderGlobals.imageFilePrefix','<RenderLayer>/' + layers[3], type = 'string')
for i in range(0,3):
createLightsAttributeOverride(layerName,lights[i],'shadowColor',colors[i])
createLightsAttributeOverride(layerName,lights[i],'color',(0,0,0))
cmds.connectAttr(overrideMTLName + 'SG.message', layerName + '.shadingGroupOverride')
#override extrashadow layer
layerName = layerN + layers[4]
cmds.editRenderLayerGlobals( currentRenderLayer = layerName)
cmds.editRenderLayerAdjustment('defaultRenderGlobals.imageFilePrefix')
cmds.setAttr('defaultRenderGlobals.imageFilePrefix','<RenderLayer>/' + layers[4], type = 'string')
for i in range(0,3):
createLightsAttributeOverride(layerName,lights[i+3],'shadowColor',colors[i])
createLightsAttributeOverride(layerName,lights[i+3],'color',(0,0,0))
cmds.connectAttr(overrideMTLName + 'SG.message', layerName + '.shadingGroupOverride')
#override ctcocclusion layer
layerName = layerN + layers[5]
cmds.editRenderLayerGlobals( currentRenderLayer = layerName)
cmds.editRenderLayerAdjustment('defaultRenderGlobals.imageFilePrefix')
cmds.setAttr('defaultRenderGlobals.imageFilePrefix','<RenderLayer>/' + layers[5], type = 'string')
#override ctcshadow layer
layerName = layerN + layers[6]
cmds.editRenderLayerGlobals( currentRenderLayer = layerName)
cmds.editRenderLayerAdjustment('defaultRenderGlobals.imageFilePrefix')
cmds.setAttr('defaultRenderGlobals.imageFilePrefix','<RenderLayer>/' + layers[6], type = 'string')
cmds.connectAttr(overrideMTLName + 'SG.message', layerName + '.shadingGroupOverride')
#override motion layer
layerName = layerN + layers[7]
cmds.editRenderLayerGlobals( currentRenderLayer = layerName)
cmds.editRenderLayerAdjustment('defaultRenderGlobals.imageFilePrefix','miDefaultFramebuffer.datatype','defaultRenderGlobals.imageFormat')
cmds.setAttr('defaultRenderGlobals.imageFormat', 51) #EXR
cmds.setAttr('defaultRenderGlobals.imageFilePrefix','<RenderLayer>/<RenderPass>/motion', type = 'string')
# RGB 4x32 frame buffer
cmds.setAttr('miDefaultFramebuffer.datatype',5)
cmds.connectAttr(layerName + '.renderPass','motionvector.owner')
cmds.connectAttr(overrideMTLName + 'SG.message', layerName + '.shadingGroupOverride')
Stay tuned!
import maya.cmds as cmds
import maya.mel as mel
import pymel.core as pm
ambientName = 'ambient'
flatDiffuseName = 'diffuseflat'
ambientOcclusionName = 'occlusion'
sssFront = 'sssfront'
sssBack = 'sssback'
colorVector = ['red','green','blue']
colors = [[1,0,0],[0,1,0],[0,0,1]]
lights = ['key','fill','rim','extraR','extraG','extraB']
overrideMTLName = 'SHD_overrideMTL'
def createOverrideMTL(name):
overrideMTL = mel.eval('shadingNode -asShader lambert')
cmds.sets(renderable=True, noSurfaceShader = True, empty = True, name = overrideMTL + 'SG')
cmds.connectAttr(overrideMTL + '.outColor', overrideMTL + 'SG.surfaceShader')
cmds.setAttr(overrideMTL + '.color',1,1,1)
cmds.rename(overrideMTL,name)
cmds.rename(overrideMTL + 'SG',name + 'SG')
def createCustomColorRenderPass(contmapMin):
mayaDir=mel.eval("getenv MAYA_LOCATION") + '/presets/attrPresets/renderPass/customColor.mel'
pm.shadingNode('renderPass',n=contmapMin, asRendering=1) #Create custom color pass
mel.eval('applyAttrPreset "'+contmapMin +'" "'+mayaDir + '" 1;')
cmds.setAttr(contmapMin+'.useTransparency',1)
cmds.setAttr(contmapMin+'.transparentAttenuation',1)
cmds.setAttr(contmapMin+'.numChannels',3)
cmds.setAttr(contmapMin+'.frameBufferType',2)
cmds.setAttr(contmapMin+'.colorProfile',3)
def createPasses():
numberOfPass = numberOfIdPasses()
createCustomColorRenderPass(ambientName)
createCustomColorRenderPass(flatDiffuseName)
createCustomColorRenderPass(ambientOcclusionName)
createCustomColorRenderPass(sssFront)
createCustomColorRenderPass(sssBack)
for j in range(0,int(numberOfPass)):
createCustomColorRenderPass('id0'+str(j+1))
def numberOfIdPasses():
result = cmds.promptDialog(
title='idPasses',
message='How many id passes? :',
button=['OK', 'Cancel'],
defaultButton='OK',
cancelButton='Cancel',
dismissString='Cancel')
if result == 'OK':
idNum = cmds.promptDialog(query=True, text=True)
return idNum
def fillBuffer(wtc):
wtcName=wtc
passName = wtc
nodes = cmd.ls(typ='writeToColorBuffer')
if nodes != None:
for node in nodes:
if node.count(wtcName):
try:
cmd.connectAttr(passName + '.message', node + '.renderPass')
except:
pass
def defineGlobals():
cmds.setAttr('defaultRenderGlobals.currentRenderer', 'mentalRay', type='string')
createPasses()
createCustomRenderPass('motionvector','2DMotionVector')
createCustomRenderPass('beauty','beauty')
cmds.setAttr('beauty.frameBufferType',2)
cmds.setAttr('beauty.numChannels',3)
createCustomRenderPass('matte','matte')
cmds.setAttr('matte.frameBufferType',2)
createOverrideMTL(overrideMTLName)
#globals adjustment
cmds.setAttr('defaultRenderGlobals.imageFormat', 3) #TIF
cmds.setAttr('defaultResolution.width',1024)
cmds.setAttr('defaultResolution.height',436)
cmds.setAttr('defaultRenderGlobals.colorProfileEnabled',1)
cmds.setAttr('defaultRenderGlobals.inputColorProfile',3) #sRGB
cmds.setAttr('defaultRenderGlobals.outputColorProfile',2) #Linear sRGB
# Adjust the frame extension name
cmds.setAttr('defaultRenderGlobals.outFormatControl',0)
cmds.setAttr('defaultRenderGlobals.animation',1)
cmds.setAttr('defaultRenderGlobals.putFrameBeforeExt',1)
cmds.setAttr('defaultRenderGlobals.extensionPadding',4)
# RGB 3x16 frame buffer
cmds.setAttr('miDefaultFramebuffer.datatype',17)
cmds.setAttr('mentalrayGlobals.exportMotionOffset',0)
cmds.setAttr('mentalrayGlobals.exportMotionOutput',0)
def deleteAll():
selectionType = ['renderLayer','renderPass']
cmds.editRenderLayerGlobals( currentRenderLayer = 'defaultRenderLayer')
for s in selectionType:
sel = cmds.ls(type = s)
cmds.delete(sel)
for l in lights:
cmds.select(l,add=True)
cmds.delete()
def getSelection():
sel = cmds.ls(sl = True)
return sel
def createCustomRenderPass(contmapMin,passType):
mayaDir=mel.eval("getenv MAYA_LOCATION") + '/presets/attrPresets/renderPass/'+ passType + '.mel'
pm.shadingNode('renderPass',n=contmapMin, asRendering=1) #Create custom pass
mel.eval('applyAttrPreset "'+contmapMin +'" "'+mayaDir + '" 1;')
def createLightRig():
for l in lights:
cmds.spotLight(n = l, ca = 80, rs = True)
cmds.sets(lights[0],lights[1],lights[2],n = 'basicLights')
cmds.sets(lights[3],lights[4],lights[5],n = 'extraLights')
cmds.select(cl = True)
def createObjectAttributeOverride(layerName, object, attribute, value):
cmds.editRenderLayerAdjustment(object + '.' + attribute, layer = layerName)
if attribute == 'color':
conn = cmds.listConnections(object + '.' + attribute)
cmds.disconnectAttr(str(conn[0]) + '.outColor',object + '.' + attribute)
cmds.setAttr(object + '.' + attribute,value[0],value[1],value[2])
else:
cmds.setAttr(object + '.' + attribute,value)
def createLightsAttributeOverride(layerName, object, attribute, value):
cmds.editRenderLayerAdjustment(object + '.' + attribute)
cmds.setAttr(object + '.' + attribute,value[0],value[1],value[2])
def addSelectionToLayer(layerName, selection):
cmds.editRenderLayerMembers(layerName,selection)
def addObjectToLayer():
selection = getSelection()
for l in layers:
layerName = layerN + l
addSelectionToLayer(layerName, selection)
#load from interface
name = 'lambert2'
sq = 'sq_001'
sh = 'sh_007'
type = 'chr'
layerN = sq + '_' + sh + '_' + type + '_'
layers = ['basic','lights','extraLights','shadows','extraShadows','ctcocclusion','ctcshadows','motion']
defineGlobals()
createLightRig()
#create all renderLayer
for i in layers:
layerName = layerN + i
cmds.createRenderLayer(makeCurrent=True, number = 1, noRecurse = True, name = layerName)
#putObject into renderLayer
sel = cmds.ls('basicLights')
layerName = layerN + layers[0]
addSelectionToLayer(layerName,sel)
layerName = layerN + layers[1]
addSelectionToLayer(layerName,sel)
layerName = layerN + layers[3]
addSelectionToLayer(layerName,sel)
sel = cmds.ls('extraLights')
layerName = layerN + layers[0]
addSelectionToLayer(layerName,sel)
layerName = layerN + layers[2]
addSelectionToLayer(layerName,sel)
layerName = layerN + layers[4]
addSelectionToLayer(layerName,sel)
#basic layer
layerName = layerN + layers[0]
cmds.editRenderLayerGlobals( currentRenderLayer = layerName)
cmds.editRenderLayerAdjustment('defaultRenderGlobals.imageFilePrefix')
cmds.setAttr('defaultRenderGlobals.imageFilePrefix','<RenderLayer>/<RenderPass>/<RenderPass>', type = 'string')
sel = cmds.ls(type = 'renderPass')
for s in sel:
if s != 'motionvector':
cmds.connectAttr(layerName + '.renderPass',s + '.owner')
#override light layer
layerName = layerN + layers[1]
cmds.editRenderLayerGlobals( currentRenderLayer = layerName)
cmds.editRenderLayerAdjustment('defaultRenderGlobals.imageFilePrefix')
cmds.setAttr('defaultRenderGlobals.imageFilePrefix','<RenderLayer>/' + layers[1], type = 'string')
for i in range(0,3):
createLightsAttributeOverride(layerName,lights[i],'color',colors[i])
createLightsAttributeOverride(layerName,lights[i],'shadowColor',(0,0,0))
cmds.connectAttr(overrideMTLName + 'SG.message', layerName + '.shadingGroupOverride')
#override extralight layer
layerName = layerN + layers[2]
cmds.editRenderLayerGlobals( currentRenderLayer = layerName)
cmds.editRenderLayerAdjustment('defaultRenderGlobals.imageFilePrefix')
cmds.setAttr('defaultRenderGlobals.imageFilePrefix','<RenderLayer>/' + layers[2], type = 'string')
for i in range(0,3):
createLightsAttributeOverride(layerName,lights[i+3],'color',colors[i])
createLightsAttributeOverride(layerName,lights[i+3],'shadowColor',(0,0,0))
cmds.connectAttr(overrideMTLName + 'SG.message', layerName + '.shadingGroupOverride')
#override shadow layer
layerName = layerN + layers[3]
cmds.editRenderLayerGlobals( currentRenderLayer = layerName)
cmds.editRenderLayerAdjustment('defaultRenderGlobals.imageFilePrefix')
cmds.setAttr('defaultRenderGlobals.imageFilePrefix','<RenderLayer>/' + layers[3], type = 'string')
for i in range(0,3):
createLightsAttributeOverride(layerName,lights[i],'shadowColor',colors[i])
createLightsAttributeOverride(layerName,lights[i],'color',(0,0,0))
cmds.connectAttr(overrideMTLName + 'SG.message', layerName + '.shadingGroupOverride')
#override extrashadow layer
layerName = layerN + layers[4]
cmds.editRenderLayerGlobals( currentRenderLayer = layerName)
cmds.editRenderLayerAdjustment('defaultRenderGlobals.imageFilePrefix')
cmds.setAttr('defaultRenderGlobals.imageFilePrefix','<RenderLayer>/' + layers[4], type = 'string')
for i in range(0,3):
createLightsAttributeOverride(layerName,lights[i+3],'shadowColor',colors[i])
createLightsAttributeOverride(layerName,lights[i+3],'color',(0,0,0))
cmds.connectAttr(overrideMTLName + 'SG.message', layerName + '.shadingGroupOverride')
#override ctcocclusion layer
layerName = layerN + layers[5]
cmds.editRenderLayerGlobals( currentRenderLayer = layerName)
cmds.editRenderLayerAdjustment('defaultRenderGlobals.imageFilePrefix')
cmds.setAttr('defaultRenderGlobals.imageFilePrefix','<RenderLayer>/' + layers[5], type = 'string')
#override ctcshadow layer
layerName = layerN + layers[6]
cmds.editRenderLayerGlobals( currentRenderLayer = layerName)
cmds.editRenderLayerAdjustment('defaultRenderGlobals.imageFilePrefix')
cmds.setAttr('defaultRenderGlobals.imageFilePrefix','<RenderLayer>/' + layers[6], type = 'string')
cmds.connectAttr(overrideMTLName + 'SG.message', layerName + '.shadingGroupOverride')
#override motion layer
layerName = layerN + layers[7]
cmds.editRenderLayerGlobals( currentRenderLayer = layerName)
cmds.editRenderLayerAdjustment('defaultRenderGlobals.imageFilePrefix','miDefaultFramebuffer.datatype','defaultRenderGlobals.imageFormat')
cmds.setAttr('defaultRenderGlobals.imageFormat', 51) #EXR
cmds.setAttr('defaultRenderGlobals.imageFilePrefix','<RenderLayer>/<RenderPass>/motion', type = 'string')
# RGB 4x32 frame buffer
cmds.setAttr('miDefaultFramebuffer.datatype',5)
cmds.connectAttr(layerName + '.renderPass','motionvector.owner')
cmds.connectAttr(overrideMTLName + 'SG.message', layerName + '.shadingGroupOverride')
Comments
Post a Comment