I’ve been trying to learn a bit about writing OSL shaders the past couple of days, and I’m finding it pretty interesting. So far I’ve just learned a bit about what osl can do and how to put together a basic shader. Here’s one of my first attempts – a procedural dirt shader based on the trace function. It’s pretty much just an ambient occlusion pass that you can use as a mask for other materials, but what’s nice about it is that it’s completely dynamic: no baking, no vertex paint etc.
Here’s what it looks like:
And here’s the shader code:
shader tracetest( normal Normal = N, float Distance = 10, float NoiseFactor = 0.5, float NoiseScale = 100, output float TraceRandom = 0.0) { normal NewNorm = Normal; // Create a randomised normal to trace with. vector RandomVec = vector(0,0,0); vector NormalVec = transform("common", N); RandomVec = NormalVec + (NoiseFactor * noise("perlin", P * NoiseScale)); RandomVec = normalize(RandomVec); int Hit2 = trace(P, RandomVec, "maxdist", Distance); if (Hit2) { float Dist = 0.0; // Get the hit distance: int HitTrace = getmessage("trace", "hitdist", Dist); // Turn Hit Distance into output: float Grad = 1 - Dist/Distance; TraceRandom = pow(Grad,2); } }
Edit: Here’s a screenshot of the node setup.
Thks a lot Ben,
And all my best Greetinsg for this new year 2014.
Could you add a screenview of the node’s setup, please.
Bye bye
SPirou4D
Added! Thanks SPirou4D
Good!
Congratulations.
Really impresses with all of your work so far Ben. I am thinking of buying a new computer. Can you tell me what are your system specs and what do you recommend?
Thanx!
Hi Playway
I’m using a 2011 iMac for my work. 8GB Ram, Quad Core processor. The most important hardware specs for blender are RAM (for handling large scenes) and CPU power (for rendering). GPU is obviously usefull as well, particularly if you want to use it for rendering. I’d advise having a quad core machine with at least 8GB of ram but the rest I’m not too up to date on…
Ah, I see. Thanx for helping me out! A little professional advice is always helpful:)
Good luck for your future projects and have a nice day!
What resources are you using to learn OSL?
Mainly Thomas Dinges’ site, OpenShading.com, and the OSL Specification. You can find the latter at https://code.google.com/p/openshadinglanguage/
So compact script and so impressive result!
Script works perfect, but it takes ages to render. Am i doing something wrong or is just normal when using OSL
Pingback: Open Shading Language from Scratch (Ubuntu) – Digital Box·