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

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