[GafferUsd] Type Token vs String Issue

178 views
Skip to first unread message

Sachin Shrestha

unread,
Jan 11, 2023, 12:48:34 PM1/11/23
to gaffe...@googlegroups.com
Hi John,

We have come across this issue when exporting usd from maya-arnold and usnig them in gaffer for some of our scenes. The arnold-usd exporter seems ot be exporting string parameter types as the TfToken type whereas gaffer expects them as String type. This could possibly be due to some updates pending on the arnold-usd side. I have attached a repro that demonstrates this using a simple cellNoise shader.

The usd file was exported from maya-arnold and the result in gaffer does not match the maya-arnold output. If I re-create the shader in gaffer (the ShaderAssignment node is disabled in the repro), then the gaffer-arnold output matches the maya-arnold output. On exporting the gaffer scene and inspecting the usda file, I realized that the parameter type in the usd exported by gaffer was string (which is correct) but the one exported from arnold-usd was token.

def Shader "aiCellNoise1"
{
    uniform token info:id = "arnold:cell_noise"
    float inputs:density = 1
    int inputs:octaves = 5
    token inputs:pattern = "worley1"
    vector3f inputs:scale = (0.001, 0.001, 0.001)
    color3f outputs:out
}


If I use a ShaderTweak or ShaderQuery node to try overriding this parameter's value, it does not add it to the tweak node due to the type not being a valid gaffer type (I guess).

I have cross posted this on the usd list too for some way to change the type in the usd via the python api but iIs there a way to handle this on the gaffer side by auto-interpreting the token type as string so that such usd scenes work out of the box in gaffer? 

Thanks,
Sachin
type_token_repro.zip

John Haddon

unread,
Jan 12, 2023, 7:40:56 AM1/12/23
to gaffer-dev
Hi Sachin,

Although we've seen various USD files that used `token` when `string` should have been supplied, I believe in this case the use of `token` was correct. I'm basing this on the note in the USDPreviewSurface spec here :


Since `pattern` is an enum in Arnold, I think it being a `token` in USD is expected. So I've opened a PR to allow this to be rendered successfully in Gaffer :


I think this also means we should switch things around in Gaffer so that the ArnoldShader node creates the equivalent of `token` parameters, and we support them in ShaderTweaks etc and write them to USD as `token`. That's a bit of a bigger topic though, so I haven't tried to tackle that yet. Hopefully this is enough to keep you moving for now?

Out of interest, what is Maya writing out for parameters like `image.filename`? Token or string?

Cheers...
John

Sachin Shrestha

unread,
Jan 12, 2023, 11:08:17 PM1/12/23
to gaffer-dev
HI John,

Thank you for debugging this and good to know that this is something that can be handled on the gaffer side. That should suffice for my specific use case for now.

I exported a shader with image texture and arnold-usd seems to be writing "string" type for the filename parameter so as you rightly said, this seems to be token type in case of enums.

def Material "aiStandardSurface1"
{
    token outputs:arnold:surface.connect = </aiStandardSurface1/aiStandardSurface1.outputs:surface>

    def Shader "aiStandardSurface1"
    {
        uniform token info:id = "arnold:standard_surface"
        color3f inputs:base_color = (0.8, 0.8, 0.8)
        prepend color3f inputs:base_color.connect = </aiStandardSurface1/file1.outputs:out>
        float inputs:specular = 0
        token outputs:surface
    }

    def Shader "file1"
    {
        uniform token info:id = "arnold:image"
        string inputs:filename = "D:/Sachin/projects/oss/gafferhq/build/gaffer-1.2.0.0a1-windows/graphics/GafferLogoMini.png"
        bool inputs:ignore_missing_textures = 1
        color4f inputs:missing_texture_color = (0.5, 0.5, 0.5, 0)
        color4f outputs:out
    }
}


Cheers,
Sachin

Sachin Shrestha

unread,
Oct 4, 2023, 10:18:53 AM10/4/23
to gaffer-dev
Hi John,

I was wondering if this part in the PR above is something that has been addressed already? In the latest gaffer version 1.3.4.0, I am still unable to get the ShaderTweaks node work on a usd file that brings in the shader with the model. Trying to add the Affected Selection does not seem to do anything yet probably due to the parameter type differences.

What this means is that we need to reconsider how we load enums in ArnoldShader (where we create StringData) and how we might support InternedString in things like ShaderTweaks. That can wait for another day though.

Cheers,
Sachin

John Haddon

unread,
Oct 5, 2023, 4:23:34 AM10/5/23
to gaffe...@googlegroups.com
Hi Sachin,

I'm afraid we haven't dealt with that part yet, and as you say, making a tweak fails because we don't have a specific plug type for representing `token` data (or the Cortex equivalent `InternedString`). Please feel free to open a GitHub issue for this. In the meantime though, you should be able to work around it by manually adding a String tweak for the appropriate parameter. I've added a screenshot below where I'm tweaking the noise pattern...
Cheers...
John

image.png


Disclaimer: This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

--
You received this message because you are subscribed to the Google Groups "gaffer-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gaffer-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gaffer-dev/b257bd45-1ed9-43e0-9e0c-4971b3e2663dn%40googlegroups.com.

Sachin Shrestha

unread,
Oct 5, 2023, 7:35:52 AM10/5/23
to gaffer-dev
Hi John,

Yes, I am manually adding the parameter names right now to handle this so we have a workaround for this. I will log a ticket.

Cheers,
Sachin

Reply all
Reply to author
Forward
0 new messages