Substance 3D Painter Specular/Glossiness PBR shader
Import from libraries.
Copied to your clipboardimport lib-pbr.glslimport lib-bent-normal.glslimport lib-emissive.glslimport lib-pom.glslimport lib-sss.glslimport lib-utils.glsl// Link Specular/Glossiness skin MDL for Iray//: metadata {//: "mdl" : "mdl::alg::materials::skin_specular_glossiness::skin_specular_glossiness"//: }
Channels needed for spec/gloss workflow are bound here.
Copied to your clipboard//: param auto channel_diffuseuniform SamplerSparse diffuse_tex;//: param auto channel_specularuniform SamplerSparse specularcolor_tex;//: param auto channel_glossinessuniform SamplerSparse glossiness_tex;void shade(V2F inputs){// Apply parallax occlusion mapping if possiblevec3 viewTS = worldSpaceToTangentSpace(getEyeVec(inputs.position), inputs);applyParallaxOffset(inputs, viewTS);float glossiness = getGlossiness(glossiness_tex, inputs.sparse_coord);vec3 specColor = getSpecularColor(specularcolor_tex, inputs.sparse_coord);vec3 diffColor = getDiffuse(diffuse_tex, inputs.sparse_coord) * (vec3(1.0) - specColor);// Get detail (ambient occlusion) and global (shadow) occlusion factors// separately in order to blend the bent normals properlyfloat shadowFactor = getShadowFactor();float occlusion = getAO(inputs.sparse_coord, true, use_bent_normal);float specOcclusion = use_bent_normal ? shadowFactor : occlusion * shadowFactor;LocalVectors vectors = computeLocalFrame(inputs);computeBentNormal(vectors,inputs);// Feed parameters for a physically based BRDF integrationemissiveColorOutput(pbrComputeEmissive(emissive_tex, inputs.sparse_coord));albedoOutput(diffColor);diffuseShadingOutput(occlusion * shadowFactor * envIrradiance(getDiffuseBentNormal(vectors)));specularShadingOutput(specOcclusion * pbrComputeSpecular(vectors, specColor, 1.0 - glossiness, occlusion, getBentNormalSpecularAmount()));sssCoefficientsOutput(getSSSCoefficients(inputs.sparse_coord));vec4 baseSSSColor = getSSSColor(inputs.sparse_coord);if (usesSSSScatteringColorChannel()) {// Must be dimmed by specColor as for diffuse colorbaseSSSColor.rgb *= vec3(1.0) - specColor;}sssColorOutput(baseSSSColor);}