Experimenting with OSL & Shader Writing

Somethings not right

For a period of time I was experimenting and developed a fascination with shaders. Although I did not have much knowledge of programming at the time, shader writing felt like a logical direction to extend my knowledge on real life material properties, and how they are generated.

Initially I was mostly importing and testing OSL shaders from a small repository of shaders from Chaosgroup's website to learn to make my hero assets more physically based with more complex fresnel properties that some renderers might not have built in.

I eventually dove into learning the basics of generating simple shaders in OSL looking at various guides online. I became comfortable with the basic structure and had the goal in mind to create a basic PBR fresnel shader from scratch, that could take roughness into consideration for the final fresnel calculation. To achieve this I needed a starting point to setup the fresnel equation, so I used this special OSL cloth shader I found online. What I effectively did was try to isolate the needed components that make up the math of the fresnel equation.Moreover using my prior knowledge of setting up the statements needed for different closures such as diffuse and specular. After some tweaking around fixing syntax I succeeded in creating the simple shader displayed above 100% in OSL.

 1 
 2 shader BasicFresnel(
 3     color DiffCol = color(1),
 4     float IOR = 1.52,
 5     float roughness = 0.25,
 6     color SpecCol = color(1),
 7     normal Normal = N,
 8     output closure color result = 0,
 9 )
10     
11 { 
12 
13 float fresnelFactor = 1.0;
14     float eta = IOR;
15     float A, B;
16     float c = abs(dot(I, Normal));
17     float g = eta * eta - 1 + c * c;
18     if (g > 0) {
19         g = sqrt(g);
20         A = (g - c) / (g + c);
21         B = (c * (g + c) - 1) / (c * (g - c) + 1);
22         fresnelFactor = (0.5 * A * A * (1 + B * B)) / (roughness + 1);        
23     }  
24 
25     normal Nn = normalize(N);
26     Ci = DiffCol * diffuse(N) + SpecCol * fresnelFactor * microfacet_ggx(N, roughness);
27     result = Ci;
28 }

Shader Gallery

Mostly examples of multi domain fractal brownian motion at the moment. This was a GLSL shader I converted to OSL, need to find the source.

Somethings not right Somethings not right Somethings not right

Home page