Stay on top of the latest 3ds Max tools and techniques. Get a new tip every Wednesday to expand your 3ds Max knowledge and skills.
- [Instructor] Open Shading Language provides an easy way to assign random maps or materials to objects in the scene. This relies upon a property of the object called its node handle. That's simply a number that's assigned to each object when it's created. We can find the node handle ID number of any object using MAXScript. I'll do that just to illustrate what the node handle is. I've got a scene here with some polyhedral objects and if we select one of them, we'll see that they're all named Hedra and then a three-digit number. In the MAXScript mini listener, the pink area down here we want to enter in a piece of code. I'll zoom in on that so we can see that better. And to find the node handle of a particular object we just enter in this string of code, ID, equals, dollar sign and then the object name and this is Hedra 008 and then a dot and handle. And then press the Enter key and that tells us that Hedra 008 has the ID number of 100. All right, so we're going to use that information in a Shading Network. Let's open up the Material Editor. And I've got a material here already assigned to all of the polyhedra objects. I want to double click on that and select it and also just make sure that I'm showing a realistic material in the Viewport so that we can see the OSL map. So, click on the button labeled Show Shaded Material in Viewport. Drag that out and select the black icon and now we're seeing a realistic version of that material in the Viewport. Now, we're going to create a base color map for this physical material. Drag out from the base color map input. Release the mouse. From the pop-up menu we'll choose a map name. Go to OSL, Switchers and we have some options here. Let's choose one of five color and that's going to give us a map that has five colors or five map inputs. Let's double click on that and rename it. We'll call it Random Map. We can see that we've got a pink color on our polyhedra objects and that's because the index value is currently set to zero. If we change that to some other number then we'll see one of the other colors shown here. And of course we can change that color and plug in some other color if we want. Or we could assign a map to any one of those inputs. So, we could cycle through bunch of different maps. Now, we want to randomize the index number per object. And to do that we'll create another node and connect it to the index input of this OSL one of five color node. Click and drag on the index input and then drag out and release the mouse, choose OSL, Switchers, Random Index by Number/Color. That's going to generate a random number based upon an input number that's provided. Double-click on that new node and we'll call it Map Randomizer. And the last part of this is we need to supply the object node handle ID. And that's going to go into the input number input of this random index node. Click and drag on input number. Release the mouse and choose OSL, Scene, Node Handle. And then as soon as we do that, now suddenly we've got random colors on all of our polyhedra. We can change that pattern. We can go back to our randomizer node and change the seed value. A different seed number will yield a different random result in the pattern distribution here. All right so that's how to change up the maps using OSL. We can also use OSL to change up the materials on objects. However, to do that we'll need to use an Arnold Shader because OSL in 3ds Max does not currently support materials or closures. It only supports maps. But we can do this with Arnold, not a problem. Let's create the Arnold node. Right click and choose Materials, Arnold, Utility, Switch Shader. And this allows us to plug in up to 20 different materials. Double-click on that and rename it. We'll call it Arnold Material Switcher. Now we want to assign this new material to all of the Hedra objects in the scene. Click in any Viewport and use the keyboard shortcut Control+A to select all of the unfrozen and unhidden objects. Go back to the Material Editor and with the Switch Shader node selected click on Assign Material to Selection. All right and they all go gray. Now we need to connect up these physical materials that I have provided. So, we've got material one, two and three and we'll connect them to their corresponding inputs. I'm going to skip input zero because that kind of makes me crazy. I don't want my numbering to start from zero. So, I'm going to use inputs one, two and three. Now, we need to duplicate some of the Shading Network here. I want to select that Map Randomizer node, hold down shift and drag out to make a duplicate. And it's connected to the node handle. We don't need to duplicate that because of course it'll provide the same numbers. Because it's deriving that from the scene itself. All right, so we're going to take this OSL node that we've duplicated, double-click to rename it and we'll call it Material Randomizer. All right and then we'll just connect that to the index number on our Switch Shader. So, take the OSL random index output, plug it into the Arnold Switch Shader index input. And we'll need to do an ActiveShade render to see the result. So, click on ActiveShade. I've got that set up already. And we see that we get different materials applied on to different objects. But some of them are rendering in black. And that's because we've only provided materials to inputs one through three back in our Material Randomizer node, we just need to change the output minimum and maximum integer values. I'll set the minimum output value to one and the maximum output value to three. So, now we're just getting values from one to three coming out of this randomizer node. All right, so we have now created a situation in which we have different materials assigned on to objects based upon their node handle ID. And once again we can change the seed value and change the pattern distribution of how those materials are assigned. That's how to use OSL to assign random maps or random materials to objects.
AuthorAaron F. Ross
Skill Level Intermediate
3ds Max 2017: Advanced Lightingwith Aaron F. Ross2h 52m Advanced
3ds Max 2017: Advanced Materialswith Aaron F. Ross2h 34m Intermediate
3ds Max 2019 Essential Trainingwith Aaron F. Ross10h 39m Intermediate
New This Week
3ds Max: Tips and Tricks
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.