Merge pull request #4087 from moonyuet/bugfix/OP-4381-Maya--Keep-existing-AOVs-when-creating-render-instance

resolves https://github.com/pypeclub/OpenPype/issues/4073
This commit is contained in:
Ondřej Samohel 2022-12-12 16:58:06 +01:00 committed by GitHub
commit 3828d11143
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 184 additions and 115 deletions

View file

@ -95,21 +95,25 @@ class RenderSettings(object):
if renderer == "redshift":
self._set_redshift_settings(width, height)
mel.eval("redshiftUpdateActiveAovList")
def _set_arnold_settings(self, width, height):
"""Sets settings for Arnold."""
from mtoa.core import createOptions # noqa
from mtoa.aovs import AOVInterface # noqa
createOptions()
arnold_render_presets = self._project_settings["maya"]["RenderSettings"]["arnold_renderer"] # noqa
render_settings = self._project_settings["maya"]["RenderSettings"]
arnold_render_presets = render_settings["arnold_renderer"] # noqa
# Force resetting settings and AOV list to avoid having to deal with
# AOV checking logic, for now.
# This is a work around because the standard
# function to revert render settings does not reset AOVs list in MtoA
# Fetch current aovs in case there's any.
current_aovs = AOVInterface().getAOVs()
remove_aovs = render_settings["remove_aovs"]
if remove_aovs:
# Remove fetched AOVs
AOVInterface().removeAOVs(current_aovs)
AOVInterface().removeAOVs(current_aovs)
mel.eval("unifiedRenderGlobalsRevertToDefault")
img_ext = arnold_render_presets["image_format"]
img_prefix = arnold_render_presets["image_prefix"]
@ -118,6 +122,8 @@ class RenderSettings(object):
multi_exr = arnold_render_presets["multilayer_exr"]
additional_options = arnold_render_presets["additional_options"]
for aov in aovs:
if aov in current_aovs and not remove_aovs:
continue
AOVInterface('defaultArnoldRenderOptions').addAOV(aov)
cmds.setAttr("defaultResolution.width", width)
@ -141,12 +147,50 @@ class RenderSettings(object):
def _set_redshift_settings(self, width, height):
"""Sets settings for Redshift."""
redshift_render_presets = (
self._project_settings
["maya"]
["RenderSettings"]
["redshift_renderer"]
)
render_settings = self._project_settings["maya"]["RenderSettings"]
redshift_render_presets = render_settings["redshift_renderer"]
remove_aovs = render_settings["remove_aovs"]
all_rs_aovs = cmds.ls(type='RedshiftAOV')
if remove_aovs:
for aov in all_rs_aovs:
enabled = cmds.getAttr("{}.enabled".format(aov))
if enabled:
cmds.delete(aov)
redshift_aovs = redshift_render_presets["aov_list"]
# list all the aovs
all_rs_aovs = cmds.ls(type='RedshiftAOV')
for rs_aov in redshift_aovs:
rs_layername = rs_aov
if " " in rs_aov:
rs_renderlayer = rs_aov.replace(" ", "")
rs_layername = "rsAov_{}".format(rs_renderlayer)
else:
rs_layername = "rsAov_{}".format(rs_aov)
if rs_layername in all_rs_aovs:
continue
cmds.rsCreateAov(type=rs_aov)
# update the AOV list
mel.eval("redshiftUpdateActiveAovList")
rs_p_engine = redshift_render_presets["primary_gi_engine"]
rs_s_engine = redshift_render_presets["secondary_gi_engine"]
if int(rs_p_engine) or int(rs_s_engine) != 0:
cmds.setAttr("redshiftOptions.GIEnabled", 1)
if int(rs_p_engine) == 0:
# reset the primary GI Engine as default
cmds.setAttr("redshiftOptions.primaryGIEngine", 4)
if int(rs_s_engine) == 0:
# reset the secondary GI Engine as default
cmds.setAttr("redshiftOptions.secondaryGIEngine", 2)
else:
cmds.setAttr("redshiftOptions.GIEnabled", 0)
cmds.setAttr("redshiftOptions.primaryGIEngine", int(rs_p_engine))
cmds.setAttr("redshiftOptions.secondaryGIEngine", int(rs_s_engine))
additional_options = redshift_render_presets["additional_options"]
ext = redshift_render_presets["image_format"]
img_exts = ["iff", "exr", "tif", "png", "tga", "jpg"]
@ -163,12 +207,31 @@ class RenderSettings(object):
"""Sets important settings for Vray."""
settings = cmds.ls(type="VRaySettingsNode")
node = settings[0] if settings else cmds.createNode("VRaySettingsNode")
vray_render_presets = (
self._project_settings
["maya"]
["RenderSettings"]
["vray_renderer"]
)
render_settings = self._project_settings["maya"]["RenderSettings"]
vray_render_presets = render_settings["vray_renderer"]
# vrayRenderElement
remove_aovs = render_settings["remove_aovs"]
all_vray_aovs = cmds.ls(type='VRayRenderElement')
lightSelect_aovs = cmds.ls(type='VRayRenderElementSet')
if remove_aovs:
for aov in all_vray_aovs:
# remove all aovs except LightSelect
enabled = cmds.getAttr("{}.enabled".format(aov))
if enabled:
cmds.delete(aov)
# remove LightSelect
for light_aovs in lightSelect_aovs:
light_enabled = cmds.getAttr("{}.enabled".format(light_aovs))
if light_enabled:
cmds.delete(lightSelect_aovs)
vray_aovs = vray_render_presets["aov_list"]
for renderlayer in vray_aovs:
renderElement = "vrayAddRenderElement {}".format(renderlayer)
RE_name = mel.eval(renderElement)
# if there is more than one same render element
if RE_name.endswith("1"):
cmds.delete(RE_name)
# Set aov separator
# First we need to explicitly set the UI items in Render Settings
# because that is also what V-Ray updates to when that Render Settings

