Advertisement
RoderickWeise

Substance Painter 2D Lighting Disable/Enable

Apr 26th, 2024 (edited)
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*************************************************************************
  2. * ADOBE CONFIDENTIAL
  3. * ___________________
  4. * Copyright 2014 Adobe
  5. * All Rights Reserved.
  6. * NOTICE:  All information contained herein is, and remains
  7. * the property of Adobe and its suppliers, if any. The intellectual
  8. * and technical concepts contained herein are proprietary to Adobe
  9. * and its suppliers and are protected by all applicable intellectual
  10. * property laws, including trade secret and copyright laws.
  11. * Dissemination of this information or reproduction of this material
  12. * is strictly forbidden unless prior written permission is obtained
  13. * from Adobe.
  14. *************************************************************************/
  15.  
  16. // 2D Lighting disabled created by Roderick Weise Weise3D.com
  17.  
  18. //- Substance 3D Painter Metal/Rough and opacity PBR shader
  19. //- ================================================
  20. //-
  21. //- Import from libraries.
  22. import lib-pbr.glsl
  23. import lib-bent-normal.glsl
  24. import lib-emissive.glsl
  25. import lib-pom.glsl
  26. import lib-sss.glsl
  27. import lib-alpha.glsl
  28. import lib-utils.glsl
  29.  
  30. // Link Metal/Roughness MDL for Iray
  31. //: metadata {
  32. //:   "mdl":"mdl::alg::materials::skin_metallic_roughness::skin_metallic_roughness"
  33. //: }
  34.  
  35. //- Show back faces as there may be holes in front faces.
  36. //: state cull_face off
  37.  
  38. //- Channels needed for metal/rough workflow are bound here.
  39. //: param auto channel_basecolor
  40. uniform SamplerSparse basecolor_tex;
  41. //: param auto channel_roughness
  42. uniform SamplerSparse roughness_tex;
  43. //: param auto channel_metallic
  44. uniform SamplerSparse metallic_tex;
  45. //: param auto channel_specularlevel
  46. uniform SamplerSparse specularlevel_tex;
  47. //: param auto texture_normal
  48. uniform SamplerSparse base_normal_tex;
  49.  
  50. //: param custom {
  51. //:   "default": -1,
  52. //:   "label": "Material",
  53. //:   "widget": "combobox",
  54. //:   "values": {
  55. //:     "Material": 1,
  56. //:     "Base Color": 2,
  57. //:     "Roughness": 3,
  58. //:     "Metalness": 4,
  59. //:     "Normal": 5
  60. //:   }
  61. //: }
  62. uniform int combobox2D;
  63.  
  64. //: param auto is_2d_view
  65. uniform bool uniform_2d_view;
  66.  
  67. //- Shader entry point.
  68. void shade(V2F inputs)
  69. {
  70.   // Apply parallax occlusion mapping if possible
  71.   vec3 viewTS = worldSpaceToTangentSpace(getEyeVec(inputs.position), inputs);
  72.   applyParallaxOffset(inputs, viewTS);
  73.  
  74.   //Normal map with height
  75.   vec3 normal_map;
  76.   vec3 tangent_base_normal = normalUnpack(textureSparse(base_normal_texture, inputs.sparse_coord), 1);
  77.   vec3 tangent_height_normal = normalFromHeight(inputs.sparse_coord, -1);
  78.   vec3 tangent_blended_normal = normalBlend(tangent_base_normal, tangent_height_normal);
  79.   normal_map = sRGB2linear((tangent_blended_normal + 1.0) * 0.5);
  80.  
  81.   // Fetch material parameters, and conversion to the specular/roughness model
  82.   float roughness = getRoughness(roughness_tex, inputs.sparse_coord);
  83.   vec3 baseColor = getBaseColor(basecolor_tex, inputs.sparse_coord);
  84.   float metallic = getMetallic(metallic_tex, inputs.sparse_coord);
  85.   float specularLevel = getSpecularLevel(specularlevel_tex, inputs.sparse_coord);
  86.  
  87.   // Get detail (ambient occlusion) and global (shadow) occlusion factors
  88.   // separately in order to blend the bent normals properly
  89.   float shadowFactor = getShadowFactor();
  90.   float occlusion = getAO(inputs.sparse_coord, true, use_bent_normal);
  91.   float specOcclusion = specularOcclusionCorrection(
  92.     use_bent_normal ? shadowFactor : occlusion * shadowFactor,
  93.     metallic,
  94.     roughness);
  95.  
  96.   LocalVectors vectors = computeLocalFrame(inputs);
  97.   computeBentNormal(vectors,inputs);
  98.  
  99.   // Feed parameters for a physically based BRDF integration
  100.   emissiveColorOutput(pbrComputeEmissive(emissive_tex, inputs.sparse_coord));
  101.   sssCoefficientsOutput(getSSSCoefficients(inputs.sparse_coord));
  102.   sssColorOutput(getSSSColor(inputs.sparse_coord));
  103.  
  104.   // Discard current fragment on the basis of the opacity channel
  105.   // and a user defined threshold
  106.   alphaKill(inputs.sparse_coord);
  107.  
  108.   vec3 specColor = generateSpecularColor(specularLevel, baseColor, metallic);
  109.   vec3 diffColor = generateDiffuseColor(baseColor, metallic);
  110.   albedoOutput(diffColor);
  111.   vec3 diffuseShading = occlusion * shadowFactor * envIrradiance(getDiffuseBentNormal(vectors));
  112.   vec3 specShading = specOcclusion * pbrComputeSpecular(vectors, specColor, roughness, occlusion, getBentNormalSpecularAmount());
  113.  
  114.     if(uniform_2d_view)
  115.     {
  116.         if(combobox2D == 1)
  117.         {
  118.             diffuseShadingOutput(diffuseShading);
  119.             specularShadingOutput(specShading);
  120.         }
  121.    
  122.         if(combobox2D == 2)
  123.         {
  124.             diffuseShading = specColor;
  125.             specShading = baseColor;
  126.         }
  127.        
  128.         if(combobox2D == 3)
  129.         {
  130.             diffuseShading = vec3(0);
  131.             specShading = sRGB2linear(vec3(roughness));
  132.         }
  133.        
  134.         if(combobox2D == 4)
  135.         {
  136.             diffuseShading = vec3(0);
  137.             specShading = sRGB2linear(vec3(metallic));
  138.         }
  139.  
  140.         if(combobox2D == 5)
  141.         {
  142.             diffuseShading = vec3(0);
  143.             specShading = normal_map;
  144.         }
  145.    }
  146.    
  147.     diffuseShadingOutput(diffuseShading);
  148.     specularShadingOutput(specShading);
  149.    
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement