@luma.gl/shaders 0.0.0-stage → 10.0.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (692) hide show
  1. package/README.md +25 -2
  2. package/dist/dist.dev.js +19686 -0
  3. package/dist/dist.min.js +12180 -0
  4. package/dist/glsl.cjs +33 -0
  5. package/dist/glsl.cjs.map +6 -0
  6. package/dist/glsl.d.ts +6 -0
  7. package/dist/glsl.d.ts.map +1 -0
  8. package/dist/glsl.js +7 -0
  9. package/dist/glsl.js.map +1 -0
  10. package/dist/index.cjs +243 -0
  11. package/dist/index.cjs.map +6 -0
  12. package/dist/index.d.ts +91 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +65 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/lib/color/normalize-byte-colors.cjs +50 -0
  17. package/dist/lib/color/normalize-byte-colors.d.ts +23 -0
  18. package/dist/lib/color/normalize-byte-colors.d.ts.map +1 -0
  19. package/dist/lib/color/normalize-byte-colors.js +42 -0
  20. package/dist/lib/color/normalize-byte-colors.js.map +1 -0
  21. package/dist/lib/filters/prop-types.cjs +90 -0
  22. package/dist/lib/filters/prop-types.d.ts +44 -0
  23. package/dist/lib/filters/prop-types.d.ts.map +1 -0
  24. package/dist/lib/filters/prop-types.js +96 -0
  25. package/dist/lib/filters/prop-types.js.map +1 -0
  26. package/dist/lib/glsl-shader-assembler.cjs +50 -0
  27. package/dist/lib/glsl-shader-assembler.d.ts +19 -0
  28. package/dist/lib/glsl-shader-assembler.d.ts.map +1 -0
  29. package/dist/lib/glsl-shader-assembler.js +29 -0
  30. package/dist/lib/glsl-shader-assembler.js.map +1 -0
  31. package/dist/lib/glsl-utils/get-shader-info.cjs +52 -0
  32. package/dist/lib/glsl-utils/get-shader-info.d.ts +9 -0
  33. package/dist/lib/glsl-utils/get-shader-info.d.ts.map +1 -0
  34. package/dist/lib/glsl-utils/get-shader-info.js +33 -0
  35. package/dist/lib/glsl-utils/get-shader-info.js.map +1 -0
  36. package/dist/lib/glsl-utils/shader-utils.cjs +126 -0
  37. package/dist/lib/glsl-utils/shader-utils.d.ts +23 -0
  38. package/dist/lib/glsl-utils/shader-utils.d.ts.map +1 -0
  39. package/dist/lib/glsl-utils/shader-utils.js +92 -0
  40. package/dist/lib/glsl-utils/shader-utils.js.map +1 -0
  41. package/dist/lib/preprocessor/preprocessor.cjs +107 -0
  42. package/dist/lib/preprocessor/preprocessor.d.ts +15 -0
  43. package/dist/lib/preprocessor/preprocessor.d.ts.map +1 -0
  44. package/dist/lib/preprocessor/preprocessor.js +99 -0
  45. package/dist/lib/preprocessor/preprocessor.js.map +1 -0
  46. package/dist/lib/shader-assembler-base.cjs +133 -0
  47. package/dist/lib/shader-assembler-base.d.ts +52 -0
  48. package/dist/lib/shader-assembler-base.d.ts.map +1 -0
  49. package/dist/lib/shader-assembler-base.js +128 -0
  50. package/dist/lib/shader-assembler-base.js.map +1 -0
  51. package/dist/lib/shader-assembler.cjs +33 -0
  52. package/dist/lib/shader-assembler.d.ts +4 -0
  53. package/dist/lib/shader-assembler.d.ts.map +1 -0
  54. package/dist/lib/shader-assembler.js +7 -0
  55. package/dist/lib/shader-assembler.js.map +1 -0
  56. package/dist/lib/shader-assembly/assemble-glsl-shaders.cjs +200 -0
  57. package/dist/lib/shader-assembly/assemble-glsl-shaders.d.ts +69 -0
  58. package/dist/lib/shader-assembly/assemble-glsl-shaders.d.ts.map +1 -0
  59. package/dist/lib/shader-assembly/assemble-glsl-shaders.js +221 -0
  60. package/dist/lib/shader-assembly/assemble-glsl-shaders.js.map +1 -0
  61. package/dist/lib/shader-assembly/assemble-shaders.cjs +42 -0
  62. package/dist/lib/shader-assembly/assemble-shaders.d.ts +10 -0
  63. package/dist/lib/shader-assembly/assemble-shaders.d.ts.map +1 -0
  64. package/dist/lib/shader-assembly/assemble-shaders.js +10 -0
  65. package/dist/lib/shader-assembly/assemble-shaders.js.map +1 -0
  66. package/dist/lib/shader-assembly/assemble-wgsl-shaders.cjs +501 -0
  67. package/dist/lib/shader-assembly/assemble-wgsl-shaders.d.ts +71 -0
  68. package/dist/lib/shader-assembly/assemble-wgsl-shaders.d.ts.map +1 -0
  69. package/dist/lib/shader-assembly/assemble-wgsl-shaders.js +473 -0
  70. package/dist/lib/shader-assembly/assemble-wgsl-shaders.js.map +1 -0
  71. package/dist/lib/shader-assembly/platform-defines.cjs +79 -0
  72. package/dist/lib/shader-assembly/platform-defines.d.ts +4 -0
  73. package/dist/lib/shader-assembly/platform-defines.d.ts.map +1 -0
  74. package/dist/lib/shader-assembly/platform-defines.js +52 -0
  75. package/dist/lib/shader-assembly/platform-defines.js.map +1 -0
  76. package/dist/lib/shader-assembly/platform-info.cjs +15 -0
  77. package/dist/lib/shader-assembly/platform-info.d.ts +20 -0
  78. package/dist/lib/shader-assembly/platform-info.d.ts.map +1 -0
  79. package/dist/lib/shader-assembly/platform-info.js +5 -0
  80. package/dist/lib/shader-assembly/platform-info.js.map +1 -0
  81. package/dist/lib/shader-assembly/shader-assembly-shared.cjs +96 -0
  82. package/dist/lib/shader-assembly/shader-assembly-shared.d.ts +16 -0
  83. package/dist/lib/shader-assembly/shader-assembly-shared.d.ts.map +1 -0
  84. package/dist/lib/shader-assembly/shader-assembly-shared.js +79 -0
  85. package/dist/lib/shader-assembly/shader-assembly-shared.js.map +1 -0
  86. package/dist/lib/shader-assembly/shader-assembly-types.cjs +15 -0
  87. package/dist/lib/shader-assembly/shader-assembly-types.d.ts +128 -0
  88. package/dist/lib/shader-assembly/shader-assembly-types.d.ts.map +1 -0
  89. package/dist/lib/shader-assembly/shader-assembly-types.js +5 -0
  90. package/dist/lib/shader-assembly/shader-assembly-types.js.map +1 -0
  91. package/dist/lib/shader-assembly/shader-hooks.cjs +103 -0
  92. package/dist/lib/shader-assembly/shader-hooks.d.ts +45 -0
  93. package/dist/lib/shader-assembly/shader-hooks.d.ts.map +1 -0
  94. package/dist/lib/shader-assembly/shader-hooks.js +84 -0
  95. package/dist/lib/shader-assembly/shader-hooks.js.map +1 -0
  96. package/dist/lib/shader-assembly/shader-injections.cjs +180 -0
  97. package/dist/lib/shader-assembly/shader-injections.d.ts +34 -0
  98. package/dist/lib/shader-assembly/shader-injections.d.ts.map +1 -0
  99. package/dist/lib/shader-assembly/shader-injections.js +183 -0
  100. package/dist/lib/shader-assembly/shader-injections.js.map +1 -0
  101. package/dist/lib/shader-assembly/shader-plugin-varyings.cjs +417 -0
  102. package/dist/lib/shader-assembly/shader-plugin-varyings.d.ts +15 -0
  103. package/dist/lib/shader-assembly/shader-plugin-varyings.d.ts.map +1 -0
  104. package/dist/lib/shader-assembly/shader-plugin-varyings.js +412 -0
  105. package/dist/lib/shader-assembly/shader-plugin-varyings.js.map +1 -0
  106. package/dist/lib/shader-assembly/shader-plugin-vertex-inputs.cjs +254 -0
  107. package/dist/lib/shader-assembly/shader-plugin-vertex-inputs.d.ts +12 -0
  108. package/dist/lib/shader-assembly/shader-plugin-vertex-inputs.d.ts.map +1 -0
  109. package/dist/lib/shader-assembly/shader-plugin-vertex-inputs.js +237 -0
  110. package/dist/lib/shader-assembly/shader-plugin-vertex-inputs.js.map +1 -0
  111. package/dist/lib/shader-assembly/wgsl-binding-debug.cjs +166 -0
  112. package/dist/lib/shader-assembly/wgsl-binding-debug.d.ts +37 -0
  113. package/dist/lib/shader-assembly/wgsl-binding-debug.d.ts.map +1 -0
  114. package/dist/lib/shader-assembly/wgsl-binding-debug.js +144 -0
  115. package/dist/lib/shader-assembly/wgsl-binding-debug.js.map +1 -0
  116. package/dist/lib/shader-assembly/wgsl-binding-scan.cjs +184 -0
  117. package/dist/lib/shader-assembly/wgsl-binding-scan.d.ts +19 -0
  118. package/dist/lib/shader-assembly/wgsl-binding-scan.d.ts.map +1 -0
  119. package/dist/lib/shader-assembly/wgsl-binding-scan.js +151 -0
  120. package/dist/lib/shader-assembly/wgsl-binding-scan.js.map +1 -0
  121. package/dist/lib/shader-assembly/wgsl-interface-scan.cjs +502 -0
  122. package/dist/lib/shader-assembly/wgsl-interface-scan.d.ts +14 -0
  123. package/dist/lib/shader-assembly/wgsl-interface-scan.d.ts.map +1 -0
  124. package/dist/lib/shader-assembly/wgsl-interface-scan.js +498 -0
  125. package/dist/lib/shader-assembly/wgsl-interface-scan.js.map +1 -0
  126. package/dist/lib/shader-generator/generate-shader.cjs +36 -0
  127. package/dist/lib/shader-generator/generate-shader.d.ts +8 -0
  128. package/dist/lib/shader-generator/generate-shader.d.ts.map +1 -0
  129. package/dist/lib/shader-generator/generate-shader.js +15 -0
  130. package/dist/lib/shader-generator/generate-shader.js.map +1 -0
  131. package/dist/lib/shader-generator/glsl/generate-glsl.cjs +94 -0
  132. package/dist/lib/shader-generator/glsl/generate-glsl.d.ts +7 -0
  133. package/dist/lib/shader-generator/glsl/generate-glsl.d.ts.map +1 -0
  134. package/dist/lib/shader-generator/glsl/generate-glsl.js +79 -0
  135. package/dist/lib/shader-generator/glsl/generate-glsl.js.map +1 -0
  136. package/dist/lib/shader-generator/utils/capitalize.cjs +29 -0
  137. package/dist/lib/shader-generator/utils/capitalize.d.ts +7 -0
  138. package/dist/lib/shader-generator/utils/capitalize.d.ts.map +1 -0
  139. package/dist/lib/shader-generator/utils/capitalize.js +12 -0
  140. package/dist/lib/shader-generator/utils/capitalize.js.map +1 -0
  141. package/dist/lib/shader-generator/wgsl/generate-wgsl.cjs +46 -0
  142. package/dist/lib/shader-generator/wgsl/generate-wgsl.d.ts +7 -0
  143. package/dist/lib/shader-generator/wgsl/generate-wgsl.d.ts.map +1 -0
  144. package/dist/lib/shader-generator/wgsl/generate-wgsl.js +23 -0
  145. package/dist/lib/shader-generator/wgsl/generate-wgsl.js.map +1 -0
  146. package/dist/lib/shader-module/composite-shader-pass.cjs +15 -0
  147. package/dist/lib/shader-module/composite-shader-pass.d.ts +41 -0
  148. package/dist/lib/shader-module/composite-shader-pass.d.ts.map +1 -0
  149. package/dist/lib/shader-module/composite-shader-pass.js +5 -0
  150. package/dist/lib/shader-module/composite-shader-pass.js.map +1 -0
  151. package/dist/lib/shader-module/shader-module-dependencies.cjs +83 -0
  152. package/dist/lib/shader-module/shader-module-dependencies.d.ts +39 -0
  153. package/dist/lib/shader-module/shader-module-dependencies.d.ts.map +1 -0
  154. package/dist/lib/shader-module/shader-module-dependencies.js +103 -0
  155. package/dist/lib/shader-module/shader-module-dependencies.js.map +1 -0
  156. package/dist/lib/shader-module/shader-module-uniform-layout.cjs +224 -0
  157. package/dist/lib/shader-module/shader-module-uniform-layout.d.ts +91 -0
  158. package/dist/lib/shader-module/shader-module-uniform-layout.d.ts.map +1 -0
  159. package/dist/lib/shader-module/shader-module-uniform-layout.js +253 -0
  160. package/dist/lib/shader-module/shader-module-uniform-layout.js.map +1 -0
  161. package/dist/lib/shader-module/shader-module.cjs +105 -0
  162. package/dist/lib/shader-module/shader-module.d.ts +98 -0
  163. package/dist/lib/shader-module/shader-module.d.ts.map +1 -0
  164. package/dist/lib/shader-module/shader-module.js +104 -0
  165. package/dist/lib/shader-module/shader-module.js.map +1 -0
  166. package/dist/lib/shader-module/shader-pass.cjs +15 -0
  167. package/dist/lib/shader-module/shader-pass.d.ts +48 -0
  168. package/dist/lib/shader-module/shader-pass.d.ts.map +1 -0
  169. package/dist/lib/shader-module/shader-pass.js +5 -0
  170. package/dist/lib/shader-module/shader-pass.js.map +1 -0
  171. package/dist/lib/shader-plugin.cjs +117 -0
  172. package/dist/lib/shader-plugin.d.ts +68 -0
  173. package/dist/lib/shader-plugin.d.ts.map +1 -0
  174. package/dist/lib/shader-plugin.js +98 -0
  175. package/dist/lib/shader-plugin.js.map +1 -0
  176. package/dist/lib/shader-transpiler/shader-transpiler.cjs +15 -0
  177. package/dist/lib/shader-transpiler/shader-transpiler.d.ts +27 -0
  178. package/dist/lib/shader-transpiler/shader-transpiler.d.ts.map +1 -0
  179. package/dist/lib/shader-transpiler/shader-transpiler.js +5 -0
  180. package/dist/lib/shader-transpiler/shader-transpiler.js.map +1 -0
  181. package/dist/lib/shader-transpiler/transpile-glsl-shader.cjs +71 -0
  182. package/dist/lib/shader-transpiler/transpile-glsl-shader.d.ts +9 -0
  183. package/dist/lib/shader-transpiler/transpile-glsl-shader.d.ts.map +1 -0
  184. package/dist/lib/shader-transpiler/transpile-glsl-shader.js +69 -0
  185. package/dist/lib/shader-transpiler/transpile-glsl-shader.js.map +1 -0
  186. package/dist/lib/utils/assert.cjs +34 -0
  187. package/dist/lib/utils/assert.d.ts +2 -0
  188. package/dist/lib/utils/assert.d.ts.map +1 -0
  189. package/dist/lib/utils/assert.js +13 -0
  190. package/dist/lib/utils/assert.js.map +1 -0
  191. package/dist/lib/utils/uniform-types.cjs +15 -0
  192. package/dist/lib/utils/uniform-types.d.ts +18 -0
  193. package/dist/lib/utils/uniform-types.d.ts.map +1 -0
  194. package/dist/lib/utils/uniform-types.js +5 -0
  195. package/dist/lib/utils/uniform-types.js.map +1 -0
  196. package/dist/lib/wgsl-shader-assembler.cjs +99 -0
  197. package/dist/lib/wgsl-shader-assembler.d.ts +34 -0
  198. package/dist/lib/wgsl-shader-assembler.d.ts.map +1 -0
  199. package/dist/lib/wgsl-shader-assembler.js +84 -0
  200. package/dist/lib/wgsl-shader-assembler.js.map +1 -0
  201. package/dist/module-injectors.cjs +59 -0
  202. package/dist/module-injectors.d.ts +3 -0
  203. package/dist/module-injectors.d.ts.map +1 -0
  204. package/dist/module-injectors.js +31 -0
  205. package/dist/module-injectors.js.map +1 -0
  206. package/dist/modules/color/float-colors.cjs +275 -0
  207. package/dist/modules/color/float-colors.d.ts +132 -0
  208. package/dist/modules/color/float-colors.d.ts.map +1 -0
  209. package/dist/modules/color/float-colors.js +248 -0
  210. package/dist/modules/color/float-colors.js.map +1 -0
  211. package/dist/modules/engine/clip/clip.cjs +152 -0
  212. package/dist/modules/engine/clip/clip.d.ts +12 -0
  213. package/dist/modules/engine/clip/clip.d.ts.map +1 -0
  214. package/dist/modules/engine/clip/clip.js +129 -0
  215. package/dist/modules/engine/clip/clip.js.map +1 -0
  216. package/dist/modules/engine/filter/filter.cjs +111 -0
  217. package/dist/modules/engine/filter/filter.d.ts +12 -0
  218. package/dist/modules/engine/filter/filter.d.ts.map +1 -0
  219. package/dist/modules/engine/filter/filter.js +88 -0
  220. package/dist/modules/engine/filter/filter.js.map +1 -0
  221. package/dist/modules/engine/geometry/geometry.cjs +63 -0
  222. package/dist/modules/engine/geometry/geometry.d.ts +9 -0
  223. package/dist/modules/engine/geometry/geometry.d.ts.map +1 -0
  224. package/dist/modules/engine/geometry/geometry.js +42 -0
  225. package/dist/modules/engine/geometry/geometry.js.map +1 -0
  226. package/dist/modules/engine/gpu-animation/gpu-animation.cjs +255 -0
  227. package/dist/modules/engine/gpu-animation/gpu-animation.d.ts +34 -0
  228. package/dist/modules/engine/gpu-animation/gpu-animation.d.ts.map +1 -0
  229. package/dist/modules/engine/gpu-animation/gpu-animation.js +228 -0
  230. package/dist/modules/engine/gpu-animation/gpu-animation.js.map +1 -0
  231. package/dist/modules/engine/picking/picking.cjs +210 -0
  232. package/dist/modules/engine/picking/picking.d.ts +77 -0
  233. package/dist/modules/engine/picking/picking.d.ts.map +1 -0
  234. package/dist/modules/engine/picking/picking.js +198 -0
  235. package/dist/modules/engine/picking/picking.js.map +1 -0
  236. package/dist/modules/engine/project/project.cjs +138 -0
  237. package/dist/modules/engine/project/project.d.ts +39 -0
  238. package/dist/modules/engine/project/project.d.ts.map +1 -0
  239. package/dist/modules/engine/project/project.js +129 -0
  240. package/dist/modules/engine/project/project.js.map +1 -0
  241. package/dist/modules/engine/skin/skin.cjs +212 -0
  242. package/dist/modules/engine/skin/skin.d.ts +52 -0
  243. package/dist/modules/engine/skin/skin.d.ts.map +1 -0
  244. package/dist/modules/engine/skin/skin.js +179 -0
  245. package/dist/modules/engine/skin/skin.js.map +1 -0
  246. package/dist/modules/engine/transform/transform.cjs +72 -0
  247. package/dist/modules/engine/transform/transform.d.ts +6 -0
  248. package/dist/modules/engine/transform/transform.d.ts.map +1 -0
  249. package/dist/modules/engine/transform/transform.js +49 -0
  250. package/dist/modules/engine/transform/transform.js.map +1 -0
  251. package/dist/modules/geometry/path-dash/path-dash.cjs +93 -0
  252. package/dist/modules/geometry/path-dash/path-dash.d.ts +10 -0
  253. package/dist/modules/geometry/path-dash/path-dash.d.ts.map +1 -0
  254. package/dist/modules/geometry/path-dash/path-dash.js +66 -0
  255. package/dist/modules/geometry/path-dash/path-dash.js.map +1 -0
  256. package/dist/modules/geometry/pattern-fill/pattern-fill-shaders.cjs +117 -0
  257. package/dist/modules/geometry/pattern-fill/pattern-fill-shaders.d.ts +3 -0
  258. package/dist/modules/geometry/pattern-fill/pattern-fill-shaders.d.ts.map +1 -0
  259. package/dist/modules/geometry/pattern-fill/pattern-fill-shaders.js +87 -0
  260. package/dist/modules/geometry/pattern-fill/pattern-fill-shaders.js.map +1 -0
  261. package/dist/modules/geometry/pattern-fill/pattern-fill.cjs +64 -0
  262. package/dist/modules/geometry/pattern-fill/pattern-fill.d.ts +14 -0
  263. package/dist/modules/geometry/pattern-fill/pattern-fill.d.ts.map +1 -0
  264. package/dist/modules/geometry/pattern-fill/pattern-fill.js +43 -0
  265. package/dist/modules/geometry/pattern-fill/pattern-fill.js.map +1 -0
  266. package/dist/modules/geometry/point-glow/point-glow.cjs +104 -0
  267. package/dist/modules/geometry/point-glow/point-glow.d.ts +11 -0
  268. package/dist/modules/geometry/point-glow/point-glow.d.ts.map +1 -0
  269. package/dist/modules/geometry/point-glow/point-glow.js +77 -0
  270. package/dist/modules/geometry/point-glow/point-glow.js.map +1 -0
  271. package/dist/modules/geometry/precipitation/precipitation.cjs +122 -0
  272. package/dist/modules/geometry/precipitation/precipitation.d.ts +40 -0
  273. package/dist/modules/geometry/precipitation/precipitation.d.ts.map +1 -0
  274. package/dist/modules/geometry/precipitation/precipitation.js +95 -0
  275. package/dist/modules/geometry/precipitation/precipitation.js.map +1 -0
  276. package/dist/modules/geometry/sketch-stroke/sketch-stroke.cjs +158 -0
  277. package/dist/modules/geometry/sketch-stroke/sketch-stroke.d.ts +60 -0
  278. package/dist/modules/geometry/sketch-stroke/sketch-stroke.d.ts.map +1 -0
  279. package/dist/modules/geometry/sketch-stroke/sketch-stroke.js +137 -0
  280. package/dist/modules/geometry/sketch-stroke/sketch-stroke.js.map +1 -0
  281. package/dist/modules/geospatial/dggs/dggs-wgsl.cjs +2304 -0
  282. package/dist/modules/geospatial/dggs/dggs-wgsl.d.ts +3 -0
  283. package/dist/modules/geospatial/dggs/dggs-wgsl.d.ts.map +1 -0
  284. package/dist/modules/geospatial/dggs/dggs-wgsl.js +2283 -0
  285. package/dist/modules/geospatial/dggs/dggs-wgsl.js.map +1 -0
  286. package/dist/modules/geospatial/dggs/dggs.cjs +31 -0
  287. package/dist/modules/geospatial/dggs/dggs.d.ts +6 -0
  288. package/dist/modules/geospatial/dggs/dggs.d.ts.map +1 -0
  289. package/dist/modules/geospatial/dggs/dggs.js +10 -0
  290. package/dist/modules/geospatial/dggs/dggs.js.map +1 -0
  291. package/dist/modules/lighting/area-lighting/area-light-types.cjs +68 -0
  292. package/dist/modules/lighting/area-lighting/area-light-types.d.ts +34 -0
  293. package/dist/modules/lighting/area-lighting/area-light-types.d.ts.map +1 -0
  294. package/dist/modules/lighting/area-lighting/area-light-types.js +40 -0
  295. package/dist/modules/lighting/area-lighting/area-light-types.js.map +1 -0
  296. package/dist/modules/lighting/area-lighting/area-lighting-shaders.cjs +101 -0
  297. package/dist/modules/lighting/area-lighting/area-lighting-shaders.d.ts +3 -0
  298. package/dist/modules/lighting/area-lighting/area-lighting-shaders.d.ts.map +1 -0
  299. package/dist/modules/lighting/area-lighting/area-lighting-shaders.js +71 -0
  300. package/dist/modules/lighting/area-lighting/area-lighting-shaders.js.map +1 -0
  301. package/dist/modules/lighting/area-lighting/area-lighting.cjs +62 -0
  302. package/dist/modules/lighting/area-lighting/area-lighting.d.ts +89 -0
  303. package/dist/modules/lighting/area-lighting/area-lighting.d.ts.map +1 -0
  304. package/dist/modules/lighting/area-lighting/area-lighting.js +41 -0
  305. package/dist/modules/lighting/area-lighting/area-lighting.js.map +1 -0
  306. package/dist/modules/lighting/area-lighting/ltc-shaders.cjs +192 -0
  307. package/dist/modules/lighting/area-lighting/ltc-shaders.d.ts +3 -0
  308. package/dist/modules/lighting/area-lighting/ltc-shaders.d.ts.map +1 -0
  309. package/dist/modules/lighting/area-lighting/ltc-shaders.js +162 -0
  310. package/dist/modules/lighting/area-lighting/ltc-shaders.js.map +1 -0
  311. package/dist/modules/lighting/atmosphere/atmosphere.cjs +253 -0
  312. package/dist/modules/lighting/atmosphere/atmosphere.d.ts +45 -0
  313. package/dist/modules/lighting/atmosphere/atmosphere.d.ts.map +1 -0
  314. package/dist/modules/lighting/atmosphere/atmosphere.js +228 -0
  315. package/dist/modules/lighting/atmosphere/atmosphere.js.map +1 -0
  316. package/dist/modules/lighting/clouds/clouds.cjs +216 -0
  317. package/dist/modules/lighting/clouds/clouds.d.ts +58 -0
  318. package/dist/modules/lighting/clouds/clouds.d.ts.map +1 -0
  319. package/dist/modules/lighting/clouds/clouds.js +192 -0
  320. package/dist/modules/lighting/clouds/clouds.js.map +1 -0
  321. package/dist/modules/lighting/firefly/firefly.cjs +74 -0
  322. package/dist/modules/lighting/firefly/firefly.d.ts +36 -0
  323. package/dist/modules/lighting/firefly/firefly.d.ts.map +1 -0
  324. package/dist/modules/lighting/firefly/firefly.js +53 -0
  325. package/dist/modules/lighting/firefly/firefly.js.map +1 -0
  326. package/dist/modules/lighting/globe-clouds/globe-clouds.cjs +143 -0
  327. package/dist/modules/lighting/globe-clouds/globe-clouds.d.ts +53 -0
  328. package/dist/modules/lighting/globe-clouds/globe-clouds.d.ts.map +1 -0
  329. package/dist/modules/lighting/globe-clouds/globe-clouds.js +119 -0
  330. package/dist/modules/lighting/globe-clouds/globe-clouds.js.map +1 -0
  331. package/dist/modules/lighting/gouraud-material/gouraud-material.cjs +61 -0
  332. package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +12 -0
  333. package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -0
  334. package/dist/modules/lighting/gouraud-material/gouraud-material.js +40 -0
  335. package/dist/modules/lighting/gouraud-material/gouraud-material.js.map +1 -0
  336. package/dist/modules/lighting/height-fog/height-fog-functions.cjs +139 -0
  337. package/dist/modules/lighting/height-fog/height-fog-functions.d.ts +14 -0
  338. package/dist/modules/lighting/height-fog/height-fog-functions.d.ts.map +1 -0
  339. package/dist/modules/lighting/height-fog/height-fog-functions.js +114 -0
  340. package/dist/modules/lighting/height-fog/height-fog-functions.js.map +1 -0
  341. package/dist/modules/lighting/height-fog/height-fog.cjs +104 -0
  342. package/dist/modules/lighting/height-fog/height-fog.d.ts +60 -0
  343. package/dist/modules/lighting/height-fog/height-fog.d.ts.map +1 -0
  344. package/dist/modules/lighting/height-fog/height-fog.js +77 -0
  345. package/dist/modules/lighting/height-fog/height-fog.js.map +1 -0
  346. package/dist/modules/lighting/ibl/ibl.cjs +63 -0
  347. package/dist/modules/lighting/ibl/ibl.d.ts +25 -0
  348. package/dist/modules/lighting/ibl/ibl.d.ts.map +1 -0
  349. package/dist/modules/lighting/ibl/ibl.js +33 -0
  350. package/dist/modules/lighting/ibl/ibl.js.map +1 -0
  351. package/dist/modules/lighting/lambert-material/lambert-material.cjs +54 -0
  352. package/dist/modules/lighting/lambert-material/lambert-material.d.ts +10 -0
  353. package/dist/modules/lighting/lambert-material/lambert-material.d.ts.map +1 -0
  354. package/dist/modules/lighting/lambert-material/lambert-material.js +33 -0
  355. package/dist/modules/lighting/lambert-material/lambert-material.js.map +1 -0
  356. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.cjs +88 -0
  357. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.d.ts +3 -0
  358. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.d.ts.map +1 -0
  359. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.js +60 -0
  360. package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.js.map +1 -0
  361. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.cjs +97 -0
  362. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.d.ts +2 -0
  363. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.d.ts.map +1 -0
  364. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.js +73 -0
  365. package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.js.map +1 -0
  366. package/dist/modules/lighting/lights/lighting-glsl.cjs +116 -0
  367. package/dist/modules/lighting/lights/lighting-glsl.d.ts +2 -0
  368. package/dist/modules/lighting/lights/lighting-glsl.d.ts.map +1 -0
  369. package/dist/modules/lighting/lights/lighting-glsl.js +92 -0
  370. package/dist/modules/lighting/lights/lighting-glsl.js.map +1 -0
  371. package/dist/modules/lighting/lights/lighting-wgsl.cjs +115 -0
  372. package/dist/modules/lighting/lights/lighting-wgsl.d.ts +2 -0
  373. package/dist/modules/lighting/lights/lighting-wgsl.d.ts.map +1 -0
  374. package/dist/modules/lighting/lights/lighting-wgsl.js +91 -0
  375. package/dist/modules/lighting/lights/lighting-wgsl.js.map +1 -0
  376. package/dist/modules/lighting/lights/lighting.cjs +210 -0
  377. package/dist/modules/lighting/lights/lighting.d.ts +163 -0
  378. package/dist/modules/lighting/lights/lighting.d.ts.map +1 -0
  379. package/dist/modules/lighting/lights/lighting.js +208 -0
  380. package/dist/modules/lighting/lights/lighting.js.map +1 -0
  381. package/dist/modules/lighting/no-material/dirlight.cjs +112 -0
  382. package/dist/modules/lighting/no-material/dirlight.d.ts +33 -0
  383. package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -0
  384. package/dist/modules/lighting/no-material/dirlight.js +86 -0
  385. package/dist/modules/lighting/no-material/dirlight.js.map +1 -0
  386. package/dist/modules/lighting/pbr-material/pbr-material-glsl.cjs +1767 -0
  387. package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts +3 -0
  388. package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts.map +1 -0
  389. package/dist/modules/lighting/pbr-material/pbr-material-glsl.js +1745 -0
  390. package/dist/modules/lighting/pbr-material/pbr-material-glsl.js.map +1 -0
  391. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.cjs +2062 -0
  392. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts +3 -0
  393. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts.map +1 -0
  394. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js +2040 -0
  395. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -0
  396. package/dist/modules/lighting/pbr-material/pbr-material.cjs +315 -0
  397. package/dist/modules/lighting/pbr-material/pbr-material.d.ts +516 -0
  398. package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -0
  399. package/dist/modules/lighting/pbr-material/pbr-material.js +292 -0
  400. package/dist/modules/lighting/pbr-material/pbr-material.js.map +1 -0
  401. package/dist/modules/lighting/pbr-material/pbr-projection.cjs +63 -0
  402. package/dist/modules/lighting/pbr-material/pbr-projection.d.ts +10 -0
  403. package/dist/modules/lighting/pbr-material/pbr-projection.d.ts.map +1 -0
  404. package/dist/modules/lighting/pbr-material/pbr-projection.js +37 -0
  405. package/dist/modules/lighting/pbr-material/pbr-projection.js.map +1 -0
  406. package/dist/modules/lighting/pbr-material/pbr-scene.cjs +109 -0
  407. package/dist/modules/lighting/pbr-material/pbr-scene.d.ts +52 -0
  408. package/dist/modules/lighting/pbr-material/pbr-scene.d.ts.map +1 -0
  409. package/dist/modules/lighting/pbr-material/pbr-scene.js +83 -0
  410. package/dist/modules/lighting/pbr-material/pbr-scene.js.map +1 -0
  411. package/dist/modules/lighting/phong-material/phong-material.cjs +61 -0
  412. package/dist/modules/lighting/phong-material/phong-material.d.ts +13 -0
  413. package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -0
  414. package/dist/modules/lighting/phong-material/phong-material.js +40 -0
  415. package/dist/modules/lighting/phong-material/phong-material.js.map +1 -0
  416. package/dist/modules/lighting/phong-material/phong-shaders-glsl.cjs +100 -0
  417. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +3 -0
  418. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -0
  419. package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +72 -0
  420. package/dist/modules/lighting/phong-material/phong-shaders-glsl.js.map +1 -0
  421. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.cjs +153 -0
  422. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts +2 -0
  423. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts.map +1 -0
  424. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js +129 -0
  425. package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js.map +1 -0
  426. package/dist/modules/lighting/surface-weather/surface-weather.cjs +199 -0
  427. package/dist/modules/lighting/surface-weather/surface-weather.d.ts +54 -0
  428. package/dist/modules/lighting/surface-weather/surface-weather.d.ts.map +1 -0
  429. package/dist/modules/lighting/surface-weather/surface-weather.js +175 -0
  430. package/dist/modules/lighting/surface-weather/surface-weather.js.map +1 -0
  431. package/dist/modules/lighting/water-material/river-water-material.cjs +56 -0
  432. package/dist/modules/lighting/water-material/river-water-material.d.ts +21 -0
  433. package/dist/modules/lighting/water-material/river-water-material.d.ts.map +1 -0
  434. package/dist/modules/lighting/water-material/river-water-material.js +36 -0
  435. package/dist/modules/lighting/water-material/river-water-material.js.map +1 -0
  436. package/dist/modules/lighting/water-material/river-water-shaders.cjs +261 -0
  437. package/dist/modules/lighting/water-material/river-water-shaders.d.ts +3 -0
  438. package/dist/modules/lighting/water-material/river-water-shaders.d.ts.map +1 -0
  439. package/dist/modules/lighting/water-material/river-water-shaders.js +233 -0
  440. package/dist/modules/lighting/water-material/river-water-shaders.js.map +1 -0
  441. package/dist/modules/lighting/water-material/water-material.cjs +188 -0
  442. package/dist/modules/lighting/water-material/water-material.d.ts +28 -0
  443. package/dist/modules/lighting/water-material/water-material.d.ts.map +1 -0
  444. package/dist/modules/lighting/water-material/water-material.js +179 -0
  445. package/dist/modules/lighting/water-material/water-material.js.map +1 -0
  446. package/dist/modules/lighting/water-material/water-shaders-glsl.cjs +260 -0
  447. package/dist/modules/lighting/water-material/water-shaders-glsl.d.ts +3 -0
  448. package/dist/modules/lighting/water-material/water-shaders-glsl.d.ts.map +1 -0
  449. package/dist/modules/lighting/water-material/water-shaders-glsl.js +232 -0
  450. package/dist/modules/lighting/water-material/water-shaders-glsl.js.map +1 -0
  451. package/dist/modules/lighting/water-material/water-shaders-wgsl.cjs +254 -0
  452. package/dist/modules/lighting/water-material/water-shaders-wgsl.d.ts +2 -0
  453. package/dist/modules/lighting/water-material/water-shaders-wgsl.d.ts.map +1 -0
  454. package/dist/modules/lighting/water-material/water-shaders-wgsl.js +230 -0
  455. package/dist/modules/lighting/water-material/water-shaders-wgsl.js.map +1 -0
  456. package/dist/modules/math/fp16/fp16-utils.cjs +112 -0
  457. package/dist/modules/math/fp16/fp16-utils.d.ts +13 -0
  458. package/dist/modules/math/fp16/fp16-utils.d.ts.map +1 -0
  459. package/dist/modules/math/fp16/fp16-utils.js +118 -0
  460. package/dist/modules/math/fp16/fp16-utils.js.map +1 -0
  461. package/dist/modules/math/fp32/fp32.cjs +310 -0
  462. package/dist/modules/math/fp32/fp32.d.ts +9 -0
  463. package/dist/modules/math/fp32/fp32.d.ts.map +1 -0
  464. package/dist/modules/math/fp32/fp32.js +288 -0
  465. package/dist/modules/math/fp32/fp32.js.map +1 -0
  466. package/dist/modules/math/fp64/fp64-arithmetic-glsl.cjs +229 -0
  467. package/dist/modules/math/fp64/fp64-arithmetic-glsl.d.ts +2 -0
  468. package/dist/modules/math/fp64/fp64-arithmetic-glsl.d.ts.map +1 -0
  469. package/dist/modules/math/fp64/fp64-arithmetic-glsl.js +205 -0
  470. package/dist/modules/math/fp64/fp64-arithmetic-glsl.js.map +1 -0
  471. package/dist/modules/math/fp64/fp64-arithmetic-wgsl-hybrid.cjs +144 -0
  472. package/dist/modules/math/fp64/fp64-arithmetic-wgsl-hybrid.d.ts +10 -0
  473. package/dist/modules/math/fp64/fp64-arithmetic-wgsl-hybrid.d.ts.map +1 -0
  474. package/dist/modules/math/fp64/fp64-arithmetic-wgsl-hybrid.js +128 -0
  475. package/dist/modules/math/fp64/fp64-arithmetic-wgsl-hybrid.js.map +1 -0
  476. package/dist/modules/math/fp64/fp64-arithmetic-wgsl-integer.cjs +583 -0
  477. package/dist/modules/math/fp64/fp64-arithmetic-wgsl-integer.d.ts +11 -0
  478. package/dist/modules/math/fp64/fp64-arithmetic-wgsl-integer.d.ts.map +1 -0
  479. package/dist/modules/math/fp64/fp64-arithmetic-wgsl-integer.js +563 -0
  480. package/dist/modules/math/fp64/fp64-arithmetic-wgsl-integer.js.map +1 -0
  481. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.cjs +946 -0
  482. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.d.ts +3 -0
  483. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.d.ts.map +1 -0
  484. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.js +923 -0
  485. package/dist/modules/math/fp64/fp64-arithmetic-wgsl.js.map +1 -0
  486. package/dist/modules/math/fp64/fp64-functions-glsl.cjs +699 -0
  487. package/dist/modules/math/fp64/fp64-functions-glsl.d.ts +2 -0
  488. package/dist/modules/math/fp64/fp64-functions-glsl.d.ts.map +1 -0
  489. package/dist/modules/math/fp64/fp64-functions-glsl.js +675 -0
  490. package/dist/modules/math/fp64/fp64-functions-glsl.js.map +1 -0
  491. package/dist/modules/math/fp64/fp64-functions-wgsl.cjs +180 -0
  492. package/dist/modules/math/fp64/fp64-functions-wgsl.d.ts +3 -0
  493. package/dist/modules/math/fp64/fp64-functions-wgsl.d.ts.map +1 -0
  494. package/dist/modules/math/fp64/fp64-functions-wgsl.js +157 -0
  495. package/dist/modules/math/fp64/fp64-functions-wgsl.js.map +1 -0
  496. package/dist/modules/math/fp64/fp64-utils.cjs +50 -0
  497. package/dist/modules/math/fp64/fp64-utils.d.ts +22 -0
  498. package/dist/modules/math/fp64/fp64-utils.d.ts.map +1 -0
  499. package/dist/modules/math/fp64/fp64-utils.js +42 -0
  500. package/dist/modules/math/fp64/fp64-utils.js.map +1 -0
  501. package/dist/modules/math/fp64/fp64.cjs +68 -0
  502. package/dist/modules/math/fp64/fp64.d.ts +24 -0
  503. package/dist/modules/math/fp64/fp64.d.ts.map +1 -0
  504. package/dist/modules/math/fp64/fp64.js +46 -0
  505. package/dist/modules/math/fp64/fp64.js.map +1 -0
  506. package/dist/modules/math/random/random.cjs +46 -0
  507. package/dist/modules/math/random/random.d.ts +7 -0
  508. package/dist/modules/math/random/random.d.ts.map +1 -0
  509. package/dist/modules/math/random/random.js +21 -0
  510. package/dist/modules/math/random/random.js.map +1 -0
  511. package/dist/modules/math/value-noise/value-noise.cjs +95 -0
  512. package/dist/modules/math/value-noise/value-noise.d.ts +7 -0
  513. package/dist/modules/math/value-noise/value-noise.d.ts.map +1 -0
  514. package/dist/modules/math/value-noise/value-noise.js +68 -0
  515. package/dist/modules/math/value-noise/value-noise.js.map +1 -0
  516. package/dist/modules/volume/volume-raymarch.cjs +107 -0
  517. package/dist/modules/volume/volume-raymarch.d.ts +6 -0
  518. package/dist/modules/volume/volume-raymarch.d.ts.map +1 -0
  519. package/dist/modules/volume/volume-raymarch.js +84 -0
  520. package/dist/modules/volume/volume-raymarch.js.map +1 -0
  521. package/dist/types/align-to.cjs +38 -0
  522. package/dist/types/align-to.d.ts +3 -0
  523. package/dist/types/align-to.d.ts.map +1 -0
  524. package/dist/types/align-to.js +13 -0
  525. package/dist/types/align-to.js.map +1 -0
  526. package/dist/types/primitive-data-types.cjs +15 -0
  527. package/dist/types/primitive-data-types.d.ts +7 -0
  528. package/dist/types/primitive-data-types.d.ts.map +1 -0
  529. package/dist/types/primitive-data-types.js +5 -0
  530. package/dist/types/primitive-data-types.js.map +1 -0
  531. package/dist/types/sampler-props.cjs +15 -0
  532. package/dist/types/sampler-props.d.ts +26 -0
  533. package/dist/types/sampler-props.d.ts.map +1 -0
  534. package/dist/types/sampler-props.js +5 -0
  535. package/dist/types/sampler-props.js.map +1 -0
  536. package/dist/types/shader-block-layout.cjs +184 -0
  537. package/dist/types/shader-block-layout.d.ts +72 -0
  538. package/dist/types/shader-block-layout.d.ts.map +1 -0
  539. package/dist/types/shader-block-layout.js +209 -0
  540. package/dist/types/shader-block-layout.js.map +1 -0
  541. package/dist/types/shader-layout.cjs +15 -0
  542. package/dist/types/shader-layout.d.ts +178 -0
  543. package/dist/types/shader-layout.d.ts.map +1 -0
  544. package/dist/types/shader-layout.js +5 -0
  545. package/dist/types/shader-layout.js.map +1 -0
  546. package/dist/types/shader-type-decoder.cjs +240 -0
  547. package/dist/types/shader-type-decoder.d.ts +41 -0
  548. package/dist/types/shader-type-decoder.d.ts.map +1 -0
  549. package/dist/types/shader-type-decoder.js +210 -0
  550. package/dist/types/shader-type-decoder.js.map +1 -0
  551. package/dist/types/shader-types.cjs +15 -0
  552. package/dist/types/shader-types.d.ts +101 -0
  553. package/dist/types/shader-types.d.ts.map +1 -0
  554. package/dist/types/shader-types.js +30 -0
  555. package/dist/types/shader-types.js.map +1 -0
  556. package/dist/types/texture-formats.cjs +15 -0
  557. package/dist/types/texture-formats.d.ts +24 -0
  558. package/dist/types/texture-formats.d.ts.map +1 -0
  559. package/dist/types/texture-formats.js +5 -0
  560. package/dist/types/texture-formats.js.map +1 -0
  561. package/dist/types.cjs +42 -0
  562. package/dist/types.cjs.map +6 -0
  563. package/dist/types.d.ts +14 -0
  564. package/dist/types.d.ts.map +1 -0
  565. package/dist/types.js +12 -0
  566. package/dist/types.js.map +1 -0
  567. package/dist/wgsl.cjs +39 -0
  568. package/dist/wgsl.cjs.map +6 -0
  569. package/dist/wgsl.d.ts +8 -0
  570. package/dist/wgsl.d.ts.map +1 -0
  571. package/dist/wgsl.js +9 -0
  572. package/dist/wgsl.js.map +1 -0
  573. package/package.json +65 -4
  574. package/src/glsl.ts +13 -0
  575. package/src/index.ts +259 -0
  576. package/src/lib/color/normalize-byte-colors.ts +57 -0
  577. package/src/lib/filters/prop-types.ts +150 -0
  578. package/src/lib/glsl-shader-assembler.ts +39 -0
  579. package/src/lib/glsl-utils/get-shader-info.ts +42 -0
  580. package/src/lib/glsl-utils/shader-utils.ts +110 -0
  581. package/src/lib/preprocessor/preprocessor.ts +132 -0
  582. package/src/lib/shader-assembler-base.ts +170 -0
  583. package/src/lib/shader-assembler.ts +7 -0
  584. package/src/lib/shader-assembly/assemble-glsl-shaders.ts +305 -0
  585. package/src/lib/shader-assembly/assemble-shaders.ts +13 -0
  586. package/src/lib/shader-assembly/assemble-wgsl-shaders.ts +801 -0
  587. package/src/lib/shader-assembly/platform-defines.ts +58 -0
  588. package/src/lib/shader-assembly/platform-info.ts +23 -0
  589. package/src/lib/shader-assembly/shader-assembly-shared.ts +95 -0
  590. package/src/lib/shader-assembly/shader-assembly-types.ts +142 -0
  591. package/src/lib/shader-assembly/shader-hooks.ts +141 -0
  592. package/src/lib/shader-assembly/shader-injections.ts +250 -0
  593. package/src/lib/shader-assembly/shader-plugin-varyings.ts +524 -0
  594. package/src/lib/shader-assembly/shader-plugin-vertex-inputs.ts +279 -0
  595. package/src/lib/shader-assembly/wgsl-binding-debug.ts +227 -0
  596. package/src/lib/shader-assembly/wgsl-binding-scan.ts +228 -0
  597. package/src/lib/shader-assembly/wgsl-interface-scan.ts +676 -0
  598. package/src/lib/shader-generator/generate-shader.ts +27 -0
  599. package/src/lib/shader-generator/glsl/generate-glsl.ts +101 -0
  600. package/src/lib/shader-generator/utils/capitalize.ts +12 -0
  601. package/src/lib/shader-generator/wgsl/generate-wgsl.ts +40 -0
  602. package/src/lib/shader-module/composite-shader-pass.ts +47 -0
  603. package/src/lib/shader-module/shader-module-dependencies.ts +128 -0
  604. package/src/lib/shader-module/shader-module-uniform-layout.ts +420 -0
  605. package/src/lib/shader-module/shader-module.ts +244 -0
  606. package/src/lib/shader-module/shader-pass.ts +69 -0
  607. package/src/lib/shader-plugin.ts +214 -0
  608. package/src/lib/shader-transpiler/shader-transpiler.ts +34 -0
  609. package/src/lib/shader-transpiler/transpile-glsl-shader.ts +78 -0
  610. package/src/lib/utils/assert.ts +13 -0
  611. package/src/lib/utils/uniform-types.ts +89 -0
  612. package/src/lib/wgsl-shader-assembler.ts +122 -0
  613. package/src/module-injectors.ts +32 -0
  614. package/src/modules/color/float-colors.ts +334 -0
  615. package/src/modules/engine/clip/clip.ts +149 -0
  616. package/src/modules/engine/filter/filter.ts +107 -0
  617. package/src/modules/engine/geometry/geometry.ts +45 -0
  618. package/src/modules/engine/gpu-animation/gpu-animation.ts +244 -0
  619. package/src/modules/engine/picking/README.md +88 -0
  620. package/src/modules/engine/picking/picking.ts +252 -0
  621. package/src/modules/engine/project/project.ts +166 -0
  622. package/src/modules/engine/skin/skin.ts +233 -0
  623. package/src/modules/engine/transform/transform.ts +50 -0
  624. package/src/modules/geometry/path-dash/path-dash.ts +68 -0
  625. package/src/modules/geometry/pattern-fill/pattern-fill-shaders.ts +88 -0
  626. package/src/modules/geometry/pattern-fill/pattern-fill.ts +54 -0
  627. package/src/modules/geometry/point-glow/point-glow.ts +87 -0
  628. package/src/modules/geometry/precipitation/README.md +19 -0
  629. package/src/modules/geometry/precipitation/precipitation.ts +108 -0
  630. package/src/modules/geometry/sketch-stroke/sketch-stroke.ts +160 -0
  631. package/src/modules/geospatial/dggs/dggs-wgsl.ts +2284 -0
  632. package/src/modules/geospatial/dggs/dggs.ts +12 -0
  633. package/src/modules/lighting/area-lighting/area-light-types.ts +71 -0
  634. package/src/modules/lighting/area-lighting/area-lighting-shaders.ts +72 -0
  635. package/src/modules/lighting/area-lighting/area-lighting.ts +63 -0
  636. package/src/modules/lighting/area-lighting/ltc-shaders.ts +163 -0
  637. package/src/modules/lighting/atmosphere/README.md +25 -0
  638. package/src/modules/lighting/atmosphere/atmosphere.ts +246 -0
  639. package/src/modules/lighting/clouds/README.md +24 -0
  640. package/src/modules/lighting/clouds/clouds.ts +216 -0
  641. package/src/modules/lighting/firefly/firefly.ts +64 -0
  642. package/src/modules/lighting/globe-clouds/globe-clouds.ts +124 -0
  643. package/src/modules/lighting/gouraud-material/gouraud-material.ts +55 -0
  644. package/src/modules/lighting/height-fog/README.md +36 -0
  645. package/src/modules/lighting/height-fog/height-fog-functions.ts +116 -0
  646. package/src/modules/lighting/height-fog/height-fog.ts +96 -0
  647. package/src/modules/lighting/ibl/ibl.ts +43 -0
  648. package/src/modules/lighting/lambert-material/lambert-material.ts +42 -0
  649. package/src/modules/lighting/lambert-material/lambert-shaders-glsl.ts +61 -0
  650. package/src/modules/lighting/lambert-material/lambert-shaders-wgsl.ts +73 -0
  651. package/src/modules/lighting/lights/lighting-glsl.ts +92 -0
  652. package/src/modules/lighting/lights/lighting-wgsl.ts +91 -0
  653. package/src/modules/lighting/lights/lighting.ts +385 -0
  654. package/src/modules/lighting/no-material/dirlight.ts +101 -0
  655. package/src/modules/lighting/pbr-material/pbr-material-glsl.ts +1748 -0
  656. package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +2043 -0
  657. package/src/modules/lighting/pbr-material/pbr-material.ts +517 -0
  658. package/src/modules/lighting/pbr-material/pbr-projection.ts +50 -0
  659. package/src/modules/lighting/pbr-material/pbr-scene.ts +112 -0
  660. package/src/modules/lighting/phong-material/phong-material.ts +53 -0
  661. package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +73 -0
  662. package/src/modules/lighting/phong-material/phong-shaders-wgsl.ts +129 -0
  663. package/src/modules/lighting/surface-weather/README.md +28 -0
  664. package/src/modules/lighting/surface-weather/surface-weather.ts +198 -0
  665. package/src/modules/lighting/water-material/river-water-material.ts +58 -0
  666. package/src/modules/lighting/water-material/river-water-shaders.ts +234 -0
  667. package/src/modules/lighting/water-material/water-material.ts +234 -0
  668. package/src/modules/lighting/water-material/water-shaders-glsl.ts +233 -0
  669. package/src/modules/lighting/water-material/water-shaders-wgsl.ts +230 -0
  670. package/src/modules/math/fp16/fp16-utils.ts +156 -0
  671. package/src/modules/math/fp32/fp32.ts +291 -0
  672. package/src/modules/math/fp64/fp64-arithmetic-glsl.ts +205 -0
  673. package/src/modules/math/fp64/fp64-arithmetic-wgsl-hybrid.ts +129 -0
  674. package/src/modules/math/fp64/fp64-arithmetic-wgsl-integer.ts +564 -0
  675. package/src/modules/math/fp64/fp64-arithmetic-wgsl.ts +924 -0
  676. package/src/modules/math/fp64/fp64-functions-glsl.ts +675 -0
  677. package/src/modules/math/fp64/fp64-functions-wgsl.ts +157 -0
  678. package/src/modules/math/fp64/fp64-utils.ts +46 -0
  679. package/src/modules/math/fp64/fp64.ts +64 -0
  680. package/src/modules/math/random/random.ts +25 -0
  681. package/src/modules/math/value-noise/value-noise.ts +70 -0
  682. package/src/modules/volume/volume-raymarch.ts +87 -0
  683. package/src/types/align-to.ts +13 -0
  684. package/src/types/primitive-data-types.ts +10 -0
  685. package/src/types/sampler-props.ts +39 -0
  686. package/src/types/shader-block-layout.ts +340 -0
  687. package/src/types/shader-layout.ts +208 -0
  688. package/src/types/shader-type-decoder.ts +285 -0
  689. package/src/types/shader-types.ts +207 -0
  690. package/src/types/texture-formats.ts +155 -0
  691. package/src/types.ts +48 -0
  692. package/src/wgsl.ts +23 -0
