Results 1 to 3 of 3

Thread: Getting the material name from state->material without "SG"

  1. #1
    Join Date
    Jan 2013
    Posts
    2

    Default Getting the material name from state->material without "SG"

    Greetings,

    how can i get the material name from a tag without the "SG" at the end?
    I'm using Maya and when i try to get the material name string it appends "SG" (Shading Group) to the name.

    for example I've used mi_api_tag_lookup(state->material) and mi_query(), etc. what i want is it to return a string like: "mib_illum_lmabert1" but instead its returning: "mib_illum_lambert1SG" with "SG" appended, i know i can use string functions to trim it, but is there some function that returns just the material name without the "SG" ? when i pass a material as a parameter to my shader from Maya it works right, but not when accessing it from the state, any help is appreciated.

    Thanks,
    -Matt

  2. #2
    Join Date
    Dec 2004
    Location
    Marina Del Rey, California
    Posts
    4,143

    Default

    First let us clarify terminology. It seems to me that you perhaps want the material shader (in other systems often called the surface shader) rather than the material, which is actually a collection of all shaders that can apply to a material. The Maya terminology for a material is a shading group and that is where the SG comes from. The different kinds of shaders that can plug into a material besides the material shader, include the photon shader, the shadow shader, the displacement shader, etc.

    Please read the first couple of chapters of the book carefully, as it discusses these differences.

    Now, specifically, the state->material is the material not the material shader. What you are passing into your geometry parameter in Maya is most likely the material shader, not the material.

    Depending on where, what kind of shader, in what part of the rendering, there are several options for you.

    And please notice that there is a shader declaration, and then the specific shader instance. For example, the mib_illum_lambert has a shader declaration, but mib_illum_lambert1, as it might be named in Maya, is an instance of this shader declaration that is used in the scene. In other words, input parameters have been specified, and it has been put in the shader network.

    Checking out the mi_query codes in the manual can be very useful. Assuming you have Maya 2013, you can find the manual here: http://docs.autodesk.com/MENTALRAY/2...ntal-ray-help/ . Then I like to go to the Manual, click on Index, find mi_* shader API functions, click on that and then mi_query under Q.

    The miQ_MTL_* codes take a material tag as input. For mi_query codes, miQ_FUNC_* codes are for the material shader instance, whereas miQ_DECL_* codes are for the shader declaration. If you use the form, mi_query(miQ_FUNC_*, state, miNULLTAG, ...), then it will use the currently running material shader. You can query a different material shader if you have its tag with the form mi_query(miQ_FUNC_*, 0, your_material_shader_tag, ...)

    There are several ways to get what you need, depending on your shader context.

    Code:
    miTag func_tag;
    mi_query(miQ_MTL_SHADER, 0, state->material, &func_tag);
    mi_query(miQ_FUNC_TAG, state, miNULLTAG, &func_tag); //from currently running shader instance
    If you want the declaration tag, from the shader instance,

    Code:
    miTag decl_tag;
    mi_query(miQ_FUNC_DECL, 0, func_tag, &decl_tag);
    mi_query(miQ_FUNC_DECL, state, miNULLTAG, &decl_tag); //decl from currently running shader instance
    Barton Gawboy

  3. #3
    Join Date
    Jan 2013
    Posts
    2

    Default

    Thank you kindly, the "miQ_MTL_SHADER" was what i needed.
    I'll be sure to rtm more closely in the future and maybe one day I'll have a difficult question that can stump you.
    Thanks again.

Tags for this Thread

Posting Permissions

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