Object thickness node

I’m trying to get a thickness/ray depth or anything similar for a surface shader.

What I want to do is a billboard-like object that gets transparent close to the intersection with other objects.

The closest thing I found is the volume absorption shader, but that only works with the volume output (no textures) and it also gets buggy when used on open objects like planes.

Any idea?

You can use OSL for that matter.

By tracing a ray into the scene, you can know if the ray hitted anything, and the distance of the hit point.
Check the OSL specification manual for the trace() and the getmessage() functions.

But you won’t be able to get the ‘thickness’ of that ray (‘thickness’ significa ‘espessura’, e não ‘distância’). Thought you can get the thickness of the incoming ray, by getting the dPdx and dPdy for each sample. (Note that the returned vectors are in Camera Space, and the incoming ray can come from anywhere, not just the camera)

That sounds interesting. Right now I’m wondering if is it possible to get a secondary ray (the length of a ray towards inside that object, from the hit of the first ray). That would give me the object thickness.

I’m actually in need for the object’s thickness, not the ray thickness. :slight_smile:

Then the trace() function is the right for you. It lets you trace a ray from any point to any direction, with a minimum and maximum distance. Then all you need is to get the distance by querying the message system; If that ray hits something (which you know if the trace returns 1) the distance will be stored in the the ‘trace’ message.

shader tracedist(point startpoint=P, vector direction=-I, float maxdistance=5, output float hitdistance=5)
     if (trace(startpoint, direction, "maxdistance", maxdistance))
         getmessage("trace", "hitdist", hitdistance);
        hitdistance = maxdistance;

Just remember that this may not correspond to the thickness of the object, but just the distance from the starting point to the hit point. It all depends in which direction you choose, and the mesh surface.

It would actually be what I’m expecting if the secondary ray hits something else inside the object instead of the internal back-face of the object itself. :slight_smile: If I get successful, I’ll post the result here. Thanks!