@@ -0,0 +1,1748 @@
1
+ // luma.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+ // SPDX-FileCopyrightText: Copyright (c) 2016-2017 Mohamad Moneimne and Contributors
5
+
6
+ // Attribution:
7
+ // MIT license, Copyright (c) 2016-2017 Mohamad Moneimne and Contributors
8
+ // This fragment shader defines a reference implementation for Physically Based Shading of
9
+ // a microfacet surface material defined by a glTF model.
10
+
11
+ // TODO - better do the checks outside of shader
12
+
13
+ export const vs = /* glsl */ `\
14
+ out vec3 pbr_vPosition;
15
+ out vec2 pbr_vUV0;
16
+ out vec2 pbr_vUV1;
17
+
18
+ #ifdef HAS_NORMALS
19
+ # ifdef HAS_TANGENTS
20
+ out mat3 pbr_vTBN;
21
+ # else
22
+ out vec3 pbr_vNormal;
23
+ # endif
24
+ #endif
25
+
26
+ void pbr_setPositionNormalTangentUV(
27
+ vec4 position,
28
+ vec4 normal,
29
+ vec4 tangent,
30
+ vec2 uv0,
31
+ vec2 uv1
32
+ )
33
+ {
34
+ vec4 pos = pbrProjection.modelMatrix * position;
35
+ pbr_vPosition = vec3(pos.xyz) / pos.w;
36
+
37
+ #ifdef HAS_NORMALS
38
+ #ifdef HAS_TANGENTS
39
+ vec3 normalW = normalize(vec3(pbrProjection.normalMatrix * vec4(normal.xyz, 0.0)));
40
+ vec3 tangentW = normalize(vec3(pbrProjection.modelMatrix * vec4(tangent.xyz, 0.0)));
41
+ vec3 bitangentW = cross(normalW, tangentW) * tangent.w;
42
+ pbr_vTBN = mat3(tangentW, bitangentW, normalW);
43
+ #else // HAS_TANGENTS != 1
44
+ pbr_vNormal = normalize(vec3(pbrProjection.modelMatrix * vec4(normal.xyz, 0.0)));
45
+ #endif
46
+ #endif
47
+
48
+ #ifdef HAS_UV
49
+ pbr_vUV0 = uv0;
50
+ #else
51
+ pbr_vUV0 = vec2(0.,0.);
52
+ #endif
53
+
54
+ pbr_vUV1 = uv1;
55
+ }
56
+ `;
57
+
58
+ export const fs = /* glsl */ `\
59
+ precision highp float;
60
+
61
+ layout(std140) uniform pbrMaterialUniforms {
62
+ // Material is unlit
63
+ bool unlit;
64
+
65
+ // Base color map
66
+ bool baseColorMapEnabled;
67
+ vec4 baseColorFactor;
68
+
69
+ bool normalMapEnabled;
70
+ float normalScale; // #ifdef HAS_NORMALMAP
71
+
72
+ bool emissiveMapEnabled;
73
+ vec3 emissiveFactor; // #ifdef HAS_EMISSIVEMAP
74
+
75
+ vec2 metallicRoughnessValues;
76
+ bool metallicRoughnessMapEnabled;
77
+
78
+ bool occlusionMapEnabled;
79
+ float occlusionStrength; // #ifdef HAS_OCCLUSIONMAP
80
+
81
+ bool alphaCutoffEnabled;
82
+ float alphaCutoff; // #ifdef ALPHA_CUTOFF
83
+
84
+ vec3 specularColorFactor;
85
+ float specularIntensityFactor;
86
+ bool specularColorMapEnabled;
87
+ bool specularIntensityMapEnabled;
88
+
89
+ float ior;
90
+
91
+ float transmissionFactor;
92
+ bool transmissionMapEnabled;
93
+
94
+ float thicknessFactor;
95
+ float attenuationDistance;
96
+ vec3 attenuationColor;
97
+
98
+ float clearcoatFactor;
99
+ float clearcoatRoughnessFactor;
100
+ bool clearcoatMapEnabled;
101
+ bool clearcoatRoughnessMapEnabled;
102
+
103
+ vec3 sheenColorFactor;
104
+ float sheenRoughnessFactor;
105
+ bool sheenColorMapEnabled;
106
+ bool sheenRoughnessMapEnabled;
107
+
108
+ float iridescenceFactor;
109
+ float iridescenceIor;
110
+ vec2 iridescenceThicknessRange;
111
+ bool iridescenceMapEnabled;
112
+
113
+ float anisotropyStrength;
114
+ float anisotropyRotation;
115
+ vec2 anisotropyDirection;
116
+ bool anisotropyMapEnabled;
117
+
118
+ float emissiveStrength;
119
+ float dispersion;
120
+
121
+ // IBL
122
+ bool IBLenabled;
123
+ vec2 scaleIBLAmbient; // #ifdef USE_IBL
124
+
125
+ // debugging flags used for shader output of intermediate PBR variables
126
+ // #ifdef PBR_DEBUG
127
+ vec4 scaleDiffBaseMR;
128
+ vec4 scaleFGDSpec;
129
+ // #endif
130
+
131
+ int baseColorUVSet;
132
+ mat3 baseColorUVTransform;
133
+ int metallicRoughnessUVSet;
134
+ mat3 metallicRoughnessUVTransform;
135
+ int normalUVSet;
136
+ mat3 normalUVTransform;
137
+ int occlusionUVSet;
138
+ mat3 occlusionUVTransform;
139
+ int emissiveUVSet;
140
+ mat3 emissiveUVTransform;
141
+ int specularColorUVSet;
142
+ mat3 specularColorUVTransform;
143
+ int specularIntensityUVSet;
144
+ mat3 specularIntensityUVTransform;
145
+ int transmissionUVSet;
146
+ mat3 transmissionUVTransform;
147
+ int thicknessUVSet;
148
+ mat3 thicknessUVTransform;
149
+ int clearcoatUVSet;
150
+ mat3 clearcoatUVTransform;
151
+ int clearcoatRoughnessUVSet;
152
+ mat3 clearcoatRoughnessUVTransform;
153
+ int clearcoatNormalUVSet;
154
+ mat3 clearcoatNormalUVTransform;
155
+ int sheenColorUVSet;
156
+ mat3 sheenColorUVTransform;
157
+ int sheenRoughnessUVSet;
158
+ mat3 sheenRoughnessUVTransform;
159
+ int iridescenceUVSet;
160
+ mat3 iridescenceUVTransform;
161
+ int iridescenceThicknessUVSet;
162
+ mat3 iridescenceThicknessUVTransform;
163
+ int anisotropyUVSet;
164
+ mat3 anisotropyUVTransform;
165
+
166
+ float bumpFactor;
167
+ bool bumpMapEnabled;
168
+ float diffuseTransmissionFactor;
169
+ bool diffuseTransmissionMapEnabled;
170
+ vec3 diffuseTransmissionColorFactor;
171
+ bool diffuseTransmissionColorMapEnabled;
172
+ vec3 multiscatterColorFactor;
173
+ bool multiscatterColorMapEnabled;
174
+ float scatterAnisotropy;
175
+
176
+ int bumpUVSet;
177
+ mat3 bumpUVTransform;
178
+ int diffuseTransmissionUVSet;
179
+ mat3 diffuseTransmissionUVTransform;
180
+ int diffuseTransmissionColorUVSet;
181
+ mat3 diffuseTransmissionColorUVTransform;
182
+ int multiscatterColorUVSet;
183
+ mat3 multiscatterColorUVTransform;
184
+ bool lightmapMapEnabled;
185
+ float lightmapIntensity;
186
+ int lightmapUVSet;
187
+ mat3 lightmapUVTransform;
188
+ float scatterStrengthFactor;
189
+ } pbrMaterial;
190
+
191
+ // Samplers
192
+ #ifdef HAS_BASECOLORMAP
193
+ uniform sampler2D pbr_baseColorSampler;
194
+ #endif
195
+ #ifdef HAS_NORMALMAP
196
+ uniform sampler2D pbr_normalSampler;
197
+ #endif
198
+ #ifdef HAS_EMISSIVEMAP
199
+ uniform sampler2D pbr_emissiveSampler;
200
+ #endif
201
+ #ifdef HAS_LIGHTMAP
202
+ uniform sampler2D pbr_lightmapSampler;
203
+ #endif
204
+ #ifdef HAS_METALROUGHNESSMAP
205
+ uniform sampler2D pbr_metallicRoughnessSampler;
206
+ #endif
207
+ #ifdef HAS_OCCLUSIONMAP
208
+ uniform sampler2D pbr_occlusionSampler;
209
+ #endif
210
+ #ifdef HAS_SPECULARCOLORMAP
211
+ uniform sampler2D pbr_specularColorSampler;
212
+ #endif
213
+ #ifdef HAS_SPECULARINTENSITYMAP
214
+ uniform sampler2D pbr_specularIntensitySampler;
215
+ #endif
216
+ #ifdef HAS_TRANSMISSIONMAP
217
+ uniform sampler2D pbr_transmissionSampler;
218
+ #endif
219
+ #ifdef HAS_THICKNESSMAP
220
+ uniform sampler2D pbr_thicknessSampler;
221
+ #endif
222
+ #ifdef HAS_CLEARCOATMAP
223
+ uniform sampler2D pbr_clearcoatSampler;
224
+ #endif
225
+ #ifdef HAS_CLEARCOATROUGHNESSMAP
226
+ uniform sampler2D pbr_clearcoatRoughnessSampler;
227
+ #endif
228
+ #ifdef HAS_CLEARCOATNORMALMAP
229
+ uniform sampler2D pbr_clearcoatNormalSampler;
230
+ #endif
231
+ #ifdef HAS_SHEENCOLORMAP
232
+ uniform sampler2D pbr_sheenColorSampler;
233
+ #endif
234
+ #ifdef HAS_SHEENROUGHNESSMAP
235
+ uniform sampler2D pbr_sheenRoughnessSampler;
236
+ #endif
237
+ #ifdef HAS_IRIDESCENCEMAP
238
+ uniform sampler2D pbr_iridescenceSampler;
239
+ #endif
240
+ #ifdef HAS_IRIDESCENCETHICKNESSMAP
241
+ uniform sampler2D pbr_iridescenceThicknessSampler;
242
+ #endif
243
+ #ifdef HAS_ANISOTROPYMAP
244
+ uniform sampler2D pbr_anisotropySampler;
245
+ #endif
246
+ #ifdef HAS_BUMPMAP
247
+ uniform sampler2D pbr_bumpSampler;
248
+ #endif
249
+ #ifdef HAS_DIFFUSETRANSMISSIONMAP
250
+ uniform sampler2D pbr_diffuseTransmissionSampler;
251
+ #endif
252
+ #ifdef HAS_DIFFUSETRANSMISSIONCOLORMAP
253
+ uniform sampler2D pbr_diffuseTransmissionColorSampler;
254
+ #endif
255
+ #ifdef HAS_MULTISCATTERCOLORMAP
256
+ uniform sampler2D pbr_multiscatterColorSampler;
257
+ #endif
258
+ // Inputs from vertex shader
259
+
260
+ in vec3 pbr_vPosition;
261
+ in vec2 pbr_vUV0;
262
+ in vec2 pbr_vUV1;
263
+
264
+ #ifdef HAS_NORMALS
265
+ #ifdef HAS_TANGENTS
266
+ in mat3 pbr_vTBN;
267
+ #else
268
+ in vec3 pbr_vNormal;
269
+ #endif
270
+ #endif
271
+
272
+ // Encapsulate the various inputs used by the various functions in the shading equation
273
+ // We store values in this struct to simplify the integration of alternative implementations
274
+ // of the shading terms, outlined in the Readme.MD Appendix.
275
+ struct PBRInfo {
276
+ float NdotL; // cos angle between normal and light direction
277
+ float NdotV; // cos angle between normal and view direction
278
+ float NdotH; // cos angle between normal and half vector
279
+ float LdotH; // cos angle between light direction and half vector
280
+ float VdotH; // cos angle between view direction and half vector
281
+ float perceptualRoughness; // roughness value, as authored by the model creator (input to shader)
282
+ float metalness; // metallic value at the surface
283
+ vec3 reflectance0; // full reflectance color (normal incidence angle)
284
+ vec3 reflectance90; // reflectance color at grazing angle
285
+ float alphaRoughness; // roughness mapped to a more linear change in the roughness (proposed by [2])
286
+ vec3 diffuseColor; // color contribution from diffuse lighting
287
+ vec3 specularColor; // color contribution from specular lighting
288
+ vec3 n; // normal at surface point
289
+ vec3 v; // vector from surface point to camera
290
+ vec3 l; // direction from the surface toward the current light
291
+ vec3 h; // half vector between the current light and camera
292
+ };
293
+
294
+ const float M_PI = 3.141592653589793;
295
+ const float c_MinRoughness = 0.04;
296
+
297
+ // Widen sub-pixel specular lobes using the screen-space normal footprint.
298
+ // This is geometric specular antialiasing: the normal variance is converted
299
+ // into an additional squared perceptual roughness before evaluating BRDFs.
300
+ float widenSpecularRoughness(float perceptualRoughness, vec3 normal)
301
+ {
302
+ vec3 normalDerivativeX = dFdx(normal);
303
+ vec3 normalDerivativeY = dFdy(normal);
304
+ float normalVariance =
305
+ dot(normalDerivativeX, normalDerivativeX) +
306
+ dot(normalDerivativeY, normalDerivativeY);
307
+ float kernelRoughnessSquared = min(2.0 * normalVariance, 1.0);
308
+ return clamp(
309
+ sqrt(perceptualRoughness * perceptualRoughness + kernelRoughnessSquared),
310
+ c_MinRoughness,
311
+ 1.0
312
+ );
313
+ }
314
+
315
+ vec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor);
316
+
317
+ vec4 SRGBtoLINEAR(vec4 srgbIn)
318
+ {
319
+ #ifdef MANUAL_SRGB
320
+ #ifdef SRGB_FAST_APPROXIMATION
321
+ vec3 linOut = pow(srgbIn.xyz,vec3(2.2));
322
+ #else // SRGB_FAST_APPROXIMATION
323
+ vec3 bLess = step(vec3(0.04045),srgbIn.xyz);
324
+ vec3 linOut = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess );
325
+ #endif //SRGB_FAST_APPROXIMATION
326
+ return vec4(linOut,srgbIn.w);;
327
+ #else //MANUAL_SRGB
328
+ return srgbIn;
329
+ #endif //MANUAL_SRGB
330
+ }
331
+
332
+ vec2 getMaterialUV(int uvSet, mat3 uvTransform)
333
+ {
334
+ vec2 baseUV = uvSet == 1 ? pbr_vUV1 : pbr_vUV0;
335
+ return (uvTransform * vec3(baseUV, 1.0)).xy;
336
+ }
337
+
338
+ // Build the tangent basis from interpolated attributes or screen-space derivatives.
339
+ mat3 getTBN(vec2 uv)
340
+ {
341
+ #ifndef HAS_TANGENTS
342
+ vec3 pos_dx = dFdx(pbr_vPosition);
343
+ vec3 pos_dy = dFdy(pbr_vPosition);
344
+ vec3 tex_dx = dFdx(vec3(uv, 0.0));
345
+ vec3 tex_dy = dFdy(vec3(uv, 0.0));
346
+ vec3 t = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);
347
+
348
+ #ifdef HAS_NORMALS
349
+ vec3 ng = normalize(pbr_vNormal);
350
+ #else
351
+ vec3 ng = cross(pos_dx, pos_dy);
352
+ #endif
353
+
354
+ t = normalize(t - ng * dot(ng, t));
355
+ vec3 b = normalize(cross(ng, t));
356
+ mat3 tbn = mat3(t, b, ng);
357
+ #else // HAS_TANGENTS
358
+ mat3 tbn = pbr_vTBN;
359
+ #endif
360
+
361
+ #ifdef DOUBLE_SIDED
362
+ #ifdef HAS_NORMALS
363
+ // Derivative normals already face the viewer; only flip an authored basis.
364
+ if (!gl_FrontFacing) tbn = mat3(-tbn[0], -tbn[1], -tbn[2]);
365
+ #endif
366
+ #endif
367
+ return tbn;
368
+ }
369
+
370
+ // Find the normal for this fragment, pulling either from a predefined normal map
371
+ // or from the interpolated mesh normal and tangent attributes.
372
+ vec3 getMappedNormal(sampler2D normalSampler, mat3 tbn, float normalScale, vec2 uv)
373
+ {
374
+ vec3 n = texture(normalSampler, uv).rgb;
375
+ return normalize(tbn * ((2.0 * n - 1.0) * vec3(normalScale, normalScale, 1.0)));
376
+ }
377
+
378
+ vec3 getNormal(mat3 tbn, vec2 uv)
379
+ {
380
+ #ifdef HAS_NORMALMAP
381
+ vec3 n = getMappedNormal(pbr_normalSampler, tbn, pbrMaterial.normalScale, uv);
382
+ #else
383
+ // The tbn matrix is linearly interpolated, so we need to re-normalize
384
+ vec3 n = normalize(tbn[2].xyz);
385
+ #endif
386
+
387
+ #ifdef HAS_BUMPMAP
388
+ vec2 bumpUV = getMaterialUV(pbrMaterial.bumpUVSet, pbrMaterial.bumpUVTransform);
389
+ vec2 bumpTexelSize = 1.0 / vec2(textureSize(pbr_bumpSampler, 0));
390
+ float bumpHeight = texture(pbr_bumpSampler, bumpUV).r;
391
+ vec2 bumpGradient = vec2(
392
+ texture(pbr_bumpSampler, bumpUV + vec2(bumpTexelSize.x, 0.0)).r - bumpHeight,
393
+ texture(pbr_bumpSampler, bumpUV + vec2(0.0, bumpTexelSize.y)).r - bumpHeight
394
+ );
395
+ n = normalize(n - pbrMaterial.bumpFactor *
396
+ (tbn[0] * bumpGradient.x + tbn[1] * bumpGradient.y));
397
+ #endif
398
+
399
+ return n;
400
+ }
401
+
402
+ vec3 getClearcoatNormal(mat3 tbn, vec3 baseNormal, vec2 uv)
403
+ {
404
+ #ifdef HAS_CLEARCOATNORMALMAP
405
+ return getMappedNormal(pbr_clearcoatNormalSampler, tbn, 1.0, uv);
406
+ #else
407
+ return baseNormal;
408
+ #endif
409
+ }
410
+
411
+ // Calculation of the lighting contribution from an optional Image Based Light source.
412
+ // Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].
413
+ // See our README.md on Environment Maps [3] for additional discussion.
414
+ #ifdef USE_IBL
415
+ vec3 getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection)
416
+ {
417
+ #ifdef USE_SCENE_ENVIRONMENT
418
+ float maximumMipLevel = max(pbrScene.environmentMipCount - 1.0, 0.0);
419
+ float rotationSine = sin(pbrScene.environmentRotation);
420
+ float rotationCosine = cos(pbrScene.environmentRotation);
421
+ mat2 environmentRotation = mat2(rotationCosine, rotationSine, -rotationSine, rotationCosine);
422
+ vec3 environmentNormal = vec3(environmentRotation * n.xz, n.y).xzy;
423
+ vec3 environmentReflection = vec3(environmentRotation * reflection.xz, reflection.y).xzy;
424
+ #else
425
+ float maximumMipLevel = 9.0;
426
+ vec3 environmentNormal = n;
427
+ vec3 environmentReflection = reflection;
428
+ #endif
429
+ float lod = pbrInfo.perceptualRoughness * maximumMipLevel;
430
+ // retrieve a scale and bias to F0. See [1], Figure 3
431
+ vec4 brdfSample = texture(pbr_brdfLUT,
432
+ vec2(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness));
433
+ vec4 diffuseSample = texture(pbr_diffuseEnvSampler, environmentNormal);
434
+
435
+ #ifdef USE_TEX_LOD
436
+ vec4 specularSample = textureLod(pbr_specularEnvSampler, environmentReflection, lod);
437
+ #else
438
+ vec4 specularSample = texture(pbr_specularEnvSampler, environmentReflection);
439
+ #endif
440
+
441
+ #ifdef USE_SCENE_ENVIRONMENT
442
+ vec3 brdf = brdfSample.rgb;
443
+ vec3 diffuseLight = diffuseSample.rgb;
444
+ vec3 specularLight = specularSample.rgb;
445
+ #else
446
+ vec3 brdf = SRGBtoLINEAR(brdfSample).rgb;
447
+ vec3 diffuseLight = SRGBtoLINEAR(diffuseSample).rgb;
448
+ vec3 specularLight = SRGBtoLINEAR(specularSample).rgb;
449
+ #endif
450
+
451
+ vec3 diffuse = diffuseLight * pbrInfo.diffuseColor;
452
+ vec3 specular = specularLight * (pbrInfo.specularColor * brdf.x + brdf.y);
453
+
454
+ // For presentation, this allows us to disable IBL terms
455
+ diffuse *= pbrMaterial.scaleIBLAmbient.x;
456
+ specular *= pbrMaterial.scaleIBLAmbient.y;
457
+
458
+ #ifdef USE_SCENE_ENVIRONMENT
459
+ return (diffuse + specular) * max(pbrScene.environmentIntensity, 0.0);
460
+ #else
461
+ return diffuse + specular;
462
+ #endif
463
+ }
464
+ #endif
465
+
466
+ // Basic Lambertian diffuse
467
+ // Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog
468
+ // See also [1], Equation 1
469
+ vec3 diffuse(PBRInfo pbrInfo)
470
+ {
471
+ return pbrInfo.diffuseColor / M_PI;
472
+ }
473
+
474
+ // The following equation models the Fresnel reflectance term of the spec equation (aka F())
475
+ // Implementation of fresnel from [4], Equation 15
476
+ vec3 specularReflection(PBRInfo pbrInfo)
477
+ {
478
+ return pbrInfo.reflectance0 +
479
+ (pbrInfo.reflectance90 - pbrInfo.reflectance0) *
480
+ pow(clamp(1.0 - pbrInfo.VdotH, 0.0, 1.0), 5.0);
481
+ }
482
+
483
+ // This calculates the specular geometric attenuation (aka G()),
484
+ // where rougher material will reflect less light back to the viewer.
485
+ // This implementation is based on [1] Equation 4, and we adopt their modifications to
486
+ // alphaRoughness as input as originally proposed in [2].
487
+ float geometricOcclusion(PBRInfo pbrInfo)
488
+ {
489
+ float NdotL = pbrInfo.NdotL;
490
+ float NdotV = pbrInfo.NdotV;
491
+ float r = pbrInfo.alphaRoughness;
492
+
493
+ float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));
494
+ float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));
495
+ return attenuationL * attenuationV;
496
+ }
497
+
498
+ // The following equation(s) model the distribution of microfacet normals across
499
+ // the area being drawn (aka D())
500
+ // Implementation from "Average Irregularity Representation of a Roughened Surface
501
+ // for Ray Reflection" by T. S. Trowbridge, and K. P. Reitz
502
+ // Follows the distribution function recommended in the SIGGRAPH 2013 course notes
503
+ // from EPIC Games [1], Equation 3.
504
+ float microfacetDistribution(PBRInfo pbrInfo)
505
+ {
506
+ float roughnessSq = pbrInfo.alphaRoughness * pbrInfo.alphaRoughness;
507
+ float f = (pbrInfo.NdotH * roughnessSq - pbrInfo.NdotH) * pbrInfo.NdotH + 1.0;
508
+ return roughnessSq / (M_PI * f * f);
509
+ }
510
+
511
+ float maxComponent(vec3 value)
512
+ {
513
+ return max(max(value.r, value.g), value.b);
514
+ }
515
+
516
+ float getDielectricF0(float ior)
517
+ {
518
+ float clampedIor = max(ior, 1.0);
519
+ float ratio = (clampedIor - 1.0) / (clampedIor + 1.0);
520
+ return ratio * ratio;
521
+ }
522
+
523
+ vec2 normalizeDirection(vec2 direction)
524
+ {
525
+ float directionLength = length(direction);
526
+ return directionLength > 0.0001 ? direction / directionLength : vec2(1.0, 0.0);
527
+ }
528
+
529
+ vec2 rotateDirection(vec2 direction, float rotation)
530
+ {
531
+ float s = sin(rotation);
532
+ float c = cos(rotation);
533
+ return vec2(direction.x * c - direction.y * s, direction.x * s + direction.y * c);
534
+ }
535
+
536
+ vec3 encodeLinearSRGB(vec3 linearColor)
537
+ {
538
+ vec3 positiveColor = max(linearColor, vec3(0.0));
539
+ return mix(
540
+ positiveColor * 12.92,
541
+ 1.055 * pow(positiveColor, vec3(1.0 / 2.4)) - 0.055,
542
+ greaterThan(positiveColor, vec3(0.0031308))
543
+ );
544
+ }
545
+
546
+ vec3 toneMapKhronosPBRNeutral(vec3 color)
547
+ {
548
+ const float startCompression = 0.76;
549
+ float darkestChannel = min(color.r, min(color.g, color.b));
550
+ float offset = darkestChannel < 0.08
551
+ ? darkestChannel - 6.25 * darkestChannel * darkestChannel
552
+ : 0.04;
553
+ color -= vec3(offset);
554
+
555
+ float peak = maxComponent(color);
556
+ if (peak < startCompression) {
557
+ return color;
558
+ }
559
+
560
+ float compressionRange = 1.0 - startCompression;
561
+ float compressedPeak = 1.0 - compressionRange * compressionRange /
562
+ (peak + compressionRange - startCompression);
563
+ color *= compressedPeak / max(peak, 0.0001);
564
+ float desaturation = 1.0 - 1.0 / (0.15 * (peak - compressedPeak) + 1.0);
565
+ return mix(color, vec3(compressedPeak), desaturation);
566
+ }
567
+
568
+ vec3 applySceneColorManagement(vec3 sceneColor)
569
+ {
570
+ #ifdef USE_SCENE_COLOR_MANAGEMENT
571
+ vec3 color = max(sceneColor, vec3(0.0)) * max(pbrScene.exposure, 0.0);
572
+ if (pbrScene.toneMapMode == 1) {
573
+ color /= vec3(1.0) + color;
574
+ } else if (pbrScene.toneMapMode == 2) {
575
+ color = toneMapKhronosPBRNeutral(color);
576
+ } else if (pbrScene.toneMapMode == 3) {
577
+ color = clamp(
578
+ (color * (2.51 * color + 0.03)) / (color * (2.43 * color + 0.59) + 0.14),
579
+ vec3(0.0),
580
+ vec3(1.0)
581
+ );
582
+ }
583
+ return pbrScene.outputEncoding == 0 ? color : encodeLinearSRGB(color);
584
+ #else
585
+ return pow(max(sceneColor, vec3(0.0)), vec3(1.0 / 2.2));
586
+ #endif
587
+ }
588
+
589
+ float dielectricSchlick(float reflectance, float cosine)
590
+ {
591
+ return reflectance + (1.0 - reflectance) * pow(clamp(1.0 - cosine, 0.0, 1.0), 5.0);
592
+ }
593
+
594
+ vec3 evaluateIridescenceSensitivity(float opticalPathDifference, vec3 phaseShift)
595
+ {
596
+ float phase = 2.0 * M_PI * opticalPathDifference * 1.0e-9;
597
+ vec3 sensitivity = vec3(5.4856e-13, 4.4201e-13, 5.2481e-13);
598
+ vec3 position = vec3(1.6810e6, 1.7953e6, 2.2084e6);
599
+ vec3 variance = vec3(4.3278e9, 9.3046e9, 6.6121e9);
600
+ vec3 xyz = sensitivity * sqrt(2.0 * M_PI * variance) *
601
+ cos(position * phase + phaseShift) * exp(-phase * phase * variance);
602
+ xyz.x += 9.7470e-14 * sqrt(2.0 * M_PI * 4.5282e9) *
603
+ cos(2.2399e6 * phase + phaseShift.x) * exp(-4.5282e9 * phase * phase);
604
+ xyz /= 1.0685e-7;
605
+ return mat3(
606
+ 3.2404542, -0.9692660, 0.0556434,
607
+ -1.5371385, 1.8760108, -0.2040259,
608
+ -0.4985314, 0.0415560, 1.0572252
609
+ ) * xyz;
610
+ }
611
+
612
+ vec3 getIridescenceTint(float iridescence, float thickness, float NdotV, vec3 baseReflectance)
613
+ {
614
+ if (iridescence <= 0.0 || thickness <= 0.0) {
615
+ return baseReflectance;
616
+ }
617
+
618
+ float filmIor = max(pbrMaterial.iridescenceIor, 1.0);
619
+ float sineSquared = (1.0 - NdotV * NdotV) / (filmIor * filmIor);
620
+ float cosineSquared = 1.0 - sineSquared;
621
+ if (cosineSquared <= 0.0) {
622
+ return mix(baseReflectance, vec3(1.0), iridescence);
623
+ }
624
+ float filmCosine = sqrt(cosineSquared);
625
+ float firstInterfaceReflectance = dielectricSchlick(getDielectricF0(filmIor), NdotV);
626
+ float transmittedEnergy = 1.0 - firstInterfaceReflectance;
627
+
628
+ vec3 baseIor = (vec3(1.0) + sqrt(clamp(baseReflectance, vec3(0.0), vec3(0.9999)))) /
629
+ (vec3(1.0) - sqrt(clamp(baseReflectance, vec3(0.0), vec3(0.9999))));
630
+ vec3 secondInterfaceF0 = (baseIor - vec3(filmIor)) / (baseIor + vec3(filmIor));
631
+ secondInterfaceF0 *= secondInterfaceF0;
632
+ vec3 secondInterfaceReflectance = secondInterfaceF0 +
633
+ (vec3(1.0) - secondInterfaceF0) * pow(1.0 - filmCosine, 5.0);
634
+ vec3 phaseShift = vec3(M_PI);
635
+ phaseShift += mix(vec3(0.0), vec3(M_PI), lessThan(baseIor, vec3(filmIor)));
636
+ float opticalPathDifference = 2.0 * filmIor * thickness * filmCosine;
637
+ vec3 combinedReflectance = clamp(
638
+ firstInterfaceReflectance * secondInterfaceReflectance,
639
+ vec3(0.00001),
640
+ vec3(0.9999)
641
+ );
642
+ vec3 recurringAmplitude = sqrt(combinedReflectance);
643
+ vec3 interfaceResponse = transmittedEnergy * transmittedEnergy * secondInterfaceReflectance /
644
+ (vec3(1.0) - combinedReflectance);
645
+ vec3 reflectedSpectrum = vec3(firstInterfaceReflectance) + interfaceResponse;
646
+ vec3 harmonicAmplitude = interfaceResponse - vec3(transmittedEnergy);
647
+ for (int harmonic = 1; harmonic <= 2; harmonic++) {
648
+ harmonicAmplitude *= recurringAmplitude;
649
+ reflectedSpectrum += harmonicAmplitude * 2.0 * evaluateIridescenceSensitivity(
650
+ float(harmonic) * opticalPathDifference,
651
+ float(harmonic) * phaseShift
652
+ );
653
+ }
654
+ return mix(baseReflectance, clamp(reflectedSpectrum, vec3(0.0), vec3(1.0)), iridescence);
655
+ }
656
+
657
+ vec3 getVolumeAttenuation(float thickness)
658
+ {
659
+ if (thickness <= 0.0) {
660
+ return vec3(1.0);
661
+ }
662
+
663
+ vec3 attenuationCoefficient =
664
+ -log(max(pbrMaterial.attenuationColor, vec3(0.0001))) /
665
+ max(pbrMaterial.attenuationDistance, 0.0001);
666
+ return exp(-attenuationCoefficient * thickness);
667
+ }
668
+
669
+ // KHR_materials_volume_scatter is an active draft. This evaluates a local,
670
+ // thickness-aware single-scattering approximation rather than random walk.
671
+ vec3 getDiffuseTransmissionAttenuation(
672
+ PBRInfo pbrInfo,
673
+ vec3 multiscatterColor,
674
+ float thickness
675
+ )
676
+ {
677
+ vec3 volumeAttenuation = getVolumeAttenuation(thickness);
678
+ float scatteringStrength = maxComponent(multiscatterColor);
679
+ if (thickness <= 0.0 || scatteringStrength <= 0.0001) {
680
+ return volumeAttenuation;
681
+ }
682
+
683
+ float anisotropy = clamp(pbrMaterial.scatterAnisotropy, -0.95, 0.95);
684
+ float scatteringCosine = clamp(dot(-pbrInfo.v, pbrInfo.l), -1.0, 1.0);
685
+ float phaseDenominator = max(
686
+ 1.0 + anisotropy * anisotropy - 2.0 * anisotropy * scatteringCosine,
687
+ 0.0001
688
+ );
689
+ float phaseWeight = clamp(
690
+ (1.0 - anisotropy * anisotropy) / pow(phaseDenominator, 1.5),
691
+ 0.0,
692
+ 4.0
693
+ );
694
+ float scatteringDepth = thickness / max(pbrMaterial.attenuationDistance, 0.0001);
695
+ float scatteringProbability = 1.0 - exp(-scatteringDepth);
696
+ vec3 scatteringColor = clamp(multiscatterColor, vec3(0.0), vec3(1.0));
697
+ return mix(
698
+ volumeAttenuation,
699
+ volumeAttenuation * mix(vec3(1.0), scatteringColor * phaseWeight, scatteringColor),
700
+ scatteringProbability
701
+ );
702
+ }
703
+
704
+ vec3 calculateDiffuseTransmissionLight(
705
+ PBRInfo pbrInfo,
706
+ vec3 lightColor,
707
+ vec3 diffuseTransmissionColor,
708
+ float diffuseTransmission,
709
+ vec3 multiscatterColor,
710
+ float thickness
711
+ )
712
+ {
713
+ float oppositeHemisphere = max(dot(-pbrInfo.n, pbrInfo.l), 0.0);
714
+ if (oppositeHemisphere <= 0.0 || diffuseTransmission <= 0.0) {
715
+ return vec3(0.0);
716
+ }
717
+
718
+ vec3 nonReflectedEnergy = vec3(1.0) - clamp(pbrInfo.reflectance0, vec3(0.0), vec3(1.0));
719
+ vec3 attenuatedColor = getDiffuseTransmissionAttenuation(
720
+ pbrInfo,
721
+ multiscatterColor,
722
+ thickness
723
+ );
724
+ return lightColor * diffuseTransmissionColor * nonReflectedEnergy *
725
+ attenuatedColor * (diffuseTransmission * oppositeHemisphere / M_PI);
726
+ }
727
+
728
+ #ifdef USE_IBL
729
+ vec3 calculateDiffuseTransmissionIBL(
730
+ PBRInfo pbrInfo,
731
+ vec3 diffuseTransmissionColor,
732
+ float diffuseTransmission,
733
+ vec3 multiscatterColor,
734
+ float thickness
735
+ )
736
+ {
737
+ if (diffuseTransmission <= 0.0) {
738
+ return vec3(0.0);
739
+ }
740
+
741
+ #ifdef USE_SCENE_ENVIRONMENT
742
+ float rotationSine = sin(pbrScene.environmentRotation);
743
+ float rotationCosine = cos(pbrScene.environmentRotation);
744
+ mat2 environmentRotation = mat2(rotationCosine, rotationSine, -rotationSine, rotationCosine);
745
+ vec3 oppositeNormal = vec3(environmentRotation * -pbrInfo.n.xz, -pbrInfo.n.y).xzy;
746
+ vec3 environmentColor = texture(pbr_diffuseEnvSampler, oppositeNormal).rgb *
747
+ max(pbrScene.environmentIntensity, 0.0);
748
+ #else
749
+ vec3 environmentColor = SRGBtoLINEAR(texture(pbr_diffuseEnvSampler, -pbrInfo.n)).rgb;
750
+ #endif
751
+ vec3 nonReflectedEnergy = vec3(1.0) - clamp(pbrInfo.reflectance0, vec3(0.0), vec3(1.0));
752
+ return environmentColor * diffuseTransmissionColor * nonReflectedEnergy *
753
+ getDiffuseTransmissionAttenuation(pbrInfo, multiscatterColor, thickness) *
754
+ diffuseTransmission * pbrMaterial.scaleIBLAmbient.x;
755
+ }
756
+ #endif
757
+
758
+ #ifdef USE_TRANSMISSION_FRAMEBUFFER
759
+ vec3 sampleTransmittedSceneColor(
760
+ vec3 position,
761
+ vec3 normal,
762
+ vec3 viewDirection,
763
+ float thickness,
764
+ float perceptualRoughness,
765
+ float indexOfRefraction
766
+ )
767
+ {
768
+ vec3 refractionDirection = refract(
769
+ -viewDirection,
770
+ normal,
771
+ 1.0 / max(indexOfRefraction, 1.0)
772
+ );
773
+ vec3 refractedPosition = position + refractionDirection * thickness;
774
+ vec4 clipPosition = pbrScene.projectionMatrix *
775
+ pbrScene.viewMatrix * vec4(refractedPosition, 1.0);
776
+ vec2 textureCoordinate = clipPosition.xy / max(clipPosition.w, 0.0001) * 0.5 + 0.5;
777
+ textureCoordinate = clamp(textureCoordinate, vec2(0.001), vec2(0.999));
778
+
779
+ vec2 blurRadius = perceptualRoughness * perceptualRoughness * 8.0 /
780
+ max(pbrScene.framebufferSize, vec2(1.0));
781
+ vec3 sceneColor = texture(pbr_transmissionFramebufferSampler, textureCoordinate).rgb * 0.4;
782
+ sceneColor += texture(
783
+ pbr_transmissionFramebufferSampler,
784
+ textureCoordinate + vec2(blurRadius.x, 0.0)
785
+ ).rgb * 0.15;
786
+ sceneColor += texture(
787
+ pbr_transmissionFramebufferSampler,
788
+ textureCoordinate - vec2(blurRadius.x, 0.0)
789
+ ).rgb * 0.15;
790
+ sceneColor += texture(
791
+ pbr_transmissionFramebufferSampler,
792
+ textureCoordinate + vec2(0.0, blurRadius.y)
793
+ ).rgb * 0.15;
794
+ sceneColor += texture(
795
+ pbr_transmissionFramebufferSampler,
796
+ textureCoordinate - vec2(0.0, blurRadius.y)
797
+ ).rgb * 0.15;
798
+ return max(sceneColor, vec3(0.0));
799
+ }
800
+
801
+ vec3 getTransmittedSceneColor(
802
+ vec3 position,
803
+ vec3 normal,
804
+ vec3 viewDirection,
805
+ float thickness,
806
+ float perceptualRoughness
807
+ )
808
+ {
809
+ if (pbrMaterial.dispersion <= 0.0) {
810
+ return sampleTransmittedSceneColor(
811
+ position,
812
+ normal,
813
+ viewDirection,
814
+ thickness,
815
+ perceptualRoughness,
816
+ pbrMaterial.ior
817
+ );
818
+ }
819
+
820
+ float halfSpread = (max(pbrMaterial.ior, 1.0) - 1.0) * 0.025 * pbrMaterial.dispersion;
821
+ vec3 indicesOfRefraction = max(
822
+ vec3(pbrMaterial.ior - halfSpread, pbrMaterial.ior, pbrMaterial.ior + halfSpread),
823
+ vec3(1.0)
824
+ );
825
+ return vec3(
826
+ sampleTransmittedSceneColor(
827
+ position, normal, viewDirection, thickness, perceptualRoughness, indicesOfRefraction.r
828
+ ).r,
829
+ sampleTransmittedSceneColor(
830
+ position, normal, viewDirection, thickness, perceptualRoughness, indicesOfRefraction.g
831
+ ).g,
832
+ sampleTransmittedSceneColor(
833
+ position, normal, viewDirection, thickness, perceptualRoughness, indicesOfRefraction.b
834
+ ).b
835
+ );
836
+ }
837
+ #endif
838
+
839
+ PBRInfo createClearcoatPBRInfo(PBRInfo basePBRInfo, vec3 clearcoatNormal, float clearcoatRoughness)
840
+ {
841
+ float perceptualRoughness = clamp(clearcoatRoughness, c_MinRoughness, 1.0);
842
+ float alphaRoughness = perceptualRoughness * perceptualRoughness;
843
+ float NdotV = clamp(abs(dot(clearcoatNormal, basePBRInfo.v)), 0.001, 1.0);
844
+
845
+ return PBRInfo(
846
+ basePBRInfo.NdotL,
847
+ NdotV,
848
+ basePBRInfo.NdotH,
849
+ basePBRInfo.LdotH,
850
+ basePBRInfo.VdotH,
851
+ perceptualRoughness,
852
+ 0.0,
853
+ vec3(0.04),
854
+ vec3(1.0),
855
+ alphaRoughness,
856
+ vec3(0.0),
857
+ vec3(0.04),
858
+ clearcoatNormal,
859
+ basePBRInfo.v,
860
+ basePBRInfo.l,
861
+ basePBRInfo.h
862
+ );
863
+ }
864
+
865
+ vec3 calculateClearcoatContribution(
866
+ PBRInfo pbrInfo,
867
+ vec3 lightColor,
868
+ vec3 clearcoatNormal,
869
+ float clearcoatFactor,
870
+ float clearcoatRoughness
871
+ ) {
872
+ if (clearcoatFactor <= 0.0) {
873
+ return vec3(0.0);
874
+ }
875
+
876
+ PBRInfo clearcoatPBRInfo = createClearcoatPBRInfo(pbrInfo, clearcoatNormal, clearcoatRoughness);
877
+ return calculateFinalColor(clearcoatPBRInfo, lightColor) * clearcoatFactor;
878
+ }
879
+
880
+ #ifdef USE_IBL
881
+ vec3 calculateClearcoatIBLContribution(
882
+ PBRInfo pbrInfo,
883
+ vec3 clearcoatNormal,
884
+ vec3 reflection,
885
+ float clearcoatFactor,
886
+ float clearcoatRoughness
887
+ ) {
888
+ if (clearcoatFactor <= 0.0) {
889
+ return vec3(0.0);
890
+ }
891
+
892
+ PBRInfo clearcoatPBRInfo = createClearcoatPBRInfo(pbrInfo, clearcoatNormal, clearcoatRoughness);
893
+ return getIBLContribution(clearcoatPBRInfo, clearcoatNormal, reflection) * clearcoatFactor;
894
+ }
895
+ #endif
896
+
897
+ vec3 calculateSheenContribution(
898
+ PBRInfo pbrInfo,
899
+ vec3 lightColor,
900
+ vec3 sheenColor,
901
+ float sheenRoughness
902
+ ) {
903
+ if (maxComponent(sheenColor) <= 0.0) {
904
+ return vec3(0.0);
905
+ }
906
+
907
+ float alpha = max(sheenRoughness * sheenRoughness, 0.0001);
908
+ float inverseAlpha = 1.0 / alpha;
909
+ float sineSquared = max(1.0 - pbrInfo.NdotH * pbrInfo.NdotH, 0.0);
910
+ float distribution = (2.0 + inverseAlpha) * pow(sineSquared, inverseAlpha * 0.5) /
911
+ (2.0 * M_PI);
912
+ float visibility = 1.0 / max(
913
+ 4.0 * (pbrInfo.NdotL + pbrInfo.NdotV - pbrInfo.NdotL * pbrInfo.NdotV),
914
+ 0.0001
915
+ );
916
+ return pbrInfo.NdotL * lightColor * sheenColor * distribution * visibility *
917
+ (1.0 - pbrInfo.metalness);
918
+ }
919
+
920
+ vec3 calculateAnisotropicLightColor(
921
+ PBRInfo pbrInfo,
922
+ vec3 lightColor,
923
+ vec3 anisotropyTangent,
924
+ float anisotropyStrength
925
+ ) {
926
+ if (anisotropyStrength <= 0.0) {
927
+ return calculateFinalColor(pbrInfo, lightColor);
928
+ }
929
+
930
+ vec3 anisotropyBitangent = normalize(cross(pbrInfo.n, anisotropyTangent));
931
+ float tangentRoughness = mix(
932
+ pbrInfo.alphaRoughness,
933
+ 1.0,
934
+ anisotropyStrength * anisotropyStrength
935
+ );
936
+ float bitangentRoughness = clamp(pbrInfo.alphaRoughness, 0.001, 1.0);
937
+ float roughnessProduct = tangentRoughness * bitangentRoughness;
938
+ vec3 distributionVector = vec3(
939
+ bitangentRoughness * dot(anisotropyTangent, pbrInfo.h),
940
+ tangentRoughness * dot(anisotropyBitangent, pbrInfo.h),
941
+ roughnessProduct * pbrInfo.NdotH
942
+ );
943
+ float distributionFactor = roughnessProduct /
944
+ max(dot(distributionVector, distributionVector), 0.000001);
945
+ float distribution = roughnessProduct * distributionFactor * distributionFactor / M_PI;
946
+ float viewMask = pbrInfo.NdotL * length(vec3(
947
+ tangentRoughness * dot(anisotropyTangent, pbrInfo.v),
948
+ bitangentRoughness * dot(anisotropyBitangent, pbrInfo.v),
949
+ pbrInfo.NdotV
950
+ ));
951
+ float lightMask = pbrInfo.NdotV * length(vec3(
952
+ tangentRoughness * dot(anisotropyTangent, pbrInfo.l),
953
+ bitangentRoughness * dot(anisotropyBitangent, pbrInfo.l),
954
+ pbrInfo.NdotL
955
+ ));
956
+ float visibility = clamp(0.5 / max(viewMask + lightMask, 0.000001), 0.0, 1.0);
957
+ vec3 fresnel = specularReflection(pbrInfo);
958
+ vec3 diffuseContribution = (vec3(1.0) - fresnel) * diffuse(pbrInfo);
959
+ return pbrInfo.NdotL * lightColor *
960
+ (diffuseContribution + fresnel * distribution * visibility);
961
+ }
962
+
963
+ vec3 getAnisotropicReflection(PBRInfo pbrInfo, vec3 anisotropyTangent, float anisotropyStrength)
964
+ {
965
+ if (anisotropyStrength <= 0.0) {
966
+ return -normalize(reflect(pbrInfo.v, pbrInfo.n));
967
+ }
968
+ vec3 anisotropyBitangent = normalize(cross(pbrInfo.n, anisotropyTangent));
969
+ vec3 anisotropicNormal = normalize(cross(anisotropyBitangent, pbrInfo.v));
970
+ anisotropicNormal = normalize(cross(anisotropicNormal, anisotropyBitangent));
971
+ float bend = anisotropyStrength * (1.0 - pbrInfo.perceptualRoughness);
972
+ return -normalize(reflect(pbrInfo.v, normalize(mix(pbrInfo.n, anisotropicNormal, bend))));
973
+ }
974
+
975
+ vec3 calculateMaterialLightColor(
976
+ PBRInfo pbrInfo,
977
+ vec3 lightColor,
978
+ vec3 clearcoatNormal,
979
+ float clearcoatFactor,
980
+ float clearcoatRoughness,
981
+ vec3 sheenColor,
982
+ float sheenRoughness,
983
+ vec3 anisotropyTangent,
984
+ float anisotropyStrength
985
+ ) {
986
+ vec3 color = calculateAnisotropicLightColor(
987
+ pbrInfo,
988
+ lightColor,
989
+ anisotropyTangent,
990
+ anisotropyStrength
991
+ );
992
+ color += calculateClearcoatContribution(
993
+ pbrInfo,
994
+ lightColor,
995
+ clearcoatNormal,
996
+ clearcoatFactor,
997
+ clearcoatRoughness
998
+ );
999
+ color += calculateSheenContribution(pbrInfo, lightColor, sheenColor, sheenRoughness);
1000
+ return color;
1001
+ }
1002
+
1003
+ void PBRInfo_setAmbientLight(inout PBRInfo pbrInfo) {
1004
+ pbrInfo.NdotL = 1.0;
1005
+ pbrInfo.NdotH = 0.0;
1006
+ pbrInfo.LdotH = 0.0;
1007
+ pbrInfo.VdotH = 1.0;
1008
+ pbrInfo.l = pbrInfo.n;
1009
+ pbrInfo.h = pbrInfo.n;
1010
+ }
1011
+
1012
+ void PBRInfo_setDirectionalLight(inout PBRInfo pbrInfo, vec3 lightDirection) {
1013
+ vec3 n = pbrInfo.n;
1014
+ vec3 v = pbrInfo.v;
1015
+ vec3 l = normalize(lightDirection); // Vector from surface point to light
1016
+ vec3 h = normalize(l+v); // Half vector between both l and v
1017
+
1018
+ pbrInfo.NdotL = clamp(dot(n, l), 0.001, 1.0);
1019
+ pbrInfo.NdotH = clamp(dot(n, h), 0.0, 1.0);
1020
+ pbrInfo.LdotH = clamp(dot(l, h), 0.0, 1.0);
1021
+ pbrInfo.VdotH = clamp(dot(v, h), 0.0, 1.0);
1022
+ pbrInfo.l = l;
1023
+ pbrInfo.h = h;
1024
+ }
1025
+
1026
+ void PBRInfo_setPointLight(inout PBRInfo pbrInfo, PointLight pointLight) {
1027
+ vec3 light_direction = normalize(pointLight.position - pbr_vPosition);
1028
+ PBRInfo_setDirectionalLight(pbrInfo, light_direction);
1029
+ }
1030
+
1031
+ void PBRInfo_setSpotLight(inout PBRInfo pbrInfo, SpotLight spotLight) {
1032
+ vec3 light_direction = normalize(spotLight.position - pbr_vPosition);
1033
+ PBRInfo_setDirectionalLight(pbrInfo, light_direction);
1034
+ }
1035
+
1036
+ vec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor) {
1037
+ // Calculate the shading terms for the microfacet specular shading model
1038
+ vec3 F = specularReflection(pbrInfo);
1039
+ float G = geometricOcclusion(pbrInfo);
1040
+ float D = microfacetDistribution(pbrInfo);
1041
+
1042
+ // Calculation of analytical lighting contribution
1043
+ vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInfo);
1044
+ vec3 specContrib = F * G * D / (4.0 * pbrInfo.NdotL * pbrInfo.NdotV);
1045
+ // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)
1046
+ return pbrInfo.NdotL * lightColor * (diffuseContrib + specContrib);
1047
+ }
1048
+
1049
+ // Visibility for the first four spotlights; environment and other lights are unaffected.
1050
+ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
1051
+ {
1052
+ vec2 baseColorUV = getMaterialUV(pbrMaterial.baseColorUVSet, pbrMaterial.baseColorUVTransform);
1053
+ vec2 metallicRoughnessUV = getMaterialUV(
1054
+ pbrMaterial.metallicRoughnessUVSet,
1055
+ pbrMaterial.metallicRoughnessUVTransform
1056
+ );
1057
+ vec2 normalUV = getMaterialUV(pbrMaterial.normalUVSet, pbrMaterial.normalUVTransform);
1058
+ vec2 occlusionUV = getMaterialUV(pbrMaterial.occlusionUVSet, pbrMaterial.occlusionUVTransform);
1059
+ vec2 emissiveUV = getMaterialUV(pbrMaterial.emissiveUVSet, pbrMaterial.emissiveUVTransform);
1060
+ vec2 lightmapUV = getMaterialUV(pbrMaterial.lightmapUVSet, pbrMaterial.lightmapUVTransform);
1061
+ vec2 specularColorUV = getMaterialUV(
1062
+ pbrMaterial.specularColorUVSet,
1063
+ pbrMaterial.specularColorUVTransform
1064
+ );
1065
+ vec2 specularIntensityUV = getMaterialUV(
1066
+ pbrMaterial.specularIntensityUVSet,
1067
+ pbrMaterial.specularIntensityUVTransform
1068
+ );
1069
+ vec2 transmissionUV = getMaterialUV(
1070
+ pbrMaterial.transmissionUVSet,
1071
+ pbrMaterial.transmissionUVTransform
1072
+ );
1073
+ vec2 thicknessUV = getMaterialUV(pbrMaterial.thicknessUVSet, pbrMaterial.thicknessUVTransform);
1074
+ vec2 clearcoatUV = getMaterialUV(pbrMaterial.clearcoatUVSet, pbrMaterial.clearcoatUVTransform);
1075
+ vec2 clearcoatRoughnessUV = getMaterialUV(
1076
+ pbrMaterial.clearcoatRoughnessUVSet,
1077
+ pbrMaterial.clearcoatRoughnessUVTransform
1078
+ );
1079
+ vec2 clearcoatNormalUV = getMaterialUV(
1080
+ pbrMaterial.clearcoatNormalUVSet,
1081
+ pbrMaterial.clearcoatNormalUVTransform
1082
+ );
1083
+ vec2 sheenColorUV = getMaterialUV(
1084
+ pbrMaterial.sheenColorUVSet,
1085
+ pbrMaterial.sheenColorUVTransform
1086
+ );
1087
+ vec2 sheenRoughnessUV = getMaterialUV(
1088
+ pbrMaterial.sheenRoughnessUVSet,
1089
+ pbrMaterial.sheenRoughnessUVTransform
1090
+ );
1091
+ vec2 iridescenceUV = getMaterialUV(
1092
+ pbrMaterial.iridescenceUVSet,
1093
+ pbrMaterial.iridescenceUVTransform
1094
+ );
1095
+ vec2 iridescenceThicknessUV = getMaterialUV(
1096
+ pbrMaterial.iridescenceThicknessUVSet,
1097
+ pbrMaterial.iridescenceThicknessUVTransform
1098
+ );
1099
+ vec2 anisotropyUV = getMaterialUV(
1100
+ pbrMaterial.anisotropyUVSet,
1101
+ pbrMaterial.anisotropyUVTransform
1102
+ );
1103
+ vec2 diffuseTransmissionUV = getMaterialUV(
1104
+ pbrMaterial.diffuseTransmissionUVSet,
1105
+ pbrMaterial.diffuseTransmissionUVTransform
1106
+ );
1107
+ vec2 diffuseTransmissionColorUV = getMaterialUV(
1108
+ pbrMaterial.diffuseTransmissionColorUVSet,
1109
+ pbrMaterial.diffuseTransmissionColorUVTransform
1110
+ );
1111
+ vec2 multiscatterColorUV = getMaterialUV(
1112
+ pbrMaterial.multiscatterColorUVSet,
1113
+ pbrMaterial.multiscatterColorUVTransform
1114
+ );
1115
+
1116
+ // The albedo may be defined from a base texture or a flat color
1117
+ #ifdef HAS_BASECOLORMAP
1118
+ vec4 baseColor =
1119
+ SRGBtoLINEAR(texture(pbr_baseColorSampler, baseColorUV)) *
1120
+ pbrMaterial.baseColorFactor * vertexColor;
1121
+ #else
1122
+ vec4 baseColor = pbrMaterial.baseColorFactor * vertexColor;
1123
+ #endif
1124
+
1125
+ #ifdef ALPHA_CUTOFF
1126
+ if (baseColor.a < pbrMaterial.alphaCutoff) {
1127
+ discard;
1128
+ }
1129
+ #endif
1130
+
1131
+ vec3 color = vec3(0, 0, 0);
1132
+
1133
+ float transmission = 0.0;
1134
+
1135
+ vec3 lightmapIrradiance = vec3(0.0);
1136
+ #ifdef HAS_LIGHTMAP
1137
+ if (pbrMaterial.lightmapMapEnabled) {
1138
+ lightmapIrradiance = texture(pbr_lightmapSampler, lightmapUV).rgb * pbrMaterial.lightmapIntensity;
1139
+ }
1140
+ #endif
1141
+
1142
+ if(pbrMaterial.unlit){
1143
+ color.rgb = baseColor.rgb;
1144
+ #ifdef HAS_LIGHTMAP
1145
+ if (pbrMaterial.lightmapMapEnabled) {
1146
+ color *= lightmapIrradiance / M_PI;
1147
+ #ifdef HAS_OCCLUSIONMAP
1148
+ if (pbrMaterial.occlusionMapEnabled) {
1149
+ float ao = texture(pbr_occlusionSampler, occlusionUV).r;
1150
+ color = mix(color, color * ao, pbrMaterial.occlusionStrength);
1151
+ }
1152
+ #endif
1153
+ }
1154
+ #endif
1155
+ }
1156
+ else{
1157
+ // Metallic and Roughness material properties are packed together
1158
+ // In glTF, these factors can be specified by fixed scalar values
1159
+ // or from a metallic-roughness map
1160
+ float perceptualRoughness = pbrMaterial.metallicRoughnessValues.y;
1161
+ float metallic = pbrMaterial.metallicRoughnessValues.x;
1162
+ #ifdef HAS_METALROUGHNESSMAP
1163
+ // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
1164
+ // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
1165
+ vec4 mrSample = texture(pbr_metallicRoughnessSampler, metallicRoughnessUV);
1166
+ perceptualRoughness = mrSample.g * perceptualRoughness;
1167
+ metallic = mrSample.b * metallic;
1168
+ #endif
1169
+ perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);
1170
+ metallic = clamp(metallic, 0.0, 1.0);
1171
+ mat3 tbn = getTBN(normalUV);
1172
+ vec3 n = getNormal(tbn, normalUV); // normal at surface point
1173
+ perceptualRoughness = widenSpecularRoughness(perceptualRoughness, n);
1174
+ vec3 v = normalize(pbrProjection.camera - pbr_vPosition); // Vector from surface point to camera
1175
+ float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
1176
+ #ifdef USE_MATERIAL_EXTENSIONS
1177
+ bool useExtendedPBR =
1178
+ pbrMaterial.specularColorMapEnabled ||
1179
+ pbrMaterial.specularIntensityMapEnabled ||
1180
+ abs(pbrMaterial.specularIntensityFactor - 1.0) > 0.0001 ||
1181
+ maxComponent(abs(pbrMaterial.specularColorFactor - vec3(1.0))) > 0.0001 ||
1182
+ abs(pbrMaterial.ior - 1.5) > 0.0001 ||
1183
+ pbrMaterial.dispersion > 0.0001 ||
1184
+ pbrMaterial.transmissionMapEnabled ||
1185
+ pbrMaterial.transmissionFactor > 0.0001 ||
1186
+ pbrMaterial.diffuseTransmissionMapEnabled ||
1187
+ pbrMaterial.diffuseTransmissionColorMapEnabled ||
1188
+ pbrMaterial.diffuseTransmissionFactor > 0.0001 ||
1189
+ pbrMaterial.multiscatterColorMapEnabled ||
1190
+ maxComponent(pbrMaterial.multiscatterColorFactor) > 0.0001 ||
1191
+ pbrMaterial.clearcoatMapEnabled ||
1192
+ pbrMaterial.clearcoatRoughnessMapEnabled ||
1193
+ pbrMaterial.clearcoatFactor > 0.0001 ||
1194
+ pbrMaterial.clearcoatRoughnessFactor > 0.0001 ||
1195
+ pbrMaterial.sheenColorMapEnabled ||
1196
+ pbrMaterial.sheenRoughnessMapEnabled ||
1197
+ maxComponent(pbrMaterial.sheenColorFactor) > 0.0001 ||
1198
+ pbrMaterial.sheenRoughnessFactor > 0.0001 ||
1199
+ pbrMaterial.iridescenceMapEnabled ||
1200
+ pbrMaterial.iridescenceFactor > 0.0001 ||
1201
+ abs(pbrMaterial.iridescenceIor - 1.3) > 0.0001 ||
1202
+ abs(pbrMaterial.iridescenceThicknessRange.x - 100.0) > 0.0001 ||
1203
+ abs(pbrMaterial.iridescenceThicknessRange.y - 400.0) > 0.0001 ||
1204
+ pbrMaterial.anisotropyMapEnabled ||
1205
+ pbrMaterial.anisotropyStrength > 0.0001 ||
1206
+ abs(pbrMaterial.anisotropyRotation) > 0.0001 ||
1207
+ length(pbrMaterial.anisotropyDirection - vec2(1.0, 0.0)) > 0.0001;
1208
+ #else
1209
+ bool useExtendedPBR = false;
1210
+ #endif
1211
+
1212
+ if (!useExtendedPBR) {
1213
+ // Keep the baseline metallic-roughness implementation byte-for-byte equivalent in behavior.
1214
+ float alphaRoughness = perceptualRoughness * perceptualRoughness;
1215
+
1216
+ vec3 f0 = vec3(0.04);
1217
+ vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);
1218
+ diffuseColor *= 1.0 - metallic;
1219
+ vec3 specularColor = mix(f0, baseColor.rgb, metallic);
1220
+
1221
+ float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
1222
+ float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
1223
+ vec3 specularEnvironmentR0 = specularColor.rgb;
1224
+ vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
1225
+ vec3 reflection = -normalize(reflect(v, n));
1226
+
1227
+ PBRInfo pbrInfo = PBRInfo(
1228
+ 0.0, // NdotL
1229
+ NdotV,
1230
+ 0.0, // NdotH
1231
+ 0.0, // LdotH
1232
+ 0.0, // VdotH
1233
+ perceptualRoughness,
1234
+ metallic,
1235
+ specularEnvironmentR0,
1236
+ specularEnvironmentR90,
1237
+ alphaRoughness,
1238
+ diffuseColor,
1239
+ specularColor,
1240
+ n,
1241
+ v,
1242
+ n,
1243
+ n
1244
+ );
1245
+
1246
+ #ifdef USE_LIGHTS
1247
+ PBRInfo_setAmbientLight(pbrInfo);
1248
+ color += calculateFinalColor(pbrInfo, lighting.ambientColor);
1249
+
1250
+ for(int i = 0; i < lighting.directionalLightCount; i++) {
1251
+ if (i < lighting.directionalLightCount) {
1252
+ PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);
1253
+ color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
1254
+ }
1255
+ }
1256
+
1257
+ for(int i = 0; i < lighting.pointLightCount; i++) {
1258
+ if (i < lighting.pointLightCount) {
1259
+ PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));
1260
+ float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
1261
+ color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
1262
+ }
1263
+ }
1264
+
1265
+ for(int i = 0; i < lighting.spotLightCount; i++) {
1266
+ if (i < lighting.spotLightCount) {
1267
+ PBRInfo_setSpotLight(pbrInfo, lighting_getSpotLight(i));
1268
+ float attenuation = getSpotLightAttenuation(lighting_getSpotLight(i), pbr_vPosition);
1269
+ color += calculateFinalColor(pbrInfo, lighting_getSpotLight(i).color * (i < 4 ? clamp(spotVisibility[min(i, 3)], 0.0, 1.0) : 1.0) / attenuation);
1270
+ }
1271
+ }
1272
+ for (int areaIndex = 0; areaIndex < areaLighting_getLightCount(); areaIndex++) {
1273
+ #ifdef USE_AREA_LIGHT_LTC
1274
+ color += areaLTC_evaluate(areaIndex, pbr_vPosition, pbrInfo.n, pbrInfo.v, pbrInfo.perceptualRoughness, pbrInfo.diffuseColor, pbrInfo.reflectance0, pbrInfo.reflectance90);
1275
+ #else
1276
+ for (int sampleIndex = 0; sampleIndex < areaLighting.sampleCount; sampleIndex++) {
1277
+ PointLight sampleLight = areaLighting_getSample(areaIndex, sampleIndex, pbr_vPosition);
1278
+ if (dot(sampleLight.color, sampleLight.color) > 0.0) {
1279
+ PBRInfo_setPointLight(pbrInfo, sampleLight);
1280
+ color += calculateFinalColor(pbrInfo, sampleLight.color);
1281
+ }
1282
+ }
1283
+ #endif
1284
+ }
1285
+ #endif
1286
+
1287
+ #ifdef USE_IBL
1288
+ if (pbrMaterial.IBLenabled) {
1289
+ color += getIBLContribution(pbrInfo, n, reflection);
1290
+ }
1291
+ #endif
1292
+
1293
+ // The pinned KHR_lightmap draft explicitly defines c_diff = (1 - metallic) * baseColor.
1294
+ color += baseColor.rgb * (1.0 - metallic) * lightmapIrradiance / M_PI;
1295
+
1296
+ #ifdef HAS_OCCLUSIONMAP
1297
+ if (pbrMaterial.occlusionMapEnabled) {
1298
+ float ao = texture(pbr_occlusionSampler, occlusionUV).r;
1299
+ color = mix(color, color * ao, pbrMaterial.occlusionStrength);
1300
+ }
1301
+ #endif
1302
+
1303
+ vec3 emissive = pbrMaterial.emissiveFactor;
1304
+ #ifdef HAS_EMISSIVEMAP
1305
+ if (pbrMaterial.emissiveMapEnabled) {
1306
+ emissive *= SRGBtoLINEAR(texture(pbr_emissiveSampler, emissiveUV)).rgb;
1307
+ }
1308
+ #endif
1309
+ color += emissive * pbrMaterial.emissiveStrength;
1310
+
1311
+ #ifdef PBR_DEBUG
1312
+ color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);
1313
+ color = mix(color, vec3(metallic), pbrMaterial.scaleDiffBaseMR.z);
1314
+ color = mix(color, vec3(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);
1315
+ #endif
1316
+
1317
+ return vec4(applySceneColorManagement(color), baseColor.a);
1318
+ }
1319
+
1320
+ float specularIntensity = pbrMaterial.specularIntensityFactor;
1321
+ #ifdef HAS_SPECULARINTENSITYMAP
1322
+ if (pbrMaterial.specularIntensityMapEnabled) {
1323
+ specularIntensity *= texture(pbr_specularIntensitySampler, specularIntensityUV).a;
1324
+ }
1325
+ #endif
1326
+
1327
+ vec3 specularFactor = pbrMaterial.specularColorFactor;
1328
+ #ifdef HAS_SPECULARCOLORMAP
1329
+ if (pbrMaterial.specularColorMapEnabled) {
1330
+ specularFactor *= SRGBtoLINEAR(texture(pbr_specularColorSampler, specularColorUV)).rgb;
1331
+ }
1332
+ #endif
1333
+
1334
+ transmission = pbrMaterial.transmissionFactor;
1335
+ #ifdef HAS_TRANSMISSIONMAP
1336
+ if (pbrMaterial.transmissionMapEnabled) {
1337
+ transmission *= texture(pbr_transmissionSampler, transmissionUV).r;
1338
+ }
1339
+ #endif
1340
+ transmission = clamp(transmission * (1.0 - metallic), 0.0, 1.0);
1341
+ float thickness = max(pbrMaterial.thicknessFactor, 0.0);
1342
+ #ifdef HAS_THICKNESSMAP
1343
+ thickness *= texture(pbr_thicknessSampler, thicknessUV).g;
1344
+ #endif
1345
+
1346
+ float diffuseTransmission = clamp(pbrMaterial.diffuseTransmissionFactor, 0.0, 1.0);
1347
+ #ifdef HAS_DIFFUSETRANSMISSIONMAP
1348
+ if (pbrMaterial.diffuseTransmissionMapEnabled) {
1349
+ diffuseTransmission *= texture(pbr_diffuseTransmissionSampler, diffuseTransmissionUV).a;
1350
+ }
1351
+ #endif
1352
+ diffuseTransmission *= (1.0 - metallic) * (1.0 - transmission);
1353
+ vec3 diffuseTransmissionColor = pbrMaterial.diffuseTransmissionColorFactor;
1354
+ #ifdef HAS_DIFFUSETRANSMISSIONCOLORMAP
1355
+ if (pbrMaterial.diffuseTransmissionColorMapEnabled) {
1356
+ diffuseTransmissionColor *= SRGBtoLINEAR(
1357
+ texture(pbr_diffuseTransmissionColorSampler, diffuseTransmissionColorUV)
1358
+ ).rgb;
1359
+ }
1360
+ #endif
1361
+ vec3 multiscatterColor = pbrMaterial.multiscatterColorFactor;
1362
+ #ifdef HAS_MULTISCATTERCOLORMAP
1363
+ if (pbrMaterial.multiscatterColorMapEnabled) {
1364
+ multiscatterColor *= SRGBtoLINEAR(
1365
+ texture(pbr_multiscatterColorSampler, multiscatterColorUV)
1366
+ ).rgb;
1367
+ }
1368
+ #endif
1369
+
1370
+ float originalTransmission = transmission;
1371
+ float scatterReflection = 0.0;
1372
+ #ifdef HAS_MATERIAL_SCATTER
1373
+ if (thickness <= 0.0) {
1374
+ float strength = clamp(pbrMaterial.scatterStrengthFactor, 0.0, 1.0);
1375
+ #ifdef HAS_DIFFUSETRANSMISSIONMAP
1376
+ if (pbrMaterial.diffuseTransmissionMapEnabled) {
1377
+ strength *= texture(pbr_diffuseTransmissionSampler, diffuseTransmissionUV).a;
1378
+ }
1379
+ #endif
1380
+ float anisotropy = pbrMaterial.scatterAnisotropy;
1381
+ scatterReflection = originalTransmission * strength * (1.0 - anisotropy) * 0.5;
1382
+ diffuseTransmission = originalTransmission * strength * (1.0 + anisotropy) * 0.5;
1383
+ diffuseTransmissionColor = multiscatterColor;
1384
+ transmission *= 1.0 - strength;
1385
+ }
1386
+ #endif
1387
+
1388
+ float clearcoatFactor = pbrMaterial.clearcoatFactor;
1389
+ float clearcoatRoughness = pbrMaterial.clearcoatRoughnessFactor;
1390
+ #ifdef HAS_CLEARCOATMAP
1391
+ if (pbrMaterial.clearcoatMapEnabled) {
1392
+ clearcoatFactor *= texture(pbr_clearcoatSampler, clearcoatUV).r;
1393
+ }
1394
+ #endif
1395
+ #ifdef HAS_CLEARCOATROUGHNESSMAP
1396
+ if (pbrMaterial.clearcoatRoughnessMapEnabled) {
1397
+ clearcoatRoughness *= texture(pbr_clearcoatRoughnessSampler, clearcoatRoughnessUV).g;
1398
+ }
1399
+ #endif
1400
+ clearcoatFactor = clamp(clearcoatFactor, 0.0, 1.0);
1401
+ clearcoatRoughness = clamp(clearcoatRoughness, c_MinRoughness, 1.0);
1402
+ vec3 clearcoatNormal = getClearcoatNormal(getTBN(clearcoatNormalUV), n, clearcoatNormalUV);
1403
+ clearcoatRoughness = widenSpecularRoughness(clearcoatRoughness, clearcoatNormal);
1404
+
1405
+ vec3 sheenColor = pbrMaterial.sheenColorFactor;
1406
+ float sheenRoughness = pbrMaterial.sheenRoughnessFactor;
1407
+ #ifdef HAS_SHEENCOLORMAP
1408
+ if (pbrMaterial.sheenColorMapEnabled) {
1409
+ sheenColor *= SRGBtoLINEAR(texture(pbr_sheenColorSampler, sheenColorUV)).rgb;
1410
+ }
1411
+ #endif
1412
+ #ifdef HAS_SHEENROUGHNESSMAP
1413
+ if (pbrMaterial.sheenRoughnessMapEnabled) {
1414
+ sheenRoughness *= texture(pbr_sheenRoughnessSampler, sheenRoughnessUV).a;
1415
+ }
1416
+ #endif
1417
+ sheenRoughness = clamp(sheenRoughness, c_MinRoughness, 1.0);
1418
+
1419
+ float iridescence = pbrMaterial.iridescenceFactor;
1420
+ #ifdef HAS_IRIDESCENCEMAP
1421
+ if (pbrMaterial.iridescenceMapEnabled) {
1422
+ iridescence *= texture(pbr_iridescenceSampler, iridescenceUV).r;
1423
+ }
1424
+ #endif
1425
+ iridescence = clamp(iridescence, 0.0, 1.0);
1426
+ float iridescenceThickness = mix(
1427
+ pbrMaterial.iridescenceThicknessRange.x,
1428
+ pbrMaterial.iridescenceThicknessRange.y,
1429
+ 0.5
1430
+ );
1431
+ #ifdef HAS_IRIDESCENCETHICKNESSMAP
1432
+ iridescenceThickness = mix(
1433
+ pbrMaterial.iridescenceThicknessRange.x,
1434
+ pbrMaterial.iridescenceThicknessRange.y,
1435
+ texture(pbr_iridescenceThicknessSampler, iridescenceThicknessUV).g
1436
+ );
1437
+ #endif
1438
+
1439
+ float anisotropyStrength = clamp(pbrMaterial.anisotropyStrength, 0.0, 1.0);
1440
+ vec2 anisotropyDirection = normalizeDirection(pbrMaterial.anisotropyDirection);
1441
+ #ifdef HAS_ANISOTROPYMAP
1442
+ if (pbrMaterial.anisotropyMapEnabled) {
1443
+ vec3 anisotropySample = texture(pbr_anisotropySampler, anisotropyUV).rgb;
1444
+ anisotropyStrength *= anisotropySample.b;
1445
+ vec2 mappedDirection = anisotropySample.rg * 2.0 - 1.0;
1446
+ if (length(mappedDirection) > 0.0001) {
1447
+ anisotropyDirection = normalize(mappedDirection);
1448
+ }
1449
+ }
1450
+ #endif
1451
+ anisotropyDirection = rotateDirection(anisotropyDirection, pbrMaterial.anisotropyRotation);
1452
+ vec3 anisotropyTangent = normalize(tbn[0] * anisotropyDirection.x + tbn[1] * anisotropyDirection.y);
1453
+ if (length(anisotropyTangent) < 0.0001) {
1454
+ anisotropyTangent = normalize(tbn[0]);
1455
+ }
1456
+ // Roughness is authored as perceptual roughness; as is convention,
1457
+ // convert to material roughness by squaring the perceptual roughness [2].
1458
+ float alphaRoughness = perceptualRoughness * perceptualRoughness;
1459
+
1460
+ float dielectricF0 = getDielectricF0(pbrMaterial.ior);
1461
+ vec3 dielectricSpecularF0 = min(
1462
+ vec3(dielectricF0) * specularFactor * specularIntensity,
1463
+ vec3(1.0)
1464
+ );
1465
+ dielectricSpecularF0 = getIridescenceTint(
1466
+ iridescence,
1467
+ iridescenceThickness,
1468
+ NdotV,
1469
+ dielectricSpecularF0
1470
+ );
1471
+ vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - dielectricSpecularF0);
1472
+ diffuseColor *= (1.0 - metallic) * (1.0 - transmission) * (1.0 - diffuseTransmission);
1473
+ #ifdef HAS_MATERIAL_SCATTER
1474
+ diffuseColor = (baseColor.rgb * (1.0 - metallic) * (1.0 - originalTransmission) +
1475
+ multiscatterColor * scatterReflection) * (vec3(1.0) - dielectricSpecularF0);
1476
+ #endif
1477
+ vec3 specularColor = mix(dielectricSpecularF0, baseColor.rgb, metallic);
1478
+
1479
+ float clearcoatViewFresnel = dielectricSchlick(
1480
+ 0.04,
1481
+ clamp(abs(dot(clearcoatNormal, v)), 0.0, 1.0)
1482
+ );
1483
+ float sheenDirectionalAlbedo = maxComponent(sheenColor) *
1484
+ (0.157 + 0.343 * (1.0 - NdotV)) * (1.0 - sheenRoughness * 0.5);
1485
+ float baseLayerEnergy = (1.0 - clearcoatFactor * clearcoatViewFresnel) *
1486
+ (1.0 - clamp(sheenDirectionalAlbedo, 0.0, 1.0));
1487
+ diffuseColor *= baseLayerEnergy;
1488
+ specularColor *= baseLayerEnergy;
1489
+
1490
+ // Compute reflectance.
1491
+ float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
1492
+
1493
+ // For typical incident reflectance range (between 4% to 100%) set the grazing
1494
+ // reflectance to 100% for typical fresnel effect.
1495
+ // For very low reflectance range on highly diffuse objects (below 4%),
1496
+ // incrementally reduce grazing reflecance to 0%.
1497
+ float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
1498
+ vec3 specularEnvironmentR0 = specularColor.rgb;
1499
+ vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
1500
+ vec3 reflection = -normalize(reflect(v, n));
1501
+
1502
+ PBRInfo pbrInfo = PBRInfo(
1503
+ 0.0, // NdotL
1504
+ NdotV,
1505
+ 0.0, // NdotH
1506
+ 0.0, // LdotH
1507
+ 0.0, // VdotH
1508
+ perceptualRoughness,
1509
+ metallic,
1510
+ specularEnvironmentR0,
1511
+ specularEnvironmentR90,
1512
+ alphaRoughness,
1513
+ diffuseColor,
1514
+ specularColor,
1515
+ n,
1516
+ v,
1517
+ n,
1518
+ n
1519
+ );
1520
+
1521
+
1522
+ #ifdef USE_LIGHTS
1523
+ // Apply ambient light
1524
+ PBRInfo_setAmbientLight(pbrInfo);
1525
+ color += calculateMaterialLightColor(
1526
+ pbrInfo,
1527
+ lighting.ambientColor,
1528
+ clearcoatNormal,
1529
+ clearcoatFactor,
1530
+ clearcoatRoughness,
1531
+ sheenColor,
1532
+ sheenRoughness,
1533
+ anisotropyTangent,
1534
+ anisotropyStrength
1535
+ );
1536
+
1537
+ // Apply directional light
1538
+ for(int i = 0; i < lighting.directionalLightCount; i++) {
1539
+ if (i < lighting.directionalLightCount) {
1540
+ PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);
1541
+ color += calculateMaterialLightColor(
1542
+ pbrInfo,
1543
+ lighting_getDirectionalLight(i).color,
1544
+ clearcoatNormal,
1545
+ clearcoatFactor,
1546
+ clearcoatRoughness,
1547
+ sheenColor,
1548
+ sheenRoughness,
1549
+ anisotropyTangent,
1550
+ anisotropyStrength
1551
+ );
1552
+ color += calculateDiffuseTransmissionLight(
1553
+ pbrInfo,
1554
+ lighting_getDirectionalLight(i).color,
1555
+ diffuseTransmissionColor,
1556
+ diffuseTransmission,
1557
+ multiscatterColor,
1558
+ thickness
1559
+ );
1560
+ }
1561
+ }
1562
+
1563
+ // Apply point light
1564
+ for(int i = 0; i < lighting.pointLightCount; i++) {
1565
+ if (i < lighting.pointLightCount) {
1566
+ PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));
1567
+ float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
1568
+ color += calculateMaterialLightColor(
1569
+ pbrInfo,
1570
+ lighting_getPointLight(i).color / attenuation,
1571
+ clearcoatNormal,
1572
+ clearcoatFactor,
1573
+ clearcoatRoughness,
1574
+ sheenColor,
1575
+ sheenRoughness,
1576
+ anisotropyTangent,
1577
+ anisotropyStrength
1578
+ );
1579
+ color += calculateDiffuseTransmissionLight(
1580
+ pbrInfo,
1581
+ lighting_getPointLight(i).color / attenuation,
1582
+ diffuseTransmissionColor,
1583
+ diffuseTransmission,
1584
+ multiscatterColor,
1585
+ thickness
1586
+ );
1587
+ }
1588
+ }
1589
+
1590
+ for(int i = 0; i < lighting.spotLightCount; i++) {
1591
+ if (i < lighting.spotLightCount) {
1592
+ PBRInfo_setSpotLight(pbrInfo, lighting_getSpotLight(i));
1593
+ float attenuation = getSpotLightAttenuation(lighting_getSpotLight(i), pbr_vPosition);
1594
+ color += calculateMaterialLightColor(
1595
+ pbrInfo,
1596
+ lighting_getSpotLight(i).color * (i < 4 ? clamp(spotVisibility[min(i, 3)], 0.0, 1.0) : 1.0) / attenuation,
1597
+ clearcoatNormal,
1598
+ clearcoatFactor,
1599
+ clearcoatRoughness,
1600
+ sheenColor,
1601
+ sheenRoughness,
1602
+ anisotropyTangent,
1603
+ anisotropyStrength
1604
+ );
1605
+ color += calculateDiffuseTransmissionLight(
1606
+ pbrInfo,
1607
+ lighting_getSpotLight(i).color * (i < 4 ? clamp(spotVisibility[min(i, 3)], 0.0, 1.0) : 1.0) / attenuation,
1608
+ diffuseTransmissionColor,
1609
+ diffuseTransmission,
1610
+ multiscatterColor,
1611
+ thickness
1612
+ );
1613
+ }
1614
+ }
1615
+ for (int areaIndex = 0; areaIndex < areaLighting_getLightCount(); areaIndex++) {
1616
+ #ifdef USE_AREA_LIGHT_LTC
1617
+ // Unsupported fits retain numerical integration rather than silently dropping material lobes.
1618
+ if (anisotropyStrength <= 0.0001 && dot(sheenColor, sheenColor) <= 0.000001 && diffuseTransmission <= 0.0001) {
1619
+ color += areaLTC_evaluate(areaIndex, pbr_vPosition, pbrInfo.n, pbrInfo.v, pbrInfo.perceptualRoughness, pbrInfo.diffuseColor, pbrInfo.reflectance0, pbrInfo.reflectance90);
1620
+ color += clearcoatFactor * areaLTC_specular(areaLighting_getLight(areaIndex), pbr_vPosition, clearcoatNormal, pbrInfo.v, clearcoatRoughness, vec3(0.04), vec3(1.0));
1621
+ } else {
1622
+ for (int sampleIndex = 0; sampleIndex < areaLighting.sampleCount; sampleIndex++) {
1623
+ PointLight sampleLight = areaLighting_getSample(areaIndex, sampleIndex, pbr_vPosition);
1624
+ if (dot(sampleLight.color, sampleLight.color) > 0.0) {
1625
+ PBRInfo_setPointLight(pbrInfo, sampleLight);
1626
+ color += calculateMaterialLightColor(pbrInfo, sampleLight.color, clearcoatNormal,
1627
+ clearcoatFactor, clearcoatRoughness, sheenColor, sheenRoughness, anisotropyTangent, anisotropyStrength);
1628
+ color += calculateDiffuseTransmissionLight(pbrInfo, sampleLight.color,
1629
+ diffuseTransmissionColor, diffuseTransmission, multiscatterColor, thickness);
1630
+ }
1631
+ }
1632
+
1633
+ }
1634
+ #else
1635
+ for (int sampleIndex = 0; sampleIndex < areaLighting.sampleCount; sampleIndex++) {
1636
+ PointLight sampleLight = areaLighting_getSample(areaIndex, sampleIndex, pbr_vPosition);
1637
+ if (dot(sampleLight.color, sampleLight.color) > 0.0) {
1638
+ PBRInfo_setPointLight(pbrInfo, sampleLight);
1639
+ color += calculateMaterialLightColor(pbrInfo, sampleLight.color, clearcoatNormal,
1640
+ clearcoatFactor, clearcoatRoughness, sheenColor, sheenRoughness, anisotropyTangent, anisotropyStrength);
1641
+ color += calculateDiffuseTransmissionLight(pbrInfo, sampleLight.color,
1642
+ diffuseTransmissionColor, diffuseTransmission, multiscatterColor, thickness);
1643
+ }
1644
+ }
1645
+
1646
+ #endif
1647
+ }
1648
+ #endif
1649
+
1650
+ // Calculate lighting contribution from image based lighting source (IBL)
1651
+ #ifdef USE_IBL
1652
+ if (pbrMaterial.IBLenabled) {
1653
+ color += getIBLContribution(
1654
+ pbrInfo,
1655
+ n,
1656
+ getAnisotropicReflection(pbrInfo, anisotropyTangent, anisotropyStrength)
1657
+ );
1658
+ color += calculateClearcoatIBLContribution(
1659
+ pbrInfo,
1660
+ clearcoatNormal,
1661
+ -normalize(reflect(v, clearcoatNormal)),
1662
+ clearcoatFactor,
1663
+ clearcoatRoughness
1664
+ );
1665
+ color += calculateDiffuseTransmissionIBL(
1666
+ pbrInfo,
1667
+ diffuseTransmissionColor,
1668
+ diffuseTransmission,
1669
+ multiscatterColor,
1670
+ thickness
1671
+ );
1672
+ color += sheenColor * pbrMaterial.scaleIBLAmbient.x * (1.0 - sheenRoughness) * 0.25;
1673
+ }
1674
+ #endif
1675
+
1676
+ #ifdef HAS_MATERIAL_SCATTER
1677
+ color += (baseColor.rgb * (1.0 - metallic) * (1.0 - originalTransmission) +
1678
+ multiscatterColor * scatterReflection) * baseLayerEnergy * lightmapIrradiance / M_PI;
1679
+ #else
1680
+ color += baseColor.rgb * (1.0 - metallic) * (1.0 - transmission) *
1681
+ (1.0 - diffuseTransmission) * baseLayerEnergy * lightmapIrradiance / M_PI;
1682
+ #endif
1683
+
1684
+ // Apply optional PBR terms for additional (optional) shading
1685
+ #ifdef HAS_OCCLUSIONMAP
1686
+ if (pbrMaterial.occlusionMapEnabled) {
1687
+ float ao = texture(pbr_occlusionSampler, occlusionUV).r;
1688
+ color = mix(color, color * ao, pbrMaterial.occlusionStrength);
1689
+ }
1690
+ #endif
1691
+
1692
+ vec3 emissive = pbrMaterial.emissiveFactor;
1693
+ #ifdef HAS_EMISSIVEMAP
1694
+ if (pbrMaterial.emissiveMapEnabled) {
1695
+ emissive *= SRGBtoLINEAR(texture(pbr_emissiveSampler, emissiveUV)).rgb;
1696
+ }
1697
+ #endif
1698
+ color += emissive * pbrMaterial.emissiveStrength;
1699
+
1700
+ if (transmission > 0.0) {
1701
+ #ifdef USE_TRANSMISSION_FRAMEBUFFER
1702
+ float dielectricFresnel = getDielectricF0(pbrMaterial.ior);
1703
+ float transmissionFresnel = dielectricFresnel +
1704
+ (1.0 - dielectricFresnel) * pow(1.0 - NdotV, 5.0);
1705
+ vec3 transmittedColor = getTransmittedSceneColor(
1706
+ pbr_vPosition,
1707
+ n,
1708
+ v,
1709
+ thickness,
1710
+ perceptualRoughness
1711
+ );
1712
+ color += transmittedColor * getVolumeAttenuation(thickness) *
1713
+ transmission * (1.0 - transmissionFresnel);
1714
+ #else
1715
+ color = mix(color, color * getVolumeAttenuation(thickness), transmission);
1716
+ #endif
1717
+ }
1718
+
1719
+ // This section uses mix to override final color for reference app visualization
1720
+ // of various parameters in the lighting equation.
1721
+ #ifdef PBR_DEBUG
1722
+ // TODO: Figure out how to debug multiple lights
1723
+
1724
+ // color = mix(color, F, pbr_scaleFGDSpec.x);
1725
+ // color = mix(color, vec3(G), pbr_scaleFGDSpec.y);
1726
+ // color = mix(color, vec3(D), pbr_scaleFGDSpec.z);
1727
+ // color = mix(color, specContrib, pbr_scaleFGDSpec.w);
1728
+
1729
+ // color = mix(color, diffuseContrib, pbr_scaleDiffBaseMR.x);
1730
+ color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);
1731
+ color = mix(color, vec3(metallic), pbrMaterial.scaleDiffBaseMR.z);
1732
+ color = mix(color, vec3(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);
1733
+ #endif
1734
+
1735
+ }
1736
+
1737
+ #ifdef USE_TRANSMISSION_FRAMEBUFFER
1738
+ float alpha = clamp(baseColor.a, 0.0, 1.0);
1739
+ #else
1740
+ float alpha = clamp(baseColor.a * (1.0 - transmission), 0.0, 1.0);
1741
+ #endif
1742
+ return vec4(applySceneColorManagement(color), alpha);
1743
+ }
1744
+
1745
+ vec4 pbr_filterColor(vec4 vertexColor) {
1746
+ return pbr_filterColorWithSpotShadows(vertexColor, vec4(1.0));
1747
+ }
1748
+ `;