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.

I tried to use that script in Blender version 2.8, but as soon as I wanted to run it a error came up. Now I don#t understnad the problem and would like to get help.

Is this the error: shader.osl:6: error: 'lt' was not declared in this scope ?
If so, it’s now fixed here in the thread. It seems it was some error in BA, that encoded the ‘<’ sign into ‘<’.

You’re not suppose to ‘Run Script’ an OSL Script as if it’s a Python Script!

Instead, in the “Script Node” (node editor), right next to the name of your script, there’s a button (two curved arrows) that will update/compile your shader.
Also, OSL errors will be only printed in the System Console, so you might want to have that opened.

That you very much. Now it worked :slight_smile:
But is there also a way to smooth that edge out?

It requires a slightly different algorithm.
For example, instead exiting the loop when Hit==1, you need to loop over all samples and store Fac = Min(getmessage(‘trace’, ‘distance’), Fac); or something similar.

Hi, I revive this old thread as i’m working on a similar thing
really interesting code, thanks for sharing !
I have a quick question, how would you do to make it work with a flat surface ? in my case, the FAC, goes inside
the scene is just a cube and an plane intersecting and I hope to have a gradient around the cube/plane intersection
My goal is to use it as a mask

thanks