pbr.fragment.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. // Do not edit.
  2. import { ShaderStore } from "../Engines/shaderStore.js";
  3. import "./ShadersInclude/prePassDeclaration.js";
  4. import "./ShadersInclude/oitDeclaration.js";
  5. import "./ShadersInclude/pbrFragmentDeclaration.js";
  6. import "./ShadersInclude/pbrUboDeclaration.js";
  7. import "./ShadersInclude/pbrFragmentExtraDeclaration.js";
  8. import "./ShadersInclude/lightFragmentDeclaration.js";
  9. import "./ShadersInclude/lightUboDeclaration.js";
  10. import "./ShadersInclude/pbrFragmentSamplersDeclaration.js";
  11. import "./ShadersInclude/imageProcessingDeclaration.js";
  12. import "./ShadersInclude/clipPlaneFragmentDeclaration.js";
  13. import "./ShadersInclude/logDepthDeclaration.js";
  14. import "./ShadersInclude/fogFragmentDeclaration.js";
  15. import "./ShadersInclude/helperFunctions.js";
  16. import "./ShadersInclude/subSurfaceScatteringFunctions.js";
  17. import "./ShadersInclude/importanceSampling.js";
  18. import "./ShadersInclude/pbrHelperFunctions.js";
  19. import "./ShadersInclude/imageProcessingFunctions.js";
  20. import "./ShadersInclude/shadowsFragmentFunctions.js";
  21. import "./ShadersInclude/harmonicsFunctions.js";
  22. import "./ShadersInclude/pbrDirectLightingSetupFunctions.js";
  23. import "./ShadersInclude/pbrDirectLightingFalloffFunctions.js";
  24. import "./ShadersInclude/pbrBRDFFunctions.js";
  25. import "./ShadersInclude/hdrFilteringFunctions.js";
  26. import "./ShadersInclude/pbrDirectLightingFunctions.js";
  27. import "./ShadersInclude/pbrIBLFunctions.js";
  28. import "./ShadersInclude/bumpFragmentMainFunctions.js";
  29. import "./ShadersInclude/bumpFragmentFunctions.js";
  30. import "./ShadersInclude/reflectionFunction.js";
  31. import "./ShadersInclude/pbrBlockAlbedoOpacity.js";
  32. import "./ShadersInclude/pbrBlockReflectivity.js";
  33. import "./ShadersInclude/pbrBlockAmbientOcclusion.js";
  34. import "./ShadersInclude/pbrBlockAlphaFresnel.js";
  35. import "./ShadersInclude/pbrBlockAnisotropic.js";
  36. import "./ShadersInclude/pbrBlockReflection.js";
  37. import "./ShadersInclude/pbrBlockSheen.js";
  38. import "./ShadersInclude/pbrBlockClearcoat.js";
  39. import "./ShadersInclude/pbrBlockIridescence.js";
  40. import "./ShadersInclude/pbrBlockSubSurface.js";
  41. import "./ShadersInclude/clipPlaneFragment.js";
  42. import "./ShadersInclude/pbrBlockNormalGeometric.js";
  43. import "./ShadersInclude/bumpFragment.js";
  44. import "./ShadersInclude/pbrBlockNormalFinal.js";
  45. import "./ShadersInclude/depthPrePass.js";
  46. import "./ShadersInclude/pbrBlockLightmapInit.js";
  47. import "./ShadersInclude/pbrBlockGeometryInfo.js";
  48. import "./ShadersInclude/pbrBlockReflectance0.js";
  49. import "./ShadersInclude/pbrBlockReflectance.js";
  50. import "./ShadersInclude/pbrBlockDirectLighting.js";
  51. import "./ShadersInclude/lightFragment.js";
  52. import "./ShadersInclude/pbrBlockFinalLitComponents.js";
  53. import "./ShadersInclude/pbrBlockFinalUnlitComponents.js";
  54. import "./ShadersInclude/pbrBlockFinalColorComposition.js";
  55. import "./ShadersInclude/logDepthFragment.js";
  56. import "./ShadersInclude/fogFragment.js";
  57. import "./ShadersInclude/pbrBlockImageProcessing.js";
  58. import "./ShadersInclude/oitFragment.js";
  59. import "./ShadersInclude/pbrDebug.js";
  60. const name = "pbrPixelShader";
  61. const shader = `#if defined(BUMP) || !defined(NORMAL) || defined(FORCENORMALFORWARD) || defined(SPECULARAA) || defined(CLEARCOAT_BUMP) || defined(ANISOTROPIC)
  62. #extension GL_OES_standard_derivatives : enable
  63. #endif
  64. #ifdef LODBASEDMICROSFURACE
  65. #extension GL_EXT_shader_texture_lod : enable
  66. #endif
  67. #define CUSTOM_FRAGMENT_BEGIN
  68. #ifdef LOGARITHMICDEPTH
  69. #extension GL_EXT_frag_depth : enable
  70. #endif
  71. #include<prePassDeclaration>[SCENE_MRT_COUNT]
  72. precision highp float;
  73. #include<oitDeclaration>
  74. #ifndef FROMLINEARSPACE
  75. #define FROMLINEARSPACE
  76. #endif
  77. #include<__decl__pbrFragment>
  78. #include<pbrFragmentExtraDeclaration>
  79. #include<__decl__lightFragment>[0..maxSimultaneousLights]
  80. #include<pbrFragmentSamplersDeclaration>
  81. #include<imageProcessingDeclaration>
  82. #include<clipPlaneFragmentDeclaration>
  83. #include<logDepthDeclaration>
  84. #include<fogFragmentDeclaration>
  85. #include<helperFunctions>
  86. #include<subSurfaceScatteringFunctions>
  87. #include<importanceSampling>
  88. #include<pbrHelperFunctions>
  89. #include<imageProcessingFunctions>
  90. #include<shadowsFragmentFunctions>
  91. #include<harmonicsFunctions>
  92. #include<pbrDirectLightingSetupFunctions>
  93. #include<pbrDirectLightingFalloffFunctions>
  94. #include<pbrBRDFFunctions>
  95. #include<hdrFilteringFunctions>
  96. #include<pbrDirectLightingFunctions>
  97. #include<pbrIBLFunctions>
  98. #include<bumpFragmentMainFunctions>
  99. #include<bumpFragmentFunctions>
  100. #ifdef REFLECTION
  101. #include<reflectionFunction>
  102. #endif
  103. #define CUSTOM_FRAGMENT_DEFINITIONS
  104. #include<pbrBlockAlbedoOpacity>
  105. #include<pbrBlockReflectivity>
  106. #include<pbrBlockAmbientOcclusion>
  107. #include<pbrBlockAlphaFresnel>
  108. #include<pbrBlockAnisotropic>
  109. #include<pbrBlockReflection>
  110. #include<pbrBlockSheen>
  111. #include<pbrBlockClearcoat>
  112. #include<pbrBlockIridescence>
  113. #include<pbrBlockSubSurface>
  114. void main(void) {
  115. #define CUSTOM_FRAGMENT_MAIN_BEGIN
  116. #include<clipPlaneFragment>
  117. #include<pbrBlockNormalGeometric>
  118. #include<bumpFragment>
  119. #include<pbrBlockNormalFinal>
  120. albedoOpacityOutParams albedoOpacityOut;
  121. #ifdef ALBEDO
  122. vec4 albedoTexture=texture2D(albedoSampler,vAlbedoUV+uvOffset);
  123. #endif
  124. #ifdef OPACITY
  125. vec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);
  126. #endif
  127. #ifdef DECAL
  128. vec4 decalColor=texture2D(decalSampler,vDecalUV+uvOffset);
  129. #endif
  130. albedoOpacityBlock(
  131. vAlbedoColor,
  132. #ifdef ALBEDO
  133. albedoTexture,
  134. vAlbedoInfos,
  135. #endif
  136. #ifdef OPACITY
  137. opacityMap,
  138. vOpacityInfos,
  139. #endif
  140. #ifdef DETAIL
  141. detailColor,
  142. vDetailInfos,
  143. #endif
  144. #ifdef DECAL
  145. decalColor,
  146. vDecalInfos,
  147. #endif
  148. albedoOpacityOut
  149. );vec3 surfaceAlbedo=albedoOpacityOut.surfaceAlbedo;float alpha=albedoOpacityOut.alpha;
  150. #define CUSTOM_FRAGMENT_UPDATE_ALPHA
  151. #include<depthPrePass>
  152. #define CUSTOM_FRAGMENT_BEFORE_LIGHTS
  153. ambientOcclusionOutParams aoOut;
  154. #ifdef AMBIENT
  155. vec3 ambientOcclusionColorMap=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb;
  156. #endif
  157. ambientOcclusionBlock(
  158. #ifdef AMBIENT
  159. ambientOcclusionColorMap,
  160. vAmbientInfos,
  161. #endif
  162. aoOut
  163. );
  164. #include<pbrBlockLightmapInit>
  165. #ifdef UNLIT
  166. vec3 diffuseBase=vec3(1.,1.,1.);
  167. #else
  168. vec3 baseColor=surfaceAlbedo;reflectivityOutParams reflectivityOut;
  169. #if defined(REFLECTIVITY)
  170. vec4 surfaceMetallicOrReflectivityColorMap=texture2D(reflectivitySampler,vReflectivityUV+uvOffset);vec4 baseReflectivity=surfaceMetallicOrReflectivityColorMap;
  171. #ifndef METALLICWORKFLOW
  172. #ifdef REFLECTIVITY_GAMMA
  173. surfaceMetallicOrReflectivityColorMap=toLinearSpace(surfaceMetallicOrReflectivityColorMap);
  174. #endif
  175. surfaceMetallicOrReflectivityColorMap.rgb*=vReflectivityInfos.y;
  176. #endif
  177. #endif
  178. #if defined(MICROSURFACEMAP)
  179. vec4 microSurfaceTexel=texture2D(microSurfaceSampler,vMicroSurfaceSamplerUV+uvOffset)*vMicroSurfaceSamplerInfos.y;
  180. #endif
  181. #ifdef METALLICWORKFLOW
  182. vec4 metallicReflectanceFactors=vMetallicReflectanceFactors;
  183. #ifdef REFLECTANCE
  184. vec4 reflectanceFactorsMap=texture2D(reflectanceSampler,vReflectanceUV+uvOffset);
  185. #ifdef REFLECTANCE_GAMMA
  186. reflectanceFactorsMap=toLinearSpace(reflectanceFactorsMap);
  187. #endif
  188. metallicReflectanceFactors.rgb*=reflectanceFactorsMap.rgb;
  189. #endif
  190. #ifdef METALLIC_REFLECTANCE
  191. vec4 metallicReflectanceFactorsMap=texture2D(metallicReflectanceSampler,vMetallicReflectanceUV+uvOffset);
  192. #ifdef METALLIC_REFLECTANCE_GAMMA
  193. metallicReflectanceFactorsMap=toLinearSpace(metallicReflectanceFactorsMap);
  194. #endif
  195. #ifndef METALLIC_REFLECTANCE_USE_ALPHA_ONLY
  196. metallicReflectanceFactors.rgb*=metallicReflectanceFactorsMap.rgb;
  197. #endif
  198. metallicReflectanceFactors*=metallicReflectanceFactorsMap.a;
  199. #endif
  200. #endif
  201. reflectivityBlock(
  202. vReflectivityColor,
  203. #ifdef METALLICWORKFLOW
  204. surfaceAlbedo,
  205. metallicReflectanceFactors,
  206. #endif
  207. #ifdef REFLECTIVITY
  208. vReflectivityInfos,
  209. surfaceMetallicOrReflectivityColorMap,
  210. #endif
  211. #if defined(METALLICWORKFLOW) && defined(REFLECTIVITY) && defined(AOSTOREINMETALMAPRED)
  212. aoOut.ambientOcclusionColor,
  213. #endif
  214. #ifdef MICROSURFACEMAP
  215. microSurfaceTexel,
  216. #endif
  217. #ifdef DETAIL
  218. detailColor,
  219. vDetailInfos,
  220. #endif
  221. reflectivityOut
  222. );float microSurface=reflectivityOut.microSurface;float roughness=reflectivityOut.roughness;
  223. #ifdef METALLICWORKFLOW
  224. surfaceAlbedo=reflectivityOut.surfaceAlbedo;
  225. #endif
  226. #if defined(METALLICWORKFLOW) && defined(REFLECTIVITY) && defined(AOSTOREINMETALMAPRED)
  227. aoOut.ambientOcclusionColor=reflectivityOut.ambientOcclusionColor;
  228. #endif
  229. #ifdef ALPHAFRESNEL
  230. #if defined(ALPHATEST) || defined(ALPHABLEND)
  231. alphaFresnelOutParams alphaFresnelOut;alphaFresnelBlock(
  232. normalW,
  233. viewDirectionW,
  234. alpha,
  235. microSurface,
  236. alphaFresnelOut
  237. );alpha=alphaFresnelOut.alpha;
  238. #endif
  239. #endif
  240. #include<pbrBlockGeometryInfo>
  241. #ifdef ANISOTROPIC
  242. anisotropicOutParams anisotropicOut;
  243. #ifdef ANISOTROPIC_TEXTURE
  244. vec3 anisotropyMapData=texture2D(anisotropySampler,vAnisotropyUV+uvOffset).rgb*vAnisotropyInfos.y;
  245. #endif
  246. anisotropicBlock(
  247. vAnisotropy,
  248. roughness,
  249. #ifdef ANISOTROPIC_TEXTURE
  250. anisotropyMapData,
  251. #endif
  252. TBN,
  253. normalW,
  254. viewDirectionW,
  255. anisotropicOut
  256. );
  257. #endif
  258. #ifdef REFLECTION
  259. reflectionOutParams reflectionOut;
  260. #ifndef USE_CUSTOM_REFLECTION
  261. reflectionBlock(
  262. vPositionW,
  263. normalW,
  264. alphaG,
  265. vReflectionMicrosurfaceInfos,
  266. vReflectionInfos,
  267. vReflectionColor,
  268. #ifdef ANISOTROPIC
  269. anisotropicOut,
  270. #endif
  271. #if defined(LODINREFLECTIONALPHA) && !defined(REFLECTIONMAP_SKYBOX)
  272. NdotVUnclamped,
  273. #endif
  274. #ifdef LINEARSPECULARREFLECTION
  275. roughness,
  276. #endif
  277. reflectionSampler,
  278. #if defined(NORMAL) && defined(USESPHERICALINVERTEX)
  279. vEnvironmentIrradiance,
  280. #endif
  281. #ifdef USESPHERICALFROMREFLECTIONMAP
  282. #if !defined(NORMAL) || !defined(USESPHERICALINVERTEX)
  283. reflectionMatrix,
  284. #endif
  285. #endif
  286. #ifdef USEIRRADIANCEMAP
  287. irradianceSampler,
  288. #endif
  289. #ifndef LODBASEDMICROSFURACE
  290. reflectionSamplerLow,
  291. reflectionSamplerHigh,
  292. #endif
  293. #ifdef REALTIME_FILTERING
  294. vReflectionFilteringInfo,
  295. #endif
  296. reflectionOut
  297. );
  298. #else
  299. #define CUSTOM_REFLECTION
  300. #endif
  301. #endif
  302. #include<pbrBlockReflectance0>
  303. #ifdef SHEEN
  304. sheenOutParams sheenOut;
  305. #ifdef SHEEN_TEXTURE
  306. vec4 sheenMapData=texture2D(sheenSampler,vSheenUV+uvOffset);
  307. #endif
  308. #if defined(SHEEN_ROUGHNESS) && defined(SHEEN_TEXTURE_ROUGHNESS) && !defined(SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE)
  309. vec4 sheenMapRoughnessData=texture2D(sheenRoughnessSampler,vSheenRoughnessUV+uvOffset)*vSheenInfos.w;
  310. #endif
  311. sheenBlock(
  312. vSheenColor,
  313. #ifdef SHEEN_ROUGHNESS
  314. vSheenRoughness,
  315. #if defined(SHEEN_TEXTURE_ROUGHNESS) && !defined(SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE)
  316. sheenMapRoughnessData,
  317. #endif
  318. #endif
  319. roughness,
  320. #ifdef SHEEN_TEXTURE
  321. sheenMapData,
  322. vSheenInfos.y,
  323. #endif
  324. reflectance,
  325. #ifdef SHEEN_LINKWITHALBEDO
  326. baseColor,
  327. surfaceAlbedo,
  328. #endif
  329. #ifdef ENVIRONMENTBRDF
  330. NdotV,
  331. environmentBrdf,
  332. #endif
  333. #if defined(REFLECTION) && defined(ENVIRONMENTBRDF)
  334. AARoughnessFactors,
  335. vReflectionMicrosurfaceInfos,
  336. vReflectionInfos,
  337. vReflectionColor,
  338. vLightingIntensity,
  339. reflectionSampler,
  340. reflectionOut.reflectionCoords,
  341. NdotVUnclamped,
  342. #ifndef LODBASEDMICROSFURACE
  343. reflectionSamplerLow,
  344. reflectionSamplerHigh,
  345. #endif
  346. #ifdef REALTIME_FILTERING
  347. vReflectionFilteringInfo,
  348. #endif
  349. #if !defined(REFLECTIONMAP_SKYBOX) && defined(RADIANCEOCCLUSION)
  350. seo,
  351. #endif
  352. #if !defined(REFLECTIONMAP_SKYBOX) && defined(HORIZONOCCLUSION) && defined(BUMP) && defined(REFLECTIONMAP_3D)
  353. eho,
  354. #endif
  355. #endif
  356. sheenOut
  357. );
  358. #ifdef SHEEN_LINKWITHALBEDO
  359. surfaceAlbedo=sheenOut.surfaceAlbedo;
  360. #endif
  361. #endif
  362. #ifdef CLEARCOAT
  363. #ifdef CLEARCOAT_TEXTURE
  364. vec2 clearCoatMapData=texture2D(clearCoatSampler,vClearCoatUV+uvOffset).rg*vClearCoatInfos.y;
  365. #endif
  366. #endif
  367. #ifdef IRIDESCENCE
  368. iridescenceOutParams iridescenceOut;
  369. #ifdef IRIDESCENCE_TEXTURE
  370. vec2 iridescenceMapData=texture2D(iridescenceSampler,vIridescenceUV+uvOffset).rg*vIridescenceInfos.y;
  371. #endif
  372. #ifdef IRIDESCENCE_THICKNESS_TEXTURE
  373. vec2 iridescenceThicknessMapData=texture2D(iridescenceThicknessSampler,vIridescenceThicknessUV+uvOffset).rg*vIridescenceInfos.w;
  374. #endif
  375. iridescenceBlock(
  376. vIridescenceParams,
  377. NdotV,
  378. specularEnvironmentR0,
  379. #ifdef IRIDESCENCE_TEXTURE
  380. iridescenceMapData,
  381. #endif
  382. #ifdef IRIDESCENCE_THICKNESS_TEXTURE
  383. iridescenceThicknessMapData,
  384. #endif
  385. #ifdef CLEARCOAT
  386. NdotVUnclamped,
  387. #ifdef CLEARCOAT_TEXTURE
  388. clearCoatMapData,
  389. #endif
  390. #endif
  391. iridescenceOut
  392. );float iridescenceIntensity=iridescenceOut.iridescenceIntensity;specularEnvironmentR0=iridescenceOut.specularEnvironmentR0;
  393. #endif
  394. clearcoatOutParams clearcoatOut;
  395. #ifdef CLEARCOAT
  396. #if defined(CLEARCOAT_TEXTURE_ROUGHNESS) && !defined(CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE)
  397. vec4 clearCoatMapRoughnessData=texture2D(clearCoatRoughnessSampler,vClearCoatRoughnessUV+uvOffset)*vClearCoatInfos.w;
  398. #endif
  399. #if defined(CLEARCOAT_TINT) && defined(CLEARCOAT_TINT_TEXTURE)
  400. vec4 clearCoatTintMapData=texture2D(clearCoatTintSampler,vClearCoatTintUV+uvOffset);
  401. #endif
  402. #ifdef CLEARCOAT_BUMP
  403. vec4 clearCoatBumpMapData=texture2D(clearCoatBumpSampler,vClearCoatBumpUV+uvOffset);
  404. #endif
  405. clearcoatBlock(
  406. vPositionW,
  407. geometricNormalW,
  408. viewDirectionW,
  409. vClearCoatParams,
  410. #if defined(CLEARCOAT_TEXTURE_ROUGHNESS) && !defined(CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE)
  411. clearCoatMapRoughnessData,
  412. #endif
  413. specularEnvironmentR0,
  414. #ifdef CLEARCOAT_TEXTURE
  415. clearCoatMapData,
  416. #endif
  417. #ifdef CLEARCOAT_TINT
  418. vClearCoatTintParams,
  419. clearCoatColorAtDistance,
  420. vClearCoatRefractionParams,
  421. #ifdef CLEARCOAT_TINT_TEXTURE
  422. clearCoatTintMapData,
  423. #endif
  424. #endif
  425. #ifdef CLEARCOAT_BUMP
  426. vClearCoatBumpInfos,
  427. clearCoatBumpMapData,
  428. vClearCoatBumpUV,
  429. #if defined(TANGENT) && defined(NORMAL)
  430. vTBN,
  431. #else
  432. vClearCoatTangentSpaceParams,
  433. #endif
  434. #ifdef OBJECTSPACE_NORMALMAP
  435. normalMatrix,
  436. #endif
  437. #endif
  438. #if defined(FORCENORMALFORWARD) && defined(NORMAL)
  439. faceNormal,
  440. #endif
  441. #ifdef REFLECTION
  442. vReflectionMicrosurfaceInfos,
  443. vReflectionInfos,
  444. vReflectionColor,
  445. vLightingIntensity,
  446. reflectionSampler,
  447. #ifndef LODBASEDMICROSFURACE
  448. reflectionSamplerLow,
  449. reflectionSamplerHigh,
  450. #endif
  451. #ifdef REALTIME_FILTERING
  452. vReflectionFilteringInfo,
  453. #endif
  454. #endif
  455. #if defined(ENVIRONMENTBRDF) && !defined(REFLECTIONMAP_SKYBOX)
  456. #ifdef RADIANCEOCCLUSION
  457. ambientMonochrome,
  458. #endif
  459. #endif
  460. #if defined(CLEARCOAT_BUMP) || defined(TWOSIDEDLIGHTING)
  461. (gl_FrontFacing ? 1. : -1.),
  462. #endif
  463. clearcoatOut
  464. );
  465. #else
  466. clearcoatOut.specularEnvironmentR0=specularEnvironmentR0;
  467. #endif
  468. #include<pbrBlockReflectance>
  469. subSurfaceOutParams subSurfaceOut;
  470. #ifdef SUBSURFACE
  471. #ifdef SS_THICKNESSANDMASK_TEXTURE
  472. vec4 thicknessMap=texture2D(thicknessSampler,vThicknessUV+uvOffset);
  473. #endif
  474. #ifdef SS_REFRACTIONINTENSITY_TEXTURE
  475. vec4 refractionIntensityMap=texture2D(refractionIntensitySampler,vRefractionIntensityUV+uvOffset);
  476. #endif
  477. #ifdef SS_TRANSLUCENCYINTENSITY_TEXTURE
  478. vec4 translucencyIntensityMap=texture2D(translucencyIntensitySampler,vTranslucencyIntensityUV+uvOffset);
  479. #endif
  480. subSurfaceBlock(
  481. vSubSurfaceIntensity,
  482. vThicknessParam,
  483. vTintColor,
  484. normalW,
  485. specularEnvironmentReflectance,
  486. #ifdef SS_THICKNESSANDMASK_TEXTURE
  487. thicknessMap,
  488. #endif
  489. #ifdef SS_REFRACTIONINTENSITY_TEXTURE
  490. refractionIntensityMap,
  491. #endif
  492. #ifdef SS_TRANSLUCENCYINTENSITY_TEXTURE
  493. translucencyIntensityMap,
  494. #endif
  495. #ifdef REFLECTION
  496. #ifdef SS_TRANSLUCENCY
  497. reflectionMatrix,
  498. #ifdef USESPHERICALFROMREFLECTIONMAP
  499. #if !defined(NORMAL) || !defined(USESPHERICALINVERTEX)
  500. reflectionOut.irradianceVector,
  501. #endif
  502. #if defined(REALTIME_FILTERING)
  503. reflectionSampler,
  504. vReflectionFilteringInfo,
  505. #endif
  506. #endif
  507. #ifdef USEIRRADIANCEMAP
  508. irradianceSampler,
  509. #endif
  510. #endif
  511. #endif
  512. #if defined(SS_REFRACTION) || defined(SS_TRANSLUCENCY)
  513. surfaceAlbedo,
  514. #endif
  515. #ifdef SS_REFRACTION
  516. vPositionW,
  517. viewDirectionW,
  518. view,
  519. vRefractionInfos,
  520. refractionMatrix,
  521. vRefractionMicrosurfaceInfos,
  522. vLightingIntensity,
  523. #ifdef SS_LINKREFRACTIONTOTRANSPARENCY
  524. alpha,
  525. #endif
  526. #ifdef SS_LODINREFRACTIONALPHA
  527. NdotVUnclamped,
  528. #endif
  529. #ifdef SS_LINEARSPECULARREFRACTION
  530. roughness,
  531. #endif
  532. alphaG,
  533. refractionSampler,
  534. #ifndef LODBASEDMICROSFURACE
  535. refractionSamplerLow,
  536. refractionSamplerHigh,
  537. #endif
  538. #ifdef ANISOTROPIC
  539. anisotropicOut,
  540. #endif
  541. #ifdef REALTIME_FILTERING
  542. vRefractionFilteringInfo,
  543. #endif
  544. #ifdef SS_USE_LOCAL_REFRACTIONMAP_CUBIC
  545. vRefractionPosition,
  546. vRefractionSize,
  547. #endif
  548. #ifdef SS_DISPERSION
  549. dispersion,
  550. #endif
  551. #endif
  552. #ifdef SS_TRANSLUCENCY
  553. vDiffusionDistance,
  554. #endif
  555. subSurfaceOut
  556. );
  557. #ifdef SS_REFRACTION
  558. surfaceAlbedo=subSurfaceOut.surfaceAlbedo;
  559. #ifdef SS_LINKREFRACTIONTOTRANSPARENCY
  560. alpha=subSurfaceOut.alpha;
  561. #endif
  562. #endif
  563. #else
  564. subSurfaceOut.specularEnvironmentReflectance=specularEnvironmentReflectance;
  565. #endif
  566. #include<pbrBlockDirectLighting>
  567. #include<lightFragment>[0..maxSimultaneousLights]
  568. #include<pbrBlockFinalLitComponents>
  569. #endif
  570. #include<pbrBlockFinalUnlitComponents>
  571. #define CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION
  572. #include<pbrBlockFinalColorComposition>
  573. #include<logDepthFragment>
  574. #include<fogFragment>(color,finalColor)
  575. #include<pbrBlockImageProcessing>
  576. #define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR
  577. #ifdef PREPASS
  578. float writeGeometryInfo=finalColor.a>0.4 ? 1.0 : 0.0;
  579. #ifdef PREPASS_POSITION
  580. gl_FragData[PREPASS_POSITION_INDEX]=vec4(vPositionW,writeGeometryInfo);
  581. #endif
  582. #ifdef PREPASS_VELOCITY
  583. vec2 a=(vCurrentPosition.xy/vCurrentPosition.w)*0.5+0.5;vec2 b=(vPreviousPosition.xy/vPreviousPosition.w)*0.5+0.5;vec2 velocity=abs(a-b);velocity=vec2(pow(velocity.x,1.0/3.0),pow(velocity.y,1.0/3.0))*sign(a-b)*0.5+0.5;gl_FragData[PREPASS_VELOCITY_INDEX]=vec4(velocity,0.0,writeGeometryInfo);
  584. #endif
  585. #ifdef PREPASS_ALBEDO_SQRT
  586. vec3 sqAlbedo=sqrt(surfaceAlbedo);
  587. #endif
  588. #ifdef PREPASS_IRRADIANCE
  589. vec3 irradiance=finalDiffuse;
  590. #ifndef UNLIT
  591. #ifdef REFLECTION
  592. irradiance+=finalIrradiance;
  593. #endif
  594. #endif
  595. #ifdef SS_SCATTERING
  596. gl_FragData[0]=vec4(finalColor.rgb-irradiance,finalColor.a);
  597. irradiance/=sqAlbedo;
  598. #else
  599. gl_FragData[0]=finalColor;
  600. float scatteringDiffusionProfile=255.;
  601. #endif
  602. gl_FragData[PREPASS_IRRADIANCE_INDEX]=vec4(clamp(irradiance,vec3(0.),vec3(1.)),writeGeometryInfo*scatteringDiffusionProfile/255.);
  603. #else
  604. gl_FragData[0]=vec4(finalColor.rgb,finalColor.a);
  605. #endif
  606. #ifdef PREPASS_DEPTH
  607. gl_FragData[PREPASS_DEPTH_INDEX]=vec4(vViewPos.z,0.0,0.0,writeGeometryInfo);
  608. #endif
  609. #ifdef PREPASS_NORMAL
  610. #ifdef PREPASS_NORMAL_WORLDSPACE
  611. gl_FragData[PREPASS_NORMAL_INDEX]=vec4(normalW,writeGeometryInfo);
  612. #else
  613. gl_FragData[PREPASS_NORMAL_INDEX]=vec4(normalize((view*vec4(normalW,0.0)).rgb),writeGeometryInfo);
  614. #endif
  615. #endif
  616. #ifdef PREPASS_ALBEDO_SQRT
  617. gl_FragData[PREPASS_ALBEDO_SQRT_INDEX]=vec4(sqAlbedo,writeGeometryInfo);
  618. #endif
  619. #ifdef PREPASS_REFLECTIVITY
  620. #ifndef UNLIT
  621. gl_FragData[PREPASS_REFLECTIVITY_INDEX]=vec4(specularEnvironmentR0,microSurface)*writeGeometryInfo;
  622. #else
  623. gl_FragData[PREPASS_REFLECTIVITY_INDEX]=vec4( 0.0,0.0,0.0,1.0 )*writeGeometryInfo;
  624. #endif
  625. #endif
  626. #endif
  627. #if !defined(PREPASS) || defined(WEBGL2)
  628. gl_FragColor=finalColor;
  629. #endif
  630. #include<oitFragment>
  631. #if ORDER_INDEPENDENT_TRANSPARENCY
  632. if (fragDepth==nearestDepth) {frontColor.rgb+=finalColor.rgb*finalColor.a*alphaMultiplier;frontColor.a=1.0-alphaMultiplier*(1.0-finalColor.a);} else {backColor+=finalColor;}
  633. #endif
  634. #include<pbrDebug>
  635. #define CUSTOM_FRAGMENT_MAIN_END
  636. }
  637. `;
  638. // Sideeffect
  639. ShaderStore.ShadersStore[name] = shader;
  640. /** @internal */
  641. export const pbrPixelShader = { name, shader };
  642. //# sourceMappingURL=pbr.fragment.js.map