OSLPY is an addon converts a subset of OSL that can be expressed in nodegroups in cycles to nodegroups that can run on the GPU
Can I just use any OSL script and expect it to work?
Sadly: no.
This add-on only converts the bits of OSL that can be expressed in cycles nodes. So if it wasn’t possible in the past it in a cycles material won’t be possible now, so…
OSL’s wide range of noise sources: unsupported
while loops: unsupported
closures: unsupported
string functions: unsupported
raytracing functions: unsupported
Returning from the middle of a function: unsupported
This doesn’t sound overly useful, what is it good for?! what does work?!
Most purely procedural texture shaders will work or can be made to work with minimal changes.
most math based functions like sin/cos/tan/asin/acos/atan/atan2/dot/length/add/subtract/multiply/ceil/floor/mod etc
Limited support for static loops, loops in the from for (i=0; i<10; i++) { do something } will automatically be unrolled at compile time. Dynamic loops (based on an input parameter for instance) are not supported.
if constructs (like if (x) y=a; else y=b; )
most logical operations and/or/xor (like if (x and not y) y=a; else y=b; )
function calls
Limited static array access
How to use
Install the plugin from https://github.com/LazyDodo/oslpy and add an OSLPY node to your material, beyond that it’ll work pretty much like the regular script node. There are a bunch of sample scripts that are compatible with oslpy include in the zip file, including the source files for bricktricks.
It’s not overly great at reporting errors yet, keep an eye on the system console, it tends to print there why it is unhappy.
And finally some results:
RenderTime OSL 5:29.16 (i7-3770)
On the gpu with oslpy 1:14.59 (gtx670)
small demo showing the addon in use
https://youtu.be/eLsujpx2ItUIt’s far far from complete, but good enough to be useful to other people, so … enjoy!