Hi Mark,
xionmark
Again, where is this documented? I've never heard this before.
Yup. In
file://$HHi/vex/html/compiler.html we get:
'Da Docs
Like with the RenderMan™ shading language, parameters to user functions are always passed by reference. This means that modifications in a user function affect the variable the function was called with.
So… careful what you modify in your user functions!! :shock:
Also; I've gotten into the habit of thinking about all global vars as reserved words (when working outside of the context functions, that is). That way you don't accidentaly clobber a global, causing a possibly hard-to-track bug.
Oh; and by-the-way…
PRMan doesn't pass parameters by reference (or rather; the compiler won't let you simply write to a parameter, even if the internal mechanics are “pass-by-reference”). If you want to overwrite a param in prman, you need to explicitly declare the parameter type as “output” – which, in the end, is no different than having to explicitly write the ‘&’ in C++. So; regardless of how it's managed internally, the end-effect for the programmer is that, in PRMan, parameters are
not passed by reference.
Here's a “clobber-the-param” example in VEX:
float f(float x) { x-=.5; return x; }
surface testpbr() { float x=1; f(x); Cf=x;} // Cf is 0.5 !!!
A direct translation to SL simply doesn't compile:
float f(float x) { x-=.5; return x; }
surface testpbr() { float x=1; f(x); Ci=x;}
However; if you declare ‘x’ as
output, then we have a “clobber-the-parm” function in SL:
float f(output float x) { x-=.5; return x; }
surface testpbr() { float x=1; f(x); Ci=x;}
The effect of
having to write the “output” modifier is pretty significant – even if it's just to remind you that you're about to do something unusual.
I think I submitted this as an RFE a while back; but if I didn't, then I'd like to do so now