after the fix (,and thank you Brecht for it!!) we can now retrieve globals from trace function.
//BE CAREFULL! for blender versions without this fix, it will crash when render//
So I’ve created this script, which hides the surface whenever the incoming ray is already coming from any object with the same material Id and also shows the surface on the exiting point of the ray.
It can be helpfull with Glass, Translucent and Transparent.
Unfortunatly it doesn’t work for SSS, but it’s a start!
without the script:
with the script:
/*
* HideInternal.osl by Miguel Porces (2014)
* (a.k.a. Secrop)
*
*
* Checks if the P is already inside an object with the same material ID,
* And if so, outputs Transparent()
*
*/
surface HideInternal
(
closure color Closure1 = 0,
output closure color Closure = 0
)
{
normal n = N;
float exteriorSurf=0.0;
float myMaterialIndex=0.0;
float hitMaterialIndex=0.0;
float hitFace=0.0;
vector VectorTrace = vector ( 0.0 , 0.0 , 0.0 );
int Hit=0;
getattribute("material:index", myMaterialIndex);
if (backfacing()) {
VectorTrace-=I;
}
else {
VectorTrace+=I;
}
int DoTrace = trace (P, VectorTrace) ;
if (DoTrace) {
int HitTrace = getmessage ("trace", "hit" , Hit ) ;
if(Hit!=0){
HitTrace = getmessage ("trace", "material:index" , hitMaterialIndex ) ;
HitTrace = getmessage ("trace", "backfacing" , hitFace ) ;
}
exteriorSurf=(myMaterialIndex==hitMaterialIndex)+hitFace;
}
if (!exteriorSurf==0){
Closure = transparent();
} else {
Closure = Closure1;
}
}
To use it just plug the original closure in.
Attachments
HideInternal.zip (605 Bytes)