Use prim name/path as a random seed in a Karma shader?

   4303   5   3
User Avatar
Member
31 posts
Joined: 2月 2014
オフライン
Hi all - any thoughts on how to read a LOP prim's path or name into a Karma compatible shader (mtlx is fine) and generate a random colour based on that string?

I'm looking to set up a debug render that has every prim coloured differently, and want the approach to be able to take an unknown set of input prims.

I can do this within Solaris with an Attribute Wrangle along the lines of:

// Seed from path
int seed = random_shash(@primpath);

// Random Color
seed = random_ihash(seed);
float hue = rand(seed);
float value = fit(rand(seed*0.1),0,1,0.4,0.9);
vector clr = hsvtorgb(hue,0.4,value);

vector clr_arr[] = {};
append(clr_arr, clr);
v[]@primvars:displayColor = clr_arr;

and that works great. But ideally, for this task, I'd be bypassing Solaris and automating this by text editing a template .usda to feed in different inputs (swapping in other .abc or .usd scene/shot caches).

Using the attribute wrangle approach records an over for each prim to set displayColor as a primvar, but in my case, I won't know the list of prims in advance so I can't target them by name.
#usda 1.0
(
    defaultPrim = "bang_GEO"
    endTimeCode = 1
    metersPerUnit = 1
    startTimeCode = 1
    subLayers = [
        @../myTestObjs.abc@
    ]
    upAxis = "Y"
)

over "bang_GEO"
{
    over "bang_GEOShape"
    {
        color3f[] primvars:displayColor = [(0.2993978, 0.34668887, 0.49899635)] (
            interpolation = "constant"
        )
    }
}

over "bing_GEO"
{
    over "bing_GEOShape"
    {
        color3f[] primvars:displayColor = [(0.59410644, 0.530563, 0.8842716)] (
            interpolation = "constant"
        )
    }
}

over "bong_GEO"
{
    over "bong_GEOShape"
    {
        color3f[] primvars:displayColor = [(0.82843405, 0.63920987, 0.49706042)] (
            interpolation = "constant"
        )
    }
}

So I'm looking for a shader setup that can generate random colours per USD prim at render time; allowing me to apply a material to the root of the scene and inherit that on to whatever comes through in the sublayered files.
Any ideas?

Attachments:
Screenshot 2021-11-18 194625.png (565.7 KB)
myTestObjs.abc (48.7 KB)
perPrimCol_v001.hip (502.6 KB)

User Avatar
Member
31 posts
Joined: 2月 2014
オフライン
Hi - I saw in this post that '__name' can be used as an input for cryptomatte creation

https://www.sidefx.com/forum/topic/81745/#post-352000 [www.sidefx.com]

Just wondering if that is an attribute/property that would be accessible via a surface shader somehow?

Would any of the staff have pointers for this?


cheers
User Avatar
スタッフ
4258 posts
Joined: 9月 2007
オフライン
With a VEX shader like the Principled Shader, you can use the Ray Import VOP, and set it to ray:objectid, and pipe that into a Random VOP.

For MaterialX the workflow is still a bit rough, but you can use a MtlX Dot node, and set the comment also to `ray:objectid`, and use that with the MtlX CellNoise2d.

Hope this helps!

Attachments:
karma_ray_import_options.hip (626.6 KB)
Screenshot from 2021-11-22 08-48-32.png (565.5 KB)

I'm o.d.d.
User Avatar
Member
31 posts
Joined: 2月 2014
オフライン
That's great - thanks for taking a look.
I'm having trouble reproducing the results you're getting at this end, both in 19.0.383 and in the latest daily build.
Also - my result seems to be reseeded when viewing different points in the node graph..?
Any suggestions as to what might be up? This is on windows10 - possibly a platform difference?
Edited by ben toogood - 2021年11月23日 07:29:59

Attachments:
out.gif (4.4 MB)

User Avatar
スタッフ
4258 posts
Joined: 9月 2007
オフライン
Indeed you are correct; I hadn't noticed this initially, my apologies! We need to figure out a different way to support this, but for now, you'll need to generate a primvar, to get frame-coherent primitive id's. Sorry for the confusion!
I'm o.d.d.
User Avatar
Member
31 posts
Joined: 2月 2014
オフライン
no worries - thanks for the tip though. primvars are good for now. cheers
  • Quick Links