MDL question, controlling multiple choices

For something I'm working on, ideally I'd want the user to select from one of several choices, and then pass that on to a function (brick) to pipe other information.

So, for example, If/Then/Else lets me toggle between using one input vs. another. I WANT to be able to toggle between 3+ inputs.

 

Is this doable, and, if so, what the heck is the brick named?

 

«1

Comments

  • ErdehelErdehel Posts: 386

    Curious to see if someone will come up with an answer that doesn't involve scripting. I think it can't be done without a script because it needs User input when prompted. Bricks are not meant to do that.

  • jag11jag11 Posts: 885
    edited April 2016

    This lands on MDL scripting territory, you can design your own brick with the required set of inputs. Just wrap your control statement inside a function and that's it.

     

    export color yourCustomWhareverYouWantItNamedSuperCoolFunctionBrick( int height, int val1, int val2, int val3 ) {...}

     

    Section 11.2 (branches) on the MDL language specification explains the if and switch control statements. It is a good reading even for people using bricks.

    Post edited by jag11 on
  • Oso3DOso3D Posts: 15,041

    Thank you!

    Erdehel: I was thinking more along the lines of 'set input variable to whole integer between 0 and N.'

    Specifically, I'm trying to do my 'perlin noise shader' in a more complete fashion, and I'd like to be able to do something like:

    Displacement Noise set 0-4.

    0: no noise

    1: Noise settings 1

    2: Noise settings 1, reverse channels

    3: Noise settings 2

    4: Noise settings 2, reverse channels

     

    And maybe even '5, multiply settings 1&2' and so on, but I doubt I'll go that far. (I'm not even sure I'll take the steps 3 and 4, but Noise and Reverse Noise would be extremely useful)

     

  • hphoenixhphoenix Posts: 1,335

    Will,

    You can do this with the existing shader bricks.  There are bricks for comparisons and you can define constant value bricks as well.  Then you just have it pass the input based on those.  

    I have this laid out for one of my shaders currently (to select between perlin, flow, voronoi, and imagemap noise).  When I get home this evening I'll post a screenshot of the bricks that handle this (assuming no-one else does in the meantime, as I just got to work a couple of hours ago.....)

     

  • hphoenixhphoenix Posts: 1,335
    Erdehel said:

    Curious to see if someone will come up with an answer that doesn't involve scripting. I think it can't be done without a script because it needs User input when prompted. Bricks are not meant to do that.

    It can be done.  The primary input is a user input of an enum type (and yes, you can define the enum.)  Then it's simply a set of blocks that compare it's value and pass along the values correctly.  See my prior post....I'll post an example this evening if nobody else has.

     

  • Oso3DOso3D Posts: 15,041

    I'd also be curious how perlin/flow/voronoi noise compares, thanks. ;)

     

  • Oso3DOso3D Posts: 15,041
    edited April 2016

    Is there a default switch brick?

    The problem is that while I CAN build the logic out of bricks (2 if else bricks, two evaluator bricks), there are 20+ channels I want to hook up, and that's setting up 80 bricks. ugh

    As for making my own custom brick, I could try that, but I'm diving into syntax blind... ;)

    Is there a way to construct a brick out of other bricks and 'wrap' it, copy/paste it a bunch?

     

    Post edited by Oso3D on
  • Oso3DOso3D Posts: 15,041

    Ok, finally figured out Group Brick and Copy/Paste brick, and things are going smoothly. Duh.

     

  • Oso3DOso3D Posts: 15,041

    Reviving this... is there something broken with custom MDL bricks? I cannot for the life of me edit a custom MDL brick. At all.

    I can't add user parameters, for example, but I think I'm supposed to be able to... what the heck?

     

  • Richard HaseltineRichard Haseltine Posts: 102,437

    Is it working, just not editable?

  • Oso3DOso3D Posts: 15,041

    If I create a custom MDL brick, it appears with it's default code.

    I cannot add user parameters.

    I can edit the code, but when I hit 'accept' it reverts to the default code.

    I can add user parameters to the User Parameters brick, and occasionally I hit a brick where I can add user parameters, but the vast majority don't allow me to -- since I don't know what the intended behavior of all those other bricks are supposed to be, I have no idea if I'm unable to do something I'm supposed to be able to do.

     

  • Oso3DOso3D Posts: 15,041

    Like, it's taken me a few weeks to realize that's why I'm unable to do any of the stuff people are discussing. I can't DO the stuff people are talking about.

     

  • Richard HaseltineRichard Haseltine Posts: 102,437

    What happens if you hold down alt(Win)/opt(Mac) and drag the mdl file (from a folder set as an MDL Directory) into the Shader Mixer?

  • Oso3DOso3D Posts: 15,041

    Same thing. No ability to add user parameters, no ability to change the code within Shader Mixer.

    Presumably I could write all the scripts offline or something (not sure how?), but then there's still the issue of being unable to add user parameters.

     

  • Oso3DOso3D Posts: 15,041

    Can anyone else do this? I'm wondering if people just haven't been tinkering with MDL in latest Studio or whether there's something odd here.

     

  • hphoenixhphoenix Posts: 1,335

    Are you properly listing out the exported parameters?  As I recall the .MDL needs these (look at the existing Iray example shader files included with DS) to get the parameters set up properly in Mixer.....

     

  • Oso3DOso3D Posts: 15,041
    edited May 2016

    I can't add user parameters first? Can someone give me a sample code that should work?

    (I tried creating a Switch code, but it reverted to the default when I tried to get it to accept it)

    It's frustrating the pee out of me that the IfThenElse for RSL has the ability to add extra values, but it won't work to pass through MDL outputs, and the MDL IfThenElse won't allow extra values. And there's no Switch brick.

    Post edited by Oso3D on
  • Oso3DOso3D Posts: 15,041

    I managed to create a custom brick that does what I want from grouped if/then and other bricks. Ugly, but I guess it works. ;)

     

  • EsemwyEsemwy Posts: 578

    This is the best I could come up with.

    mdl 1.1;using df import *;using state import *;using base import *;using tex import *;using math import *;export color ifelse (    uniform int selection = 0,    uniform color tint0 = color(0.),    uniform color tint1 = color(0.),    uniform color tint2 = color(0.),    uniform color tint3 = color(0.)) {    color tint = color(0.,0.,0.);        switch (selection) {     case 0:        tint = tint0;        break;    case 1:        tint = tint1;        break;    case 2:        tint = tint2;        break;    case 3:        tint = tint3;        break;    default:        tint = color(0.,0.,0.);        break;    }        return tint;}

     

  • Oso3DOso3D Posts: 15,041

    Ok, something is definitely wrong, then, because I copy/paste that into the custom MDL callable, and ... it doesn't accept it and reverts back to 'state::position()'

     

  • EsemwyEsemwy Posts: 578

    Ok, something is definitely wrong, then, because I copy/paste that into the custom MDL callable, and ... it doesn't accept it and reverts back to 'state::position()'

     

    It loads for me as a standalone brick. Is the directory where you place the file setup as an MDL directory?

  • EsemwyEsemwy Posts: 578

    Ok, something is definitely wrong, then, because I copy/paste that into the custom MDL callable, and ... it doesn't accept it and reverts back to 'state::position()'

     

    Oh, and I just dragged and dropped from Finder (Explorer on Windows) into the Shader Mixer pane. 

  • Oso3DOso3D Posts: 15,041

    What I'm doing: dragging/double-clicking/alt-dragging 'MDL > Custom MDL' from the Brickyard into Shader Mixer.

    I then click the '...' for the MDL Callable and paste in the code snippets people have suggested. I hit accept.

    It then shows... the same default as when I had initially dragged/double-clicked/alt-dragged.

     

  • mjc1016mjc1016 Posts: 15,001

    Open a text editor, copy the code Esemwy posted and save it as <something>.mdl into a folder mapped as an mdl directory.  Then drag and drop into Shader Mixer...

     

  • Oso3DOso3D Posts: 15,041

    THAT did it! THANK YOU!

     

  • Oso3DOso3D Posts: 15,041

    ... But the color output of perlin noise can't plug into the color input of the switch.

     

    My wife often wonders why I don't go into coding because I seem to have an 'aptitude' for it. Yeah. This is why. So screamingly frustrating.

     

  • hphoenixhphoenix Posts: 1,335
    edited May 2016

    ... But the color output of perlin noise can't plug into the color input of the switch.

     

    I think that's because the MDL listing above is using a 'uniform' tag, instead of a 'varying' tag.  Perlin (and other noise) functions vary across the surface, so they can't be considered 'uniform'.

    Try it by altering the inputs to the shader definition to be 'varying' instead of 'uniform'.

    Post edited by hphoenix on
  • Oso3DOso3D Posts: 15,041

    Derp. I actually tried turning most of them to varying, but I either didn't refresh or ... something.

    Thanks for helping this noob. ;)

     

  • EsemwyEsemwy Posts: 578
    edited May 2016

    ... But the color output of perlin noise can't plug into the color input of the switch.

     

    My wife often wonders why I don't go into coding because I seem to have an 'aptitude' for it. Yeah. This is why. So screamingly frustrating.

    Found it! The parameters do need to be varying rather than uniform. And you have to exit DS before it will discover the new parameter settings.

    mdl 1.1;using df import *;using state import *;using base import *;using tex import *;using math import *;export color ifelse (    varying int selection = 0,    varying color tint0 = color(0.),    varying color tint1 = color(0.),    varying color tint2 = color(0.),    varying color tint3 = color(0.)) {    color tint = color(0.,0.,0.);        switch (selection) {     case 0:        tint = tint0;        break;    case 1:        tint = tint1;        break;    case 2:        tint = tint2;        break;    case 3:        tint = tint3;        break;    default:        tint = color(0.,0.,0.);        break;    }        return tint;}

    Post edited by Esemwy on
  • Oso3DOso3D Posts: 15,041

    It's the exiting DS part that I was tripping on.

     

Sign In or Register to comment.