pbrBlockSheen.fx 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. #ifdef REFLECTIONMAP_3D
  55. const in samplerCube reflectionSamplerLow,
  56. const in samplerCube reflectionSamplerHigh,
  57. #else
  58. const in sampler2D reflectionSamplerLow,
  59. const in sampler2D reflectionSamplerHigh,
  60. #endif
  61. #endif
  62. #if !defined(REFLECTIONMAP_SKYBOX) && defined(RADIANCEOCCLUSION)
  63. const in float seo,
  64. #endif
  65. #if !defined(REFLECTIONMAP_SKYBOX) && defined(HORIZONOCCLUSION) && defined(BUMP) && defined(REFLECTIONMAP_3D)
  66. const in float eho,
  67. #endif
  68. #endif
  69. out sheenOutParams outParams
  70. )
  71. {
  72. float sheenIntensity = vSheenColor.a;
  73. #ifdef SHEEN_TEXTURE
  74. sheenIntensity *= sheenMapData.a;
  75. #if DEBUGMODE > 0
  76. outParams.sheenMapData = sheenMapData;
  77. #endif
  78. #endif
  79. #ifdef SHEEN_LINKWITHALBEDO
  80. float sheenFactor = pow5(1.0-sheenIntensity);
  81. vec3 sheenColor = baseColor.rgb*(1.0-sheenFactor);
  82. float sheenRoughness = sheenIntensity;
  83. outParams.surfaceAlbedo = surfaceAlbedo * sheenFactor;
  84. #else
  85. vec3 sheenColor = vSheenColor.rgb;
  86. #ifdef SHEEN_TEXTURE
  87. sheenColor.rgb *= sheenMapData.rgb;
  88. #endif
  89. #ifdef SHEEN_ROUGHNESS
  90. float sheenRoughness = vSheenRoughness;
  91. #else
  92. float sheenRoughness = roughness;
  93. #endif
  94. // Sheen Lobe Layering.
  95. #if !defined(SHEEN_ALBEDOSCALING)
  96. sheenIntensity *= (1. - reflectance);
  97. #endif
  98. // Remap F0 and sheen.
  99. sheenColor *= sheenIntensity;
  100. #endif
  101. // _____________________________ Sheen Environment __________________________
  102. #ifdef ENVIRONMENTBRDF
  103. /*#ifdef SHEEN_SOFTER
  104. vec3 environmentSheenBrdf = vec3(0., 0., getBRDFLookupCharlieSheen(NdotV, sheenRoughness));
  105. #else*/
  106. #ifdef SHEEN_ROUGHNESS
  107. vec3 environmentSheenBrdf = getBRDFLookup(NdotV, sheenRoughness);
  108. #else
  109. vec3 environmentSheenBrdf = environmentBrdf;
  110. #endif
  111. /*#endif*/
  112. #endif
  113. #if defined(REFLECTION) && defined(ENVIRONMENTBRDF)
  114. float sheenAlphaG = convertRoughnessToAverageSlope(sheenRoughness);
  115. #ifdef SPECULARAA
  116. // Adapt linear roughness (alphaG) to geometric curvature of the current pixel.
  117. sheenAlphaG += AARoughnessFactors.y;
  118. #endif
  119. vec4 environmentSheenRadiance = vec4(0., 0., 0., 0.);
  120. sampleReflectionTexture(
  121. sheenAlphaG,
  122. vReflectionMicrosurfaceInfos,
  123. vReflectionInfos,
  124. #if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)
  125. NdotVUnclamped,
  126. #endif
  127. #ifdef LINEARSPECULARREFLECTION
  128. sheenRoughness,
  129. #endif
  130. reflectionSampler,
  131. reflectionCoords,
  132. #ifndef LODBASEDMICROSFURACE
  133. reflectionSamplerLow,
  134. reflectionSamplerHigh,
  135. #endif
  136. environmentSheenRadiance
  137. );
  138. vec3 sheenEnvironmentReflectance = getSheenReflectanceFromBRDFLookup(sheenColor, environmentSheenBrdf);
  139. #if !defined(REFLECTIONMAP_SKYBOX) && defined(RADIANCEOCCLUSION)
  140. sheenEnvironmentReflectance *= seo;
  141. #endif
  142. #if !defined(REFLECTIONMAP_SKYBOX) && defined(HORIZONOCCLUSION) && defined(BUMP) && defined(REFLECTIONMAP_3D)
  143. sheenEnvironmentReflectance *= eho;
  144. #endif
  145. #if DEBUGMODE > 0
  146. outParams.sheenEnvironmentReflectance = sheenEnvironmentReflectance;
  147. #endif
  148. outParams.finalSheenRadianceScaled =
  149. environmentSheenRadiance.rgb *
  150. sheenEnvironmentReflectance *
  151. vLightingIntensity.z;
  152. // #if defined(MS_BRDF_ENERGY_CONSERVATION)
  153. // The sheen does not use the same BRDF so not energy conservation is possible
  154. // Should be less a problem as it is usually not metallic
  155. // finalSheenScaled *= energyConservationFactor;
  156. // #endif
  157. #endif
  158. #if defined(ENVIRONMENTBRDF) && defined(SHEEN_ALBEDOSCALING)
  159. // Sheen Lobe Layering.
  160. // environmentSheenBrdf.b is (integral on hemisphere)[f_sheen*cos(theta)*dtheta*dphi], which happens to also be the directional albedo needed for albedo scaling.
  161. // See section 6.2.3 in https://dassaultsystemes-technology.github.io/EnterprisePBRShadingModel/spec-2021x.md.html#components/sheen
  162. outParams.sheenAlbedoScaling = 1.0 - sheenIntensity * max(max(sheenColor.r, sheenColor.g), sheenColor.b) * environmentSheenBrdf.b;
  163. #endif
  164. // _____________________________ Out parameters __________________________
  165. outParams.sheenIntensity = sheenIntensity;
  166. outParams.sheenColor = sheenColor;
  167. outParams.sheenRoughness = sheenRoughness;
  168. }
  169. #endif