Results 1 to 4 of 4

Thread: From shadow ray to object material

  1. #1
    Join Date
    Aug 2013
    Posts
    42

    Question From shadow ray to object material

    In a shadow shader I would like to find out the material tag of the object hit by the shadow ray.

    state->material seems to give me the shadow shader itself, but that's not what I want.
    I want the surface material assigned to the object, the shadow ray hit.

    What's the best way to get to this?

    Andreas

  2. #2

    Default

    Hi Andreas,

    the surface shader is set in miMaterial::shader, so you could access it with the following code (it works for simple materials,
    not material phenomena)
    miMaterial * mtl = (miMaterial*)mi_db_access(state->material);
    shader used for surface hit: mtl->shader
    mi_db_unpin..

    If you however just want to call the surface/volume etc shaders, there is a much better method:
    simply use mi_call_material, it will call the surface shader. There are also other similar functions such as
    mi_call_shadow_material etc. More details could be found in the mental ray manual.

    Best regards,
    Gunter

    Quote Originally Posted by acb View Post
    In a shadow shader I would like to find out the material tag of the object hit by the shadow ray.

    state->material seems to give me the shadow shader itself, but that's not what I want.
    I want the surface material assigned to the object, the shadow ray hit.

    What's the best way to get to this?

    Andreas
    Last edited by gunter; February 4th, 2016 at 18:30.

  3. #3
    Join Date
    Aug 2013
    Posts
    42

    Default

    Hi Gunter,

    Thanks for your reply.

    It seems to me though that during shadow calculation (when state->type == miRAY_SHADOW) none of the surface material shader slots are defined.
    Yet I could not find any verification for this in the documentation.
    Which state attribute is available in which context seems poorly explained, if at all.
    Or perhaps I just did not find this info.

    During shadow calculation the only material slot that seems to be defined is the shadow shader slot.
    Which you can query for example via:
    mi_query( miQ_MTL_SHADOW, 0, state->material, &shaderTag );


    That slot is not the shadow shader of the object hit by the shadow ray, but rather the shadow shader which cast the ray.
    Either is not what I am looking for.


    The only, admittedly rather hacky, workaround I found is this:
    Force the user to use 'segmented' shadows, which means shadow rays travel reverse from the object hit back to the light.
    In this case state->org is actually a point on the surface hit (the surface material of which I want).
    And state->point is the origin of the shadow ray segment.

    If I then use trace_probe in the reverse direction (from state->point to state->org) I will hit the shadow receiving object.
    And luckily the trace_probe child->material is defined and available for query.


    Though I wonder if there is a better solution. There must be.
    One that works with all shadow methods and does not require an extra trace_probe...

  4. #4

    Default

    Andreas, what kind of material is used in your scene (regular material, phenomenon ?). Could you perhaps show us a short fragment of
    the material definition (even better would be an example scene) ?

    gunter

Posting Permissions

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