Cornell.osl || Open Shading Language || http://thhube.github.io/tutorials/osl/osl.html
// -- Cornell.osl - Generate the Cornell box material --------------- | |
#include "stdosl.h" | |
#define POS_Y normal(0.0, 1.0, 0.0) | |
#define NEG_Y normal(0.0, -1.0, 0.0) | |
#define EPSILON 1e-5 | |
surface Cornell(output closure color bsdf = 0) | |
{ | |
color result = color(0, 1, 0); | |
if (dot(N, POS_Y) < EPSILON) { | |
result = color(1, 0, 0); | |
} | |
if (fabs(dot(N, NEG_Y)) < EPSILON) { | |
result = color(1, 1, 1); | |
} | |
bsdf = result * diffuse(N); | |
} | |
// -- Glass.osl - Generate the glass material on Suzanne ------------ | |
#include "stdosl.h" | |
#define IOR_THRESHOLD 1.000001 | |
float FresnelDielectric(vector i, normal n, float eta) | |
{ | |
float c = fabs(dot(i, n)); | |
float g = eta * eta - 1 + c * c; | |
float result = 1.0; | |
if (g > 0) { | |
g = sqrt(g); | |
float a = (g - c) / (g + c); | |
float b = (c * (g + c) - 1) / (c * (g + c) + 1); | |
result = 0.5 * a * a * (1 + b * b); | |
} | |
return result; | |
} | |
surface Glass( | |
color diffuse_col = 0.8, | |
float ior = 1.45, | |
output closure color bsdf = 0) | |
{ | |
float real_ior = max(ior, IOR_THRESHOLD); | |
float eta = backfacing()? 1.0 / real_ior : real_ior; | |
float fr = FresnelDielectric(I, N, eta); | |
bsdf = diffuse_col * (fr * reflection(N) + (1.0 - fr) * refraction(N, eta)); | |
} | |
// -- Metal.osl - Generate the metal reflection --------------------- | |
#include "stdosl.h" | |
surface Metal( | |
color diffuse_col = 0.8, | |
float roughness = 1.5, | |
output closure color bsdf = 0) | |
{ | |
bsdf = diffuse_col * reflection(N); | |
} | |
// -- Velvet.osl - Generate the velvet surface ---------------------- | |
#include "stdosl.h" | |
surface Metal( | |
color diffuse_col = 0.8, | |
float roughness = 1.5, | |
output closure color bsdf = 0) | |
{ | |
bsdf = diffuse_col * reflection(N); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment