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

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