1
$\begingroup$

I'm trying to create a way to calculate imaginary numbers in OSL using the struct constructor. Here is the beginning of my code:

#include "stdosl.h"

struct complex {
    color r;
    color i;
};

complex test;

According to the documentation, that should create a complex datatype, then initialize a variable named test. Instead, I get these errors:

ERROR: <path-to-file>.osl:8: error: Unknown shader type: complex
ERROR: <path-to-file>.osl:8: error: Syntax error: syntax error
Error: OSL script compilation failed, see console for errors

This seems to indicate a syntax error on line 8, but I can't figure out what is wrong.

$\endgroup$
2
$\begingroup$

You should declare the variable inside a shader

struct complex {
    color r;
    color i;
};

shader node_complex(output float result=0.0)
{
    complex test;
}

This will resolve the compilation error. The issue is that Global variables in OSL are predefined and it is not possible to create custom global variables.

You can use these structs inside shaders and pass it around.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.