angular-three-soba 1.13.0 → 1.14.1

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 (257) hide show
  1. package/abstractions/lib/billboard/billboard.d.ts +1 -1
  2. package/abstractions/lib/catmull-rom-line/catmull-rom-line.d.ts +1 -1
  3. package/abstractions/lib/cubic-bezier-line/cubic-bezier-line.d.ts +1 -1
  4. package/abstractions/lib/edges/edges.d.ts +2 -2
  5. package/abstractions/lib/gizmo-helper/gizmo-helper.d.ts +1 -1
  6. package/abstractions/lib/gizmo-helper/gizmo-viewcube/gizmo-viewcube-edge.d.ts +1 -1
  7. package/abstractions/lib/gizmo-helper/gizmo-viewcube/gizmo-viewcube-face.d.ts +2 -2
  8. package/abstractions/lib/gizmo-helper/gizmo-viewcube/gizmo-viewcube-inputs.d.ts +1 -1
  9. package/abstractions/lib/gizmo-helper/gizmo-viewcube/gizmo-viewcube.d.ts +1 -1
  10. package/abstractions/lib/gizmo-helper/gizmo-viewport/gizmo-viewport-axis.d.ts +2 -2
  11. package/abstractions/lib/gizmo-helper/gizmo-viewport/gizmo-viewport.d.ts +1 -1
  12. package/abstractions/lib/line/line-input.d.ts +1 -1
  13. package/abstractions/lib/line/line.d.ts +1 -1
  14. package/abstractions/lib/quadratic-bezier-line/quadratic-bezier-line.d.ts +1 -1
  15. package/abstractions/lib/text/text.d.ts +1 -1
  16. package/abstractions/lib/text-3d/text-3d.d.ts +1 -1
  17. package/cameras/lib/camera/camera-content.d.ts +1 -1
  18. package/cameras/lib/camera/camera.d.ts +1 -1
  19. package/cameras/lib/cube-camera/cube-camera.d.ts +1 -1
  20. package/cameras/lib/orthographic-camera/orthographic-camera.d.ts +1 -1
  21. package/controls/lib/orbit-controls/orbit-controls.d.ts +1 -1
  22. package/esm2022/abstractions/lib/billboard/billboard.mjs +74 -0
  23. package/esm2022/abstractions/lib/catmull-rom-line/catmull-rom-line.mjs +120 -0
  24. package/esm2022/abstractions/lib/cubic-bezier-line/cubic-bezier-line.mjs +99 -0
  25. package/esm2022/abstractions/lib/edges/edges.mjs +96 -0
  26. package/esm2022/abstractions/lib/gizmo-helper/gizmo-helper.mjs +213 -0
  27. package/esm2022/abstractions/lib/gizmo-helper/gizmo-viewcube/gizmo-viewcube-edge.mjs +92 -0
  28. package/esm2022/abstractions/lib/gizmo-helper/gizmo-viewcube/gizmo-viewcube-face.mjs +184 -0
  29. package/esm2022/abstractions/lib/gizmo-helper/gizmo-viewcube/gizmo-viewcube-inputs.mjs +46 -0
  30. package/{esm2020 → esm2022}/abstractions/lib/gizmo-helper/gizmo-viewcube/gizmo-viewcube.mjs +8 -7
  31. package/esm2022/abstractions/lib/gizmo-helper/gizmo-viewport/gizmo-viewport-axis.mjs +195 -0
  32. package/{esm2020 → esm2022}/abstractions/lib/gizmo-helper/gizmo-viewport/gizmo-viewport.mjs +8 -7
  33. package/esm2022/abstractions/lib/line/line-input.mjs +76 -0
  34. package/esm2022/abstractions/lib/line/line.mjs +133 -0
  35. package/esm2022/abstractions/lib/quadratic-bezier-line/quadratic-bezier-line.mjs +128 -0
  36. package/esm2022/abstractions/lib/text/text.mjs +115 -0
  37. package/esm2022/abstractions/lib/text-3d/text-3d.mjs +145 -0
  38. package/esm2022/cameras/lib/camera/camera-content.mjs +21 -0
  39. package/esm2022/cameras/lib/camera/camera.mjs +75 -0
  40. package/esm2022/cameras/lib/cube-camera/cube-camera.mjs +131 -0
  41. package/esm2022/cameras/lib/orthographic-camera/orthographic-camera.mjs +93 -0
  42. package/{esm2020 → esm2022}/cameras/lib/perspective-camera/perspective-camera.mjs +8 -7
  43. package/esm2022/controls/lib/orbit-controls/orbit-controls.mjs +147 -0
  44. package/{esm2020 → esm2022}/loaders/lib/cube-texture-loader/cube-texture-loader.mjs +3 -3
  45. package/esm2022/loaders/lib/loader/loader.mjs +134 -0
  46. package/esm2022/materials/lib/mesh-distort-material/mesh-distort-material.mjs +75 -0
  47. package/esm2022/materials/lib/mesh-reflector-material/mesh-reflector-material.mjs +328 -0
  48. package/esm2022/materials/lib/mesh-refraction-material/mesh-refraction-material.mjs +158 -0
  49. package/esm2022/materials/lib/mesh-transmission-material/mesh-transmission-material.mjs +238 -0
  50. package/esm2022/materials/lib/mesh-wobble-material/mesh-wobble-material.mjs +68 -0
  51. package/esm2022/misc/lib/bake-shadows/bake-shadows.mjs +26 -0
  52. package/esm2022/performance/lib/adaptive/adaptive-dpr.mjs +47 -0
  53. package/esm2022/performance/lib/adaptive/adaptive-events.mjs +37 -0
  54. package/esm2022/performance/lib/detailed/detailed.mjs +54 -0
  55. package/esm2022/performance/lib/stats/stats.mjs +80 -0
  56. package/esm2022/shaders/lib/blur-pass/blur-pass.mjs +61 -0
  57. package/esm2022/staging/lib/accumulative-shadows/accumulative-shadows.mjs +249 -0
  58. package/esm2022/staging/lib/accumulative-shadows/randomized-lights.mjs +201 -0
  59. package/{esm2020 → esm2022}/staging/lib/bounds/bounds.mjs +8 -7
  60. package/esm2022/staging/lib/camera-shake/camera-shake.mjs +122 -0
  61. package/esm2022/staging/lib/caustics/caustics.mjs +364 -0
  62. package/esm2022/staging/lib/center/center.mjs +143 -0
  63. package/esm2022/staging/lib/cloud/cloud.mjs +160 -0
  64. package/esm2022/staging/lib/contact-shadows/contact-shadows.mjs +228 -0
  65. package/esm2022/staging/lib/environment/environment-cube.mjs +41 -0
  66. package/esm2022/staging/lib/environment/environment-ground.mjs +67 -0
  67. package/esm2022/staging/lib/environment/environment-inputs.mjs +87 -0
  68. package/esm2022/staging/lib/environment/environment-map.mjs +39 -0
  69. package/esm2022/staging/lib/environment/environment-portal.mjs +111 -0
  70. package/{esm2020 → esm2022}/staging/lib/environment/environment.mjs +13 -11
  71. package/esm2022/staging/lib/float/float.mjs +77 -0
  72. package/esm2022/staging/lib/sky/sky.mjs +109 -0
  73. package/esm2022/staging/lib/sparkles/sparkles.mjs +210 -0
  74. package/esm2022/staging/lib/spot-light/shadow-mesh-input.mjs +51 -0
  75. package/esm2022/staging/lib/spot-light/spot-light-input.mjs +62 -0
  76. package/esm2022/staging/lib/spot-light/spot-light-shadow-no-shader.mjs +74 -0
  77. package/esm2022/staging/lib/spot-light/spot-light-shadow-shader.mjs +126 -0
  78. package/{esm2020 → esm2022}/staging/lib/spot-light/spot-light-shadow.mjs +8 -7
  79. package/esm2022/staging/lib/spot-light/spot-light.mjs +117 -0
  80. package/esm2022/staging/lib/spot-light/volumetric-mesh.mjs +86 -0
  81. package/{esm2020 → esm2022}/staging/lib/stage/stage.mjs +13 -11
  82. package/esm2022/staging/lib/stars/stars.mjs +140 -0
  83. package/{fesm2020 → fesm2022}/angular-three-soba-abstractions.mjs +89 -89
  84. package/{fesm2015 → fesm2022}/angular-three-soba-abstractions.mjs.map +1 -1
  85. package/{fesm2015 → fesm2022}/angular-three-soba-cameras.mjs +21 -21
  86. package/{fesm2015 → fesm2022}/angular-three-soba-cameras.mjs.map +1 -1
  87. package/{fesm2020 → fesm2022}/angular-three-soba-controls.mjs +5 -5
  88. package/fesm2022/angular-three-soba-controls.mjs.map +1 -0
  89. package/{fesm2020 → fesm2022}/angular-three-soba-loaders.mjs +7 -7
  90. package/{fesm2020 → fesm2022}/angular-three-soba-loaders.mjs.map +1 -1
  91. package/{fesm2020 → fesm2022}/angular-three-soba-materials.mjs +25 -25
  92. package/{fesm2020 → fesm2022}/angular-three-soba-materials.mjs.map +1 -1
  93. package/{fesm2020 → fesm2022}/angular-three-soba-misc.mjs +3 -3
  94. package/{fesm2020 → fesm2022}/angular-three-soba-misc.mjs.map +1 -1
  95. package/{fesm2020 → fesm2022}/angular-three-soba-performance.mjs +14 -14
  96. package/{fesm2020 → fesm2022}/angular-three-soba-performance.mjs.map +1 -1
  97. package/{fesm2020 → fesm2022}/angular-three-soba-shaders.mjs +2 -2
  98. package/fesm2022/angular-three-soba-shaders.mjs.map +1 -0
  99. package/{fesm2020 → fesm2022}/angular-three-soba-staging.mjs +139 -139
  100. package/{fesm2020 → fesm2022}/angular-three-soba-staging.mjs.map +1 -1
  101. package/loaders/lib/loader/loader.d.ts +1 -1
  102. package/materials/lib/mesh-distort-material/mesh-distort-material.d.ts +1 -1
  103. package/materials/lib/mesh-reflector-material/mesh-reflector-material.d.ts +1 -1
  104. package/materials/lib/mesh-refraction-material/mesh-refraction-material.d.ts +1 -1
  105. package/materials/lib/mesh-transmission-material/mesh-transmission-material.d.ts +1 -1
  106. package/materials/lib/mesh-wobble-material/mesh-wobble-material.d.ts +1 -1
  107. package/package.json +45 -70
  108. package/performance/lib/adaptive/adaptive-dpr.d.ts +1 -1
  109. package/performance/lib/detailed/detailed.d.ts +1 -1
  110. package/performance/lib/stats/stats.d.ts +1 -1
  111. package/plugin/package.json +1 -1
  112. package/plugin/src/generators/init/compat.js +1 -1
  113. package/plugin/src/generators/init/compat.js.map +1 -1
  114. package/plugin/src/generators/init/init.d.ts +1 -1
  115. package/plugin/src/generators/init/init.js +1 -1
  116. package/plugin/src/generators/init/init.js.map +1 -1
  117. package/staging/lib/accumulative-shadows/accumulative-shadows.d.ts +2 -2
  118. package/staging/lib/accumulative-shadows/randomized-lights.d.ts +1 -1
  119. package/staging/lib/bounds/bounds.d.ts +1 -1
  120. package/staging/lib/camera-shake/camera-shake.d.ts +1 -1
  121. package/staging/lib/caustics/caustics.d.ts +2 -2
  122. package/staging/lib/center/center.d.ts +1 -1
  123. package/staging/lib/cloud/cloud.d.ts +1 -1
  124. package/staging/lib/contact-shadows/contact-shadows.d.ts +1 -1
  125. package/staging/lib/environment/environment-inputs.d.ts +1 -1
  126. package/staging/lib/float/float.d.ts +1 -1
  127. package/staging/lib/sky/sky.d.ts +1 -1
  128. package/staging/lib/sparkles/sparkles.d.ts +2 -2
  129. package/staging/lib/spot-light/shadow-mesh-input.d.ts +1 -1
  130. package/staging/lib/spot-light/spot-light-input.d.ts +1 -1
  131. package/staging/lib/spot-light/spot-light-shadow-no-shader.d.ts +1 -1
  132. package/staging/lib/spot-light/spot-light-shadow-shader.d.ts +1 -1
  133. package/staging/lib/spot-light/spot-light.d.ts +1 -1
  134. package/staging/lib/spot-light/volumetric-mesh.d.ts +1 -1
  135. package/staging/lib/stage/stage.d.ts +2 -2
  136. package/staging/lib/stars/stars.d.ts +2 -2
  137. package/esm2020/abstractions/lib/billboard/billboard.mjs +0 -73
  138. package/esm2020/abstractions/lib/catmull-rom-line/catmull-rom-line.mjs +0 -119
  139. package/esm2020/abstractions/lib/cubic-bezier-line/cubic-bezier-line.mjs +0 -98
  140. package/esm2020/abstractions/lib/edges/edges.mjs +0 -95
  141. package/esm2020/abstractions/lib/gizmo-helper/gizmo-helper.mjs +0 -211
  142. package/esm2020/abstractions/lib/gizmo-helper/gizmo-viewcube/gizmo-viewcube-edge.mjs +0 -91
  143. package/esm2020/abstractions/lib/gizmo-helper/gizmo-viewcube/gizmo-viewcube-face.mjs +0 -182
  144. package/esm2020/abstractions/lib/gizmo-helper/gizmo-viewcube/gizmo-viewcube-inputs.mjs +0 -45
  145. package/esm2020/abstractions/lib/gizmo-helper/gizmo-viewport/gizmo-viewport-axis.mjs +0 -193
  146. package/esm2020/abstractions/lib/line/line-input.mjs +0 -75
  147. package/esm2020/abstractions/lib/line/line.mjs +0 -132
  148. package/esm2020/abstractions/lib/quadratic-bezier-line/quadratic-bezier-line.mjs +0 -127
  149. package/esm2020/abstractions/lib/text/text.mjs +0 -114
  150. package/esm2020/abstractions/lib/text-3d/text-3d.mjs +0 -144
  151. package/esm2020/cameras/lib/camera/camera-content.mjs +0 -20
  152. package/esm2020/cameras/lib/camera/camera.mjs +0 -74
  153. package/esm2020/cameras/lib/cube-camera/cube-camera.mjs +0 -130
  154. package/esm2020/cameras/lib/orthographic-camera/orthographic-camera.mjs +0 -92
  155. package/esm2020/controls/lib/orbit-controls/orbit-controls.mjs +0 -146
  156. package/esm2020/loaders/lib/loader/loader.mjs +0 -133
  157. package/esm2020/materials/lib/mesh-distort-material/mesh-distort-material.mjs +0 -74
  158. package/esm2020/materials/lib/mesh-reflector-material/mesh-reflector-material.mjs +0 -327
  159. package/esm2020/materials/lib/mesh-refraction-material/mesh-refraction-material.mjs +0 -157
  160. package/esm2020/materials/lib/mesh-transmission-material/mesh-transmission-material.mjs +0 -237
  161. package/esm2020/materials/lib/mesh-wobble-material/mesh-wobble-material.mjs +0 -67
  162. package/esm2020/misc/lib/bake-shadows/bake-shadows.mjs +0 -25
  163. package/esm2020/performance/lib/adaptive/adaptive-dpr.mjs +0 -46
  164. package/esm2020/performance/lib/adaptive/adaptive-events.mjs +0 -36
  165. package/esm2020/performance/lib/detailed/detailed.mjs +0 -53
  166. package/esm2020/performance/lib/stats/stats.mjs +0 -79
  167. package/esm2020/shaders/lib/blur-pass/blur-pass.mjs +0 -61
  168. package/esm2020/staging/lib/accumulative-shadows/accumulative-shadows.mjs +0 -247
  169. package/esm2020/staging/lib/accumulative-shadows/randomized-lights.mjs +0 -199
  170. package/esm2020/staging/lib/camera-shake/camera-shake.mjs +0 -121
  171. package/esm2020/staging/lib/caustics/caustics.mjs +0 -363
  172. package/esm2020/staging/lib/center/center.mjs +0 -142
  173. package/esm2020/staging/lib/cloud/cloud.mjs +0 -159
  174. package/esm2020/staging/lib/contact-shadows/contact-shadows.mjs +0 -227
  175. package/esm2020/staging/lib/environment/environment-cube.mjs +0 -40
  176. package/esm2020/staging/lib/environment/environment-ground.mjs +0 -66
  177. package/esm2020/staging/lib/environment/environment-inputs.mjs +0 -86
  178. package/esm2020/staging/lib/environment/environment-map.mjs +0 -38
  179. package/esm2020/staging/lib/environment/environment-portal.mjs +0 -110
  180. package/esm2020/staging/lib/float/float.mjs +0 -76
  181. package/esm2020/staging/lib/sky/sky.mjs +0 -108
  182. package/esm2020/staging/lib/sparkles/sparkles.mjs +0 -209
  183. package/esm2020/staging/lib/spot-light/shadow-mesh-input.mjs +0 -50
  184. package/esm2020/staging/lib/spot-light/spot-light-input.mjs +0 -61
  185. package/esm2020/staging/lib/spot-light/spot-light-shadow-no-shader.mjs +0 -73
  186. package/esm2020/staging/lib/spot-light/spot-light-shadow-shader.mjs +0 -125
  187. package/esm2020/staging/lib/spot-light/spot-light.mjs +0 -116
  188. package/esm2020/staging/lib/spot-light/volumetric-mesh.mjs +0 -85
  189. package/esm2020/staging/lib/stars/stars.mjs +0 -139
  190. package/fesm2015/angular-three-soba-abstractions.mjs +0 -2048
  191. package/fesm2015/angular-three-soba-controls.mjs +0 -153
  192. package/fesm2015/angular-three-soba-controls.mjs.map +0 -1
  193. package/fesm2015/angular-three-soba-loaders.mjs +0 -229
  194. package/fesm2015/angular-three-soba-loaders.mjs.map +0 -1
  195. package/fesm2015/angular-three-soba-materials.mjs +0 -851
  196. package/fesm2015/angular-three-soba-materials.mjs.map +0 -1
  197. package/fesm2015/angular-three-soba-misc.mjs +0 -148
  198. package/fesm2015/angular-three-soba-misc.mjs.map +0 -1
  199. package/fesm2015/angular-three-soba-performance.mjs +0 -210
  200. package/fesm2015/angular-three-soba-performance.mjs.map +0 -1
  201. package/fesm2015/angular-three-soba-shaders.mjs +0 -1239
  202. package/fesm2015/angular-three-soba-shaders.mjs.map +0 -1
  203. package/fesm2015/angular-three-soba-staging.mjs +0 -3772
  204. package/fesm2015/angular-three-soba-staging.mjs.map +0 -1
  205. package/fesm2020/angular-three-soba-abstractions.mjs.map +0 -1
  206. package/fesm2020/angular-three-soba-cameras.mjs +0 -347
  207. package/fesm2020/angular-three-soba-cameras.mjs.map +0 -1
  208. package/fesm2020/angular-three-soba-controls.mjs.map +0 -1
  209. package/fesm2020/angular-three-soba-shaders.mjs.map +0 -1
  210. package/fesm2020/angular-three-soba.mjs +0 -6
  211. package/fesm2020/angular-three-soba.mjs.map +0 -1
  212. /package/{esm2020 → esm2022}/abstractions/angular-three-soba-abstractions.mjs +0 -0
  213. /package/{esm2020 → esm2022}/abstractions/index.mjs +0 -0
  214. /package/{esm2020 → esm2022}/abstractions/lib/gizmo-helper/gizmo-viewcube/constants.mjs +0 -0
  215. /package/{esm2020 → esm2022}/angular-three-soba.mjs +0 -0
  216. /package/{esm2020 → esm2022}/cameras/angular-three-soba-cameras.mjs +0 -0
  217. /package/{esm2020 → esm2022}/cameras/index.mjs +0 -0
  218. /package/{esm2020 → esm2022}/controls/angular-three-soba-controls.mjs +0 -0
  219. /package/{esm2020 → esm2022}/controls/index.mjs +0 -0
  220. /package/{esm2020 → esm2022}/index.mjs +0 -0
  221. /package/{esm2020 → esm2022}/loaders/angular-three-soba-loaders.mjs +0 -0
  222. /package/{esm2020 → esm2022}/loaders/index.mjs +0 -0
  223. /package/{esm2020 → esm2022}/loaders/lib/gltf-loader/gltf-loader.mjs +0 -0
  224. /package/{esm2020 → esm2022}/loaders/lib/progress/progress.mjs +0 -0
  225. /package/{esm2020 → esm2022}/loaders/lib/texture-loader/texture-loader.mjs +0 -0
  226. /package/{esm2020 → esm2022}/materials/angular-three-soba-materials.mjs +0 -0
  227. /package/{esm2020 → esm2022}/materials/index.mjs +0 -0
  228. /package/{esm2020 → esm2022}/misc/angular-three-soba-misc.mjs +0 -0
  229. /package/{esm2020 → esm2022}/misc/index.mjs +0 -0
  230. /package/{esm2020 → esm2022}/misc/lib/animations/animations.mjs +0 -0
  231. /package/{esm2020 → esm2022}/misc/lib/depth-buffer/depth-buffer.mjs +0 -0
  232. /package/{esm2020 → esm2022}/misc/lib/fbo/fbo.mjs +0 -0
  233. /package/{esm2020 → esm2022}/performance/angular-three-soba-performance.mjs +0 -0
  234. /package/{esm2020 → esm2022}/performance/index.mjs +0 -0
  235. /package/{esm2020 → esm2022}/shaders/angular-three-soba-shaders.mjs +0 -0
  236. /package/{esm2020 → esm2022}/shaders/index.mjs +0 -0
  237. /package/{esm2020 → esm2022}/shaders/lib/caustics-material/caustics-material.mjs +0 -0
  238. /package/{esm2020 → esm2022}/shaders/lib/caustics-projection-material/caustics-projection-material.mjs +0 -0
  239. /package/{esm2020 → esm2022}/shaders/lib/convolution-material/convolution-material.mjs +0 -0
  240. /package/{esm2020 → esm2022}/shaders/lib/discard-material/discard-material.mjs +0 -0
  241. /package/{esm2020 → esm2022}/shaders/lib/mesh-distort-material/mesh-distort-material.mjs +0 -0
  242. /package/{esm2020 → esm2022}/shaders/lib/mesh-reflector-material/mesh-reflector-material.mjs +0 -0
  243. /package/{esm2020 → esm2022}/shaders/lib/mesh-refraction-material/mesh-refraction-material.mjs +0 -0
  244. /package/{esm2020 → esm2022}/shaders/lib/mesh-transmission-material/mesh-transmission-material.mjs +0 -0
  245. /package/{esm2020 → esm2022}/shaders/lib/mesh-wobble-material/mesh-wobble-material.mjs +0 -0
  246. /package/{esm2020 → esm2022}/shaders/lib/shader-material/shader-material.mjs +0 -0
  247. /package/{esm2020 → esm2022}/shaders/lib/soft-shadow-material/soft-shadow-material.mjs +0 -0
  248. /package/{esm2020 → esm2022}/shaders/lib/spot-light-material/spot-light-material.mjs +0 -0
  249. /package/{esm2020 → esm2022}/shaders/lib/star-field-material/star-field-material.mjs +0 -0
  250. /package/{esm2020 → esm2022}/staging/angular-three-soba-staging.mjs +0 -0
  251. /package/{esm2020 → esm2022}/staging/index.mjs +0 -0
  252. /package/{esm2020 → esm2022}/staging/lib/accumulative-shadows/progressive-light-map.mjs +0 -0
  253. /package/{esm2020 → esm2022}/staging/lib/environment/assets.mjs +0 -0
  254. /package/{esm2020 → esm2022}/staging/lib/environment/utils.mjs +0 -0
  255. /package/{esm2020 → esm2022}/staging/lib/spot-light/common.mjs +0 -0
  256. /package/{fesm2015 → fesm2022}/angular-three-soba.mjs +0 -0
  257. /package/{fesm2015 → fesm2022}/angular-three-soba.mjs.map +0 -0
