Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*************************************************************************
- * ADOBE CONFIDENTIAL
- * ___________________
- * Copyright 2014 Adobe
- * All Rights Reserved.
- * NOTICE: All information contained herein is, and remains
- * the property of Adobe and its suppliers, if any. The intellectual
- * and technical concepts contained herein are proprietary to Adobe
- * and its suppliers and are protected by all applicable intellectual
- * property laws, including trade secret and copyright laws.
- * Dissemination of this information or reproduction of this material
- * is strictly forbidden unless prior written permission is obtained
- * from Adobe.
- *************************************************************************/
- // 2D Lighting disabled created by Roderick Weise Weise3D.com
- //- Substance 3D Painter Metal/Rough and opacity PBR shader
- //- ================================================
- //-
- //- Import from libraries.
- import lib-pbr.glsl
- import lib-bent-normal.glsl
- import lib-emissive.glsl
- import lib-pom.glsl
- import lib-sss.glsl
- import lib-alpha.glsl
- import lib-utils.glsl
- // Link Metal/Roughness MDL for Iray
- //: metadata {
- //: "mdl":"mdl::alg::materials::skin_metallic_roughness::skin_metallic_roughness"
- //: }
- //- Show back faces as there may be holes in front faces.
- //: state cull_face off
- //- Channels needed for metal/rough workflow are bound here.
- //: param auto channel_basecolor
- uniform SamplerSparse basecolor_tex;
- //: param auto channel_roughness
- uniform SamplerSparse roughness_tex;
- //: param auto channel_metallic
- uniform SamplerSparse metallic_tex;
- //: param auto channel_specularlevel
- uniform SamplerSparse specularlevel_tex;
- //: param auto texture_normal
- uniform SamplerSparse base_normal_tex;
- //: param custom {
- //: "default": -1,
- //: "label": "Material",
- //: "widget": "combobox",
- //: "values": {
- //: "Material": 1,
- //: "Base Color": 2,
- //: "Roughness": 3,
- //: "Metalness": 4,
- //: "Normal": 5
- //: }
- //: }
- uniform int combobox2D;
- //: param auto is_2d_view
- uniform bool uniform_2d_view;
- //- Shader entry point.
- void shade(V2F inputs)
- {
- // Apply parallax occlusion mapping if possible
- vec3 viewTS = worldSpaceToTangentSpace(getEyeVec(inputs.position), inputs);
- applyParallaxOffset(inputs, viewTS);
- //Normal map with height
- vec3 normal_map;
- vec3 tangent_base_normal = normalUnpack(textureSparse(base_normal_texture, inputs.sparse_coord), 1);
- vec3 tangent_height_normal = normalFromHeight(inputs.sparse_coord, -1);
- vec3 tangent_blended_normal = normalBlend(tangent_base_normal, tangent_height_normal);
- normal_map = sRGB2linear((tangent_blended_normal + 1.0) * 0.5);
- // Fetch material parameters, and conversion to the specular/roughness model
- float 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);
- // Get detail (ambient occlusion) and global (shadow) occlusion factors
- // separately in order to blend the bent normals properly
- float 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 integration
- emissiveColorOutput(pbrComputeEmissive(emissive_tex, inputs.sparse_coord));
- sssCoefficientsOutput(getSSSCoefficients(inputs.sparse_coord));
- sssColorOutput(getSSSColor(inputs.sparse_coord));
- // Discard current fragment on the basis of the opacity channel
- // and a user defined threshold
- alphaKill(inputs.sparse_coord);
- vec3 specColor = generateSpecularColor(specularLevel, baseColor, metallic);
- vec3 diffColor = generateDiffuseColor(baseColor, metallic);
- albedoOutput(diffColor);
- vec3 diffuseShading = occlusion * shadowFactor * envIrradiance(getDiffuseBentNormal(vectors));
- vec3 specShading = specOcclusion * pbrComputeSpecular(vectors, specColor, roughness, occlusion, getBentNormalSpecularAmount());
- if(uniform_2d_view)
- {
- if(combobox2D == 1)
- {
- diffuseShadingOutput(diffuseShading);
- specularShadingOutput(specShading);
- }
- if(combobox2D == 2)
- {
- diffuseShading = specColor;
- specShading = baseColor;
- }
- if(combobox2D == 3)
- {
- diffuseShading = vec3(0);
- specShading = sRGB2linear(vec3(roughness));
- }
- if(combobox2D == 4)
- {
- diffuseShading = vec3(0);
- specShading = sRGB2linear(vec3(metallic));
- }
- if(combobox2D == 5)
- {
- diffuseShading = vec3(0);
- specShading = normal_map;
- }
- }
- diffuseShadingOutput(diffuseShading);
- specularShadingOutput(specShading);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement