Do recursive functions work in OSL?


(RadioactiveNRG) #1

I’ve been trying to make a custom math node for factorial function using recursion in my script, but I’ve been getting errors and it seems to me that the “self referencing” part is the issue because whenever i remove it the script runs fine. I’m not sure if there is something wrong with my syntax or does OSL simply not work with recursion.
Here’s my code:

shader factorial(
int i = 1,
output int o = 0)
{
int fac(int n){if (n == 0)
{
return 1;
}
else
{
return (n * fac(n-1));
}
}
o = fac(i);
}


(Secrop) #2

AFAIK, no recursive functions. I don’t know if it will ever be implemented, and it’s not a so wealthy thing to put in shaders. For now, you must turn it into a loop (also not so wealthy).