Skill Level Intermediate
- [Instructor] Wrapping up the series on the basics of Open Shading Language in 3ds Max. We will now save the OSL code out to an external document. This allows us to link to a file, share that file among users and scenes, and also make the map visible in the Material Map Browser. I've got the material editor open, and I'm displaying the Material Map Browser from the tools menu here. And, we can actually add our own categories in here and populate them with our custom OSL maps.
I've got a version of the Simplex noise map that we created over the past few exercises. This version has a new input parameter, the iteration phase offset. Its purpose is to break up the pattern a little bit more and give us more options for our directing the look or characteristics of the texture. Let's open up the code editor, click on the pencil icon, and we can see that I've added a new float input parameter called iteration phase, and it's simply a numerical amount added to the phase with each successive iteration.
Scrolling down a bit into the statements section, we see that I've added a new variable current phase, and I've set that initially to the value of the phase input parameter. And, inside the noise function, I'm using the current phase as the argument for the fourth dimension, or the time dimension. Then, near the bottom, I'm iterating the phase, just as we iterated the frequency and amplitude. With each repeat of the four loop, the iteration phase amount is added to the current phase.
And in a previous movie, we just added the integer value of the current iteration to the phase, but the iteration phase parameter that I've created here is a little more sophisticated, because it doesn't just offset the phase by whole numbers, but by any arbitrary float value. We're ready to save the OSL document. Remember that an OSL map can be linked to a file, and if it is linked, then this little link icon'll be turned on. All of the stock OSL maps provided with 3ds Max, that we see here in the Material Map Browser, they're all linked to files in the Program Directory.
Now, with the link button in the material parameters is off, then the map isn't linked to a file, and the code exists uniquely inside the current map, inside the current scene. Once we save an OSL file, then we'll have the ability to link to that file, and we can also reveal it in the Material Map Browser. There are two ways to reveal a custom OSL map, and I'll show you both. The first way is to save into a special folder in the 3ds Max Program directory.
The second way is to save to any directory we want, and then edit the 3ds Max system paths to look in that directory. If you wish to save into the 3ds Max program files, you will need to be logged in as an administrator. If you're not, then you might not have permissions to save to the Program Files directory from within 3ds Max, but you can save to a temporary location, and then move the document into the Program Files folder.
Let's do that. I've got the code editor open. In the lower right corner, is a button save OSL file. I'll click on that, and I'll simply save onto the desktop temporarily, and I'll call the file Simplex noise version one dash one. Click the save button, and now we can see that some data is showing up here. It's showing us the file name, but it's not currently linked to that file. If we wish, we could just click that link button now, and now, in the code editor, we're looking at a read only version.
If we wish to resume editing, we'll need to turn the link back off again. Okay, to make the map show up in the Material Map Browser, we will need to exit 3ds Max completely. So, I'll go to the file menu and choose exit, and I don't need to save these changes. And then, on the desktop, we should see an icon, and you might need to hit F5 to refresh the desktop, but now I've got Simplex noise version one dash one.
And, I want to move that document into my 3ds Max Program directory. It's going to be on the Operating System C drive. Program Files, autodesk, version number, plugins, OSL, and if you want it to appear inside a folder in the Material Map Browser, then you just create a directory here. I'll right click and choose new, folder, and I'll give this folder the name custom maps. Then, navigate into that folder, and move the Simplex noise OSL document into that folder, and now I get a Windows prompt, because I'm not currently logged in as an administrator.
But in my case, I can just click the continue button, and I'll be able to copy into that folder, and now that's complete. And now, I'll need to relaunch 3ds Max. When 3ds Max launches once again, I can go to the material editor, and in the Material Map Browser under maps, OSL, indeed I have a custom maps directory. I can open that up, and here's my Simplex noise that I've authored. Drag that over, maybe double-click it to enlarge it. Double-click it to load its parameters.
And this one is linked to the version in the 3ds Max Program directory. If I change that file in the Program directory, then I will invalidate any scenes that depend on that file. If you're experimenting a lot, or making a lot of versions of things, or we just wanna make sure that your project is completely bulletproof, then I recommend taking an asset based approach instead of this Program Files directory approach. So, let me show you the other way to go about this.
I'm going to exit out of 3ds Max once again. I'm not saving any changes. Back in Windows Explorer. I've got my Simplex noise document. I'm going to cut that and move it into my current project, and that way the project will always load the version of the OSL document that is specific to that project. In the scene assets, I will create a new folder in here. Just right click and choose new, folder, and it needs to be called OSL.
If it's not called OSL, then 3ds Max won't find it. And I could put my document directly in there, but if I wanted a subcategory, then I'd need a subfolder. So, I'll go in there, right click, and make a new folder once again. Instead of calling my subdirectory custom maps, as I did before, this time, I will name it current project. Alright, then go into that folder, and I'll move my OSL document over there, leaving the custom maps directory empty.
In fact, if I want, I can even delete that just as an illustration of how we're switching over to a completely different workflow. So, I'll select that and delete that custom maps directory. Once again, I'll need to click through the Windows prompts to provide administrator permissions, and I'll also need to relaunch 3ds Max. Back in the 3ds Max, we'll need to set up a system path so that the program will be able to find the OSL document that we've put in the current project. Just because it's in a project folder does not mean that 3ds Max is looking for it.
We'll need to tell it where to find the files. And that'll be done in the customize menu. Configure system paths, and go to the 3rd party plugins tab. Even though OSL is not technically a plugin, this is where we will add the system path to find those OSL files. Click on the add button, and then you'll need to navigate to your current project. And, in my case, I just go to the desktop. Exercise files, and then go into the scene assets folder, and once the contents of the scene assets folder are displayed, and its path is listed here, we need to change the label, and that's just going to be the name of this path in that customized dialogue.
We'll call it scene assets. And, very importantly, there's already a folder in there called OSL, and that's the key here, you have to have a folder called OSL inside the current path. Click on the use path button, and double check it, make sure, that it's listing the path ending in scene assets. Click okay, and now, 3ds Max should be able to find our custom OSL map.
Let's reset the program. Go into the material editor, and then in the maps OSL category, we find current project, and here is the Simplex noise map. We can drag that over into the view. Alright, terrific, so now we know that anything that we drop into that OSL folder is going to show up in the Material Map Browser, and that way we can also make sure that we are archiving all of that code along with the project.
And in case we version the map later, we won't have any version conflicts. Alright? That then concludes this movie on the OSL file paths and assets, and it also wraps up our series on OSL and 3ds Max 2019.