Script Material Node

So I’ve learned already that you can add OSL-materials with the Script node. I’ve also seen people creating materials with python.

My question, can you use the Script node to run simple python scripts? For the begining I just want a node with a random number output, maybe two boxes where you can define random min and max. (I know there’s the Object Info node with a random output but it’s not what I need)

I kinda imagine it like this, does this work somehow?


                   |--------------------------------------------------------------|
Node input |                                                                           | Node output
--------------o|  python variable -> process -> python variable |o---------
                   |                                                                          |
                   |--------------------------------------------------------------|

Thanks in advance!

Interesting question…does anyone know the answer to this?

frMage,

I say you just give it a try. I think the difficulty is that OSL has a clear method for producing inputs and outputs specific to the material node editor. I wouldn’t know of any equivalent in python, but you could look into it.

You could create a real basic script in the Blender text editor. If it were python it would be something (loosely) like:

import random

maxValue = 10 #for example
randomNumber = random.random() * maxValue

makebelievepythonnodeoutputfunction(randomNumber)


I’m not sure if my syntax is correct, I’m new and still work with references, but if you have any experience I’m sure you know what I mean.

BUT…given that it is not clear whether or not Python is compatible with the script node (and given the lack of answer or experimentation), it is worth noting that OSL can perform all of these functions itself, and anything that is not immediately available I am rather sure can be added as a module. So, while using a slightly different syntax, producing a custom random number and outputting it would work perfectly with OSL.

Thanks for your answer @arcarsenal, sorry must have overlooked it the last couple of days.

I did in fact try to load some lines of scripting into the Script Node and at least didn’t get an error. It seems something like this existed before in Blender 2.4x: http://wiki.blender.org/index.php/Doc:2.4/Manual/Materials/Nodes/Types/Dynamic
Of course not for Cycles. The main problem is however to figure out how those input / output functions should be made. That’s beyond my horizon I guess.

I already thought that OSL could do those things easily but I’m not too excited about OSL atm, simply because of the lack of GPU support (and furthermore the developers talk that it may never happen, if I recall correctly).

It would be sooo helpful to have this, e.g. if you use the random output from Object info then the random value is per object. With Python you could generate 10 random values on the fly if you need them. Furthermore thinking about logical operations without some hacky math/mixing node setup. With Python it could be done in a minute.