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

Thread: shader param's values from miQ_FUNC_PARAM in mi_sample_light

  1. #1
    Join Date
    Sep 2007
    Location
    China
    Posts
    54

    Default shader param's values from miQ_FUNC_PARAM in mi_sample_light

    Hi, everyone
    I wanna get light color from light shader parameters in mi_sample_light(), so I used the following codec:
    Code:
    mi_query( miQ_INST_ITEM,NULL,*light,&realLight);
    mi_query( miQ_LIGHT_SHADER, state, realLight, &shaderTag );
    mi_query( miQ_FUNC_PARAM, state, shaderTag, &values );     //values is what I realy need
    mi_query( miQ_FUNC_PARAM_SIZE, state, shaderTag, &paramsSize );
    mi_query( miQ_FUNC_DECL, state, shaderTag, &shaderDeclTag );
    mi_query( miQ_DECL_PARAM, state, shaderDeclTag, &params );   //params is name of parameters
    and suppose there was a maya light shader, like: "maya_directionallight", in the scene, then the values returned by miQ_FUNC_PARAM was always the value of first parameter in the params, so the value is not what I want since the first parameter was not light color.
    I have tried to receive values by using struct which is same as "maya_directionallight" struct, but failed;

    So how to get the values which be any of what I want from light shader in mi_sample_light?

    The main purpose is to calculate the diffuse pass without shadow even the shadow option is on, and then I can output the diffuse, shadow, etc passes at one time.

    Thanks!
    For all from Heav'n stark-naked came;
    But Poetry their garments gave,
    And then not one had cause for shame.

    1816. Goethe

  2. #2
    Join Date
    Sep 2007
    Location
    China
    Posts
    54

    Default Re: shader param's values from miQ_FUNC_PARAM in mi_sample_light

    Code:
    mi_query( miQ_INST_ITEM,NULL,*light,&realLight);
    mi_query( miQ_LIGHT_SHADER, state, realLight, &shaderTag );
    mi_query( miQ_FUNC_PARAM, state, shaderTag, &values );
    mi_query( miQ_FUNC_PARAM_SIZE, state, shaderTag, &paramsSize );
    mi_query( miQ_FUNC_DECL, state, shaderTag, &shaderDeclTag );
    mi_query( miQ_DECL_PARAM, state, shaderDeclTag, &params );
    char *tmp,*token;
    token= mi_mem_allocate(sizeof(char)*(strlen(params)+1));
    strcpy(token,params);
    offset=0;
    tmp = strtok(token, "\"");
    while(tmp!=NULL)
    {
        if(strcmp(tmp,"color")==0) break;
        if(strcmp(tmp,"c")==0) offset += 16;
        if(strcmp(tmp,"b")==0||strcmp(tmp,"s")==0||strcmp(tmp,"$")==0||strcmp(tmp,"i")==0||strcmp(tmp,"al")==0) offset += 4;
        if(strcmp(tmp,"v")==0) offset += 12;
        tmp = strtok(NULL,"\"");
    }
    mi_warning("Values: %f", *((miScalar*)(values+offset)) );
    mi_mem_release(token);
    ah, I got it.
    So, does this way work well? I mean, in order to get diffuse pass without shadow, is there any better way?
    For all from Heav'n stark-naked came;
    But Poetry their garments gave,
    And then not one had cause for shame.

    1816. Goethe

  3. #3
    Join Date
    Dec 2004
    Location
    Marina Del Rey, California
    Posts
    2,914

    Default Re: shader param's values from miQ_FUNC_PARAM in mi_sample_light

    Shadows are automatically controlled withing mi_trace_shadow. So the way to control them is through the options.

    This is a bit problematic for shadow passes, etc. that need to flexibly turn on and off shadows without needing to know about or change the light shader.

    The common hack to flip shadows on and off is to make a copy of options, temporarily set your shadow on or off, sample the light, and then restore the options.

    Recently, this has become a bit tricky because of the options being categorized as a const in later mr releases. I think there's an example of this somewhere in this forum. Again, I'd have to search.
    Barton Gawboy
    Training and Special Projects, NVIDIA ARC
    LAmrUG Forum Originator

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

    Default Re: shader param's values from miQ_FUNC_PARAM in mi_sample_light

    Better example of the hack, from Andy's upcoming book ...

    http://www.writingshaders.com/shader_pa ... wpass.html

    Check out how options is copied in miaux_add_light_color toward the bottom of the page.
    Barton Gawboy
    Training and Special Projects, NVIDIA ARC
    LAmrUG Forum Originator

  5. #5
    Join Date
    Sep 2007
    Location
    China
    Posts
    54

    Default Re: shader param's values from miQ_FUNC_PARAM in mi_sample_light

    Thanks bart!
    I know the way change options->shadow to get diffuse color without shadow, but I thought it couldn't work because the manaul said the options may never be changed by user. now your example shows it could work, really thanks! I really need to improve my C programming skill...
    For all from Heav'n stark-naked came;
    But Poetry their garments gave,
    And then not one had cause for shame.

    1816. Goethe

  6. #6
    Join Date
    Dec 2004
    Location
    Marina Del Rey, California
    Posts
    2,914

    Default Re: shader param's values from miQ_FUNC_PARAM in mi_sample_light

    Yeah, it's a subtle point, which is why we call it a hack. We are not really changing the options, we are changing a copy of the options that we stick in to replace the original options temporarily. So the state for this shader on this thread is changed, but it doesn't affect any other thread accessing the original options.
    Barton Gawboy
    Training and Special Projects, NVIDIA ARC
    LAmrUG Forum Originator

  7. #7
    Join Date
    Feb 2008
    Posts
    13

    Default Re: shader param's values from miQ_FUNC_PARAM in mi_sample_light

    in all the code that is posted,
    where did he actually gets the color of the light?

  8. #8
    Join Date
    Dec 2004
    Location
    Marina Del Rey, California
    Posts
    2,914

    Default Re: shader param's values from miQ_FUNC_PARAM in mi_sample_light

    The phrase color of light could mean a lot of things.
    It could mean the parameter value given to the shader definition/usage, or it could mean the result of the light shader, or the value of the color somewhere inside the light shader.

    So I went off the original statement "The main purpose is to calculate the diffuse pass without shadow even the shadow option is on, and then I can output the diffuse, shadow, etc passes at one time."

    That can be done without any light shader argument passing as suggested above.

    However, the argument passing information might be useful for others.

    As I've said, the code to get the actual argument is somewhere in this forum, though it's probably not general, as it relies on pretty shader specific naming.
    Barton Gawboy
    Training and Special Projects, NVIDIA ARC
    LAmrUG Forum Originator

  9. #9
    Join Date
    Dec 2004
    Location
    Marina Del Rey, California
    Posts
    2,914

    Default Re: shader param's values from miQ_FUNC_PARAM in mi_sample_light

    I couldn't find it on searching here, so maybe I'm recalling it from the email forum. I'll look through that. Ultimately, I'll try to post something useful.
    Barton Gawboy
    Training and Special Projects, NVIDIA ARC
    LAmrUG Forum Originator

  10. #10
    Join Date
    Feb 2008
    Posts
    13

    Default Re: shader param's values from miQ_FUNC_PARAM in mi_sample_light

    Bart thanks for the help.
    I am very close get this to work, and once I do, I'll put a document together
    to put somewhere in the forums for other people to read.

Posting Permissions

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