Material Variation Node - Example Please ?

   4057   6   0
User Avatar
Member
42 posts
Joined: Aug. 2016
Offline
I am having a bit difficulty of figuring out a way of how material variation node is working.

I can't so far find a solution for it. Is there an simple example of hip file how it is used ? Thanks.

For example I have need to change a diffuse texture to one of the primitives assigned but rest primitives maintain the same.

Redshift Material.
Edited by cgmagic.sunhe - Oct. 12, 2020 17:23:36
User Avatar
Member
2625 posts
Joined: June 2008
Offline
Try using a primitive wrangle after the initial material assignment. Use the viewport to identify which primitive number where you want the special assignment, and write a simple if statement.
// Default all materials to one value.
s@shop_materialpath = "/mat/ordinary_plastic";
if (@primnum==12){
    //Special case here.
    s@shop_materialpath = "/mat/special_plastic";
}

Another way is to add the candidate to a group.
if (@primnum==12){i@group_material_special=1;}
Then you can process the special cases as an entire group inside the standard material node.
Edited by Enivob - Oct. 13, 2020 09:16:41
Using Houdini Indie 20.0
Windows 11 64GB Ryzen 16 core.
nVidia 3050RTX 8BG RAM.
User Avatar
Member
8038 posts
Joined: Sept. 2011
Offline
The material variation node authors primvars used by the material to vary the appearance on the selected prim locations.

For Karma materials, the primvar must be the same as a parameter/bind in the material. Other renderers may need to use a primvar/attribute read node to bind the primvar to the shader.
User Avatar
Member
199 posts
Joined: Nov. 2013
Offline
jsmack
The material variation node authors primvars used by the material to vary the appearance on the selected prim locations.

For Karma materials, the primvar must be the same as a parameter/bind in the material. Other renderers may need to use a primvar/attribute read node to bind the primvar to the shader.

Do you have any snippet examples? It's quite confusing having different vex syntaxes depending on what you're doing. For example, if I have a material variation LOP varying the diffuse_color, it creates a primvars:diffuse_color primvar.

If I Check ‘Use Snippet’ and attempt to edit this primvar with the code below, it doesn't update the value.

usd_setprimvar(0, @primpath, "diffuse_color", {0.0, 1.0, 1.0});

The help says i@primvars:foo is the syntax to use, but I'm not sure how to go about getting that to work, as the followig throws an error:
v@primvars:diffuse_color = set(0,0,1);
User Avatar
Member
199 posts
Joined: Nov. 2013
Offline
Discovered you can avoid using the materialvariation LOP altogether if you do something like this.

float colorx = fit01(rand(@elemnum), 0.29, 0.44);
float colory = fit01(rand(@elemnum), 0.185, 0.35);
float colorz = fit01(rand(@elemnum), 0.13, 0.32);
vector color = set(colorx, colory, colorz) *0.75;

vector colorpath[];
int colorpathindex[];
append(colorpath, color);
append(colorpathindex, 0);
usd_addprimvar(0, @primpath, "diff_color", "color3f[]");
usd_setprimvar(0, @primpath, "diff_color", colorpath);
usd_setprimvarindices(0, @primpath, "diff_color", colorpathindex);
User Avatar
Member
199 posts
Joined: Nov. 2013
Offline
Better yet, use a color ramp!

float r=rand(@elemnum);
vector color = vector(chramp('color', r));

vector colorpath[];
int colorpathindex[];
append(colorpath, color);
append(colorpathindex, 0);
usd_addprimvar(0, @primpath, "diff_color", "color3f[]");
usd_setprimvar(0, @primpath, "diff_color", colorpath);
usd_setprimvarindices(0, @primpath, "diff_color", colorpathindex);

// Viewport color
//usd_addprimvar(0, @primpath, "displayColor", "color3f[]");
//usd_setprimvar(0, @primpath, "displayColor", colorpath);
//usd_setprimvarindices(0, @primpath, "displayColor", colorpathindex);
Edited by Hamilton Meathouse - Nov. 7, 2020 22:02:38
User Avatar
Member
8038 posts
Joined: Sept. 2011
Offline
Hamilton Meathouse
Discovered you can avoid using the materialvariation LOP altogether if you do something like this.

Isn't the point of a material variation to make it easy by avoiding writing that kind of explicit code?

The sop modes make it easy and familiar to vary the attribute values using geometry ops. Just vary the attribute in sops how you always do.

In uniform (use snippet), mode the syntax is the same as other vexpressions such as those used in popforce nodes. The tooltip says how to use it.
Set the value using a VEX snippet. The snippet should write the override value to the value variable. @ptnum is the index of the current prim/instance. You can use npoints(0) to get the total number of prims/instances to compute values for. You can use @Frame and @Time to make the value time-dependent.

E.g.: to pick a random color from the element index use:
value = random(@elemnum);
  • Quick Links