Generate a material change at mesh intersection

It will be a matter of tracing rays in the direction you want, and most probably filtering all traces that don’t hit the ‘plane’…
In the code above, the process of creating rays was simplified to work just with tangent rays (because the surface was a sphere)… Other shapes and effects require different methods, so you need to illustrate exactly what you’re really trying to accomplish.

my goal is to create a mask to helps create procedural foams around objects in ocean to avoid particles system on certain shots.
so far, with your code, I was able to have a little start but i guess it’s not a matter of twicking it here
my try :
image
the target is something like this, with a controled ramp around objects (same ramp for all) :
image

What about AO shader for masking?

the problem with AO is that the mask isn’t constant, it’s depends a lot of the object’s shape

If your “water” is a plane without any displacement, you might try to trace a ray slightly above the surface from P+(w*N) (for a very small w) to any tangent direction… But as soon as you add some displacement to the plane (waves), this will no longer work correctly.

here’s what it would look like: (haven’t tried it, as I don’t have blender atm)

shader ShadeNearGeom(int Samples = 8, float Radius=0.01, output float Fac = 0.0)
{
    float delta=0.0001;
    point orig= P + (delta*N);
    point initp=P+cross(vector(0.0,0.0,1.0),N);    
    float angle=2*M_PI/Samples;  
    
    for(int i = 0; i < Samples; i++){
        if(trace(orig, initp, "maxdist", Radius)) {
            Fac=1;
            break;
            }
        initp=rotate( initp, angle, orig, P+N);
    }
}

thanks for your help,
I have tried something similar, it gives almost exactly the result from my first picture in previous post, so it work only if the immerged object is in the center of the “ocean”. otherwise, it will offset the mask in ocean center direction like on my picture1 from previous post
you’re right, that doesn’t work as is with displacement, as it counsider it’s own shape in ray cast. But without that, it seems to works

What you need is a diffusion gradient, where the distance is a curve on the surface and not a direct vector… You could try DynamicPaint instead.

It’s possible to filter out trace hits and exclude the water object from the calculation, but it still a very cheap and flawed way to to something a fluid simulator is better suited.
In Arnold, you can add a ‘traceset’ parameter to the trace function, and declare that you just want hits to the objects in that set (osl specs - pag.82);
(iirc, in cycles you need to use getmessage(“trace”, “geom:name”, stringholder) after each trace, and discard hits based on the result)
And it’s also possible (thought, an heavy process to put in a shader) to create ‘walkers’ over the surface to mimic diffusion. But that is something way different from what this thread is about.

note that in surfaces mainly oriented to Z+, you should use some other way to produce the tangent vector (instead of cross(N, Z), since the result vector can be very near to nothing).

I’m on the OSL path because I don’t use blender for this (even if I render with both cycles and arnold) so I don’t have access to DynamicPaint
I will try to found an other way then, thanks for your help

Just looping back to my original issue, I have decided to use a boolean and 2 materials to replicate the intersection effect in Eevee that you can achieve in Cycles.

1 Like