Jump to content

How to calculate a distance?


hoknamahn

Recommended Posts

Hi guys!

Imagine what we have some object... Maybe sphere or cube. I want to calculate  a thickness of this object in the surface shader. I mean to calculate a distance from one side of object to other side along view vector. How can i do this?

If you want to do this for an arbitrarily-shaped object, then you might want to enlist the ray tracer for some help. Something like this:

#pragma hint alongN  toggle

surface RTDepth(
      int    alongN = 0;      // ON: trace along -N; OFF: trace along I
      float  dmax   = 1e+6;   // max length of intersection test
      float  rbias  = 0.005;  // ray bias to avoid self-intersections
   )
{
   string oname = getobjectname();
   vector D     = alongN ? normalize(-frontface(N,I)) : normalize(I);
   float  dhit  = rayhittest(P,D*dmax,rbias,"scope",oname);

   // Final coloring to show missed rays ...
   // -- look at the red and green channels separately --
   Cf = dhit<0. ? {0,30,0} : set(dhit,0,0);
}

This will show you depth in the red channel and missed hits (boosted X30) in the green.

Two things to note here. First, it works :P And second, it doesn't work as well as you might think :( (try it on a NURBs torus with everything at default... lots of "stars" over in the green channel).

I've tried doing my own super-sampling over the patch to get rid of the ray misses but, alas, to no avail -- I don't think it has anything to do with sampling density (well...past a certain minimum threshold, that is), and everything to do with micropolys, patch boundaries, dicing, etc.

So.... what to do... the only remedy I've found so far is to turn off micropoly rendering, up the "Ray Tracing Level of Detail" to at least 2, and set "Super Sample" to a minimum of 4X4.... but your mileage may vary since we're heading squarely into "voodoo" land at that point ;)

Cheers!

-- Mario.

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...