Substance 3D Painter Metal/Rough Anisotropy PBR shader
Import from libraries.
Copied to your clipboardimport lib-pbr.glslimport lib-pbr-aniso.glslimport lib-bent-normal.glslimport lib-emissive.glslimport lib-sss.glslimport lib-alpha.glslimport lib-utils.glsl
Declare the iray mdl material to use with this shader.
Copied to your clipboard//: metadata {//: "mdl":"mdl::alg::materials::skin_metallic_roughness::skin_metallic_roughness"//: }
Show back faces as there may be holes in front faces.
Copied to your clipboard//: state cull_face off
Channels needed for metal/rough workflow are bound here.
Copied to your clipboard//: param auto channel_basecoloruniform SamplerSparse basecolor_tex;//: param auto channel_roughnessuniform SamplerSparse roughness_tex;//: param auto channel_metallicuniform SamplerSparse metallic_tex;//: param auto channel_anisotropyleveluniform SamplerSparse anisotropylevel_tex;//: param auto channel_anisotropyangleuniform SamplerSparse anisotropyangle_tex;
Shader entry point.
Copied to your clipboardvoid shade(V2F inputs){// Fetch material parameters, and conversion to the specular/roughness modelfloat roughness = getRoughness(roughness_tex, inputs.sparse_coord);float anisotropyLevel = getAnisotropyLevel(anisotropylevel_tex, inputs.sparse_coord);vec2 roughnessAniso = generateAnisotropicRoughness(roughness, anisotropyLevel);float anisotropyAngle = getAnisotropyAngle(anisotropyangle_tex, inputs.sparse_coord);vec3 baseColor = getBaseColor(basecolor_tex, inputs.sparse_coord);float metallic = getMetallic(metallic_tex, inputs.sparse_coord);// 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 = specularOcclusionCorrection(use_bent_normal ? shadowFactor : occlusion * shadowFactor,metallic,roughness);vec3 normal = computeWSNormal(inputs.sparse_coord, inputs.tangent, inputs.bitangent, inputs.normal);LocalVectors vectors = computeLocalFrame(inputs, normal, anisotropyAngle);computeBentNormal(vectors,inputs);// Feed parameters for a physically based BRDF integrationalphaOutput(getOpacity(opacity_tex, inputs.sparse_coord));emissiveColorOutput(pbrComputeEmissive(emissive_tex, inputs.sparse_coord));sssCoefficientsOutput(getSSSCoefficients(inputs.sparse_coord));vec4 baseSSSColor = getSSSColor(inputs.sparse_coord);if (usesSSSScatteringColorChannel()) {// Must be dimmed by metallic factor as for diffuse colorbaseSSSColor.rgb = generateDiffuseColor(baseSSSColor.rgb, metallic);}sssColorOutput(baseSSSColor);// Discard current fragment on the basis of the opacity channel// and a user defined thresholdalphaKill(inputs.sparse_coord);vec3 diffColor = generateDiffuseColor(baseColor, metallic);albedoOutput(diffColor);diffuseShadingOutput(occlusion * shadowFactor * envIrradiance(getDiffuseBentNormal(vectors)));vec3 specColor = generateSpecularColor(baseColor, metallic);specularShadingOutput(specOcclusion * pbrComputeSpecularAnisotropic(vectors, specColor, roughnessAniso, occlusion, getBentNormalSpecularAmount()));}