View file

@ -59,6 +59,7 @@
"default_render_image_folder": "renders/maya",
"enable_all_lights": true,
"aov_separator": "underscore",
"remove_aovs": false,
"reset_current_frame": false,
"arnold_renderer": {
"image_prefix": "<Scene>/<RenderLayer>/<RenderLayer>_<RenderPass>",

View file

@ -31,6 +31,11 @@
{"dot": ". (dot)"}
]
},
{
"key": "remove_aovs",
"label": "Remove existing AOVs",
"type": "boolean"
},
{
"key": "reset_current_frame",
"label": "Reset Current Frame",
@ -204,74 +209,76 @@
"defaults": "empty",
"enum_items": [
{"empty": "< empty >"},
{"atmosphereChannel": "atmosphere"},
{"backgroundChannel": "background"},
{"bumpNormalsChannel": "bumpnormals"},
{"causticsChannel": "caustics"},
{"coatFilterChannel": "coat_filter"},
{"coatGlossinessChannel": "coatGloss"},
{"coatReflectionChannel": "coat_reflection"},
{"vrayCoatChannel": "coat_specular"},
{"CoverageChannel": "coverage"},
{"cryptomatteChannel": "cryptomatte"},
{"customColor": "custom_color"},
{"drBucketChannel": "DR"},
{"denoiserChannel": "denoiser"},
{"diffuseChannel": "diffuse"},
{"ExtraTexElement": "extraTex"},
{"giChannel": "GI"},
{"LightMixElement": "None"},
{"lightingChannel": "lighting"},
{"LightingAnalysisChannel": "LightingAnalysis"},
{"materialIDChannel": "materialID"},
{"MaterialSelectElement": "materialSelect"},
{"matteShadowChannel": "matteShadow"},
{"MultiMatteElement": "multimatte"},
{"multimatteIDChannel": "multimatteID"},
{"normalsChannel": "normals"},
{"nodeIDChannel": "objectId"},
{"objectSelectChannel": "objectSelect"},
{"rawCoatFilterChannel": "raw_coat_filter"},
{"rawCoatReflectionChannel": "raw_coat_reflection"},
{"rawDiffuseFilterChannel": "rawDiffuseFilter"},
{"rawGiChannel": "rawGI"},
{"rawLightChannel": "rawLight"},
{"rawReflectionChannel": "rawReflection"},
{"rawReflectionFilterChannel": "rawReflectionFilter"},
{"rawRefractionChannel": "rawRefraction"},
{"rawRefractionFilterChannel": "rawRefractionFilter"},
{"rawShadowChannel": "rawShadow"},
{"rawSheenFilterChannel": "raw_sheen_filter"},
{"rawSheenReflectionChannel": "raw_sheen_reflection"},
{"rawTotalLightChannel": "rawTotalLight"},
{"reflectIORChannel": "reflIOR"},
{"reflectChannel": "reflect"},
{"reflectionFilterChannel": "reflectionFilter"},
{"reflectGlossinessChannel": "reflGloss"},
{"refractChannel": "refract"},
{"refractionFilterChannel": "refractionFilter"},
{"refractGlossinessChannel": "refrGloss"},
{"renderIDChannel": "renderId"},
{"FastSSS2Channel": "SSS"},
{"sampleRateChannel": "sampleRate"},
{"atmosphereChannel": "atmosphereChannel"},
{"backgroundChannel": "backgroundChannel"},
{"bumpNormalsChannel": "bumpNormalsChannel"},
{"causticsChannel": "causticsChannel"},
{"coatFilterChannel": "coatFilterChannel"},
{"coatGlossinessChannel": "coatGlossinessChannel"},
{"coatReflectionChannel": "coatReflectionChannel"},
{"vrayCoatChannel": "vrayCoatChannel"},
{"CoverageChannel": "CoverageChannel"},
{"cryptomatteChannel": "cryptomatteChannel"},
{"customColor": "customColor"},
{"drBucketChannel": "drBucketChannel"},
{"denoiserChannel": "denoiserChannel"},
{"diffuseChannel": "diffuseChannel"},
{"ExtraTexElement": "ExtraTexElement"},
{"giChannel": "giChannel"},
{"LightMixElement": "LightMixElement"},
{"LightSelectElement": "LightSelectElement"},
{"lightingChannel": "lightingChannel"},
{"LightingAnalysisChannel": "LightingAnalysisChannel"},
{"materialIDChannel": "materialIDChannel"},
{"MaterialSelectElement": "MaterialSelectElement"},
{"matteShadowChannel": "matteShadowChannel"},
{"metalnessChannel": "metalnessChannel"},
{"MultiMatteElement": "MultiMatteElement"},
{"multimatteIDChannel": "multimatteIDChannel"},
{"noiseLevelChannel": "noiseLevelChannel"},
{"normalsChannel": "normalsChannel"},
{"nodeIDChannel": "nodeIDChannel"},
{"objectSelectChannel": "objectSelectChannel"},
{"rawCoatFilterChannel": "rawCoatFilterChannel"},
{"rawCoatReflectionChannel": "rawCoatReflectionChannel"},
{"rawDiffuseFilterChannel": "rawDiffuseFilterChannel"},
{"rawGiChannel": "rawGiChannel"},
{"rawLightChannel": "rawLightChannel"},
{"rawReflectionChannel": "rawReflectionChannel"},
{"rawReflectionFilterChannel": "rawReflectionFilterChannel"},
{"rawRefractionChannel": "rawRefractionChannel"},
{"rawRefractionFilterChannel": "rawRefractionFilterChannel"},
{"rawShadowChannel": "rawShadowChannel"},
{"rawSheenFilterChannel": "rawSheenFilterChannel"},
{"rawSheenReflectionChannel": "rawSheenReflectionChannel"},
{"rawTotalLightChannel": "rawTotalLightChannel"},
{"reflectIORChannel": "reflectIORChannel"},
{"reflectChannel": "reflectChannel"},
{"reflectionFilterChannel": "reflectionFilterChannel"},
{"reflectGlossinessChannel": "reflectGlossinessChannel"},
{"refractChannel": "refractChannel"},
{"refractionFilterChannel": "refractionFilterChannel"},
{"refractGlossinessChannel": "refractGlossinessChannel"},
{"renderIDChannel": "renderIDChannel"},
{"FastSSS2Channel": "FastSSS2Channel"},
{"sampleRateChannel": "sampleRateChannel"},
{"samplerInfo": "samplerInfo"},
{"selfIllumChannel": "selfIllum"},
{"shadowChannel": "shadow"},
{"sheenFilterChannel": "sheen_filter"},
{"sheenGlossinessChannel": "sheenGloss"},
{"sheenReflectionChannel": "sheen_reflection"},
{"vraySheenChannel": "sheen_specular"},
{"specularChannel": "specular"},
{"selfIllumChannel": "selfIllumChannel"},
{"shadowChannel": "shadowChannel"},
{"sheenFilterChannel": "sheenFilterChannel"},
{"sheenGlossinessChannel": "sheenGlossinessChannel"},
{"sheenReflectionChannel": "sheenReflectionChannel"},
{"vraySheenChannel": "vraySheenChannel"},
{"specularChannel": "specularChannel"},
{"Toon": "Toon"},
{"toonLightingChannel": "toonLighting"},
{"toonSpecularChannel": "toonSpecular"},
{"totalLightChannel": "totalLight"},
{"unclampedColorChannel": "unclampedColor"},
{"VRScansPaintMaskChannel": "VRScansPaintMask"},
{"VRScansZoneMaskChannel": "VRScansZoneMask"},
{"velocityChannel": "velocity"},
{"zdepthChannel": "zDepth"},
{"LightSelectElement": "lightselect"}
{"toonLightingChannel": "toonLightingChannel"},
{"toonSpecularChannel": "toonSpecularChannel"},
{"totalLightChannel": "totalLightChannel"},
{"unclampedColorChannel": "unclampedColorChannel"},
{"VRScansPaintMaskChannel": "VRScansPaintMaskChannel"},
{"VRScansZoneMaskChannel": "VRScansZoneMaskChannel"},
{"velocityChannel": "velocityChannel"},
{"zdepthChannel": "zdepthChannel"}
]
},
{
@ -310,9 +317,8 @@
"defaults": "0",
"enum_items": [
{"0": "None"},
{"1": "Photon Map"},
{"2": "Irradiance Cache"},
{"3": "Brute Force"}
{"3": "Irradiance Cache"},
{"4": "Brute Force"}
]
},
{
@ -323,9 +329,8 @@
"defaults": "0",
"enum_items": [
{"0": "None"},
{"1": "Photon Map"},
{"2": "Irradiance Cache"},
{"3": "Brute Force"}
{"2": "Irradiance Point Cloud"},
{"4": "Brute Force"}
]
},
{
@ -361,46 +366,46 @@
"defaults": "empty",
"enum_items": [
{"empty": "< none >"},
{"AO": "Ambient Occlusion"},
{"Ambient Occlusion": "Ambient Occlusion"},
{"Background": "Background"},
{"Beauty": "Beauty"},
{"BumpNormals": "Bump Normals"},
{"Bump Normals": "Bump Normals"},
{"Caustics": "Caustics"},
{"CausticsRaw": "Caustics Raw"},
{"Caustics Raw": "Caustics Raw"},
{"Cryptomatte": "Cryptomatte"},
{"Custom": "Custom"},
{"Z": "Depth"},
{"DiffuseFilter": "Diffuse Filter"},
{"DiffuseLighting": "Diffuse Lighting"},
{"DiffuseLightingRaw": "Diffuse Lighting Raw"},
{"Depth": "Depth"},
{"Diffuse Filter": "Diffuse Filter"},
{"Diffuse Lighting": "Diffuse Lighting"},
{"Diffuse Lighting Raw": "Diffuse Lighting Raw"},
{"Emission": "Emission"},
{"GI": "Global Illumination"},
{"GIRaw": "Global Illumination Raw"},
{"Global Illumination": "Global Illumination"},
{"Global Illumination Raw": "Global Illumination Raw"},
{"Matte": "Matte"},
{"MotionVectors": "Ambient Occlusion"},
{"N": "Normals"},
{"ID": "ObjectID"},
{"ObjectBumpNormal": "Object-Space Bump Normals"},
{"ObjectPosition": "Object-Space Positions"},
{"PuzzleMatte": "Puzzle Matte"},
{"Motion Vectors": "Motion Vectors"},
{"Normals": "Normals"},
{"ObjectID": "ObjectID"},
{"Object-Space Bump Normals": "Object-Space Bump Normals"},
{"Object-Space Positions": "Object-Space Positions"},
{"Puzzle Matte": "Puzzle Matte"},
{"Reflections": "Reflections"},
{"ReflectionsFilter": "Reflections Filter"},
{"ReflectionsRaw": "Reflections Raw"},
{"Reflections Filter": "Reflections Filter"},
{"Reflections Raw": "Reflections Raw"},
{"Refractions": "Refractions"},
{"RefractionsFilter": "Refractions Filter"},
{"RefractionsRaw": "Refractions Filter"},
{"Refractions Filter": "Refractions Filter"},
{"Refractions Raw": "Refractions Filter"},
{"Shadows": "Shadows"},
{"SpecularLighting": "Specular Lighting"},
{"SSS": "Sub Surface Scatter"},
{"SSSRaw": "Sub Surface Scatter Raw"},
{"TotalDiffuseLightingRaw": "Total Diffuse Lighting Raw"},
{"TotalTransLightingRaw": "Total Translucency Filter"},
{"TransTint": "Translucency Filter"},
{"TransGIRaw": "Translucency Lighting Raw"},
{"VolumeFogEmission": "Volume Fog Emission"},
{"VolumeFogTint": "Volume Fog Tint"},
{"VolumeLighting": "Volume Lighting"},
{"P": "World Position"}
{"Sub Surface Scatter": "Sub Surface Scatter"},
{"Sub Surface Scatter Raw": "Sub Surface Scatter Raw"},
{"Total Diffuse Lighting Raw": "Total Diffuse Lighting Raw"},
{"Total Translucency Filter": "Total Translucency Filter"},
{"Translucency Filter": "Translucency Filter"},
{"Translucency Lighting Raw": "Translucency Lighting Raw"},
{"Volume Fog Emission": "Volume Fog Emission"},
{"Volume Fog Tint": "Volume Fog Tint"},
{"Volume Lighting": "Volume Lighting"},
{"World Position": "World Position"}
]
},
{