Skip to content

Commit

Permalink
nodule visibility metadata
Browse files Browse the repository at this point in the history
Should add a todo in the Cycles metadata to adopt this approach whereby the ShaderUI does the lookups for us. This allows other people to register their own metadata to override ours.
  • Loading branch information
johnhaddon committed Nov 20, 2024
1 parent 827d498 commit 2c142f4
Show file tree
Hide file tree
Showing 3 changed files with 256 additions and 6 deletions.
21 changes: 20 additions & 1 deletion python/GafferRenderManUITest/RenderManShaderUITest.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

class RenderManShaderUITest( GafferUITest.TestCase ) :

def testMetadata( self ) :
def testArgFileMetadata( self ) :

n = GafferRenderMan.RenderManShader()
n.loadShader( "PxrSurface" )
Expand Down Expand Up @@ -80,6 +80,25 @@ def testMetadata( self ) :
IECore.IntVectorData( [ 0, 1, 2 ] )
)

def testCustomMetadata( self ) :

# Check that all the metadata registered by
# `startup/GafferRenderManUII/shaderMetadata.py` refers to shaders and
# parameters that actually exist.

node = GafferRenderMan.RenderManShader()

for key in [ "noduleLayout:visible", "userDefault" ] :
targets = Gaffer.Metadata.targetsWithMetadata( "ri:surface:*", key )
shaders = { t.split( ":" )[2] for t in targets }
for shader in shaders :
with self.subTest( shader = shader ) :
node.loadShader( shader )
for target in targets :
_, _, s, parameter = target.split( ":" )
if s == shader :
self.assertIn( parameter, node["parameters"] )

def testLoadAllStandardShaders( self ) :

def __shaderType( argsFile ) :
Expand Down
16 changes: 11 additions & 5 deletions python/GafferSceneUI/ShaderUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,19 @@ def __shaderMetadata( node, key ) :
node["type"].getValue() + ":" + node["name"].getValue(), key
)

def __parameterUserDefault( plug ) :
def __parameterMetadata( plug, key, shaderFallbackKey = None ) :

shader = plug.node()
return Gaffer.Metadata.value(
result = Gaffer.Metadata.value(
shader["type"].getValue() + ":" + shader["name"].getValue() + ":" + plug.relativeName( shader["parameters"] ),
"userDefault"
key
)

if result is not None :
return result

return __shaderMetadata( shader, shaderFallbackKey ) if shaderFallbackKey is not None else None

Gaffer.Metadata.registerNode(

GafferScene.Shader,
Expand Down Expand Up @@ -135,7 +140,7 @@ def __parameterUserDefault( plug ) :

],

"parameters..." : [
"parameters.*..." : [

# Although the parameters plug is positioned
# as we want above, we must also register
Expand All @@ -144,7 +149,8 @@ def __parameterUserDefault( plug ) :
# individually.
"noduleLayout:section", "left",

"userDefault", __parameterUserDefault,
"userDefault", functools.partial( __parameterMetadata, key = "userDefault" ),
"noduleLayout:visible", functools.partial( __parameterMetadata, key = "noduleLayout:visible", shaderFallbackKey = "noduleLayout:defaultVisibility" ),

],

Expand Down
225 changes: 225 additions & 0 deletions startup/GafferRenderManUI/shaderMetadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
##########################################################################
#
# Copyright (c) 2024, Cinesite VFX Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
#
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided with
# the distribution.
#
# * Neither the name of John Haddon nor the names of
# any other contributors to this software may be used to endorse or
# promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
##########################################################################

import Gaffer

# RenderManShaderUI derives UI metadata from `.args` files automatically. But
# this doesn't cover everything we need for a good user experience, so here we
# manually register additional Gaffer-specific metadata for that.

shaderMetadata = {

"ri:surface:PxrDisney" : {

"noduleLayout:defaultVisibility" : False,

"parameters" : {

k : { "noduleLayout:visible" : True }
for k in [ "baseColor", "subsurfaceColor", "metallic", "specular", "roughness", "bumpNormal" ]

},

},

"ri:surface:PxrDisneyBsdf" : {

"noduleLayout:defaultVisibility" : False,

"parameters" : {

k : { "noduleLayout:visible" : True }
for k in [ "baseColor", "subsurfaceColor", "metallic", "specularTint", "roughness", "bumpNormal" ]

},

},

"ri:surface:LamaConductor" : {

"noduleLayout:defaultVisibility" : False,

"parameters" : {

k : { "noduleLayout:visible" : True }
for k in [ "tint", "reflectivity", "edgeColor", "roughness", "conductorNormal" ]

},

},

"ri:surface:LamaDielectric" : {

"noduleLayout:defaultVisibility" : False,

"parameters" : {

k : { "noduleLayout:visible" : True }
for k in [ "reflectionTint", "transmissionTint", "roughness", "normal" ]

},

},

"ri:surface:LamaGeneralizedSchlick" : {

"noduleLayout:defaultVisibility" : False,

"parameters" : {

k : { "noduleLayout:visible" : True }
for k in [ "reflectionTint", "transmissionTint", "roughness", "normal" ]

},

},

"ri:surface:LamaHairChiang" : {

"noduleLayout:defaultVisibility" : False,

"parameters" : {

k : { "noduleLayout:visible" : True }
for k in [ "colorR", "colorTT", "colorTintTT" ]

},

},

"ri:surface:LamaIridescence" : {

"noduleLayout:defaultVisibility" : False,

"parameters" : {

"roughness" : { "noduleLayout:visible" : True }

},

},

"ri:surface:LamaSSS" : {

"noduleLayout:defaultVisibility" : False,

"parameters" : {

k : { "noduleLayout:visible" : True }
for k in [ "sssColor", "sssNormal" ]

},

},

"ri:surface:LamaTricolorSSS" : {

"noduleLayout:defaultVisibility" : False,

"parameters" : {

k : { "noduleLayout:visible" : True }
for k in [ "nearColor", "farColor", "shadowColor", "sssNormal" ]

},

},

"ri:surface:PxrLayerSurface" : {

"noduleLayout:defaultVisibility" : False,

"parameters" : {

"inputMaterial" : { "noduleLayout:visible" : True }

},

},

"ri:surface:PxrMarschnerHair" : {

"noduleLayout:defaultVisibility" : False,

"parameters" : {

k : { "noduleLayout:visible" : True }
for k in [ "diffuseGain", "diffuseColor", "specularColorR", "specularColorTRT", "specularColorTT" ]

},

},

"ri:surface:PxrSurface" : {

"noduleLayout:defaultVisibility" : False,

"parameters" : {

k : { "noduleLayout:visible" : True }
for k in [ "diffuseGain", "diffuseColor", "specularFaceColor", "specularEdgeColor", "specularRoughness", "subsurfaceColor", "bumpNormal" ]

},

},

"ri:surface:PxrVolume" : {

"noduleLayout:defaultVisibility" : False,

"parameters" : {

k : { "noduleLayout:visible" : True }
for k in [ "diffuseColor", "emitColor", "densityFloat", "densityColor" ]

},

},

}

for shader, metadata in shaderMetadata.items() :

for key, value in metadata.items() :

if key == "parameters" :
for parameterName, parameterMetadata in value.items() :
for parameterKey, parameterValue in parameterMetadata.items() :
Gaffer.Metadata.registerValue( shader + ":" + parameterName, parameterKey, parameterValue )

else :

Gaffer.Metadata.registerValue( shader, key, value )

0 comments on commit 2c142f4

Please sign in to comment.