From d5ed153760d32ca6c5f6ca5acc5ec6126a7f3eee Mon Sep 17 00:00:00 2001 From: Thomas Dinges Date: Thu, 30 Oct 2014 11:33:27 +0100 Subject: Cycles / OSL: Support microfacet() closure color function from OSL 1.5 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 | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'intern/cycles/kernel') diff --git a/intern/cycles/kernel/shaders/stdosl.h b/intern/cycles/kernel/shaders/stdosl.h index 1ff8f363b49..6babe98717c 100644 --- a/intern/cycles/kernel/shaders/stdosl.h +++ b/intern/cycles/kernel/shaders/stdosl.h @@ -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; -- cgit v1.2.3