Playing around with Iray MDL

EsemwyEsemwy Posts: 578
edited July 2015 in Daz Studio Discussion

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...

image

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.

image

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. 

image

This gives us a very simple brick, and all we need to change is the "MDL Callable" parameter.

image

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].

image

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.

image

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.

image

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.

image

Now, render some objects like they came directly out of your Commodore 64 screen!

 

image

image

image

Edit: Updated with information regarding drag and drop of MDL files to the Shader Mixer c/o Richard Hazeltine

Post edited by Esemwy on
«1

Comments

  • MBuschMBusch Posts: 547

    Thank you for this! Now that I have a clear starting point, maybe I take the challenge.

  • EsemwyEsemwy Posts: 578
    MBusch said:

    Thank you for this! Now that I have a clear starting point, maybe I take the challenge.

    You're quite welcome. Once I found the iray dev blog, things really started to come together. The talks and slides from GTC 2015 linked there were especially helpful. 

  • Richard HaseltineRichard Haseltine Posts: 102,449

    You can also drag an MDL file into the Shader Mixer pane.

  • EsemwyEsemwy Posts: 578

    You can also drag an MDL file into the Shader Mixer pane

    Updated. Thanks! 

  • You can also drag an MDL file into the Shader Mixer pane.

    Is this feature working, because as I drag the file nothing happens...

  • EsemwyEsemwy Posts: 578

    You can also drag an MDL file into the Shader Mixer pane.

    Is this feature working, because as I drag the file nothing happens...

    It works, but you don't get any visible error when it fails. You'll probably see a compile time error in your log. 

  • Cris PalominoCris Palomino Posts: 11,624

    The MDL file needs to reside within a mapped MDL directory.

  • ronmolinaronmolina Posts: 118

    Cool stuff!

  • jag11jag11 Posts: 885

    The MDL file needs to reside within a mapped MDL directory.

    Here's how to add one.

    MdlDirMgr.png
    870 x 748 - 54K
  • Thanks a lot for the information guys, i'm going to try asap!

  • almahiedraalmahiedra Posts: 1,353
    jag11 said:

    The MDL file needs to reside within a mapped MDL directory.

    Here's how to add one.

    Super!!!! just that I needed. Thanks for share the info.

  • kitakoredazkitakoredaz Posts: 3,526
    edited November 2015

    Hi, I played when fist see this topic, then it work well.. then I believe, maybe next step is,  write simple MDL code, then use it in shader Mixer

    to learn MDL.  Now I reading MDL handbook with dictionary carefully, then I hope to test the discribed code work or not,, .

    material testplaster ()= material (	surface: material_surface (		scattering: df::diffuse_reflection_bsdf (			tint: color(0.2,0.5,0.7),                        roughness_u: 0.1 )));

    yes, I just change tint color of diffuse and roughness_u

    then I save it, as test.MDL in the location where I stored my MDL but when I drug the test.MDL from same directory (MDL manager assigned) DS return erroer,, everytime. Is there code which I need to add, apply MDL in DAZ shader mixer? I checked your sample code, then feel if I need to change code, as "export material" etc? eg about this MDL code,, how you modify to imput it as custom MDL in shader mixer? ^^; I really hope to know the way (use code in DS) to learn MDL code one by one with MDL handbook way,,

    Post edited by kitakoredaz on
  • kitakoredazkitakoredaz Posts: 3,526

    I am afraid,, everytime I  arrange Shader mixer MDL blicks  to  check MDL codes in handbooks,  for daz studio like my pic?cool

     

    I believe, I need only add some code for pure MDL,  to use "Custom MDL blicks" 

    there should be clear simple rule,  (use Export Material,,etc,, ) then,,   MDL file,  can easy input to  Custom MDL blick

    then, apply surface in DAZ studio.

     

    though I  play with Iray Shader mixer MDL blicks,, it seems take time a lot, to check each blick for learning MDL (not daz  shader mixer  blick usage,,)

     at current, I simply hope to learn MDL structure,, not hope to learn how to arrange MDL blick and how they work,, in shader mixer,, it is different,,.

    mdlblicks.PNG
    1315 x 839 - 295K
  • EsemwyEsemwy Posts: 578

    You do need an export statement. Otherwise, Shader Mixer will discard the material as unreferenced. Other problems I see in your example is the lack of an mdl version statement (i.e. "mdl 1.1;"), and you are missing a couple of imports.  The exact syntax is left as an exercise. laugh

    Your only real debugging assistance is from "Help -> Troubleshooting -> View Log File...". If you scroll to the end of the file you will see somewhat better error messages than what Studio displays in the dialog. 

    At least on OS X, the log file doesn't update in the viewer, so you'll need to re-open it each time you want to view the newer messages.

    Bang your head against it for a while, and let me know if you have any more difficulties.

  • kitakoredazkitakoredaz Posts: 3,526

    Thnaks. wink  Does this  cook book will  discribe "Export" or, "let" or mdl version usage,, lator ?  (to use MDL in other aprication)

    or I need to serch another document?  then,, yes I actually ,find later, my  misscode about roughness_u (it may not work for diffuse_reflection_bsdf ?)

    then I check log too, and yes I understand DS can not import my MDL, but it not help me well ^^;  

    Then,, OK  untill I change bad-mode, then my evil emotion order me to shout,,  "why daz can not offer these usage with easy clearl document etc,,"

     I take shower smiley Actually I  learn many about BSDF ,BRDF etc today, (before I often see these words, but I can not what actually meaning at all

    Nvidia hand book is well  documented I think,,

    (But DAZ customize iray shader ,to usable in shadermixer,  for daz stuido, then DAZ need

    to offer, their customer,, more clear document I bellllllllllllllllllliiiiiiiiiiieeeve!!  so!! 

    as soon as they can ,Quick Quick Quick!
  • EsemwyEsemwy Posts: 578

    Besides the MDL Handbook, you also need to take a look at the Language Specification. DAZ does, in fact, use standard MDL. It's just that we have a newer version of Iray than most, if not all, other software packages. 

    As for Shader Mixer, and the other DAZ specific parts, this forum, along with a number of Youtube videos (especially by Carnite) are your best bet. Most of it is pre-Iray, but the mechanics are still the same. 

  • kitakoredazkitakoredaz Posts: 3,526
    edited November 2015

    I got it now .... wooo,,,, just input too simple shader, add rougness,, I felt almost give up^^; why I  could not,, I almost cry ^^;  finally,,

    yes I picked up the Language Specification,, but I believe  it should be written by Martian,, I can not understand,, half of them,,

    I often feel programmer is different human,,, they talk another world language,,,

    " really thank you to teach me many about MDL"smiley

    mdl 1.0;import df::*;import state::*;import base::*;import tex::*;import anno::*;export material nulmat ()	= material (		surface: material_surface (			scattering: df::diffuse_reflection_bsdf (			tint: color(0.2, 0.6, 0.7),			roughness: 0.95 )));

     

     

    mdlblock2.PNG
    1221 x 846 - 296K
    Post edited by kitakoredaz on
  • kitakoredazkitakoredaz Posts: 3,526

    Can I ask  about Shader Mixer MDL parameter, blicks  here ?smiley

    (I know sticky topic about shader mixer, but most of user seems use there for asking 3delight blicks, and I think  we may better separate topic, about

    different renderer blicks for 3delght and Iray (MDL) to both user serch easy., I hope someone make new topic, about shader mixer blick (MDL).

     

    My question is, how to add  new "map User parameter" , like uber surface "base color (map)"

    I want to add  user parameter for maps like MDL style,, that means,  user can controll Color as  (R G B) 3 float (0.0 to 1.00) value. + image map like my pic

    but I can not find such parameter type, when I add new paramter. indecision

    "float"  type, only offer , 1 float value + mappable.   "color" offer three  RGB (0 to 255) value way,, I think.

    Shold I need to  delete others from these shader,  then save it as new shader blick, and edit?  or there is another way to add it?

    MDLmap.PNG
    563 x 427 - 75K
  • EsemwyEsemwy Posts: 578

    The easiest way to get matching parameters is to drag from 'Auto Add' in the 'User Parameters' brick to the input value of the other brick. Shader Mixer will create a parameter matching the data type, then you can edit the result to fill in the details.

  • kitakoredazkitakoredaz Posts: 3,526
    edited November 2015

    @Esemwy  thank you !  yes,, I could remember the way after I asked  here ^^;  (drug in to the "Auto add" of User parameter).

    Now,,  I hope to know the way to add file texture blicks as same as Iray Uber shader ,,from scratch, (without drug from each map of Uber shader,,)

    and to learn the way to code in MDL ,show it as new parameter on custome MDL blick..(then drug into user parameter "auto add")

    At current,, about Shader mixer blick,  I could find  "MDL>Defualt Modules>base>File texture,, then use it,, but it is not same as these Map blicks.

    ================================

    Anyaway I  keep leraning, then Made "simple Diffuse Emission  light shader + (reflect type, trancerucent type (non shadow) ), as User MDL,smiley  (code)

    mdl 1.0;import df::*;import state::*;import base::*;import tex::*;import anno::*;export material emission (	color Transmission_Color = color(1.0, 1.0, 1.0), 	uniform df::scatter_mode modeswitch = df::scatter_reflect,	color Emission_Color = color(1.0, 1.0, 1.0 ),        float multi_intensity = 10000)= material (	surface: material_surface (		scattering: df::specular_bsdf (				mode: modeswitch,				tint: Transmission_Color ),		emission: material_emission (			emission: df::diffuse_edf(),			intensity: Emission_Color * multi_intensity )));

    I felt  difficultiy about intensity of diffuse edf,, (if I do not set user intensity parameter, just set (1.0) color, in daz studio, the Diffule edf can not emissinon light (I can not see it).   (user may  need to test with simple MDL code, then customize, as you like,,)

     I feel, multiple 10000 with  Color value, is correct  for DAZ unit ?  (I can not undersatnd detail, maybe scale problem, I felt)

    And to improve this diffuse light shader, I hope to controll the "specular bsdf :: scatter mode" by " intensity map",,,

    white color (1.0) point > mode = reflect ,  (Mirror light)  ,Black (0.0) point  > mode=  tranculecent, (non visible,  light emission only)   then I plan  to use,,

    "choose value " blick,, but it seems not work,  the scatter mode can  change As Uniform only, 

    then  I feel,, color (or intensity map)  can not controll this mode value,,,,,)  may I need to use "layer weight etc"  to achive it?

    anyway I keep learning MDL and shader mixer (MDL) ,, then will  ask here thanks.smiley

    deflight.PNG
    1283 x 910 - 235K
    deflight2.PNG
    1198 x 816 - 141K
    Post edited by kitakoredaz on
  • kitakoredazkitakoredaz Posts: 3,526
    edited November 2015

    I hope someone check DAZ shader mixer   simple glossy bsdf, it seems not set correctly about roughness_v default value. as same as MDL difined.  

    the simple glossy bsdf blick is located in  "MDL>default module>df>simple glossy bsdf ", then make simple glossy shader.  like my pic1

    I believe, the node arrangement is right.    I set two parameters ,   tint = color(0.2, 0.3, 0.7)   , roughness_u= 0.5

     

    MDL structure have default value ,about most of field. then if there is field which have not set value, it simply use "default"

    so that we need not set all filed value of structure, when we make material.

    then   bsdf :: simple glossy bsdf  , filed  roughness_v is as default,  roughness_v = roughness_u

    I need not set rougness_v value.  only need to set roughness_u value,  if I hope so.

    actually it work when I code them as MDL.     it is really simple shader, then you can easy check if there is problem.(but not,,)

    mdl 1.2;import df::*;import state::*;import base::*;import tex::*;import anno::*;export const color blue = color(0.2, 0.3, 0.7);export material blue_glossy()=material (	surface: material_surface (		scattering: df::simple_glossy_bsdf(			tint: blue,			roughness_u: 0.5)));

     

    then apply it and render same scene, is like that. I felt if I miss some light setting etc, at first. because I have tried to test layer shader, with MDL handbook, but I felt if I set same shader with shader mixer, something wrong. I could not find clear difference, when I change roughness_u value of shader mixer blick.Though  I couuld see, it change. but it is not same when I make shader by MDL custome blick. then I find, DAZ offer "simple glossy bsdf" blick not set value for roughness V correctly, if I do not set value. I need to set roughness_v value , as same as roughness_u in shader mixer. (I do not think it is heavy problem for me, though it caused troble, when I test mix shader with simple_glossy_bsdf, but it seems better daz up-date this shader blick.

    shadermixerglossy.PNG
    1241 x 735 - 283K
    userMDLglossy.PNG
    1031 x 558 - 236K
    Post edited by kitakoredaz on
  • PendraiaPendraia Posts: 3,598

    Cool thread...I will have a play and see if I can add something useful.

  • algovincianalgovincian Posts: 2,636

    Just wanted to say thank you for the information in this thread - it's been extremely helpful as I attempt to write my first MDL shader and get it into DAZ. If any of you experts know anything about backface transmission (and are interested), here's the thread:

    http://www.daz3d.com/forums/discussion/comment/1491746/#Comment_1491746

    - Greg

  • ProPoseProPose Posts: 531

    Substance Designer 5.5 might be of interest for folks interested mdl

  • evilded777evilded777 Posts: 2,465
    edited August 2016

    withdrawn.

     

    Anyone getting stuff out of SD 5.5 and into Studio yet?

     

    Trying with the Allegorythmic car paint example and there's some steps I seem to be missing, but the log file is helping a bit.

    Post edited by evilded777 on
  • algovincianalgovincian Posts: 2,636
    jag11 said:

    The MDL file needs to reside within a mapped MDL directory.

    Here's how to add one.

    Have you mapped the directory of the MDL file you're dragging/dropping?

    - Greg

  • evilded777evilded777 Posts: 2,465
    edited August 2016

    I had not done that Greg, but it does not seem to make a difference.

    "2016-08-26 11:54:28.719 WARNING: dzneuraymgr.cpp(261): Iray ERROR - module:category(SCENE:IO):   1.0   SCENE  io   error: Unable to resolve file path "carpaint_resource_0.png" in "C:\Program Files\DAZ 3D\DAZStudio4 Public Build\shaders\iray\local\carpaint.mdl"."

    There is no such resource referenced in the MDL file that I can see. But...I may be missing something as the tutorial did not cover every specific of creating the substance.  There certainly is no reference to it in the MDL file itself, so that leads me to believe something else is wrong.

     

    //hell I am blind there it is! And why the hell would it not export the required resources when generating an MDL file? That's a bit of a problem.

     

    ...and there it is right in front of my face, but since I wasn't looking for it, I didn't see it.

    But its still being a pain.

    2016-08-26 12:03:03.987 WARNING: dzneuraymgr.cpp(261): Iray ERROR - module:category(API:DATABASE):   1.0   API    db   error: DB element "mdl::local::carpaint" is still referenced while transaction 5 is committed.

    I don't expect it to be easy per se... but I really want this! Time to take a break.

     

    Post edited by evilded777 on
  •  

    ...and there it is right in front of my face, but since I wasn't looking for it, I didn't see it.

    But its still being a pain.

    I don't expect it to be easy per se... but I really want this! Time to take a break.

     

    evilded77, thanks for the updates!  I'll be downloading 5.5 at some point today. I watched the demo on creating MDLs last night, and I'm pretty psyched about it, but any head start gotchas and tips will be appreciated.

     

     

  • The problem I see is that besides several adjustments to be done manually (variables etc.), there are allegorithmic core libraries necessary for the shader functionality and I'm not sure if those can be included and compiled in DS.

  • evilded777evilded777 Posts: 2,465

    The problem I see is that besides several adjustments to be done manually (variables etc.), there are allegorithmic core libraries necessary for the shader functionality and I'm not sure if those can be included and compiled in DS.

    Alessandro... if that was the case, they wouldn't be very portable, would they? Wouldn't that kind of defeat the purpose?

    I hope you are incorrect, sir.

    I did go ahead and create and name all the User Parameters I needed before trying to import my MDL, it didn't help.

Sign In or Register to comment.