Results 1 to 3 of 3

Thread: SELECTING From a MATERIAL ARRAY SWITCH

  1. #1
    Join Date
    Aug 2016
    Posts
    23

    Cool SELECTING From a MATERIAL ARRAY SWITCH



    HI FRIENDS !

    We Got this Code Here That we Use Alot for Switching Betwen a Array of Colors ...

    BUT Can We Have a Example how to Make it "properly" for Switching betwen a Array of MATERIALS And Bsdfs And Other Surface Properties ? !

    And Can We Have a Option for Dynamic Specify The Number of How Many Materials we can Switch .

    With a Enumeration Drop Down With the Material Name For Selector !

    THANKS SO MUCH !



    PS: Is there a Way to Hide From Interface Complete Material Branches Properties
    That Currently are Not Selected and Not Used ?

    Code:
    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;
    }

    Ps: This SHould be Obvious ... But i Can Only do it with a Nested Booleans Conditions ...

    Code:
    material switch_material( uniform bool condition,
    material m1,
    material m2)
    = condition ? m1 : m2;
    I tried Doing Achaic Nested Bolean conditions Like
    If less than 5 biger than 3 Then 4, if Less then 4 bigger than 2 then 3

    Code:
    if (x < 2)
      count1++;
    else if (x >= 2 && x < 5 )
      count2++;
    else if (x >= 5 && x < 7 )
      count3++;
    else
      count4++;
    But even That Simple Thing In MDL Code Ended up in a BIG MESS !

    I Dont know whats happening with my Code Skills or Even Mathematics xD


    THANKS SO MUCH FOR THE SUPPORT !








    ...
    Last edited by SOULSSAGA; July 2nd, 2017 at 16:59.

  2. #2
    Join Date
    Jan 2007
    Posts
    314

    Default

    somehow overlooked this, sorry for that!

    the problem is that on the material level there is no control flow. switch and if are statements that control the flow of execution. "?" is just an operator. While ? and if to pretty much the same at the first glance, they are pretty different from a language perspective. control flow we only allow inside functions but not inside the material in order to make it easier for a renderer to analyze the material and be efficient. So you will need to stick with "?" even though it can become complicated and you will also need to know the number of materials in advance.


    As for hiding parameters in the UI: MDL uses annotations to tell an integration about UI related things. disabling and enabling parameters based on conditions is not among the default set of annotations. But applications can define their own annotations. Iray for maya for example understands an annotation
    export annotation visibleIf(string attribute, string expression);
    defined in ifm.mdl. Since a few integrations decided to define such annotations we are working on defining a standard way to define such behavior.

  3. #3
    Join Date
    Aug 2016
    Posts
    23

    Default

    ...


    DEAR JAN JORDAN !

    Thank you so much for your Deep Explanation and examples.

    I think i Got All this to work now !

    Keep Rulling the MDL world !



    Thanks so much for everything !


    3DD SOULS STUDIO
    www.3DD.us
    SOULSSHINE.deviantart.com

Posting Permissions

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