Cycles / OSL: Support microfacet() closure color function from OSL 1.5
authorThomas Dinges <blender@dingto.org>
Thu, 30 Oct 2014 10:33:27 +0000 (11:33 +0100)
committerThomas Dinges <blender@dingto.org>
Thu, 30 Oct 2014 10:33:27 +0000 (11:33 +0100)
This is basically just a wrapper class, which maps the generic call from the OSL spec to our closures.

Example usage:

shader microfacet_osl(
    color Color = color(0.8),
    int Distribution = 0,
    normal Normal = N,
    vector Tangent = normalize(dPdu),
    float RoughnessU = 0.0,
    float RoughnessV = 0.0,
    float IOR = 1.4,
    int Refract = 0,
    output closure color BSDF = 0)
{
    if (Distribution == 0)
        BSDF = Color * microfacet("ggx", Normal, Tangent, RoughnessU, RoughnessV, IOR, Refract);
    else
        BSDF = Color * microfacet("beckmann", Normal, Tangent, RoughnessU, RoughnessV, IOR, Refract);
}

intern/cycles/kernel/shaders/stdosl.h

index 1ff8f363b492e43833e6b12d30dc35258380068c..6babe98717cfee225f3fa314b8cb665d35e3d59f 100644 (file)
@@ -505,6 +505,47 @@ closure color hair_transmission(normal N, float roughnessu, float roughnessv, ve
 closure color henyey_greenstein(float g) BUILTIN;
 closure color absorption() BUILTIN;
 
+// OSL 1.5 Microfacet functions
+closure color microfacet(string distribution, normal N, vector U, float xalpha, float yalpha, float eta, int refract) {
+       /* GGX */
+       if (distribution == "ggx" || distribution == "default") {
+               if (!refract) {
+                       if (xalpha == yalpha) {
+                               /* Isotropic */
+                               return microfacet_ggx(N, xalpha);
+                       }
+                       else {
+                               /* Anisotropic */
+                               return microfacet_ggx_aniso(N, U, xalpha, yalpha);
+                       }
+               }
+               else {
+                       return microfacet_ggx_refraction(N, xalpha, eta);
+               }
+       }
+       /* Beckmann */
+       else {
+               if (!refract) {
+                       if (xalpha == yalpha) {
+                               /* Isotropic */
+                               return microfacet_beckmann(N, xalpha);
+                       }
+                       else {
+                               /* Anisotropic */
+                               return microfacet_beckmann_aniso(N, U, xalpha, yalpha);
+                       }
+               }
+               else {
+                       return microfacet_beckmann_refraction(N, xalpha, eta);
+               }
+       }
+}
+
+closure color microfacet (string distribution, normal N, float alpha, float eta, int refract) {
+       return microfacet(distribution, N, vector(0), alpha, alpha, eta, refract);
+}
+
+
 // Renderer state
 int backfacing () BUILTIN;
 int raytype (string typename) BUILTIN;