use osl to create custome math node?


(andgarrett) #1

I want to create a custom node that can do complex math such as julia sets. I’ve tried using the script node in cycles, but I can’t even get a simple bit of code to work. the script is just a test. I know I can do the same thing with math nodes. this is just a test to make sure I know what I am doing before I move on to more complex things that the math nodes can’t do.

here’s the code I used:

shader Sphere(
    float X = 0,
    float Y = 0,
    float Z = 0,
    output float X_out = 0,
    output float Y_out = 0,
    output float Z_out = 0)
{
    X_out = X*X;
    Y_out = Y*Y;
    Z_out = Z*Z;
}

can someone either link a guide on how to do math in a script node or tell me what I am doing wrong.


(Ko.) #2

Works fine here. Make sure you activated OSL in Cycles render properties. Also, OSL don’t like non-latin literals in Blender installation directory address (but I guess it’s not your problem).


(andgarrett) #3

ah, no wonder. I didn’t realize I needed to enable it. Thanks.


(Secrop) #4

For that code, you don’t even need OSL… just multiply the vector XYZ by itself using a RGBMix node set to multiply. Using the vector math dot function, if you plug the vector into both inputs will return XX+YY+Z*Z.
There is already some scripts doing julia and mandelbrot fractals… you may want to take a look at them.