pbrBlockSheen.fx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. #ifdef SHEEN
  2. struct sheenOutParams
  3. {
  4. float sheenIntensity;
  5. vec3 sheenColor;
  6. float sheenRoughness;
  7. #ifdef SHEEN_LINKWITHALBEDO
  8. vec3 surfaceAlbedo;
  9. #endif
  10. #if defined(ENVIRONMENTBRDF) && defined(SHEEN_ALBEDOSCALING)
  11. float sheenAlbedoScaling;
  12. #endif
  13. #if defined(REFLECTION) && defined(ENVIRONMENTBRDF)
  14. vec3 finalSheenRadianceScaled;
  15. #endif
  16. #if DEBUGMODE > 0
  17. vec4 sheenMapData;
  18. vec3 sheenEnvironmentReflectance;
  19. #endif
  20. };
  21. void sheenBlock(
  22. const in vec4 vSheenColor,
  23. #ifdef SHEEN_ROUGHNESS
  24. const in float vSheenRoughness,
  25. #endif
  26. const in float roughness,
  27. #ifdef SHEEN_TEXTURE
  28. const in vec4 sheenMapData,
  29. #endif
  30. const in float reflectance,
  31. #ifdef SHEEN_LINKWITHALBEDO
  32. const in vec3 baseColor,
  33. const in vec3 surfaceAlbedo,
  34. #endif
  35. #ifdef ENVIRONMENTBRDF
  36. const in float NdotV,
  37. const in vec3 environmentBrdf,
  38. #endif
  39. #if defined(REFLECTION) && defined(ENVIRONMENTBRDF)
  40. const in vec2 AARoughnessFactors,
  41. const in vec3 vReflectionMicrosurfaceInfos,
  42. const in vec2 vReflectionInfos,
  43. const in vec3 vReflectionColor,
  44. const in vec4 vLightingIntensity,
  45. #ifdef REFLECTIONMAP_3D
  46. const in samplerCube reflectionSampler,
  47. const in vec3 reflectionCoords,
  48. #else
  49. const in sampler2D reflectionSampler,
  50. const in vec2 reflectionCoords,
  51. #endif
  52. const in float NdotVUnclamped,
  53. #ifndef LODBASEDMICROSFURACE
  54. const in sampler2D reflectionSamplerLow,
  55. const in sampler2D reflectionSamplerHigh,
  56. #endif
  57. #if !defined(REFLECTIONMAP_SKYBOX) && defined(RADIANCEOCCLUSION)
  58. const in float seo,
  59. #endif
  60. #if !defined(REFLECTIONMAP_SKYBOX) && defined(HORIZONOCCLUSION) && defined(BUMP) && defined(REFLECTIONMAP_3D)
  61. const in float eho,
  62. #endif
  63. #endif
  64. out sheenOutParams outParams
  65. )
  66. {
  67. float sheenIntensity = vSheenColor.a;
  68. #ifdef SHEEN_TEXTURE
  69. sheenIntensity *= sheenMapData.a;
  70. #if DEBUGMODE > 0
  71. outParams.sheenMapData = sheenMapData;
  72. #endif
  73. #endif
  74. #ifdef SHEEN_LINKWITHALBEDO
  75. float sheenFactor = pow5(1.0-sheenIntensity);
  76. vec3 sheenColor = baseColor.rgb*(1.0-sheenFactor);
  77. float sheenRoughness = sheenIntensity;
  78. outParams.surfaceAlbedo = surfaceAlbedo * sheenFactor;
  79. #else
  80. vec3 sheenColor = vSheenColor.rgb;
  81. #ifdef SHEEN_TEXTURE
  82. sheenColor.rgb *= sheenMapData.rgb;
  83. #endif
  84. #ifdef SHEEN_ROUGHNESS
  85. float sheenRoughness = vSheenRoughness;
  86. #else
  87. float sheenRoughness = roughness;
  88. #endif
  89. // Sheen Lobe Layering.
  90. #if !defined(SHEEN_ALBEDOSCALING)
  91. sheenIntensity *= (1. - reflectance);
  92. #endif
  93. // Remap F0 and sheen.
  94. sheenColor *= sheenIntensity;
  95. #endif
  96. // _____________________________ Sheen Environment __________________________
  97. #ifdef ENVIRONMENTBRDF
  98. /*#ifdef SHEEN_SOFTER
  99. vec3 environmentSheenBrdf = vec3(0., 0., getBRDFLookupCharlieSheen(NdotV, sheenRoughness));
  100. #else*/
  101. #ifdef SHEEN_ROUGHNESS
  102. vec3 environmentSheenBrdf = getBRDFLookup(NdotV, sheenRoughness);
  103. #else
  104. vec3 environmentSheenBrdf = environmentBrdf;
  105. #endif
  106. /*#endif*/
  107. #endif
  108. #if defined(REFLECTION) && defined(ENVIRONMENTBRDF)
  109. float sheenAlphaG = convertRoughnessToAverageSlope(sheenRoughness);
  110. #ifdef SPECULARAA
  111. // Adapt linear roughness (alphaG) to geometric curvature of the current pixel.
  112. sheenAlphaG += AARoughnessFactors.y;
  113. #endif
  114. vec4 environmentSheenRadiance = vec4(0., 0., 0., 0.);
  115. sampleReflectionTexture(
  116. sheenAlphaG,
  117. vReflectionMicrosurfaceInfos,
  118. vReflectionInfos,
  119. #if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)
  120. NdotVUnclamped,
  121. #endif
  122. #ifdef LINEARSPECULARREFLECTION
  123. sheenRoughness,
  124. #endif
  125. reflectionSampler,
  126. reflectionCoords,
  127. environmentSheenRadiance
  128. );
  129. vec3 sheenEnvironmentReflectance = getSheenReflectanceFromBRDFLookup(sheenColor, environmentSheenBrdf);
  130. #if !defined(REFLECTIONMAP_SKYBOX) && defined(RADIANCEOCCLUSION)
  131. sheenEnvironmentReflectance *= seo;
  132. #endif
  133. #if !defined(REFLECTIONMAP_SKYBOX) && defined(HORIZONOCCLUSION) && defined(BUMP) && defined(REFLECTIONMAP_3D)
  134. sheenEnvironmentReflectance *= eho;
  135. #endif
  136. #if DEBUGMODE > 0
  137. outParams.sheenEnvironmentReflectance = sheenEnvironmentReflectance;
  138. #endif
  139. outParams.finalSheenRadianceScaled =
  140. environmentSheenRadiance.rgb *
  141. sheenEnvironmentReflectance *
  142. vLightingIntensity.z;
  143. // #if defined(MS_BRDF_ENERGY_CONSERVATION)
  144. // The sheen does not use the same BRDF so not energy conservation is possible
  145. // Should be less a problem as it is usually not metallic
  146. // finalSheenScaled *= energyConservationFactor;
  147. // #endif
  148. #endif
  149. #if defined(ENVIRONMENTBRDF) && defined(SHEEN_ALBEDOSCALING)
  150. // Sheen Lobe Layering.
  151. // environmentSheenBrdf.b is (integral on hemisphere)[f_sheen*cos(theta)*dtheta*dphi], which happens to also be the directional albedo needed for albedo scaling.
  152. // See section 6.2.3 in https://dassaultsystemes-technology.github.io/EnterprisePBRShadingModel/spec-2021x.md.html#components/sheen
  153. outParams.sheenAlbedoScaling = 1.0 - sheenIntensity * max(max(sheenColor.r, sheenColor.g), sheenColor.b) * environmentSheenBrdf.b;
  154. #endif
  155. // _____________________________ Out parameters __________________________
  156. outParams.sheenIntensity = sheenIntensity;
  157. outParams.sheenColor = sheenColor;
  158. outParams.sheenRoughness = sheenRoughness;
  159. }
  160. #endif