OSL script node : detect if two object collides and output a bool I would like to have a script node that would output a boolean depending of if two objects are intersecting or not.

The goals is to use it in a mix shader and to hide / show my object depending of the intersection (kind of a mask).



The available inputs of my script node should be two objects ("active" object and "mask" object); and the output should be a boolean (0 or 1) for the FAC of a mix shader.

After having read this, I think it is possible, but don't know Blender scripting good enough yet to achieve it.


https://blenderartists.org/forum/showthread.php?390733-Generate-a-material-change-at-mesh-intersection
https://blender.stackexchange.com/a/9080/14306


Can anyone help ?

Thanks !
I've been working on something that goes somewhere towards answering your problem.. don't take it too seriously, I'm only getting used to some of the quirks of OSL in Blender/Cycles: some of these conditionals may look unnecessary, but for example, if I don't use the 'hit' local variable, it won't work, even though I don't need to.

#include "stdosl.h"

shader Dipper(
    string Container = "",
    output int IsInside = 0
)

{      
    if  ( raytype("refraction") != 1 ) IsInside = 0;
    else{

        int ray_depth;
        getattribute("path:ray_depth", ray_depth);

        if  ( ray_depth % 2  != 0){

            string source_name;
            int hit;
            hit = trace (P,I);
            getmessage ("trace", "geom:name", source_name);

            if (hit==1){
                if (source_name == Container ){ 
                    IsInside =1;
                }
            }
        }
    }   
}




You enter the name of your container object in the 'Container' input,(unquoted).



I'm also pretty sure you could make the logic of this shader fail, without too much effort.