Substance 3D Painter Metal/Rough and opacity PBR shader
Import from libraries.
Copied to your clipboardimport lib-pbr.glslimport lib-bent-normal.glslimport lib-emissive.glslimport lib-pom.glslimport lib-utils.glsl// Link Metal/Roughness MDL for Iray//: metadata {//: "mdl":"mdl::alg::materials::physically_metallic_roughness::physically_metallic_roughness"//: }
Show back faces as there may be holes in front faces.
Copied to your clipboard//: state cull_face off
Enable alpha blending
Copied to your clipboard//: state blend over
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_specularleveluniform SamplerSparse specularlevel_tex;//: param auto channel_opacityuniform SamplerSparse opacity_tex;
Shader entry point.
Copied to your clipboardvoid shade(V2F inputs){// Apply parallax occlusion mapping if possiblevec3 viewTS = worldSpaceToTangentSpace(getEyeVec(inputs.position), inputs);applyParallaxOffset(inputs, viewTS);// Fetch material parameters, and conversion to the specular/roughness modelfloat roughness = getRoughness(roughness_tex, inputs.sparse_coord);vec3 baseColor = getBaseColor(basecolor_tex, inputs.sparse_coord);float metallic = getMetallic(metallic_tex, inputs.sparse_coord);float specularLevel = getSpecularLevel(specularlevel_tex, inputs.sparse_coord);vec3 diffColor = generateDiffuseColor(baseColor, metallic);vec3 specColor = generateSpecularColor(specularLevel, baseColor, metallic);// 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);LocalVectors vectors = computeLocalFrame(inputs);computeBentNormal(vectors,inputs);// Feed parameters for a physically based BRDF integrationalphaOutput(getOpacity(opacity_tex, inputs.sparse_coord));emissiveColorOutput(pbrComputeEmissive(emissive_tex, inputs.sparse_coord));diffuseShadingOutput(occlusion * shadowFactor * pbrComputeDiffuse(getDiffuseBentNormal(vectors), diffColor));specularShadingOutput(specOcclusion * pbrComputeSpecular(vectors, specColor, roughness, occlusion, getBentNormalSpecularAmount()));}