Generate a material change at mesh intersection

Can I make a material or texture change to show an intersection between meshes? Or would I have to use NPR? I though perhaps a very tight AO type effect.

Thank you. I was trying to draw an outline on the surface of an object as another one passes through it

is the surface a single plane? that could simplify alot…

can you elaborate ?
do you mean showing edges
or one mat per faces group ?

happy bl

As i slide one mesh into another i wanted the oblique edge to appear on the other receiving mesh. I should not be avle to see the first mesh. I was hoping to draw outline shapes and rings on the surface of a sphere dynamicaly.

made a small OSL script… Since it is a sphere, the script will only sample directions tangential to the sphere surface…

Try it, and tell us if is enough… Some modifications can still be made. :wink:

shader ShadeNearGeom(int Samples = 8, float Radius=0.01, output float Fac = 0.0){
    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(P, initp, "maxdist", Radius)) {
            Fac=1;
            break;
            }
        else {
        rotate( initp, angle, P, P+N);       
        }
    }
}

“…to draw outline shapes and rings on the surface of a sphere dynamically” sounds like Dynamic Paint could be used.

@Eppo. Oh sorry, I wasn’t clear as I was typing on my phone. I don’t want the image to persist (as in Dynamic Paint). It should only last as long as there is an intersection. I toyed with trying to illuminate the surface of the receiver by having a short through emission material on the projecting mesh.

Thanks @Secrop but I get a syntax error on run. I have OSL active in scene properties.

EDIT: Ok I haven’t used uncompiled OSL scripts before, so now I know that I have to add a script node in my material window. Then select the text block to run.

It works really great! Thank you so much.

For some reason after I make my intersecting object transparent I still see a shadow from it falling on the receiving surface. Why would that be?


The OSL works great but I notice that it gets thin at some angles. Could I control the size of the line that is drawn?

Heres the effect:

[ATTACH=CONFIG]420168[/ATTACH]

ohhh… sorry!! I made a mistake in the code… I was rotating the sample direction, but forgot to set the new direction of the next sample… (it was only sampling in the X axis! :o)

shader ShadeNearGeom(int Samples = 8, float Radius=0.01, output float Fac = 0.0)
{
    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(P, initp, "maxdist", Radius)) {
            Fac=1;
            break;
            }
        initp=rotate( initp, angle, P, P+N);
    }
}

Higher samples will give you a better shape (also, it works better with high resolution meshes), and the radius defines the line width.

Hope it helps now. :wink:

edit: about the shadow… check if the transparent shader has a pure white color.

Yeah the shadow seems to be a bug, I checked the material colour first but shadow remained. Then I changed the scene Seed to “auto change” and the shadow went away. The bug tracker has a report but it seems notoriously hard to pin down.

Oh and I just noticed that the variable “radius” is in the actual node, silly me I was trying to alter the source code. Works great!

I’ve notice some small problems using OSL and Dynamic BHV (at least in my machine)… But changing to Static BHV solves most of them.