Jump to content

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?


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()?



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

bounces(float ior = 1.46;
        int raylength = 0;
        export float last = 0)
    if (raylength)
        last = length(I);
        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;




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