Results 1 to 2 of 2
  1. #1

    Do recursive functions work in OSL?

    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;
    return (n * fac(n-1));
    o = fac(i);

  2. #2
    Member Secrop's Avatar
    Join Date
    Dec 2011
    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).
    Last edited by Secrop; 24-Dec-17 at 10:12.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts