Jump to content

Override local variable on materials


Recommended Posts

Hi guys,

 

I am facing a problem while trying to use the same shader but different texture maps for each piece (I use connectivity and $CLASS)

 

In the details view (or geometry spreadsheet :D) I see the material override working, in other words, I have 5 textures called texture01.jpg texture02.jpg etc.. and for each piece is assigned a different texture.

 

But, here comes the problem, when I click render or in the viewport I see the same texture everywhere. I assume that the override parameter is not working. But I can't find a way to call an attribute ($CLASS) into Shops to be able to get the expression for example:

 

$HIP/textures/texture `int(rand($CLASS)*5)+1`.jpg

 

It would be awesome if someone knows how to fix this!!

 

Thanks!

 

 

Link to comment
Share on other sites

You want your attribute on the Primitives type of the geometry spreadsheet, not the Details type for Mantra to detect the variable. Also, what is $CLASS, an integer, a float? If $CLASS is your value then you are using your value as your seed, probably not what you want.

 

You may want to look into Material Stylesheets instead. I put together a short tutorial on how to link textures from the disk to various planes along a line using Material Stylesheets.

 

You can check it out here.

Link to comment
Share on other sites

Hi Atom,

 

Thanks for the tutorial!

 

Sorry if I was a bit vague on my explanation. I made this simplified version of my file. You can see in the spreadsheet primitive's type that there is the material_override attribute with one texture assigned for each $class. (in the file there is just one houdini's default texture)

 

 

 

 

 

Random_Textures.hip

Link to comment
Share on other sites

Here is my re-work of your scene using the technique mentioned in the video I posted.

 

Basically the filename creation work is done in the Attribute Wrangle. It makes a random full path file name from a list. So you can just alter the list and path to textures all in one place. It also adds a Random Seed to the Attribute Wrangle so you can randomly change the result of you like.

 

The image shows random metal textures from the library on my disk.

post-12295-0-10294500-1448388037_thumb.j

 

The Attribute Wrangle VEX code:

s@image_name = "";
float rnd_seed = 0;
string full_path = "";
string extension = "";

//NOTE: Do not put spaces in your file names! (won't work with Material Stylesheet)

// Path to maps on your system.
string path_to_maps ="E:/ARNAU/log/textures/";
string image_maps[] = {"BarkDecidious0","BarkDecidious1","BarkDecidious2","BarkDecidious3","BarkDecidious4","BarkDecidious5"};
extension = ".jpg";

/*
// Path to test maps on my system.
string path_to_maps ="C:/Users/Developer/Documents/Maps/cc0_Tileable_Textures_Library/Metal/";
string image_maps[] = {"Rusted_Metal01","Rusted_Metal02","Rusted_Metal03","Rusted_Metal04","Rusted_Metal05","Rusted_Metal06"};
extension = ".png";
*/

for(int i=0; i< @numpt; i++) {
    // Randomly pick which image mape to use.
    rnd_seed = i + ch("rnd_seed");

    int ndx = int(random(rnd_seed)*(len(image_maps)));
    full_path = concat(path_to_maps,image_maps[ndx],extension);

    // Assign the full path file name result to the attribute.
    setpointattrib(geoself(), "image_name", i, full_path, "set");
    full_path = "";
}

The Material Stylesheet code: (at the object level of the box)

// Houdini 15 style for stylesheets.
{
    "styles":
    [
        {
            "target" : {"primitiveGroup" : "*"},
            "overrides" : {
                "materialParameters":{"basecolor_texture":{"script":{"binding":"image_name"}}}
            }
        }
    ]
}

Remember you must promote the attribute from point to primitive for this to work. In this example the promotion occurs in the Copy SOP under the Attributes TAB.

ap_Random_Textures.hipnc

Edited by Atom
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...