Results 1 to 4 of 4

Thread: Getting shadow information during surface shading.

  1. #1
    Join Date
    Oct 2011
    Posts
    3

    Default Getting shadow information during surface shading.

    Hi everyone,

    I bumped into a roadblock with my surface shader recently. What I'm trying to do is generate a matte of the shadow being cast on the surface (in a scene with maya light shaders). Essentially, I'm trying to replicate maya usebackground shader functionality in producing shadow mattes.

    Problem is, I don't know how I can get any shadowing information reliably. I tried working with luminance of light color returned by mi_sample_light, but, if a light was textured, dark areas of the texture would get falsely interpreted as a shadow. Trying a probe ray to determine occlusion isn't the way out either because maya lights can produce fake soft shadows, that a probe ray can detect.

    So I'm really trying to know if there's any reliable way I can find out if a sample is being shadowed. And owing to the complications of my setup, I can't just use the usebackground shader directly .

    Any hints/assistance is much appreciated!

  2. #2
    Join Date
    Feb 2010
    Posts
    9

    Default

    You can call mi_trace_shadow(result, state->child) again in your material shader to get the filter value and use it directly or apply the filter to the light color result.

  3. #3
    Join Date
    Aug 2005
    Posts
    169

    Default

    DLLEXPORT miBoolean mat_shadow(miColor *result,
    miState *state,
    mat_shadow_p *params)
    {
    miTag *light; // tag of light instance
    int n_l; // number of light sources
    int i_l; // offset of light sources
    int m; // light mode: 0=all, 1=incl, 2=excl
    int n; // light counter
    int samples; // # of samples taken
    miColor color; // color from light source
    miColor sum; // summed sample colors
    miVector dir; // direction towards light
    miScalar dot_nl; // dot prod of normal and dir
    miVector oldNormals;
    int numLights; // the number of lights affecting this point
    // (does not include spotlights if the point
    // is not in their cone)

    // check for illegal calls
    if (state->type == miRAY_SHADOW || state->type == miRAY_DISPLACE ) {
    return(miFALSE);
    }

    m = *mi_eval_integer(&params->mode);

    n_l = *mi_eval_integer(&params->n_light);
    i_l = *mi_eval_integer(&params->i_light);
    light = mi_eval_tag(params->light) + i_l;

    if (m == 1) // modify light list (inclusive mode)
    mi_inclusive_lightlist(&n_l, &light, state);
    else if (m == 2) // modify light list (exclusive mode)
    mi_exclusive_lightlist(&n_l, &light, state);


    // Temporarily clear normal so that points which face away from
    // the light will not be discarded from the shadow pass
    oldNormals = state->normal;
    state->normal.x = 0;
    state->normal.y = 0;
    state->normal.z = 0;

    numLights = 0;

    // Loop over all light sources
    for (n=0; n < n_l; n++, light++) {
    sum.r = sum.g = sum.b = 0;
    samples = 0;

    // Initialize dir
    dir.x = NO_LIGHT_DIRECTION;
    dir.y = NO_LIGHT_DIRECTION;
    dir.z = NO_LIGHT_DIRECTION;

    while (mi_sample_light(&color, &dir, &dot_nl, state,
    *light, &samples))
    {
    sum.r += color.r;
    sum.g += color.g;
    sum.b += color.b;
    }

    // Only consider lights which have a valid direction and have been
    // sampled at least once (the direction test throws out points that
    // are outside the cone of a spotlight)
    if(!(dir.x == NO_LIGHT_DIRECTION
    && dir.y == NO_LIGHT_DIRECTION
    && dir.z == NO_LIGHT_DIRECTION) && samples)
    {
    result->r += sum.r / samples;
    result->g += sum.g / samples;
    result->b += sum.b / samples;
    numLights++;
    }

    }

    state->normal = oldNormals;

    result->a = 1 - ((result->r + result->g + result->b) / numLights) / 3;
    result->r = 1 - result->r / numLights;
    result->g = 1 - result->g / numLights;
    result->b = 1 - result->b / numLights;

    return(miTRUE);
    }

  4. #4
    Join Date
    Feb 2010
    Posts
    9

    Default

    @1armedScissor
    I guesss this is the normal shadow shader. It won't work for pentio's case, because if the light has a texture filter on the color or indensity and if at one spot it is black , this shader will consider it to be in the 'shadow'. The 'shadow' concept here in pentio's case is if the spot being rendered is blocked by some objects from the light. And I guess the only way you can do it is to trace the shadow ray again yourself to see if it hits any object. I might be wrong.

Posting Permissions

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