Cracks, Creases, Lightening etc in OSL

Hi all

I am in the process of learning OSL so that I can create a shader that draws lines similar to these.
These sort of random lines are very common in nature and I would like to be able to drive a bump node or the like.

My question here is basically has someone already done this.
Every time I do something like this, someone with more time and skill seems to come out with the same thing.
I do love coding but it seems like a waste to double up.


hi, it would be a welcome addition

maybe a Blender Laplacian Lightning on funkboxing
thread here:
[AddOn] Blender Lightning Generator [UPDATED 06.20.11]

OH, missed the OSL preference… well, may it help at least.

Ok I thought it could be useful.
This could take a while so don’t hold your breath.
As I go I’ll report back here.
If anyone has any math knowledge and can give me a hand getting my head around the calculations that would really help.
Otherwise I have to sort through the papers on it and code that does heaps of unnecessary stuff to get to the actual bits that I want.
Coding is the easy part the math does my head in.

Even if someone can bang out some pseudo code that would help


Yeah eppo put me onto that which sent me to the site I linked.
OSL seems to be the way to make it really easy to use.
I will go through it as well to try and reverse engineer it and strip out the bits I want.

Thanks anyway

I always seem to jump in the deep end and swim like hell then some bloody Olympic swimmer comes along and jumps in the water and gets to the other end before I’m even off the bottom of the pool. :slight_smile:
But hey life would be pretty boring if it was easy.

I believe that OSL alone won’t be able to do it. At least in Cycles where the code to write data (i.e. point clouds) is not writen yet… Well, unless we calculate the global laplacian or random walker every time the shader is called, but this would be way tooo slow!!

The best approach (at least the one I think it can work), could be a fusion of Python and OSL. Calculate the Laplacian/RW in Python for each frame (this is rather good, since you can access to the object data and the whole scene), store the final data in point clouds or in xml which can be used in OSL, and use the OSL to define how to draw the data.

Re-read this
Good point.
persistent data ah yes
thinking thinking
mmmm tricky

The shader is built once for each render, is that correct?
So this would only be a problem for animation would it not?


The script is compiled at the first time it is called (if it wasn’t compiled before). Then every time a ray is casted and hit’s a surface that has the shader, then the shader is executed, which means that the shader is executed for every sample.

For animations, there’s no problem, as each frame is treated independently by the engine . You just need new data for each frame, but since you need to calculate all the steps as part of the laplacian/rw process, you can store each frame state in a xml sequence.

OK so a node texture must store it’s info.
What are the scope rules then.
Can I store the data between calls
Or does this have to be written to a file.

I suppose this now needs to be in the other thread.

Actually don’t worry I got the book I’ll read it play around a bit and ask some more difficult questions as I get deeper into it.

Anyway thanks.