Skip to main content
Tweeted twitter.com/StackBlender/status/1458585306748366853

In the OSL spec, there is a an optional parameter in a trace call for a 'traceset'.

I would like to restrict a trace to only hit the same object. The solution I have right now is to get the object name and test the trace object name after it hits like this:

// start OSL code fragment string thisobjname = ""; getattribute("geom:name",thisobjname); int hit = trace(P, ((_var_42 - 0.5) * 2.0), ); string hitobjname = ""; getmessage("trace","geom:name",hitobjname); if( hit && hitobjname==thisobjname) printf("trace hit the same object"); // end OSL code fragment
// start OSL code fragment
string thisobjname = "";
getattribute("geom:name",thisobjname);
int hit = trace(P, 
           ((_var_42 - 0.5) * 2.0), 
           );
string hitobjname = "";
getmessage("trace","geom:name",hitobjname);
if( hit && hitobjname==thisobjname)
           printf("trace hit the same object");
// end OSL code fragment

I tried the following, but it does not work.

// start OSL code fragment string thisobjname = ""; getattribute("geom:name",thisobjname); int hit = trace(P, ((_var_42 - 0.5) * 2.0), "traceset", thisobjname ); string hitobjname = ""; getmessage("trace","geom:name",hitobjname); if( hit) printf("trace hit the same object"); // end OSL code fragment
// start OSL code fragment
string thisobjname = "";
getattribute("geom:name",thisobjname);
int hit = trace(P, 
           ((_var_42 - 0.5) * 2.0), 
           "traceset", thisobjname
           );
string hitobjname = "";
getmessage("trace","geom:name",hitobjname);
if( hit)
           printf("trace hit the same object");
// end OSL code fragment

How does the 'traceset' need to be formatted to work? Is there something else wrong?

In the OSL spec, there is a an optional parameter in a trace call for a 'traceset'.

I would like to restrict a trace to only hit the same object. The solution I have right now is to get the object name and test the trace object name after it hits like this:

// start OSL code fragment string thisobjname = ""; getattribute("geom:name",thisobjname); int hit = trace(P, ((_var_42 - 0.5) * 2.0), ); string hitobjname = ""; getmessage("trace","geom:name",hitobjname); if( hit && hitobjname==thisobjname) printf("trace hit the same object"); // end OSL code fragment

I tried the following, but it does not work.

// start OSL code fragment string thisobjname = ""; getattribute("geom:name",thisobjname); int hit = trace(P, ((_var_42 - 0.5) * 2.0), "traceset", thisobjname ); string hitobjname = ""; getmessage("trace","geom:name",hitobjname); if( hit) printf("trace hit the same object"); // end OSL code fragment

How does the 'traceset' need to be formatted to work? Is there something else wrong?

In the OSL spec, there is a an optional parameter in a trace call for a 'traceset'.

I would like to restrict a trace to only hit the same object. The solution I have right now is to get the object name and test the trace object name after it hits like this:

// start OSL code fragment
string thisobjname = "";
getattribute("geom:name",thisobjname);
int hit = trace(P, 
           ((_var_42 - 0.5) * 2.0), 
           );
string hitobjname = "";
getmessage("trace","geom:name",hitobjname);
if( hit && hitobjname==thisobjname)
           printf("trace hit the same object");
// end OSL code fragment

I tried the following, but it does not work.

// start OSL code fragment
string thisobjname = "";
getattribute("geom:name",thisobjname);
int hit = trace(P, 
           ((_var_42 - 0.5) * 2.0), 
           "traceset", thisobjname
           );
string hitobjname = "";
getmessage("trace","geom:name",hitobjname);
if( hit)
           printf("trace hit the same object");
// end OSL code fragment

How does the 'traceset' need to be formatted to work? Is there something else wrong?

Source Link
Ed Tate
  • 5.2k
  • 1
  • 31
  • 54

How to specify a traceset in OSL

In the OSL spec, there is a an optional parameter in a trace call for a 'traceset'.

I would like to restrict a trace to only hit the same object. The solution I have right now is to get the object name and test the trace object name after it hits like this:

// start OSL code fragment string thisobjname = ""; getattribute("geom:name",thisobjname); int hit = trace(P, ((_var_42 - 0.5) * 2.0), ); string hitobjname = ""; getmessage("trace","geom:name",hitobjname); if( hit && hitobjname==thisobjname) printf("trace hit the same object"); // end OSL code fragment

I tried the following, but it does not work.

// start OSL code fragment string thisobjname = ""; getattribute("geom:name",thisobjname); int hit = trace(P, ((_var_42 - 0.5) * 2.0), "traceset", thisobjname ); string hitobjname = ""; getmessage("trace","geom:name",hitobjname); if( hit) printf("trace hit the same object"); // end OSL code fragment

How does the 'traceset' need to be formatted to work? Is there something else wrong?