pbrBlockSheen.fx 7.3 KB

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