Skip to content

Instantly share code, notes, and snippets.

@whaison

whaison/emily_material.osl

Last active Feb 12, 2017
Embed
What would you like to do?
emily_material.osl  |||| Open Shading Langage
float phongExponent(float glossiness) {
return (1/pow(1-glossiness, 3.5)-1);
}
surface emily_material
(
string specularUnlitNormTexture="00_specular_unlit.exr",
string singleScatterTexture="00_single_scatter.exr",
string diffuseUnlitTexture="00_diffuse_unlit.exr",
float scatterRadius=0.5,
color scatterColor=color(0.482, 0.169, 0.109),
float ior=1.33,
float phaseFunction=0.8
)
{
color diffuseUnlit=texture(diffuseUnlitTexture, u, v);
color singleScatter=texture(singleScatterTexture, u, v);
color specularUnlit=texture(specularUnlitNormTexture, u, v);
// Single scattering is approximated with a diffuse closure
color diffuseAmount=singleScatter;
// Multiple scattering reduced with the single scattering amount
color sssAmount=(color(1,1,1)-singleScatter)*diffuseUnlit;
// We have two Phong specular lobes with equal strength, so each is half as bright
color specularAmount=specularUnlit*0.5;
// Fresnel coefficient; this should really be glossy Fresnel that takes into
// account the specular roughness, but for the moment we are just using the
// perfect mirror Fresnel.
float fresnelCoeff, refractionStrength;
vector reflectDir, refractDir;
fresnel(I, N, ior, fresnelCoeff, refractionStrength, reflectDir, refractDir);
specularAmount*=fresnelCoeff;
// Compute the final result.
Ci=
specularAmount*phong(N, phongExponent(0.55))+
specularAmount*phong(N, phongExponent(0.75))+
diffuseAmount*diffuse(N)+
subsurface(ior, phaseFunction, scatterColor*scatterRadius, sssAmount);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment