Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Expression Node

  1. #1
    Join Date
    Aug 2008
    Location
    Ravenna, Ohio, United States
    Posts
    125

    Default Expression Node

    Okay, I am really stuck on this one, I am trying to figure out how to write a shader in MSL that has two color inputs, and a character string that would perform a calculation on the two color inputs, such if the user typed a + sign, or has to type A + B in the string, the two colors would be added together. This way I don't need a switch statement that has to store multiple calculations. If anyone knows how to do this, please, please let me know.

  2. #2
    Join Date
    Jun 2007
    Location
    Berlin
    Posts
    447

    Default

    Hi Ian,

    the interpreatation of strings is something that is a bigger mess than doing it with the good old switch statement.
    That's why the switch-case statement is part of many programming languages whereas strings are usually specialized classes that may offer easier usage at the drawback of lower performance.

    My recommendation to stick to the good old switch case. -> you can use an enumerator for the operation which gives you a nice dropdown in mental mill.

    Cheers,
    Ruediger

  3. #3
    Join Date
    Aug 2008
    Location
    Ravenna, Ohio, United States
    Posts
    125

    Default

    Hey, thanks for replying, the switch case is great but, all the possible choices from the switch are exported into whatever file is chosen from mental mill. Is there a way of having the selected result from the integer that the switch statement is using, be the only result that is exported, instead of the whole switch statement?

    An example of this would be to a switch statement that at 0, adds, at 1 subtracts, at 2 multiplies, and 3 divides two color inputs, but say when 2 is selected in mental mill, all that is exported in say, an fx file is color 1 * color 2, instead of all the if and then else statements it takes to create that whole switch statement.In other words, you would be making a final decision on the result that is exported. I would think that having this would be better for performance, and I would definitely incorporate this in all my shaders. Hopefully you understand what I'm talking about.

  4. #4
    Join Date
    Aug 2008
    Location
    Ravenna, Ohio, United States
    Posts
    125

    Default

    Does anyone know how to do this? I don't mean to be impatient and sorry if this is a dumb question, as I said before I'm still learning msl and I'd like to make msl shaders that are efficient as can be, where they are exported out of mental mill. BTW the enumeration you suggested works great, the shader I'm currently working on, that I used it for, is a shader that has all the blend modes, screen, overlay, etc with those in a switch statement.

  5. #5
    Join Date
    Jan 2007
    Location
    Berlin
    Posts
    5

    Default

    Hi Ian,

    in brief: No, MetaSL can't do that (yet). If I understand you correctly, you want the code generated
    from a shader _instance_ to differ depending on the shaders instance parameters. This is currently
    not the case, all shader instances will share the same code from the shader's definition. If an application
    is compiling shader instances instead of shader definitions, there is indeed some opportunity for
    optimization by taking the instance parameters into account. We are actually planning this for
    a future release. However, the power of these anlyses and subsequent optimizations is limited
    (both in theory and in practice), and it is unlikely that it would catch the particualr case you are
    mentioning. Passing an integer that controls a switch would be much more likely to achieve the
    result you want: If the controling expression of the switch is a compile-time constant, the whole
    switch can potentially be optimized away.

    Regards,
    Robert

  6. #6
    Join Date
    Aug 2008
    Location
    Ravenna, Ohio, United States
    Posts
    125

    Default

    Hey, thanks for replying. But yeah pretty much I've been trying to figure out a way to have "controls" in a shader that are only used and calculated in mental mill. So for example, having a shader which turns from red to blue with a Boolean, when exported to an fx file it only lists red or blue in the code, and not an if then statement. If you are saying that, currently this is not possible, then the best you could have, in terms of performance, would be to have 2 outputs in the shader, red or blue. But in cases of very complicated shaders, this wouldn't be practical, since then, the combination of outputs could lead to very large numbers. But if these options will be available in the future, then that would be great Also another feature that would be essential to creating efficient shaders is having techniques. Are techniques available in MetaSL? If they are, then could you post a simple example of an msl file with 2 techniques please? Thanks for your time.

  7. #7
    Join Date
    Jan 2007
    Location
    Berlin
    Posts
    5

    Default

    Hi Ian,

    thinking about it, there is a mechanism in MetaSL that allows different code to be
    generated: The preprocessor. Having said that, there is currently no GUI in the
    mill to set defines from outside of a shader.

    Regarding techniques: We have them in the spec, but no renderer (including mill)
    supports a mechanism for selecting a technique yet.

    Regards,
    Robert

  8. #8
    Join Date
    Aug 2008
    Location
    Ravenna, Ohio, United States
    Posts
    125

    Default

    So, you're saying that having GUI controls that control what is exported out of a shader isn't possible from metasl?

    As far as techniques, I was talking about having an msl shader that has multiple techniques contained within it, that can be exported to an fx file where I can later choose the different techniques inside 3dsmax or maya. There was some metasl documentation about techniques, but as I said, I'm still learning metasl. This would be a lot easier than having to export separate shaders and combine them in the fx file, and make sure that there are no duplicate declarations and UI controls. Most of my shaders that I want to recreate from Shader FX, have several techniques, where one the first technique is the complete shader, the second only has normal and specular shading , the third has only specular, etc. So yeah I really hope there is a way of eexporting multiple techniques from metsl shaders, if not hopefully this feature will be added soon in mental mill, maybe like creating techniques from selected phenomenons.

  9. #9
    Join Date
    Jan 2007
    Location
    Berlin
    Posts
    5

    Default

    Yes, more precisely it is a limitation of the applications, not MetaSL.

    Regards,
    Robert

  10. #10
    Join Date
    Aug 2008
    Location
    Ravenna, Ohio, United States
    Posts
    125

    Default

    Ok, then if neither are possible right now, will we maybe see either of these features in the next release?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •