MDL question, controlling multiple choices
![Oso3D](https://farnsworth-prod.uc.r.appspot.com/forums/uploads/userpics/964/nKUSSXH2JM34Y.jpg)
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?
Comments
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.
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.
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.
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)
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.....)
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.
I'd also be curious how perlin/flow/voronoi noise compares, thanks. ;)
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?
Ok, finally figured out Group Brick and Copy/Paste brick, and things are going smoothly. Duh.
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?
Is it working, just not editable?
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.
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.
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?
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.
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.
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.....
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.
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. ;)
This is the best I could come up with.
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?
Oh, and I just dragged and dropped from Finder (Explorer on Windows) into the Shader Mixer pane.
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.
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...
THAT did it! THANK YOU!
... 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.
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'.
Derp. I actually tried turning most of them to varying, but I either didn't refresh or ... something.
Thanks for helping this noob. ;)
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.
It's the exiting DS part that I was tripping on.