I've recently been groping around the web looking to educate myself about this new Iray thing. ;-) In doing so I've found a couple of really useful sites (which are probably documented elsewhere in these forums as well), and a very few good descriptions of the Material Definition Language or MDL used at the heart of Iray materials. Most of the useful information I've found has been off of the iray dev blog and the MDL Handbook. Of particular use to me were two articles that I found while reading through the blog. The first, at migenius.com entitled Procedurally Retro with MDL is the inspiration for this post. Go off and read it now. I'll wait....
Back? OK then.
Adding MDL shaders is actually pretty easy, but for goodness sake, don't start with the DAZ Iray Uber Base shader. It's quite complicated, and will likely inspire the relative novice to give up before starting. I started with one of the car paints from the Shader Presets/Iray/NVidia MDL Examples.
Apply a shader to a surface then go into Shader Mixer, you can File -> Import From Scene...
If you chose a suitably simple one, you should see three bricks, User Parameters, Custom MDL, and MDL Surface. Delete the Custom MDL brick, and all but the "Material ID" from the User Parameters brick. We do it this way because Using File -> New Material... will start with something much more complicated than we need.
Before we can move on, we need our actual MDL file. You can pull up the one I started with from here. You need to make a simple change to the file before it's ready for DAZ. Near the bottom third of the file where it reads:
export material tenprint_example (
uniform float tiling = 100.0
) = let {
change it to read:
export material tenprint_example (
uniform float tiling = 100.0
[[
anno::display_name("Tiling"),
anno::soft_range(0.1, 1000.0),
anno::description("Describes the tiling of the texture across the surface.")
]]
) = let {
This gives Shader Mixer the some type hints and friendly names for the brick inputs. You need to save your new MDL file to the DAZ Studio application directory under shaders/. I created a new directory <App Dir>/shaders/iray/local, for anything I might want to do and saved my file as tenprint.mdl.
Now right click on the canvas and choose Insert... -> Bricks (Default) ---> Functions -> MDL -> Custom MDL.
This gives us a very simple brick, and all we need to change is the "MDL Callable" parameter.
The MDL Callable parameter becomes the path under the shaders directory to our MDL file, with '::' replacing whichever slash your operating system uses followed by the material we wish to call. So, for this example where I'm refering to tenprint_example in <App Dir>/shaders/local/tenprint.mdl I enter local::tenprint::tenprint_example. You can also drag and drop the MDL file directly from your shader subdirectory to accomplish the same thing[1].
Now we need to add our new property to the User Parameters brick. That's pretty easy. Click on the flyout menu and select Add User Parameter..., and make it look like the example below. The parts you'll need to change are Name and Label at the top, and the Float Attributes at the bottom.
Now wire things back up. Tiling in User Parameters connects to Tiling in Custom MDL, and Result in Custom MDL connects to Material in MDL Surface. The Material ID fields in User Parameters and MDL Surface should still be connected from when we imported.
Now you can click Apply in the bottom right hand corner of the Shader Mixer pane. This applies your brand spanking new shader to the geometry you originally imported our starting material from (assuming you didn't change your surface selection in the mean time). Now would be a good time to save all your hard work as a Shader Preset, File -> Save As -> Shader Preset. Choose an appropriate location and file name. In the properties dialog make sure only the General and User Parameters are checked. It won't hurt anything if you check them all, but we don't really need to.
Now, render some objects like they came directly out of your Commodore 64 screen!
Edit: Updated with information regarding drag and drop of MDL files to the Shader Mixer c/o Richard Hazeltine