Jump to content

Total refraction bounces as surface color


mightcouldb1

Recommended Posts

Hey guys,

I understand the refract function returns a refraction vector.  The refractlight function returns a color.  I would like to store the number of refraction bounces as the final surface color, or perhaps the length the ray traveled.  Can anyone help me understand how this works for multiple bounces?

Best,
Jason

Link to comment
Share on other sites

Awesome thanks for that!  Can anyone post a snippet of code for multiple bounce refraction?  Say I had an complex surface that had multiple refractions and I wanted to know the distance that the 6th ray bounce traveled.  I'm assuming I would have to handle this with the rayhittest()?

 

Thanks!

Link to comment
Share on other sites

There is simple shader.

By default it shows the number of bounces of last hit. Toggle raylength on to show length of the last ray.

Play with refract limit to get desired level.

#pragma hint last invisible
#pragma hint raylength toggle

surface
bounces(float ior = 1.46;
        int raylength = 0;
        export float last = 0)
{
    if (raylength)
        last = length(I);
    else
        last = getraylevel();


    vector ni = normalize(I);
    vector nn = normalize(N);
    vector tdir = refract(ni, nn, 1./ior);

    Cf = 0;
    float imported;
    if (trace(P, tdir, Time,
              "samplefilter", "closest",
              "last", imported))
        last = imported;

    Cf = last;
}

post-5934-0-86300400-1416304488_thumb.jp

bounce_test1.hiplc

post-5934-0-25975300-1416304853_thumb.jp

Edited by rsd
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...