Override USD materials surface but keep displacement

   3190   10   2
User Avatar
Member
16 posts
Joined: March 2019
Offline
Hi,

I am looking to recreate a workflow that we have in katana.

My whole scene is coming in one USD layer stack.

I need to render shadow layer from character onto environment therefore I want to override just surface shader of all meshes on that render layer but keep displacement from original shader. Is that possible to do somehow in Solaris?

thanks for any suggestions

Dawid
Edited by daveborck - Sept. 20, 2022 11:39:37
User Avatar
Member
75 posts
Joined: Dec. 2017
Offline
It sounds like your requirement can be satisfied by sublayer, sublayer for all surface shader, material is also a primitive in usd as long as the path is the same sublayer will overwrite them
User Avatar
Member
8532 posts
Joined: July 2007
Online
I would be also curious if such overrides are possible
But instead of replacing whole surface shader I need to also preserve opacity codepath

Imagine leaf with Opacity cutout mask and Displacement

So if I use Mantra terms (as I'm not familiar how Karma differentiates shading codepaths) the need is to override just Ce, Cf, F of Surface portion but keep Of and whole Displacement shader the same

This is something that matte shading does so I'm curious if there is a way to do it in more general way

Ideally by inheriting Of graph from existing shader as there is likely a need to multiply AOVs with Of in my new surface shader etc
Edited by tamte - Sept. 24, 2022 12:15:49
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Staff
4159 posts
Joined: Sept. 2007
Offline
Here is an example of how to override the Surface output for a Material, by referencing or inheriting a material that sets the surface output, but leaves the displacement blank; those compose together, and this lets you override the surface shader, while leaving the displacement shader. Assets setup to inherit from a class prim, or even materials setup like this, make it fairly straightforward.

As far as more granular overrides within a shader would probably require some sort of Edit Material Network approach... which should theoretically be possible for anything except old-school VOP/VEX shaders (which in USD are one large string on a prim, so there's no way to re-create the shading network from that code).

There is certainly room to improve this workflow (and possibly some bugs to fix) but hopefully this will help get you started.

Attachments:
modifypaths.hip (530.0 KB)
Screenshot from 2022-09-28 10-26-42.png (467.0 KB)

I'm o.d.d.
User Avatar
Member
16 posts
Joined: March 2019
Offline
Thank you for providing the scene goldleaf but I am totally not getting the result you mention using it.


That's the karma render before override


that's the result after override. I am loosing both displacement and surface when trying to change just outputs:mtlx:surface Value.


I tried it with Arnold as well and same result

Dawid
Edited by daveborck - Oct. 6, 2022 12:55:55

Attachments:
Surface+Displacement.JPG (209.8 KB)
SurfaceReplace+DisplacementGone.JPG (197.0 KB)

User Avatar
Member
8532 posts
Joined: July 2007
Online
it worked initially, but its very sensitive to any changes

if after opening the file you display edit_my_material1 it works
if you then disable duplicate1 and enable it again, the displacement is gone
or if you just enable XPU the displacement is gone

and even Restart Render doesn't seem to correct it

this LOP sensitivity to changes and showing incorrect results is why I'm still hesitant to start using it
Edited by tamte - Oct. 6, 2022 22:00:31
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
16 posts
Joined: March 2019
Offline
Hmm, I feel like it keeps displacement for a moment only because of some displacement geo caching not because it works but nevertheless it's not ideal.
User Avatar
Member
8532 posts
Joined: July 2007
Online
daveborck
I feel like it keeps displacement for a moment only because of some displacement geo caching not because it works
ah, right, that seems to be the case
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
8532 posts
Joined: July 2007
Online
goldleaf
Here is an example of how to override the Surface output for a Material, by referencing or inheriting a material that sets the surface output, but leaves the displacement blank; those compose together, and this lets you override the surface shader, while leaving the displacement shader. Assets setup to inherit from a class prim, or even materials setup like this, make it fairly straightforward.
I'm not able to see the same result as in the picture
displaying edit_my_material1 essentially kills the whole material
also looking at SGD, it's not setting up a new relationship/connection for outputs:mtlx:surface, but overwriting it's value, which is not how shaders are usually connected to materials
What is the way to correctly edit such relationships?
Edit Properties seems very limited UI wise so its hard to tell if its setting a path relationship or just overwriting a string value or if I want to overwrite just a single target out of many current ones, etc
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
16 posts
Joined: March 2019
Offline
I spent a bit more time on the topic and figured out a way to do that with simple python script lop, here is my example:

from pxr import UsdShade
node = hou.pwd()
hda = node.parent()
ls = hou.LopSelectionRule()

primpattern = hda.parm("grey_primpattern").evalAsString()
if primpattern != "":

    ls.setPathPattern('%matfromgeo({})'.format(primpattern))
    paths = ls.expandedPaths(node.inputs()[0])
    stage = node.editableStage()
    for path in paths:
    
        basemat = UsdShade.Material.Get(stage, path)
    
        chromeShader = UsdShade.Shader.Get(stage, '/materials/breakdown/breakdown_grey')
        for output in basemat.GetSurfaceOutputs():
            if "outputs:surface" in output.GetFullName():
                output.ConnectToSource(chromeShader.ConnectableAPI(), "surface")

Cheers!
User Avatar
Staff
1448 posts
Joined: July 2005
Offline
Indeed. The modifypaths.hip example above tries to set the value of Material prim's output attribute. Instead, it needs to connect that output attribute to a new surface shader. Unfortunately, Edit Properties LOP does not offer this functionality at the moment (it allows only to disconnect it).

Thus you would need Edit Material Network LOP, but the problem then is that it operates only on a single material, while in that .hip file you have five different ones. Although, you could still use Edit Mat Net LOP to edit the single original material.
  • Quick Links