Jump to content
mightcouldb1

Total refraction bounces as surface color

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

Share this post


Link to post
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!

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×