@@ -1,1239 +0,0 @@
1
- import * as THREE from 'three';
2
- import { ShaderMaterial, Uniform, Vector2, NoBlending, WebGLRenderTarget, LinearFilter, Scene, Camera, BufferGeometry, BufferAttribute, Mesh, MeshStandardMaterial, Vector3, Color } from 'three';
3
- import { InjectionToken } from '@angular/core';
4
- import { MeshBVHUniformStruct, shaderStructs, shaderIntersectFunction } from 'three-mesh-bvh';
5
-
6
- class ConvolutionMaterial extends ShaderMaterial {
7
- constructor(texelSize = new Vector2()) {
8
- super({
9
- uniforms: {
10
- inputBuffer: new Uniform(null),
11
- depthBuffer: new Uniform(null),
12
- resolution: new Uniform(new Vector2()),
13
- texelSize: new Uniform(new Vector2()),
14
- halfTexelSize: new Uniform(new Vector2()),
15
- kernel: new Uniform(0.0),
16
- scale: new Uniform(1.0),
17
- cameraNear: new Uniform(0.0),
18
- cameraFar: new Uniform(1.0),
19
- minDepthThreshold: new Uniform(0.0),
20
- maxDepthThreshold: new Uniform(1.0),
21
- depthScale: new Uniform(0.0),
22
- depthToBlurRatioBias: new Uniform(0.25),
23
- },
24
- fragmentShader: `#include <common>
25
- #include <dithering_pars_fragment>
26
- uniform sampler2D inputBuffer;
27
- uniform sampler2D depthBuffer;
28
- uniform float cameraNear;
29
- uniform float cameraFar;
30
- uniform float minDepthThreshold;
31
- uniform float maxDepthThreshold;
32
- uniform float depthScale;
33
- uniform float depthToBlurRatioBias;
34
- varying vec2 vUv;
35
- varying vec2 vUv0;
36
- varying vec2 vUv1;
37
- varying vec2 vUv2;
38
- varying vec2 vUv3;
39
-
40
- void main() {
41
- float depthFactor = 0.0;
42
-
43
- #ifdef USE_DEPTH
44
- vec4 depth = texture2D(depthBuffer, vUv);
45
- depthFactor = smoothstep(minDepthThreshold, maxDepthThreshold, 1.0-(depth.r * depth.a));
46
- depthFactor *= depthScale;
47
- depthFactor = max(0.0, min(1.0, depthFactor + 0.25));
48
- #endif
49
-
50
- vec4 sum = texture2D(inputBuffer, mix(vUv0, vUv, depthFactor));
51
- sum += texture2D(inputBuffer, mix(vUv1, vUv, depthFactor));
52
- sum += texture2D(inputBuffer, mix(vUv2, vUv, depthFactor));
53
- sum += texture2D(inputBuffer, mix(vUv3, vUv, depthFactor));
54
- gl_FragColor = sum * 0.25 ;
55
-
56
- #include <dithering_fragment>
57
- #include <tonemapping_fragment>
58
- #include <encodings_fragment>
59
- }`,
60
- vertexShader: `uniform vec2 texelSize;
61
- uniform vec2 halfTexelSize;
62
- uniform float kernel;
63
- uniform float scale;
64
- varying vec2 vUv;
65
- varying vec2 vUv0;
66
- varying vec2 vUv1;
67
- varying vec2 vUv2;
68
- varying vec2 vUv3;
69
-
70
- void main() {
71
- vec2 uv = position.xy * 0.5 + 0.5;
72
- vUv = uv;
73
-
74
- vec2 dUv = (texelSize * vec2(kernel) + halfTexelSize) * scale;
75
- vUv0 = vec2(uv.x - dUv.x, uv.y + dUv.y);
76
- vUv1 = vec2(uv.x + dUv.x, uv.y + dUv.y);
77
- vUv2 = vec2(uv.x + dUv.x, uv.y - dUv.y);
78
- vUv3 = vec2(uv.x - dUv.x, uv.y - dUv.y);
79
-
80
- gl_Position = vec4(position.xy, 1.0, 1.0);
81
- }`,
82
- blending: NoBlending,
83
- depthWrite: false,
84
- depthTest: false,
85
- });
86
- this.toneMapped = false;
87
- this.setTexelSize(texelSize.x, texelSize.y);
88
- this.kernel = new Float32Array([0.0, 1.0, 2.0, 2.0, 3.0]);
89
- }
90
- setTexelSize(x, y) {
91
- this.uniforms['texelSize'].value.set(x, y);
92
- this.uniforms['halfTexelSize'].value.set(x, y).multiplyScalar(0.5);
93
- }
94
- setResolution(resolution) {
95
- this.uniforms['resolution'].value.copy(resolution);
96
- }
97
- }
98
-
99
- class BlurPass {
100
- constructor({ gl, resolution, width = 500, height = 500, minDepthThreshold = 0, maxDepthThreshold = 1, depthScale = 0, depthToBlurRatioBias = 0.25, }) {
101
- this.renderToScreen = false;
102
- this.renderTargetA = new WebGLRenderTarget(resolution, resolution, {
103
- minFilter: LinearFilter,
104
- magFilter: LinearFilter,
105
- stencilBuffer: false,
106
- depthBuffer: false,
107
- encoding: gl.outputEncoding,
108
- });
109
- this.renderTargetB = this.renderTargetA.clone();
110
- this.convolutionMaterial = new ConvolutionMaterial();
111
- this.convolutionMaterial.setTexelSize(1.0 / width, 1.0 / height);
112
- this.convolutionMaterial.setResolution(new Vector2(width, height));
113
- this.scene = new Scene();
114
- this.camera = new Camera();
115
- this.convolutionMaterial.uniforms['minDepthThreshold'].value = minDepthThreshold;
116
- this.convolutionMaterial.uniforms['maxDepthThreshold'].value = maxDepthThreshold;
117
- this.convolutionMaterial.uniforms['depthScale'].value = depthScale;
118
- this.convolutionMaterial.uniforms['depthToBlurRatioBias'].value = depthToBlurRatioBias;
119
- this.convolutionMaterial.defines['USE_DEPTH'] = depthScale > 0;
120
- const vertices = new Float32Array([-1, -1, 0, 3, -1, 0, -1, 3, 0]);
121
- const uvs = new Float32Array([0, 0, 2, 0, 0, 2]);
122
- const geometry = new BufferGeometry();
123
- geometry.setAttribute('position', new BufferAttribute(vertices, 3));
124
- geometry.setAttribute('uv', new BufferAttribute(uvs, 2));
125
- this.screen = new Mesh(geometry, this.convolutionMaterial);
126
- this.screen.frustumCulled = false;
127
- this.scene.add(this.screen);
128
- }
129
- render(renderer, inputBuffer, outputBuffer) {
130
- const scene = this.scene;
131
- const camera = this.camera;
132
- const renderTargetA = this.renderTargetA;
133
- const renderTargetB = this.renderTargetB;
134
- const material = this.convolutionMaterial;
135
- const uniforms = material.uniforms;
136
- uniforms['depthBuffer'].value = inputBuffer.depthTexture;
137
- const kernel = material.kernel;
138
- let lastRT = inputBuffer;
139
- let destRT;
140
- let i, l;
141
- // Apply the multi-pass blur.
142
- for (i = 0, l = kernel.length - 1; i < l; ++i) {
143
- // Alternate between targets.
144
- destRT = (i & 1) === 0 ? renderTargetA : renderTargetB;
145
- uniforms['kernel'].value = kernel[i];
146
- uniforms['inputBuffer'].value = lastRT.texture;
147
- renderer.setRenderTarget(destRT);
148
- renderer.render(scene, camera);
149
- lastRT = destRT;
150
- }
151
- uniforms['kernel'].value = kernel[i];
152
- uniforms['inputBuffer'].value = lastRT.texture;
153
- renderer.setRenderTarget(this.renderToScreen ? null : outputBuffer);
154
- renderer.render(scene, camera);
155
- }
156
- }
157
-
158
- function shaderMaterial(uniforms, vertexShader, fragmentShader, onInit) {
159
- const material = class extends THREE.ShaderMaterial {
160
- constructor(parameters = {}) {
161
- const entries = Object.entries(uniforms);
162
- // Create unforms and shaders
163
- super({
164
- uniforms: entries.reduce((acc, [name, value]) => {
165
- const uniform = THREE.UniformsUtils.clone({ [name]: { value } });
166
- return Object.assign(Object.assign({}, acc), uniform);
167
- }, {}),
168
- vertexShader,
169
- fragmentShader,
170
- });
171
- this.key = '';
172
- // Create getter/setters
173
- entries.forEach(([name]) => Object.defineProperty(this, name, {
174
- get: () => this.uniforms[name].value,
175
- set: (v) => (this.uniforms[name].value = v),
176
- }));
177
- // Assign parameters, this might include uniforms
178
- Object.assign(this, parameters);
179
- // Call onInit
180
- if (onInit)
181
- onInit(this);
182
- }
183
- };
184
- material.key = THREE.MathUtils.generateUUID();
185
- return material;
186
- }
187
-
188
- const CausticsMaterial = shaderMaterial({
189
- cameraMatrixWorld: new THREE.Matrix4(),
190
- cameraProjectionMatrixInv: new THREE.Matrix4(),
191
- normalTexture: null,
192
- depthTexture: null,
193
- lightDir: new THREE.Vector3(0, 1, 0),
194
- lightPlaneNormal: new THREE.Vector3(0, 1, 0),
195
- lightPlaneConstant: 0,
196
- near: 0.1,
197
- far: 100,
198
- modelMatrix: new THREE.Matrix4(),
199
- worldRadius: 1 / 40,
200
- ior: 1.1,
201
- bounces: 0,
202
- resolution: 1024,
203
- size: 10,
204
- intensity: 0.5,
205
- },
206
- /* glsl */ `varying vec2 vUv;
207
- void main() {
208
- vUv = uv;
209
- gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
210
- }`,
211
- /* glsl */ `uniform mat4 cameraMatrixWorld;
212
- uniform mat4 cameraProjectionMatrixInv;
213
- uniform vec3 lightDir;
214
- uniform vec3 lightPlaneNormal;
215
- uniform float lightPlaneConstant;
216
- uniform float near;
217
- uniform float far;
218
- uniform float time;
219
- uniform float worldRadius;
220
- uniform float resolution;
221
- uniform float size;
222
- uniform float intensity;
223
- uniform float ior;
224
- precision highp isampler2D;
225
- precision highp usampler2D;
226
- uniform sampler2D normalTexture;
227
- uniform sampler2D depthTexture;
228
- uniform float bounces;
229
- varying vec2 vUv;
230
- vec3 WorldPosFromDepth(float depth, vec2 coord) {
231
- float z = depth * 2.0 - 1.0;
232
- vec4 clipSpacePosition = vec4(coord * 2.0 - 1.0, z, 1.0);
233
- vec4 viewSpacePosition = cameraProjectionMatrixInv * clipSpacePosition;
234
- // Perspective division
235
- viewSpacePosition /= viewSpacePosition.w;
236
- vec4 worldSpacePosition = cameraMatrixWorld * viewSpacePosition;
237
- return worldSpacePosition.xyz;
238
- }
239
- float sdPlane( vec3 p, vec3 n, float h ) {
240
- // n must be normalized
241
- return dot(p,n) + h;
242
- }
243
- float planeIntersect( vec3 ro, vec3 rd, vec4 p ) {
244
- return -(dot(ro,p.xyz)+p.w)/dot(rd,p.xyz);
245
- }
246
- vec3 totalInternalReflection(vec3 ro, vec3 rd, vec3 pos, vec3 normal, float ior, out vec3 rayOrigin, out vec3 rayDirection) {
247
- rayOrigin = ro;
248
- rayDirection = rd;
249
- rayDirection = refract(rayDirection, normal, 1.0 / ior);
250
- rayOrigin = pos + rayDirection * 0.1;
251
- return rayDirection;
252
- }
253
- void main() {
254
- // Each sample consists of random offset in the x and y direction
255
- float caustic = 0.0;
256
- float causticTexelSize = (1.0 / resolution) * size * 2.0;
257
- float texelsNeeded = worldRadius / causticTexelSize;
258
- float sampleRadius = texelsNeeded / resolution;
259
- float sum = 0.0;
260
- if (texture2D(depthTexture, vUv).x == 1.0) {
261
- gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
262
- return;
263
- }
264
- vec2 offset1 = vec2(-0.5, -0.5);//vec2(rand() - 0.5, rand() - 0.5);
265
- vec2 offset2 = vec2(-0.5, 0.5);//vec2(rand() - 0.5, rand() - 0.5);
266
- vec2 offset3 = vec2(0.5, 0.5);//vec2(rand() - 0.5, rand() - 0.5);
267
- vec2 offset4 = vec2(0.5, -0.5);//vec2(rand() - 0.5, rand() - 0.5);
268
- vec2 uv1 = vUv + offset1 * sampleRadius;
269
- vec2 uv2 = vUv + offset2 * sampleRadius;
270
- vec2 uv3 = vUv + offset3 * sampleRadius;
271
- vec2 uv4 = vUv + offset4 * sampleRadius;
272
- vec3 normal1 = texture2D(normalTexture, uv1, -10.0).rgb * 2.0 - 1.0;
273
- vec3 normal2 = texture2D(normalTexture, uv2, -10.0).rgb * 2.0 - 1.0;
274
- vec3 normal3 = texture2D(normalTexture, uv3, -10.0).rgb * 2.0 - 1.0;
275
- vec3 normal4 = texture2D(normalTexture, uv4, -10.0).rgb * 2.0 - 1.0;
276
- float depth1 = texture2D(depthTexture, uv1, -10.0).x;
277
- float depth2 = texture2D(depthTexture, uv2, -10.0).x;
278
- float depth3 = texture2D(depthTexture, uv3, -10.0).x;
279
- float depth4 = texture2D(depthTexture, uv4, -10.0).x;
280
- // Sanity check the depths
281
- if (depth1 == 1.0 || depth2 == 1.0 || depth3 == 1.0 || depth4 == 1.0) {
282
- gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
283
- return;
284
- }
285
- vec3 pos1 = WorldPosFromDepth(depth1, uv1);
286
- vec3 pos2 = WorldPosFromDepth(depth2, uv2);
287
- vec3 pos3 = WorldPosFromDepth(depth3, uv3);
288
- vec3 pos4 = WorldPosFromDepth(depth4, uv4);
289
- vec3 originPos1 = WorldPosFromDepth(0.0, uv1);
290
- vec3 originPos2 = WorldPosFromDepth(0.0, uv2);
291
- vec3 originPos3 = WorldPosFromDepth(0.0, uv3);
292
- vec3 originPos4 = WorldPosFromDepth(0.0, uv4);
293
- vec3 endPos1, endPos2, endPos3, endPos4;
294
- vec3 endDir1, endDir2, endDir3, endDir4;
295
- totalInternalReflection(originPos1, lightDir, pos1, normal1, ior, endPos1, endDir1);
296
- totalInternalReflection(originPos2, lightDir, pos2, normal2, ior, endPos2, endDir2);
297
- totalInternalReflection(originPos3, lightDir, pos3, normal3, ior, endPos3, endDir3);
298
- totalInternalReflection(originPos4, lightDir, pos4, normal4, ior, endPos4, endDir4);
299
- float lightPosArea = length(cross(originPos2 - originPos1, originPos3 - originPos1)) + length(cross(originPos3 - originPos1, originPos4 - originPos1));
300
- float t1 = planeIntersect(endPos1, endDir1, vec4(lightPlaneNormal, lightPlaneConstant));
301
- float t2 = planeIntersect(endPos2, endDir2, vec4(lightPlaneNormal, lightPlaneConstant));
302
- float t3 = planeIntersect(endPos3, endDir3, vec4(lightPlaneNormal, lightPlaneConstant));
303
- float t4 = planeIntersect(endPos4, endDir4, vec4(lightPlaneNormal, lightPlaneConstant));
304
- vec3 finalPos1 = endPos1 + endDir1 * t1;
305
- vec3 finalPos2 = endPos2 + endDir2 * t2;
306
- vec3 finalPos3 = endPos3 + endDir3 * t3;
307
- vec3 finalPos4 = endPos4 + endDir4 * t4;
308
- float finalArea = length(cross(finalPos2 - finalPos1, finalPos3 - finalPos1)) + length(cross(finalPos3 - finalPos1, finalPos4 - finalPos1));
309
- caustic += intensity * (lightPosArea / finalArea);
310
- // Calculate the area of the triangle in light spaces
311
- gl_FragColor = vec4(vec3(max(caustic, 0.0)), 1.0);
312
- }`);
313
-
314
- const CausticsProjectionMaterial = shaderMaterial({
315
- causticsTexture: null,
316
- causticsTextureB: null,
317
- color: new THREE.Color(),
318
- lightProjMatrix: new THREE.Matrix4(),
319
- lightViewMatrix: new THREE.Matrix4(),
320
- },
321
- /* glsl */ `varying vec3 vWorldPosition;
322
- void main() {
323
- gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.);
324
- vec4 worldPosition = modelMatrix * vec4(position, 1.);
325
- vWorldPosition = worldPosition.xyz;
326
- }`,
327
- /* glsl */ `varying vec3 vWorldPosition;
328
- uniform vec3 color;
329
- uniform sampler2D causticsTexture;
330
- uniform sampler2D causticsTextureB;
331
- uniform mat4 lightProjMatrix;
332
- uniform mat4 lightViewMatrix;
333
- void main() {
334
- // Apply caustics
335
- vec4 lightSpacePos = lightProjMatrix * lightViewMatrix * vec4(vWorldPosition, 1.0);
336
- lightSpacePos.xyz /= lightSpacePos.w;
337
- lightSpacePos.xyz = lightSpacePos.xyz * 0.5 + 0.5;
338
- vec3 front = texture2D(causticsTexture, lightSpacePos.xy).rgb;
339
- vec3 back = texture2D(causticsTextureB, lightSpacePos.xy).rgb;
340
- gl_FragColor = vec4((front + back) * color, 1.0);
341
- #include <tonemapping_fragment>
342
- #include <encodings_fragment>
343
- }`);
344
-
345
- const DiscardMaterial = shaderMaterial({}, 'void main() { }', 'void main() { gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); discard; }');
346
-
347
- const NGTS_DISTORT_MATERIAL_SHADER = new InjectionToken('DistortMaterialShader');
348
- function provideNgtsMeshDistortMaterialShader(distortShader) {
349
- return {
350
- provide: NGTS_DISTORT_MATERIAL_SHADER,
351
- useFactory: () => {
352
- return class extends THREE.MeshPhysicalMaterial {
353
- constructor(parameters = {}) {
354
- super(parameters);
355
- this.setValues(parameters);
356
- this._time = { value: 0 };
357
- this._distort = { value: 0.4 };
358
- this._radius = { value: 1 };
359
- }
360
- onBeforeCompile(shader) {
361
- shader.uniforms['time'] = this._time;
362
- shader.uniforms['radius'] = this._radius;
363
- shader.uniforms['distort'] = this._distort;
364
- shader.vertexShader = `
365
- uniform float time;
366
- uniform float radius;
367
- uniform float distort;
368
- ${distortShader}
369
- ${shader.vertexShader}
370
- `;
371
- shader.vertexShader = shader.vertexShader.replace('#include <begin_vertex>', `
372
- float updateTime = time / 50.0;
373
- float noise = snoise(vec3(position / 2.0 + updateTime * 5.0));
374
- vec3 transformed = vec3(position * (noise * pow(distort, 2.0) + radius));
375
- `);
376
- }
377
- get time() {
378
- return this._time.value;
379
- }
380
- set time(v) {
381
- this._time.value = v;
382
- }
383
- get distort() {
384
- return this._distort.value;
385
- }
386
- set distort(v) {
387
- this._distort.value = v;
388
- }
389
- get radius() {
390
- return this._radius.value;
391
- }
392
- set radius(v) {
393
- this._radius.value = v;
394
- }
395
- };
396
- },
397
- };
398
- }
399
-
400
- class MeshReflectorMaterial extends MeshStandardMaterial {
401
- constructor(parameters = {}) {
402
- super(parameters);
403
- this._tDepth = { value: null };
404
- this._distortionMap = { value: null };
405
- this._tDiffuse = { value: null };
406
- this._tDiffuseBlur = { value: null };
407
- this._textureMatrix = { value: null };
408
- this._hasBlur = { value: false };
409
- this._mirror = { value: 0.0 };
410
- this._mixBlur = { value: 0.0 };
411
- this._blurStrength = { value: 0.5 };
412
- this._minDepthThreshold = { value: 0.9 };
413
- this._maxDepthThreshold = { value: 1 };
414
- this._depthScale = { value: 0 };
415
- this._depthToBlurRatioBias = { value: 0.25 };
416
- this._distortion = { value: 1 };
417
- this._mixContrast = { value: 1.0 };
418
- this.setValues(parameters);
419
- }
420
- onBeforeCompile(shader) {
421
- var _a;
422
- if (!((_a = shader.defines) === null || _a === void 0 ? void 0 : _a.USE_UV)) {
423
- shader.defines.USE_UV = '';
424
- }
425
- shader.uniforms.hasBlur = this._hasBlur;
426
- shader.uniforms.tDiffuse = this._tDiffuse;
427
- shader.uniforms.tDepth = this._tDepth;
428
- shader.uniforms.distortionMap = this._distortionMap;
429
- shader.uniforms.tDiffuseBlur = this._tDiffuseBlur;
430
- shader.uniforms.textureMatrix = this._textureMatrix;
431
- shader.uniforms.mirror = this._mirror;
432
- shader.uniforms.mixBlur = this._mixBlur;
433
- shader.uniforms.mixStrength = this._blurStrength;
434
- shader.uniforms.minDepthThreshold = this._minDepthThreshold;
435
- shader.uniforms.maxDepthThreshold = this._maxDepthThreshold;
436
- shader.uniforms.depthScale = this._depthScale;
437
- shader.uniforms.depthToBlurRatioBias = this._depthToBlurRatioBias;
438
- shader.uniforms.distortion = this._distortion;
439
- shader.uniforms.mixContrast = this._mixContrast;
440
- shader.vertexShader = `
441
- uniform mat4 textureMatrix;
442
- varying vec4 my_vUv;
443
- ${shader.vertexShader}`;
444
- shader.vertexShader = shader.vertexShader.replace('#include <project_vertex>', `#include <project_vertex>
445
- my_vUv = textureMatrix * vec4( position, 1.0 );
446
- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );`);
447
- shader.fragmentShader = `
448
- uniform sampler2D tDiffuse;
449
- uniform sampler2D tDiffuseBlur;
450
- uniform sampler2D tDepth;
451
- uniform sampler2D distortionMap;
452
- uniform float distortion;
453
- uniform float cameraNear;
454
- uniform float cameraFar;
455
- uniform bool hasBlur;
456
- uniform float mixBlur;
457
- uniform float mirror;
458
- uniform float mixStrength;
459
- uniform float minDepthThreshold;
460
- uniform float maxDepthThreshold;
461
- uniform float mixContrast;
462
- uniform float depthScale;
463
- uniform float depthToBlurRatioBias;
464
- varying vec4 my_vUv;
465
- ${shader.fragmentShader}`;
466
- shader.fragmentShader = shader.fragmentShader.replace('#include <emissivemap_fragment>', `#include <emissivemap_fragment>
467
-
468
- float distortionFactor = 0.0;
469
- #ifdef USE_DISTORTION
470
- distortionFactor = texture2D(distortionMap, vUv).r * distortion;
471
- #endif
472
-
473
- vec4 new_vUv = my_vUv;
474
- new_vUv.x += distortionFactor;
475
- new_vUv.y += distortionFactor;
476
-
477
- vec4 base = texture2DProj(tDiffuse, new_vUv);
478
- vec4 blur = texture2DProj(tDiffuseBlur, new_vUv);
479
-
480
- vec4 merge = base;
481
-
482
- #ifdef USE_NORMALMAP
483
- vec2 normal_uv = vec2(0.0);
484
- vec4 normalColor = texture2D(normalMap, vUv * normalScale);
485
- vec3 my_normal = normalize( vec3( normalColor.r * 2.0 - 1.0, normalColor.b, normalColor.g * 2.0 - 1.0 ) );
486
- vec3 coord = new_vUv.xyz / new_vUv.w;
487
- normal_uv = coord.xy + coord.z * my_normal.xz * 0.05;
488
- vec4 base_normal = texture2D(tDiffuse, normal_uv);
489
- vec4 blur_normal = texture2D(tDiffuseBlur, normal_uv);
490
- merge = base_normal;
491
- blur = blur_normal;
492
- #endif
493
-
494
- float depthFactor = 0.0001;
495
- float blurFactor = 0.0;
496
-
497
- #ifdef USE_DEPTH
498
- vec4 depth = texture2DProj(tDepth, new_vUv);
499
- depthFactor = smoothstep(minDepthThreshold, maxDepthThreshold, 1.0-(depth.r * depth.a));
500
- depthFactor *= depthScale;
501
- depthFactor = max(0.0001, min(1.0, depthFactor));
502
-
503
- #ifdef USE_BLUR
504
- blur = blur * min(1.0, depthFactor + depthToBlurRatioBias);
505
- merge = merge * min(1.0, depthFactor + 0.5);
506
- #else
507
- merge = merge * depthFactor;
508
- #endif
509
-
510
- #endif
511
-
512
- float reflectorRoughnessFactor = roughness;
513
- #ifdef USE_ROUGHNESSMAP
514
- vec4 reflectorTexelRoughness = texture2D( roughnessMap, vUv );
515
- reflectorRoughnessFactor *= reflectorTexelRoughness.g;
516
- #endif
517
-
518
- #ifdef USE_BLUR
519
- blurFactor = min(1.0, mixBlur * reflectorRoughnessFactor);
520
- merge = mix(merge, blur, blurFactor);
521
- #endif
522
-
523
- vec4 newMerge = vec4(0.0, 0.0, 0.0, 1.0);
524
- newMerge.r = (merge.r - 0.5) * mixContrast + 0.5;
525
- newMerge.g = (merge.g - 0.5) * mixContrast + 0.5;
526
- newMerge.b = (merge.b - 0.5) * mixContrast + 0.5;
527
-
528
- diffuseColor.rgb = diffuseColor.rgb * ((1.0 - min(1.0, mirror)) + newMerge.rgb * mixStrength);
529
- `);
530
- }
531
- get tDiffuse() {
532
- return this._tDiffuse.value;
533
- }
534
- set tDiffuse(v) {
535
- this._tDiffuse.value = v;
536
- }
537
- get tDepth() {
538
- return this._tDepth.value;
539
- }
540
- set tDepth(v) {
541
- this._tDepth.value = v;
542
- }
543
- get distortionMap() {
544
- return this._distortionMap.value;
545
- }
546
- set distortionMap(v) {
547
- this._distortionMap.value = v;
548
- }
549
- get tDiffuseBlur() {
550
- return this._tDiffuseBlur.value;
551
- }
552
- set tDiffuseBlur(v) {
553
- this._tDiffuseBlur.value = v;
554
- }
555
- get textureMatrix() {
556
- return this._textureMatrix.value;
557
- }
558
- set textureMatrix(v) {
559
- this._textureMatrix.value = v;
560
- }
561
- get hasBlur() {
562
- return this._hasBlur.value;
563
- }
564
- set hasBlur(v) {
565
- this._hasBlur.value = v;
566
- }
567
- get mirror() {
568
- return this._mirror.value;
569
- }
570
- set mirror(v) {
571
- this._mirror.value = v;
572
- }
573
- get mixBlur() {
574
- return this._mixBlur.value;
575
- }
576
- set mixBlur(v) {
577
- this._mixBlur.value = v;
578
- }
579
- get mixStrength() {
580
- return this._blurStrength.value;
581
- }
582
- set mixStrength(v) {
583
- this._blurStrength.value = v;
584
- }
585
- get minDepthThreshold() {
586
- return this._minDepthThreshold.value;
587
- }
588
- set minDepthThreshold(v) {
589
- this._minDepthThreshold.value = v;
590
- }
591
- get maxDepthThreshold() {
592
- return this._maxDepthThreshold.value;
593
- }
594
- set maxDepthThreshold(v) {
595
- this._maxDepthThreshold.value = v;
596
- }
597
- get depthScale() {
598
- return this._depthScale.value;
599
- }
600
- set depthScale(v) {
601
- this._depthScale.value = v;
602
- }
603
- get depthToBlurRatioBias() {
604
- return this._depthToBlurRatioBias.value;
605
- }
606
- set depthToBlurRatioBias(v) {
607
- this._depthToBlurRatioBias.value = v;
608
- }
609
- get distortion() {
610
- return this._distortion.value;
611
- }
612
- set distortion(v) {
613
- this._distortion.value = v;
614
- }
615
- get mixContrast() {
616
- return this._mixContrast.value;
617
- }
618
- set mixContrast(v) {
619
- this._mixContrast.value = v;
620
- }
621
- }
622
-
623
- // Author: N8Programs
624
- const MeshRefractionMaterial = shaderMaterial({
625
- envMap: null,
626
- bounces: 3,
627
- ior: 2.4,
628
- correctMips: true,
629
- aberrationStrength: 0.01,
630
- fresnel: 0,
631
- bvh: new MeshBVHUniformStruct(),
632
- color: new THREE.Color('white'),
633
- resolution: new THREE.Vector2(),
634
- viewMatrixInverse: new THREE.Matrix4(),
635
- projectionMatrixInverse: new THREE.Matrix4(),
636
- },
637
- /*glsl*/ `
638
- uniform mat4 viewMatrixInverse;
639
-
640
- varying vec3 vWorldPosition;
641
- varying vec3 vNormal;
642
- varying mat4 vModelMatrixInverse;
643
-
644
- #ifdef USE_INSTANCING_COLOR
645
- varying vec3 vInstanceColor;
646
- #endif
647
-
648
- void main() {
649
- vec4 transformedNormal = vec4(normal, 0.0);
650
- vec4 transformedPosition = vec4(position, 1.0);
651
- #ifdef USE_INSTANCING
652
- transformedNormal = instanceMatrix * transformedNormal;
653
- transformedPosition = instanceMatrix * transformedPosition;
654
- #endif
655
-
656
- #ifdef USE_INSTANCING
657
- vModelMatrixInverse = inverse(modelMatrix * instanceMatrix);
658
- #else
659
- vModelMatrixInverse = inverse(modelMatrix);
660
- #endif
661
-
662
- #ifdef USE_INSTANCING_COLOR
663
- vInstanceColor = instanceColor.rgb;
664
- #endif
665
-
666
- vWorldPosition = (modelMatrix * transformedPosition).xyz;
667
- vNormal = normalize((viewMatrixInverse * vec4(normalMatrix * transformedNormal.xyz, 0.0)).xyz);
668
- gl_Position = projectionMatrix * viewMatrix * modelMatrix * transformedPosition;
669
- }`,
670
- /*glsl*/ `
671
- #define ENVMAP_TYPE_CUBE_UV
672
- precision highp isampler2D;
673
- precision highp usampler2D;
674
- varying vec3 vWorldPosition;
675
- varying vec3 vNormal;
676
- varying mat4 vModelMatrixInverse;
677
-
678
- #ifdef USE_INSTANCING_COLOR
679
- varying vec3 vInstanceColor;
680
- #endif
681
-
682
- #ifdef ENVMAP_TYPE_CUBEM
683
- uniform samplerCube envMap;
684
- #else
685
- uniform sampler2D envMap;
686
- #endif
687
-
688
- uniform float bounces;
689
- ${shaderStructs}
690
- ${shaderIntersectFunction}
691
- uniform BVH bvh;
692
- uniform float ior;
693
- uniform bool correctMips;
694
- uniform vec2 resolution;
695
- uniform float fresnel;
696
- uniform mat4 modelMatrix;
697
- uniform mat4 projectionMatrixInverse;
698
- uniform mat4 viewMatrixInverse;
699
- uniform float aberrationStrength;
700
- uniform vec3 color;
701
-
702
- float fresnelFunc(vec3 viewDirection, vec3 worldNormal) {
703
- return pow( 1.0 + dot( viewDirection, worldNormal), 10.0 );
704
- }
705
-
706
- vec3 totalInternalReflection(vec3 ro, vec3 rd, vec3 normal, float ior, mat4 modelMatrixInverse) {
707
- vec3 rayOrigin = ro;
708
- vec3 rayDirection = rd;
709
- rayDirection = refract(rayDirection, normal, 1.0 / ior);
710
- rayOrigin = vWorldPosition + rayDirection * 0.001;
711
- rayOrigin = (modelMatrixInverse * vec4(rayOrigin, 1.0)).xyz;
712
- rayDirection = normalize((modelMatrixInverse * vec4(rayDirection, 0.0)).xyz);
713
- for(float i = 0.0; i < bounces; i++) {
714
- uvec4 faceIndices = uvec4( 0u );
715
- vec3 faceNormal = vec3( 0.0, 0.0, 1.0 );
716
- vec3 barycoord = vec3( 0.0 );
717
- float side = 1.0;
718
- float dist = 0.0;
719
- bvhIntersectFirstHit( bvh, rayOrigin, rayDirection, faceIndices, faceNormal, barycoord, side, dist );
720
- vec3 hitPos = rayOrigin + rayDirection * max(dist - 0.001, 0.0);
721
- vec3 tempDir = refract(rayDirection, faceNormal, ior);
722
- if (length(tempDir) != 0.0) {
723
- rayDirection = tempDir;
724
- break;
725
- }
726
- rayDirection = reflect(rayDirection, faceNormal);
727
- rayOrigin = hitPos + rayDirection * 0.01;
728
- }
729
- rayDirection = normalize((modelMatrix * vec4(rayDirection, 0.0)).xyz);
730
- return rayDirection;
731
- }
732
-
733
- #include <common>
734
- #include <cube_uv_reflection_fragment>
735
-
736
- #ifdef ENVMAP_TYPE_CUBEM
737
- vec4 textureGradient(samplerCube envMap, vec3 rayDirection, vec3 directionCamPerfect) {
738
- return textureGrad(envMap, rayDirection, dFdx(correctMips ? directionCamPerfect: rayDirection), dFdy(correctMips ? directionCamPerfect: rayDirection));
739
- }
740
- #else
741
- vec4 textureGradient(sampler2D envMap, vec3 rayDirection, vec3 directionCamPerfect) {
742
- vec2 uvv = equirectUv( rayDirection );
743
- vec2 smoothUv = equirectUv( directionCamPerfect );
744
- return textureGrad(envMap, uvv, dFdx(correctMips ? smoothUv : uvv), dFdy(correctMips ? smoothUv : uvv));
745
- }
746
- #endif
747
-
748
- void main() {
749
- vec2 uv = gl_FragCoord.xy / resolution;
750
- vec3 directionCamPerfect = (projectionMatrixInverse * vec4(uv * 2.0 - 1.0, 0.0, 1.0)).xyz;
751
- directionCamPerfect = (viewMatrixInverse * vec4(directionCamPerfect, 0.0)).xyz;
752
- directionCamPerfect = normalize(directionCamPerfect);
753
- vec3 normal = vNormal;
754
- vec3 rayOrigin = cameraPosition;
755
- vec3 rayDirection = normalize(vWorldPosition - cameraPosition);
756
- vec3 finalColor;
757
- #ifdef CHROMATIC_ABERRATIONS
758
- vec3 rayDirectionG = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior, 1.0), vModelMatrixInverse);
759
- #ifdef FAST_CHROMA
760
- vec3 rayDirectionR = normalize(rayDirectionG + 1.0 * vec3(aberrationStrength / 2.0));
761
- vec3 rayDirectionB = normalize(rayDirectionG - 1.0 * vec3(aberrationStrength / 2.0));
762
- #else
763
- vec3 rayDirectionR = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior * (1.0 - aberrationStrength), 1.0), vModelMatrixInverse);
764
- vec3 rayDirectionB = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior * (1.0 + aberrationStrength), 1.0), vModelMatrixInverse);
765
- #endif
766
- float finalColorR = textureGradient(envMap, rayDirectionR, directionCamPerfect).r;
767
- float finalColorG = textureGradient(envMap, rayDirectionG, directionCamPerfect).g;
768
- float finalColorB = textureGradient(envMap, rayDirectionB, directionCamPerfect).b;
769
- finalColor = vec3(finalColorR, finalColorG, finalColorB);
770
- #else
771
- rayDirection = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior, 1.0), vModelMatrixInverse);
772
- finalColor = textureGradient(envMap, rayDirection, directionCamPerfect).rgb;
773
- #endif
774
-
775
- finalColor *= color;
776
- #ifdef USE_INSTANCING_COLOR
777
- finalColor *= vInstanceColor;
778
- #endif
779
-
780
- vec3 viewDirection = normalize(vWorldPosition - cameraPosition);
781
- float nFresnel = fresnelFunc(viewDirection, normal) * fresnel;
782
- gl_FragColor = vec4(mix(finalColor, vec3(1.0), nFresnel), 1.0);
783
- #include <tonemapping_fragment>
784
- #include <encodings_fragment>
785
- }`);
786
-
787
- class MeshTransmissionMaterial extends THREE.MeshPhysicalMaterial {
788
- constructor(samples = 6, transmissionSampler = false) {
789
- super();
790
- this.uniforms = {
791
- chromaticAberration: { value: 0.05 },
792
- // Transmission must always be 0, unless transmissionSampler is being used
793
- transmission: { value: 0 },
794
- // Instead a workaround is used, see below for reasons why
795
- _transmission: { value: 1 },
796
- transmissionMap: { value: null },
797
- // Roughness is 1 in THREE.MeshPhysicalMaterial but it makes little sense in a transmission material
798
- roughness: { value: 0 },
799
- thickness: { value: 0 },
800
- thicknessMap: { value: null },
801
- attenuationDistance: { value: Infinity },
802
- attenuationColor: { value: new THREE.Color('white') },
803
- anisotropy: { value: 0.1 },
804
- time: { value: 0 },
805
- distortion: { value: 0.0 },
806
- distortionScale: { value: 0.5 },
807
- temporalDistortion: { value: 0.0 },
808
- buffer: { value: null },
809
- };
810
- this.onBeforeCompile = (shader) => {
811
- shader.uniforms = Object.assign(Object.assign({}, shader.uniforms), this.uniforms);
812
- // If the transmission sampler is active inject a flag
813
- if (transmissionSampler)
814
- shader.defines['USE_SAMPLER'] = '';
815
- // Otherwise we do use use .transmission and must therefore force USE_TRANSMISSION
816
- // because threejs won't inject it for us
817
- else
818
- shader.defines['USE_TRANSMISSION'] = '';
819
- // Head
820
- shader.fragmentShader =
821
- /*glsl*/ `
822
- uniform float chromaticAberration;
823
- uniform float anisotropy;
824
- uniform float time;
825
- uniform float distortion;
826
- uniform float distortionScale;
827
- uniform float temporalDistortion;
828
- uniform sampler2D buffer;
829
-
830
- vec3 random3(vec3 c) {
831
- float j = 4096.0*sin(dot(c,vec3(17.0, 59.4, 15.0)));
832
- vec3 r;
833
- r.z = fract(512.0*j);
834
- j *= .125;
835
- r.x = fract(512.0*j);
836
- j *= .125;
837
- r.y = fract(512.0*j);
838
- return r-0.5;
839
- }
840
-
841
- float seed = 0.0;
842
- uint hash( uint x ) {
843
- x += ( x << 10u );
844
- x ^= ( x >> 6u );
845
- x += ( x << 3u );
846
- x ^= ( x >> 11u );
847
- x += ( x << 15u );
848
- return x;
849
- }
850
-
851
- // Compound versions of the hashing algorithm I whipped together.
852
- uint hash( uvec2 v ) { return hash( v.x ^ hash(v.y) ); }
853
- uint hash( uvec3 v ) { return hash( v.x ^ hash(v.y) ^ hash(v.z) ); }
854
- uint hash( uvec4 v ) { return hash( v.x ^ hash(v.y) ^ hash(v.z) ^ hash(v.w) ); }
855
-
856
- // Construct a float with half-open range [0:1] using low 23 bits.
857
- // All zeroes yields 0.0, all ones yields the next smallest representable value below 1.0.
858
- float floatConstruct( uint m ) {
859
- const uint ieeeMantissa = 0x007FFFFFu; // binary32 mantissa bitmask
860
- const uint ieeeOne = 0x3F800000u; // 1.0 in IEEE binary32
861
- m &= ieeeMantissa; // Keep only mantissa bits (fractional part)
862
- m |= ieeeOne; // Add fractional part to 1.0
863
- float f = uintBitsToFloat( m ); // Range [1:2]
864
- return f - 1.0; // Range [0:1]
865
- }
866
-
867
- // Pseudo-random value in half-open range [0:1].
868
- float random( float x ) { return floatConstruct(hash(floatBitsToUint(x))); }
869
- float random( vec2 v ) { return floatConstruct(hash(floatBitsToUint(v))); }
870
- float random( vec3 v ) { return floatConstruct(hash(floatBitsToUint(v))); }
871
- float random( vec4 v ) { return floatConstruct(hash(floatBitsToUint(v))); }
872
-
873
- float rand() {
874
- float result = random(vec3(gl_FragCoord.xy, seed));
875
- seed += 1.0;
876
- return result;
877
- }
878
-
879
- const float F3 = 0.3333333;
880
- const float G3 = 0.1666667;
881
-
882
- float snoise(vec3 p) {
883
- vec3 s = floor(p + dot(p, vec3(F3)));
884
- vec3 x = p - s + dot(s, vec3(G3));
885
- vec3 e = step(vec3(0.0), x - x.yzx);
886
- vec3 i1 = e*(1.0 - e.zxy);
887
- vec3 i2 = 1.0 - e.zxy*(1.0 - e);
888
- vec3 x1 = x - i1 + G3;
889
- vec3 x2 = x - i2 + 2.0*G3;
890
- vec3 x3 = x - 1.0 + 3.0*G3;
891
- vec4 w, d;
892
- w.x = dot(x, x);
893
- w.y = dot(x1, x1);
894
- w.z = dot(x2, x2);
895
- w.w = dot(x3, x3);
896
- w = max(0.6 - w, 0.0);
897
- d.x = dot(random3(s), x);
898
- d.y = dot(random3(s + i1), x1);
899
- d.z = dot(random3(s + i2), x2);
900
- d.w = dot(random3(s + 1.0), x3);
901
- w *= w;
902
- w *= w;
903
- d *= w;
904
- return dot(d, vec4(52.0));
905
- }
906
-
907
- float snoiseFractal(vec3 m) {
908
- return 0.5333333* snoise(m)
909
- +0.2666667* snoise(2.0*m)
910
- +0.1333333* snoise(4.0*m)
911
- +0.0666667* snoise(8.0*m);
912
- }\n` + shader.fragmentShader;
913
- // Remove transmission
914
- shader.fragmentShader = shader.fragmentShader.replace('#include <transmission_pars_fragment>',
915
- /*glsl*/ `
916
- #ifdef USE_TRANSMISSION
917
- // Transmission code is based on glTF-Sampler-Viewer
918
- // https://github.com/KhronosGroup/glTF-Sample-Viewer
919
- uniform float _transmission;
920
- uniform float thickness;
921
- uniform float attenuationDistance;
922
- uniform vec3 attenuationColor;
923
- #ifdef USE_TRANSMISSIONMAP
924
- uniform sampler2D transmissionMap;
925
- #endif
926
- #ifdef USE_THICKNESSMAP
927
- uniform sampler2D thicknessMap;
928
- #endif
929
- uniform vec2 transmissionSamplerSize;
930
- uniform sampler2D transmissionSamplerMap;
931
- uniform mat4 modelMatrix;
932
- uniform mat4 projectionMatrix;
933
- varying vec3 vWorldPosition;
934
- vec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {
935
- // Direction of refracted light.
936
- vec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );
937
- // Compute rotation-independant scaling of the model matrix.
938
- vec3 modelScale;
939
- modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );
940
- modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );
941
- modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );
942
- // The thickness is specified in local space.
943
- return normalize( refractionVector ) * thickness * modelScale;
944
- }
945
- float applyIorToRoughness( const in float roughness, const in float ior ) {
946
- // Scale roughness with IOR so that an IOR of 1.0 results in no microfacet refraction and
947
- // an IOR of 1.5 results in the default amount of microfacet refraction.
948
- return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );
949
- }
950
- vec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {
951
- float framebufferLod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );
952
- #ifdef USE_SAMPLER
953
- #ifdef texture2DLodEXT
954
- return texture2DLodEXT(transmissionSamplerMap, fragCoord.xy, framebufferLod);
955
- #else
956
- return texture2D(transmissionSamplerMap, fragCoord.xy, framebufferLod);
957
- #endif
958
- #else
959
- return texture2D(buffer, fragCoord.xy);
960
- #endif
961
- }
962
- vec3 applyVolumeAttenuation( const in vec3 radiance, const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {
963
- if ( isinf( attenuationDistance ) ) {
964
- // Attenuation distance is +∞, i.e. the transmitted color is not attenuated at all.
965
- return radiance;
966
- } else {
967
- // Compute light attenuation using Beer's law.
968
- vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;
969
- vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance ); // Beer's law
970
- return transmittance * radiance;
971
- }
972
- }
973
- vec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,
974
- const in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,
975
- const in mat4 viewMatrix, const in mat4 projMatrix, const in float ior, const in float thickness,
976
- const in vec3 attenuationColor, const in float attenuationDistance ) {
977
- vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );
978
- vec3 refractedRayExit = position + transmissionRay;
979
- // Project refracted vector on the framebuffer, while mapping to normalized device coordinates.
980
- vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );
981
- vec2 refractionCoords = ndcPos.xy / ndcPos.w;
982
- refractionCoords += 1.0;
983
- refractionCoords /= 2.0;
984
- // Sample framebuffer to get pixel the refracted ray hits.
985
- vec4 transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );
986
- vec3 attenuatedColor = applyVolumeAttenuation( transmittedLight.rgb, length( transmissionRay ), attenuationColor, attenuationDistance );
987
- // Get the specular component.
988
- vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );
989
- return vec4( ( 1.0 - F ) * attenuatedColor * diffuseColor, transmittedLight.a );
990
- }
991
- #endif\n`);
992
- // Add refraction
993
- shader.fragmentShader = shader.fragmentShader.replace('#include <transmission_fragment>',
994
- /*glsl*/ `
995
- // Improve the refraction to use the world pos
996
- material.transmission = _transmission;
997
- material.transmissionAlpha = 1.0;
998
- material.thickness = thickness;
999
- material.attenuationDistance = attenuationDistance;
1000
- material.attenuationColor = attenuationColor;
1001
- #ifdef USE_TRANSMISSIONMAP
1002
- material.transmission *= texture2D( transmissionMap, vUv ).r;
1003
- #endif
1004
- #ifdef USE_THICKNESSMAP
1005
- material.thickness *= texture2D( thicknessMap, vUv ).g;
1006
- #endif
1007
-
1008
- vec3 pos = vWorldPosition;
1009
- vec3 v = normalize( cameraPosition - pos );
1010
- vec3 n = inverseTransformDirection( normal, viewMatrix );
1011
- vec3 transmission = vec3(0.0);
1012
- float transmissionR, transmissionB, transmissionG;
1013
- float randomCoords = rand();
1014
- float thickness_smear = thickness * max(pow(roughnessFactor, 0.33), anisotropy);
1015
- vec3 distortionNormal = vec3(0.0);
1016
- vec3 temporalOffset = vec3(time, -time, -time) * temporalDistortion;
1017
- if (distortion > 0.0) {
1018
- distortionNormal = distortion * vec3(snoiseFractal(vec3((pos * distortionScale + temporalOffset))), snoiseFractal(vec3(pos.zxy * distortionScale - temporalOffset)), snoiseFractal(vec3(pos.yxz * distortionScale + temporalOffset)));
1019
- }
1020
- for (float i = 0.0; i < ${samples}.0; i ++) {
1021
- vec3 sampleNorm = normalize(n + roughnessFactor * roughnessFactor * 2.0 * normalize(vec3(rand() - 0.5, rand() - 0.5, rand() - 0.5)) * pow(rand(), 0.33) + distortionNormal);
1022
- transmissionR = getIBLVolumeRefraction(
1023
- sampleNorm, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,
1024
- pos, modelMatrix, viewMatrix, projectionMatrix, material.ior, material.thickness + thickness_smear * (i + randomCoords) / float(${samples}),
1025
- material.attenuationColor, material.attenuationDistance
1026
- ).r;
1027
- transmissionG = getIBLVolumeRefraction(
1028
- sampleNorm, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,
1029
- pos, modelMatrix, viewMatrix, projectionMatrix, material.ior * (1.0 + chromaticAberration * (i + randomCoords) / float(${samples})) , material.thickness + thickness_smear * (i + randomCoords) / float(${samples}),
1030
- material.attenuationColor, material.attenuationDistance
1031
- ).g;
1032
- transmissionB = getIBLVolumeRefraction(
1033
- sampleNorm, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,
1034
- pos, modelMatrix, viewMatrix, projectionMatrix, material.ior * (1.0 + 2.0 * chromaticAberration * (i + randomCoords) / float(${samples})), material.thickness + thickness_smear * (i + randomCoords) / float(${samples}),
1035
- material.attenuationColor, material.attenuationDistance
1036
- ).b;
1037
- transmission.r += transmissionR;
1038
- transmission.g += transmissionG;
1039
- transmission.b += transmissionB;
1040
- }
1041
- transmission /= ${samples}.0;
1042
- totalDiffuse = mix( totalDiffuse, transmission.rgb, material.transmission );\n`);
1043
- };
1044
- Object.keys(this.uniforms).forEach((name) => Object.defineProperty(this, name, {
1045
- get: () => this.uniforms[name].value,
1046
- set: (v) => (this.uniforms[name].value = v),
1047
- }));
1048
- }
1049
- }
1050
-
1051
- class MeshWobbleMaterial extends THREE.MeshStandardMaterial {
1052
- constructor(parameters = {}) {
1053
- super(parameters);
1054
- this.setValues(parameters);
1055
- this._time = { value: 0 };
1056
- this._factor = { value: 1 };
1057
- }
1058
- onBeforeCompile(shader) {
1059
- shader.uniforms['time'] = this._time;
1060
- shader.uniforms['factor'] = this._factor;
1061
- shader.vertexShader = `
1062
- uniform float time;
1063
- uniform float factor;
1064
- ${shader.vertexShader}
1065
- `;
1066
- shader.vertexShader = shader.vertexShader.replace('#include <begin_vertex>', `float theta = sin( time + position.y ) / 2.0 * factor;
1067
- float c = cos( theta );
1068
- float s = sin( theta );
1069
- mat3 m = mat3( c, 0, s, 0, 1, 0, -s, 0, c );
1070
- vec3 transformed = vec3( position ) * m;
1071
- vNormal = vNormal * m;`);
1072
- }
1073
- get time() {
1074
- return this._time.value;
1075
- }
1076
- set time(v) {
1077
- this._time.value = v;
1078
- }
1079
- get factor() {
1080
- return this._factor.value;
1081
- }
1082
- set factor(v) {
1083
- this._factor.value = v;
1084
- }
1085
- }
1086
-
1087
- const SoftShadowMaterial = shaderMaterial({
1088
- color: new THREE.Color(),
1089
- blend: 2.0,
1090
- alphaTest: 0.75,
1091
- opacity: 0,
1092
- map: null,
1093
- },
1094
- // language=GLSL
1095
- `
1096
- varying vec2 vUv;
1097
- void main() {
1098
- gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.);
1099
- vUv = uv;
1100
- }
1101
- `,
1102
- // language=GLSL
1103
- `
1104
- varying vec2 vUv;
1105
- uniform sampler2D map;
1106
- uniform vec3 color;
1107
- uniform float blend;
1108
- uniform float opacity;
1109
- uniform float alphaTest;
1110
- void main() {
1111
- vec4 sampledDiffuseColor = texture2D(map, vUv);
1112
- gl_FragColor = vec4(color * sampledDiffuseColor.r * blend, max(0.0, (1.0 - (sampledDiffuseColor.r + sampledDiffuseColor.g + sampledDiffuseColor.b) / alphaTest)) * opacity);
1113
- #include <tonemapping_fragment>
1114
- #include <encodings_fragment>
1115
- }
1116
- `);
1117
-
1118
- class SpotLightMaterial extends ShaderMaterial {
1119
- constructor() {
1120
- super({
1121
- uniforms: {
1122
- depth: { value: null },
1123
- opacity: { value: 1 },
1124
- attenuation: { value: 2.5 },
1125
- anglePower: { value: 12 },
1126
- spotPosition: { value: new Vector3(0, 0, 0) },
1127
- lightColor: { value: new Color('white') },
1128
- cameraNear: { value: 0 },
1129
- cameraFar: { value: 1 },
1130
- resolution: { value: new Vector2(0, 0) },
1131
- },
1132
- transparent: true,
1133
- depthWrite: false,
1134
- vertexShader: /* glsl */ `
1135
- varying vec3 vNormal;
1136
- varying vec3 vWorldPosition;
1137
- varying float vViewZ;
1138
- varying float vIntensity;
1139
- uniform vec3 spotPosition;
1140
- uniform float attenuation;
1141
-
1142
- void main() {
1143
- // compute intensity
1144
- vNormal = normalize( normalMatrix * normal );
1145
- vec4 worldPosition = modelMatrix * vec4( position, 1.0 );
1146
- vWorldPosition = worldPosition.xyz;
1147
- vec4 viewPosition = viewMatrix * worldPosition;
1148
- vViewZ = viewPosition.z;
1149
- float intensity = distance(worldPosition.xyz, spotPosition) / attenuation;
1150
- intensity = 1.0 - clamp(intensity, 0.0, 1.0);
1151
- vIntensity = intensity;
1152
- // set gl_Position
1153
- gl_Position = projectionMatrix * viewPosition;
1154
-
1155
- }`,
1156
- fragmentShader: /* glsl */ `
1157
- #include <packing>
1158
-
1159
- varying vec3 vNormal;
1160
- varying vec3 vWorldPosition;
1161
- uniform vec3 lightColor;
1162
- uniform vec3 spotPosition;
1163
- uniform float attenuation;
1164
- uniform float anglePower;
1165
- uniform sampler2D depth;
1166
- uniform vec2 resolution;
1167
- uniform float cameraNear;
1168
- uniform float cameraFar;
1169
- varying float vViewZ;
1170
- varying float vIntensity;
1171
- uniform float opacity;
1172
-
1173
- float readDepth( sampler2D depthSampler, vec2 coord ) {
1174
- float fragCoordZ = texture2D( depthSampler, coord ).x;
1175
- float viewZ = perspectiveDepthToViewZ(fragCoordZ, cameraNear, cameraFar);
1176
- return viewZ;
1177
- }
1178
-
1179
- void main() {
1180
- float d = 1.0;
1181
- bool isSoft = resolution[0] > 0.0 && resolution[1] > 0.0;
1182
- if (isSoft) {
1183
- vec2 sUv = gl_FragCoord.xy / resolution;
1184
- d = readDepth(depth, sUv);
1185
- }
1186
- float intensity = vIntensity;
1187
- vec3 normal = vec3(vNormal.x, vNormal.y, abs(vNormal.z));
1188
- float angleIntensity = pow( dot(normal, vec3(0.0, 0.0, 1.0)), anglePower );
1189
- intensity *= angleIntensity;
1190
- // fades when z is close to sampled depth, meaning the cone is intersecting existing geometry
1191
- if (isSoft) {
1192
- intensity *= smoothstep(0., 1., vViewZ - d);
1193
- }
1194
- gl_FragColor = vec4(lightColor, intensity * opacity);
1195
-
1196
- #include <tonemapping_fragment>
1197
- #include <encodings_fragment>
1198
- }`,
1199
- });
1200
- }
1201
- }
1202
-
1203
- const StarFieldMaterial = shaderMaterial({ time: 0.0, fade: 0.0 },
1204
- // language=GLSL
1205
- `
1206
- uniform float time;
1207
- attribute float size;
1208
- varying vec3 vColor;
1209
- void main() {
1210
- vColor = color;
1211
- vec4 mvPosition = modelViewMatrix * vec4(position, 0.5);
1212
- gl_PointSize = size * (30.0 / -mvPosition.z) * (3.0 + sin(time + 100.0));
1213
- gl_Position = projectionMatrix * mvPosition;
1214
- }
1215
- `,
1216
- // language=GLSL
1217
- `
1218
- uniform sampler2D pointTexture;
1219
- uniform float fade;
1220
- varying vec3 vColor;
1221
- void main() {
1222
- float opacity = 1.0;
1223
- if (fade == 1.0) {
1224
- float d = distance(gl_PointCoord, vec2(0.5, 0.5));
1225
- opacity = 1.0 / (1.0 + exp(16.0 * (d - 0.25)));
1226
- }
1227
- gl_FragColor = vec4(vColor, opacity);
1228
-
1229
- #include <tonemapping_fragment>
1230
- #include <encodings_fragment>
1231
- }
1232
- `);
1233
-
1234
- /**
1235
- * Generated bundle index. Do not edit.
1236
- */
1237
-
1238
- export { BlurPass, CausticsMaterial, CausticsProjectionMaterial, ConvolutionMaterial, DiscardMaterial, MeshReflectorMaterial, MeshRefractionMaterial, MeshTransmissionMaterial, MeshWobbleMaterial, NGTS_DISTORT_MATERIAL_SHADER, SoftShadowMaterial, SpotLightMaterial, StarFieldMaterial, provideNgtsMeshDistortMaterialShader, shaderMaterial };
1239
- //# sourceMappingURL=angular-three-soba-shaders.mjs.map