@react-three/postprocessing 2.18.0 → 3.0.0-rc.0

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 (271) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +81 -81
  3. package/dist/index.d.ts +1 -38
  4. package/dist/index.js +554 -88
  5. package/dist/index.js.map +1 -1
  6. package/package.json +69 -96
  7. package/src/EffectComposer.test.tsx +126 -0
  8. package/src/EffectComposer.tsx +202 -0
  9. package/src/Selection.tsx +46 -0
  10. package/src/effects/ASCII.tsx +135 -0
  11. package/src/effects/Autofocus.tsx +153 -0
  12. package/src/effects/Bloom.tsx +6 -0
  13. package/src/effects/BrightnessContrast.tsx +4 -0
  14. package/src/effects/ChromaticAberration.tsx +5 -0
  15. package/src/effects/ColorAverage.tsx +15 -0
  16. package/src/effects/ColorDepth.tsx +4 -0
  17. package/src/effects/Depth.tsx +4 -0
  18. package/src/effects/DepthOfField.tsx +89 -0
  19. package/src/effects/DotScreen.tsx +4 -0
  20. package/src/effects/FXAA.tsx +4 -0
  21. package/src/effects/Glitch.tsx +40 -0
  22. package/src/effects/GodRays.tsx +16 -0
  23. package/src/effects/Grid.tsx +21 -0
  24. package/src/effects/HueSaturation.tsx +4 -0
  25. package/src/effects/LUT.tsx +26 -0
  26. package/src/effects/LensFlare.tsx +611 -0
  27. package/src/effects/N8AO.tsx +81 -0
  28. package/src/effects/Noise.tsx +4 -0
  29. package/src/effects/Outline.tsx +117 -0
  30. package/src/effects/Pixelation.tsx +15 -0
  31. package/{dist/effects/Ramp.js → src/effects/Ramp.tsx} +150 -156
  32. package/src/effects/SMAA.tsx +4 -0
  33. package/src/effects/SSAO.tsx +41 -0
  34. package/src/effects/ScanlineEffect.tsx +7 -0
  35. package/src/effects/SelectiveBloom.tsx +126 -0
  36. package/src/effects/Sepia.tsx +4 -0
  37. package/src/effects/ShockWave.tsx +4 -0
  38. package/src/effects/Texture.tsx +23 -0
  39. package/src/effects/TiltShift.tsx +4 -0
  40. package/{dist/effects/TiltShift2.js → src/effects/TiltShift2.tsx} +90 -98
  41. package/src/effects/ToneMapping.tsx +6 -0
  42. package/src/effects/Vignette.tsx +4 -0
  43. package/{dist/effects/Water.js → src/effects/Water.tsx} +35 -38
  44. package/src/index.ts +40 -0
  45. package/src/util.tsx +55 -0
  46. package/dist/EffectComposer.cjs +0 -137
  47. package/dist/EffectComposer.cjs.map +0 -1
  48. package/dist/EffectComposer.d.ts +0 -27
  49. package/dist/EffectComposer.js +0 -137
  50. package/dist/EffectComposer.js.map +0 -1
  51. package/dist/EffectComposer.test.d.ts +0 -4
  52. package/dist/Selection.cjs +0 -36
  53. package/dist/Selection.cjs.map +0 -1
  54. package/dist/Selection.d.ts +0 -16
  55. package/dist/Selection.js +0 -36
  56. package/dist/Selection.js.map +0 -1
  57. package/dist/compat.cjs +0 -77
  58. package/dist/compat.cjs.map +0 -1
  59. package/dist/compat.js +0 -60
  60. package/dist/compat.js.map +0 -1
  61. package/dist/effects/ASCII.cjs +0 -113
  62. package/dist/effects/ASCII.cjs.map +0 -1
  63. package/dist/effects/ASCII.d.ts +0 -17
  64. package/dist/effects/ASCII.js +0 -113
  65. package/dist/effects/ASCII.js.map +0 -1
  66. package/dist/effects/Autofocus.cjs +0 -126
  67. package/dist/effects/Autofocus.cjs.map +0 -1
  68. package/dist/effects/Autofocus.d.ts +0 -22
  69. package/dist/effects/Autofocus.js +0 -109
  70. package/dist/effects/Autofocus.js.map +0 -1
  71. package/dist/effects/Bloom.cjs +0 -9
  72. package/dist/effects/Bloom.cjs.map +0 -1
  73. package/dist/effects/Bloom.d.ts +0 -6
  74. package/dist/effects/Bloom.js +0 -9
  75. package/dist/effects/Bloom.js.map +0 -1
  76. package/dist/effects/BrightnessContrast.cjs +0 -7
  77. package/dist/effects/BrightnessContrast.cjs.map +0 -1
  78. package/dist/effects/BrightnessContrast.d.ts +0 -10
  79. package/dist/effects/BrightnessContrast.js +0 -7
  80. package/dist/effects/BrightnessContrast.js.map +0 -1
  81. package/dist/effects/ChromaticAberration.cjs +0 -7
  82. package/dist/effects/ChromaticAberration.cjs.map +0 -1
  83. package/dist/effects/ChromaticAberration.d.ts +0 -13
  84. package/dist/effects/ChromaticAberration.js +0 -7
  85. package/dist/effects/ChromaticAberration.js.map +0 -1
  86. package/dist/effects/ColorAverage.cjs +0 -11
  87. package/dist/effects/ColorAverage.cjs.map +0 -1
  88. package/dist/effects/ColorAverage.d.ts +0 -8
  89. package/dist/effects/ColorAverage.js +0 -11
  90. package/dist/effects/ColorAverage.js.map +0 -1
  91. package/dist/effects/ColorDepth.cjs +0 -7
  92. package/dist/effects/ColorDepth.cjs.map +0 -1
  93. package/dist/effects/ColorDepth.d.ts +0 -9
  94. package/dist/effects/ColorDepth.js +0 -7
  95. package/dist/effects/ColorDepth.js.map +0 -1
  96. package/dist/effects/Depth.cjs +0 -7
  97. package/dist/effects/Depth.cjs.map +0 -1
  98. package/dist/effects/Depth.d.ts +0 -9
  99. package/dist/effects/Depth.js +0 -7
  100. package/dist/effects/Depth.js.map +0 -1
  101. package/dist/effects/DepthOfField.cjs +0 -74
  102. package/dist/effects/DepthOfField.cjs.map +0 -1
  103. package/dist/effects/DepthOfField.d.ts +0 -25
  104. package/dist/effects/DepthOfField.js +0 -74
  105. package/dist/effects/DepthOfField.js.map +0 -1
  106. package/dist/effects/DotScreen.cjs +0 -7
  107. package/dist/effects/DotScreen.cjs.map +0 -1
  108. package/dist/effects/DotScreen.d.ts +0 -10
  109. package/dist/effects/DotScreen.js +0 -7
  110. package/dist/effects/DotScreen.js.map +0 -1
  111. package/dist/effects/FXAA.cjs +0 -7
  112. package/dist/effects/FXAA.cjs.map +0 -1
  113. package/dist/effects/FXAA.d.ts +0 -8
  114. package/dist/effects/FXAA.js +0 -7
  115. package/dist/effects/FXAA.js.map +0 -1
  116. package/dist/effects/Glitch.cjs +0 -31
  117. package/dist/effects/Glitch.cjs.map +0 -1
  118. package/dist/effects/Glitch.d.ts +0 -30
  119. package/dist/effects/Glitch.js +0 -31
  120. package/dist/effects/Glitch.js.map +0 -1
  121. package/dist/effects/GodRays.cjs +0 -15
  122. package/dist/effects/GodRays.cjs.map +0 -1
  123. package/dist/effects/GodRays.d.ts +0 -21
  124. package/dist/effects/GodRays.js +0 -15
  125. package/dist/effects/GodRays.js.map +0 -1
  126. package/dist/effects/Grid.cjs +0 -18
  127. package/dist/effects/Grid.cjs.map +0 -1
  128. package/dist/effects/Grid.d.ts +0 -12
  129. package/dist/effects/Grid.js +0 -18
  130. package/dist/effects/Grid.js.map +0 -1
  131. package/dist/effects/HueSaturation.cjs +0 -7
  132. package/dist/effects/HueSaturation.cjs.map +0 -1
  133. package/dist/effects/HueSaturation.d.ts +0 -10
  134. package/dist/effects/HueSaturation.js +0 -7
  135. package/dist/effects/HueSaturation.js.map +0 -1
  136. package/dist/effects/LUT.cjs +0 -20
  137. package/dist/effects/LUT.cjs.map +0 -1
  138. package/dist/effects/LUT.d.ts +0 -9
  139. package/dist/effects/LUT.js +0 -20
  140. package/dist/effects/LUT.js.map +0 -1
  141. package/dist/effects/LensFlare.cjs +0 -189
  142. package/dist/effects/LensFlare.cjs.map +0 -1
  143. package/dist/effects/LensFlare.d.ts +0 -52
  144. package/dist/effects/LensFlare.js +0 -172
  145. package/dist/effects/LensFlare.js.map +0 -1
  146. package/dist/effects/N8AO/BlueNoise.cjs +0 -4
  147. package/dist/effects/N8AO/BlueNoise.cjs.map +0 -1
  148. package/dist/effects/N8AO/BlueNoise.js +0 -5
  149. package/dist/effects/N8AO/BlueNoise.js.map +0 -1
  150. package/dist/effects/N8AO/DepthDownSample.cjs +0 -183
  151. package/dist/effects/N8AO/DepthDownSample.cjs.map +0 -1
  152. package/dist/effects/N8AO/DepthDownSample.js +0 -166
  153. package/dist/effects/N8AO/DepthDownSample.js.map +0 -1
  154. package/dist/effects/N8AO/EffectCompositer.cjs +0 -278
  155. package/dist/effects/N8AO/EffectCompositer.cjs.map +0 -1
  156. package/dist/effects/N8AO/EffectCompositer.js +0 -261
  157. package/dist/effects/N8AO/EffectCompositer.js.map +0 -1
  158. package/dist/effects/N8AO/EffectShader.cjs +0 -236
  159. package/dist/effects/N8AO/EffectShader.cjs.map +0 -1
  160. package/dist/effects/N8AO/EffectShader.js +0 -219
  161. package/dist/effects/N8AO/EffectShader.js.map +0 -1
  162. package/dist/effects/N8AO/FullScreenTriangle.cjs +0 -59
  163. package/dist/effects/N8AO/FullScreenTriangle.cjs.map +0 -1
  164. package/dist/effects/N8AO/FullScreenTriangle.js +0 -42
  165. package/dist/effects/N8AO/FullScreenTriangle.js.map +0 -1
  166. package/dist/effects/N8AO/N8AOPostPass.cjs +0 -502
  167. package/dist/effects/N8AO/N8AOPostPass.cjs.map +0 -1
  168. package/dist/effects/N8AO/N8AOPostPass.js +0 -485
  169. package/dist/effects/N8AO/N8AOPostPass.js.map +0 -1
  170. package/dist/effects/N8AO/PoissionBlur.cjs +0 -186
  171. package/dist/effects/N8AO/PoissionBlur.cjs.map +0 -1
  172. package/dist/effects/N8AO/PoissionBlur.js +0 -169
  173. package/dist/effects/N8AO/PoissionBlur.js.map +0 -1
  174. package/dist/effects/N8AO/index.cjs +0 -60
  175. package/dist/effects/N8AO/index.cjs.map +0 -1
  176. package/dist/effects/N8AO/index.d.ts +0 -18
  177. package/dist/effects/N8AO/index.js +0 -60
  178. package/dist/effects/N8AO/index.js.map +0 -1
  179. package/dist/effects/Noise.cjs +0 -7
  180. package/dist/effects/Noise.cjs.map +0 -1
  181. package/dist/effects/Noise.d.ts +0 -9
  182. package/dist/effects/Noise.js +0 -7
  183. package/dist/effects/Noise.js.map +0 -1
  184. package/dist/effects/Outline.cjs +0 -100
  185. package/dist/effects/Outline.cjs.map +0 -1
  186. package/dist/effects/Outline.d.ts +0 -30
  187. package/dist/effects/Outline.js +0 -100
  188. package/dist/effects/Outline.js.map +0 -1
  189. package/dist/effects/Pixelation.cjs +0 -11
  190. package/dist/effects/Pixelation.cjs.map +0 -1
  191. package/dist/effects/Pixelation.d.ts +0 -6
  192. package/dist/effects/Pixelation.js +0 -11
  193. package/dist/effects/Pixelation.js.map +0 -1
  194. package/dist/effects/Ramp.cjs +0 -156
  195. package/dist/effects/Ramp.cjs.map +0 -1
  196. package/dist/effects/Ramp.d.ts +0 -88
  197. package/dist/effects/Ramp.js.map +0 -1
  198. package/dist/effects/SMAA.cjs +0 -7
  199. package/dist/effects/SMAA.cjs.map +0 -1
  200. package/dist/effects/SMAA.d.ts +0 -10
  201. package/dist/effects/SMAA.js +0 -7
  202. package/dist/effects/SMAA.js.map +0 -1
  203. package/dist/effects/SSAO.cjs +0 -37
  204. package/dist/effects/SSAO.cjs.map +0 -1
  205. package/dist/effects/SSAO.d.ts +0 -30
  206. package/dist/effects/SSAO.js +0 -37
  207. package/dist/effects/SSAO.js.map +0 -1
  208. package/dist/effects/SSR/index.cjs +0 -33
  209. package/dist/effects/SSR/index.cjs.map +0 -1
  210. package/dist/effects/SSR/index.d.ts +0 -55
  211. package/dist/effects/SSR/index.js +0 -33
  212. package/dist/effects/SSR/index.js.map +0 -1
  213. package/dist/effects/SSR/screen-space-reflections.cjs +0 -1699
  214. package/dist/effects/SSR/screen-space-reflections.cjs.map +0 -1
  215. package/dist/effects/SSR/screen-space-reflections.js +0 -1699
  216. package/dist/effects/SSR/screen-space-reflections.js.map +0 -1
  217. package/dist/effects/ScanlineEffect.cjs +0 -7
  218. package/dist/effects/ScanlineEffect.cjs.map +0 -1
  219. package/dist/effects/ScanlineEffect.d.ts +0 -9
  220. package/dist/effects/ScanlineEffect.js +0 -7
  221. package/dist/effects/ScanlineEffect.js.map +0 -1
  222. package/dist/effects/SelectiveBloom.cjs +0 -94
  223. package/dist/effects/SelectiveBloom.cjs.map +0 -1
  224. package/dist/effects/SelectiveBloom.d.ts +0 -20
  225. package/dist/effects/SelectiveBloom.js +0 -94
  226. package/dist/effects/SelectiveBloom.js.map +0 -1
  227. package/dist/effects/Sepia.cjs +0 -7
  228. package/dist/effects/Sepia.cjs.map +0 -1
  229. package/dist/effects/Sepia.d.ts +0 -9
  230. package/dist/effects/Sepia.js +0 -7
  231. package/dist/effects/Sepia.js.map +0 -1
  232. package/dist/effects/ShockWave.cjs +0 -7
  233. package/dist/effects/ShockWave.cjs.map +0 -1
  234. package/dist/effects/ShockWave.d.ts +0 -6
  235. package/dist/effects/ShockWave.js +0 -7
  236. package/dist/effects/ShockWave.js.map +0 -1
  237. package/dist/effects/Texture.cjs +0 -21
  238. package/dist/effects/Texture.cjs.map +0 -1
  239. package/dist/effects/Texture.d.ts +0 -11
  240. package/dist/effects/Texture.js +0 -21
  241. package/dist/effects/Texture.js.map +0 -1
  242. package/dist/effects/TiltShift.cjs +0 -7
  243. package/dist/effects/TiltShift.cjs.map +0 -1
  244. package/dist/effects/TiltShift.d.ts +0 -17
  245. package/dist/effects/TiltShift.js +0 -7
  246. package/dist/effects/TiltShift.js.map +0 -1
  247. package/dist/effects/TiltShift2.cjs +0 -98
  248. package/dist/effects/TiltShift2.cjs.map +0 -1
  249. package/dist/effects/TiltShift2.d.ts +0 -30
  250. package/dist/effects/TiltShift2.js.map +0 -1
  251. package/dist/effects/ToneMapping.cjs +0 -7
  252. package/dist/effects/ToneMapping.cjs.map +0 -1
  253. package/dist/effects/ToneMapping.d.ts +0 -19
  254. package/dist/effects/ToneMapping.js +0 -7
  255. package/dist/effects/ToneMapping.js.map +0 -1
  256. package/dist/effects/Vignette.cjs +0 -7
  257. package/dist/effects/Vignette.cjs.map +0 -1
  258. package/dist/effects/Vignette.d.ts +0 -12
  259. package/dist/effects/Vignette.js +0 -7
  260. package/dist/effects/Vignette.js.map +0 -1
  261. package/dist/effects/Water.cjs +0 -38
  262. package/dist/effects/Water.cjs.map +0 -1
  263. package/dist/effects/Water.d.ts +0 -15
  264. package/dist/effects/Water.js.map +0 -1
  265. package/dist/index.cjs +0 -89
  266. package/dist/index.cjs.map +0 -1
  267. package/dist/util.cjs +0 -69
  268. package/dist/util.cjs.map +0 -1
  269. package/dist/util.d.ts +0 -13
  270. package/dist/util.js +0 -52
  271. package/dist/util.js.map +0 -1
@@ -0,0 +1,117 @@
1
+ import { OutlineEffect } from 'postprocessing'
2
+ import { Ref, RefObject, forwardRef, useMemo, useEffect, useContext, useRef } from 'react'
3
+ import { Object3D } from 'three'
4
+ import { useThree } from '@react-three/fiber'
5
+ import { EffectComposerContext } from '../EffectComposer.tsx'
6
+ import { selectionContext } from '../Selection.tsx'
7
+ import { resolveRef } from '../util.tsx'
8
+
9
+ type ObjectRef = RefObject<Object3D>
10
+
11
+ export type OutlineProps = ConstructorParameters<typeof OutlineEffect>[2] &
12
+ Partial<{
13
+ selection: Object3D | Object3D[] | ObjectRef | ObjectRef[]
14
+ selectionLayer: number
15
+ }>
16
+
17
+ export const Outline = /* @__PURE__ */ forwardRef(function Outline(
18
+ {
19
+ selection = [],
20
+ selectionLayer = 10,
21
+ blendFunction,
22
+ patternTexture,
23
+ edgeStrength,
24
+ pulseSpeed,
25
+ visibleEdgeColor,
26
+ hiddenEdgeColor,
27
+ width,
28
+ height,
29
+ kernelSize,
30
+ blur,
31
+ xRay,
32
+ ...props
33
+ }: OutlineProps,
34
+ forwardRef: Ref<OutlineEffect>
35
+ ) {
36
+ const invalidate = useThree((state) => state.invalidate)
37
+ const { scene, camera } = useContext(EffectComposerContext)
38
+
39
+ const effect = useMemo(
40
+ () =>
41
+ new OutlineEffect(scene, camera, {
42
+ blendFunction,
43
+ patternTexture,
44
+ edgeStrength,
45
+ pulseSpeed,
46
+ visibleEdgeColor,
47
+ hiddenEdgeColor,
48
+ width,
49
+ height,
50
+ kernelSize,
51
+ blur,
52
+ xRay,
53
+ ...props,
54
+ }),
55
+ // NOTE: `props` is an unstable reference, so we can't memoize it
56
+ // eslint-disable-next-line react-hooks/exhaustive-deps
57
+ [
58
+ blendFunction,
59
+ blur,
60
+ camera,
61
+ edgeStrength,
62
+ height,
63
+ hiddenEdgeColor,
64
+ kernelSize,
65
+ patternTexture,
66
+ pulseSpeed,
67
+ scene,
68
+ visibleEdgeColor,
69
+ width,
70
+ xRay,
71
+ ]
72
+ )
73
+
74
+ const api = useContext(selectionContext)
75
+
76
+ useEffect(() => {
77
+ // Do not allow array selection if declarative selection is active
78
+ // TODO: array selection should probably be deprecated altogether
79
+ if (!api && selection) {
80
+ effect.selection.set(
81
+ Array.isArray(selection) ? (selection as Object3D[]).map(resolveRef) : [resolveRef(selection) as Object3D]
82
+ )
83
+ invalidate()
84
+ return () => {
85
+ effect.selection.clear()
86
+ invalidate()
87
+ }
88
+ }
89
+ }, [effect, selection, api, invalidate])
90
+
91
+ useEffect(() => {
92
+ effect.selectionLayer = selectionLayer
93
+ invalidate()
94
+ }, [effect, invalidate, selectionLayer])
95
+
96
+ const ref = useRef<OutlineEffect>(undefined)
97
+ useEffect(() => {
98
+ if (api && api.enabled) {
99
+ if (api.selected?.length) {
100
+ effect.selection.set(api.selected)
101
+ invalidate()
102
+ return () => {
103
+ effect.selection.clear()
104
+ invalidate()
105
+ }
106
+ }
107
+ }
108
+ }, [api, effect.selection, invalidate])
109
+
110
+ useEffect(() => {
111
+ return () => {
112
+ effect.dispose()
113
+ }
114
+ }, [effect])
115
+
116
+ return <primitive ref={forwardRef} object={effect} />
117
+ })
@@ -0,0 +1,15 @@
1
+ import { forwardRef, useMemo, Ref } from 'react'
2
+ import { PixelationEffect } from 'postprocessing'
3
+
4
+ export type PixelationProps = {
5
+ granularity?: number
6
+ }
7
+
8
+ export const Pixelation = /* @__PURE__ */ forwardRef<PixelationEffect, PixelationProps>(function Pixelation(
9
+ { granularity = 5 }: PixelationProps,
10
+ ref: Ref<PixelationEffect>
11
+ ) {
12
+ /** Because GlitchEffect granularity is not an object but a number, we have to define a custom prop "granularity" */
13
+ const effect = useMemo(() => new PixelationEffect(granularity), [granularity])
14
+ return <primitive ref={ref} object={effect} dispose={null} />
15
+ })
@@ -1,156 +1,150 @@
1
- import { Uniform } from "three";
2
- import { Effect } from "postprocessing";
3
- import { wrapEffect } from "../util.js";
4
- const RampShader = {
5
- fragmentShader: (
6
- /* glsl */
7
- `
8
- uniform int rampType;
9
-
10
- uniform vec2 rampStart;
11
- uniform vec2 rampEnd;
12
-
13
- uniform vec4 startColor;
14
- uniform vec4 endColor;
15
-
16
- uniform float rampBias;
17
- uniform float rampGain;
18
-
19
- uniform bool rampMask;
20
- uniform bool rampInvert;
21
-
22
- float getBias(float time, float bias) {
23
- return time / (((1.0 / bias) - 2.0) * (1.0 - time) + 1.0);
24
- }
25
-
26
- float getGain(float time, float gain) {
27
- if (time < 0.5)
28
- return getBias(time * 2.0, gain) / 2.0;
29
- else
30
- return getBias(time * 2.0 - 1.0, 1.0 - gain) / 2.0 + 0.5;
31
- }
32
-
33
- void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
34
- vec2 centerPixel = uv * resolution;
35
- vec2 startPixel = rampStart * resolution;
36
- vec2 endPixel = rampEnd * resolution;
37
-
38
- float rampAlpha;
39
-
40
- if (rampType == 1) {
41
- vec2 fuv = centerPixel / resolution.y;
42
- vec2 suv = startPixel / resolution.y;
43
- vec2 euv = endPixel / resolution.y;
44
-
45
- float radius = length(suv - euv);
46
- float falloff = length(fuv - suv);
47
- rampAlpha = smoothstep(0.0, radius, falloff);
48
- } else {
49
- float radius = length(startPixel - endPixel);
50
- vec2 direction = normalize(vec2(endPixel.x - startPixel.x, -(startPixel.y - endPixel.y)));
51
-
52
- float fade = dot(centerPixel - startPixel, direction);
53
- if (rampType == 2) fade = abs(fade);
54
-
55
- rampAlpha = smoothstep(0.0, 1.0, fade / radius);
56
- }
57
-
58
- rampAlpha = abs((rampInvert ? 1.0 : 0.0) - getBias(rampAlpha, rampBias) * getGain(rampAlpha, rampGain));
59
-
60
- if (rampMask) {
61
- vec4 inputBuff = texture2D(inputBuffer, uv);
62
- outputColor = mix(inputBuff, inputColor, rampAlpha);
63
- } else {
64
- outputColor = mix(startColor, endColor, rampAlpha);
65
- }
66
- }
67
- `
68
- )
69
- };
70
- var RampType = /* @__PURE__ */ ((RampType2) => {
71
- RampType2[RampType2["Linear"] = 0] = "Linear";
72
- RampType2[RampType2["Radial"] = 1] = "Radial";
73
- RampType2[RampType2["MirroredLinear"] = 2] = "MirroredLinear";
74
- return RampType2;
75
- })(RampType || {});
76
- class RampEffect extends Effect {
77
- constructor({
78
- /**
79
- * Type of ramp gradient.
80
- */
81
- rampType = 0,
82
- /**
83
- * Starting point of the ramp gradient in normalized coordinates.
84
- *
85
- * Ranges from `[0 - 1]` as `[x, y]`. Default is `[0.5, 0.5]`.
86
- */
87
- rampStart = [0.5, 0.5],
88
- /**
89
- * Ending point of the ramp gradient in normalized coordinates.
90
- *
91
- * Ranges from `[0 - 1]` as `[x, y]`. Default is `[1, 1]`
92
- */
93
- rampEnd = [1, 1],
94
- /**
95
- * Color at the starting point of the gradient.
96
- *
97
- * Default is black: `[0, 0, 0, 1]`
98
- */
99
- startColor = [0, 0, 0, 1],
100
- /**
101
- * Color at the ending point of the gradient.
102
- *
103
- * Default is white: `[1, 1, 1, 1]`
104
- */
105
- endColor = [1, 1, 1, 1],
106
- /**
107
- * Bias for the interpolation curve when both bias and gain are 0.5.
108
- *
109
- * Ranges from `[0 - 1]`. Default is `0.5`.
110
- */
111
- rampBias = 0.5,
112
- /**
113
- * Gain for the interpolation curve when both bias and gain are 0.5.
114
- *
115
- * Ranges from `[0 - 1]`. Default is `0.5`.
116
- */
117
- rampGain = 0.5,
118
- /**
119
- * When enabled, the ramp gradient is used as an effect mask, and colors are ignored.
120
- *
121
- * Default is `false`.
122
- */
123
- rampMask = false,
124
- /**
125
- * Controls whether the ramp gradient is inverted.
126
- *
127
- * When disabled, rampStart is transparent and rampEnd is opaque.
128
- *
129
- * Default is `false`.
130
- */
131
- rampInvert = false,
132
- ...params
133
- } = {}) {
134
- super("RampEffect", RampShader.fragmentShader, {
135
- ...params,
136
- uniforms: /* @__PURE__ */ new Map([
137
- ["rampType", new Uniform(rampType)],
138
- ["rampStart", new Uniform(rampStart)],
139
- ["rampEnd", new Uniform(rampEnd)],
140
- ["startColor", new Uniform(startColor)],
141
- ["endColor", new Uniform(endColor)],
142
- ["rampBias", new Uniform(rampBias)],
143
- ["rampGain", new Uniform(rampGain)],
144
- ["rampMask", new Uniform(rampMask)],
145
- ["rampInvert", new Uniform(rampInvert)]
146
- ])
147
- });
148
- }
149
- }
150
- const Ramp = /* @__PURE__ */ wrapEffect(RampEffect);
151
- export {
152
- Ramp,
153
- RampEffect,
154
- RampType
155
- };
156
- //# sourceMappingURL=Ramp.js.map
1
+ import { Uniform } from 'three'
2
+ import { Effect } from 'postprocessing'
3
+ import { wrapEffect } from '../util.tsx'
4
+
5
+ const RampShader = {
6
+ fragmentShader: /* glsl */ `
7
+ uniform int rampType;
8
+
9
+ uniform vec2 rampStart;
10
+ uniform vec2 rampEnd;
11
+
12
+ uniform vec4 startColor;
13
+ uniform vec4 endColor;
14
+
15
+ uniform float rampBias;
16
+ uniform float rampGain;
17
+
18
+ uniform bool rampMask;
19
+ uniform bool rampInvert;
20
+
21
+ float getBias(float time, float bias) {
22
+ return time / (((1.0 / bias) - 2.0) * (1.0 - time) + 1.0);
23
+ }
24
+
25
+ float getGain(float time, float gain) {
26
+ if (time < 0.5)
27
+ return getBias(time * 2.0, gain) / 2.0;
28
+ else
29
+ return getBias(time * 2.0 - 1.0, 1.0 - gain) / 2.0 + 0.5;
30
+ }
31
+
32
+ void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
33
+ vec2 centerPixel = uv * resolution;
34
+ vec2 startPixel = rampStart * resolution;
35
+ vec2 endPixel = rampEnd * resolution;
36
+
37
+ float rampAlpha;
38
+
39
+ if (rampType == 1) {
40
+ vec2 fuv = centerPixel / resolution.y;
41
+ vec2 suv = startPixel / resolution.y;
42
+ vec2 euv = endPixel / resolution.y;
43
+
44
+ float radius = length(suv - euv);
45
+ float falloff = length(fuv - suv);
46
+ rampAlpha = smoothstep(0.0, radius, falloff);
47
+ } else {
48
+ float radius = length(startPixel - endPixel);
49
+ vec2 direction = normalize(vec2(endPixel.x - startPixel.x, -(startPixel.y - endPixel.y)));
50
+
51
+ float fade = dot(centerPixel - startPixel, direction);
52
+ if (rampType == 2) fade = abs(fade);
53
+
54
+ rampAlpha = smoothstep(0.0, 1.0, fade / radius);
55
+ }
56
+
57
+ rampAlpha = abs((rampInvert ? 1.0 : 0.0) - getBias(rampAlpha, rampBias) * getGain(rampAlpha, rampGain));
58
+
59
+ if (rampMask) {
60
+ vec4 inputBuff = texture2D(inputBuffer, uv);
61
+ outputColor = mix(inputBuff, inputColor, rampAlpha);
62
+ } else {
63
+ outputColor = mix(startColor, endColor, rampAlpha);
64
+ }
65
+ }
66
+ `,
67
+ }
68
+
69
+ export enum RampType {
70
+ Linear,
71
+ Radial,
72
+ MirroredLinear,
73
+ }
74
+
75
+ export class RampEffect extends Effect {
76
+ constructor({
77
+ /**
78
+ * Type of ramp gradient.
79
+ */
80
+ rampType = RampType.Linear,
81
+ /**
82
+ * Starting point of the ramp gradient in normalized coordinates.
83
+ *
84
+ * Ranges from `[0 - 1]` as `[x, y]`. Default is `[0.5, 0.5]`.
85
+ */
86
+ rampStart = [0.5, 0.5],
87
+ /**
88
+ * Ending point of the ramp gradient in normalized coordinates.
89
+ *
90
+ * Ranges from `[0 - 1]` as `[x, y]`. Default is `[1, 1]`
91
+ */
92
+ rampEnd = [1, 1],
93
+ /**
94
+ * Color at the starting point of the gradient.
95
+ *
96
+ * Default is black: `[0, 0, 0, 1]`
97
+ */
98
+ startColor = [0, 0, 0, 1],
99
+ /**
100
+ * Color at the ending point of the gradient.
101
+ *
102
+ * Default is white: `[1, 1, 1, 1]`
103
+ */
104
+ endColor = [1, 1, 1, 1],
105
+ /**
106
+ * Bias for the interpolation curve when both bias and gain are 0.5.
107
+ *
108
+ * Ranges from `[0 - 1]`. Default is `0.5`.
109
+ */
110
+ rampBias = 0.5,
111
+ /**
112
+ * Gain for the interpolation curve when both bias and gain are 0.5.
113
+ *
114
+ * Ranges from `[0 - 1]`. Default is `0.5`.
115
+ */
116
+ rampGain = 0.5,
117
+ /**
118
+ * When enabled, the ramp gradient is used as an effect mask, and colors are ignored.
119
+ *
120
+ * Default is `false`.
121
+ */
122
+ rampMask = false,
123
+ /**
124
+ * Controls whether the ramp gradient is inverted.
125
+ *
126
+ * When disabled, rampStart is transparent and rampEnd is opaque.
127
+ *
128
+ * Default is `false`.
129
+ */
130
+ rampInvert = false,
131
+ ...params
132
+ } = {}) {
133
+ super('RampEffect', RampShader.fragmentShader, {
134
+ ...params,
135
+ uniforms: new Map<string, Uniform>([
136
+ ['rampType', new Uniform(rampType)],
137
+ ['rampStart', new Uniform(rampStart)],
138
+ ['rampEnd', new Uniform(rampEnd)],
139
+ ['startColor', new Uniform(startColor)],
140
+ ['endColor', new Uniform(endColor)],
141
+ ['rampBias', new Uniform(rampBias)],
142
+ ['rampGain', new Uniform(rampGain)],
143
+ ['rampMask', new Uniform(rampMask)],
144
+ ['rampInvert', new Uniform(rampInvert)],
145
+ ]),
146
+ })
147
+ }
148
+ }
149
+
150
+ export const Ramp = /* @__PURE__ */ wrapEffect(RampEffect)
@@ -0,0 +1,4 @@
1
+ import { SMAAEffect } from 'postprocessing'
2
+ import { wrapEffect } from '../util.tsx'
3
+
4
+ export const SMAA = /* @__PURE__ */ wrapEffect(SMAAEffect)
@@ -0,0 +1,41 @@
1
+ import { Ref, forwardRef, useContext, useMemo } from 'react'
2
+ import { SSAOEffect, BlendFunction } from 'postprocessing'
3
+ import { EffectComposerContext } from '../EffectComposer.tsx'
4
+
5
+ // first two args are camera and texture
6
+ type SSAOProps = ConstructorParameters<typeof SSAOEffect>[2]
7
+
8
+ export const SSAO = /* @__PURE__ */ forwardRef<SSAOEffect, SSAOProps>(function SSAO(
9
+ props: SSAOProps,
10
+ ref: Ref<SSAOEffect>
11
+ ) {
12
+ const { camera, normalPass, downSamplingPass, resolutionScale } = useContext(EffectComposerContext)
13
+ const effect = useMemo<SSAOEffect | {}>(() => {
14
+ if (normalPass === null && downSamplingPass === null) {
15
+ console.error('Please enable the NormalPass in the EffectComposer in order to use SSAO.')
16
+ return {}
17
+ }
18
+ return new SSAOEffect(camera, normalPass && !downSamplingPass ? (normalPass as any).texture : null, {
19
+ blendFunction: BlendFunction.MULTIPLY,
20
+ samples: 30,
21
+ rings: 4,
22
+ distanceThreshold: 1.0,
23
+ distanceFalloff: 0.0,
24
+ rangeThreshold: 0.5,
25
+ rangeFalloff: 0.1,
26
+ luminanceInfluence: 0.9,
27
+ radius: 20,
28
+ bias: 0.5,
29
+ intensity: 1.0,
30
+ color: undefined,
31
+ // @ts-ignore
32
+ normalDepthBuffer: downSamplingPass ? downSamplingPass.texture : null,
33
+ resolutionScale: resolutionScale ?? 1,
34
+ depthAwareUpsampling: true,
35
+ ...props,
36
+ })
37
+ // NOTE: `props` is an unstable reference, so we can't memoize it
38
+ // eslint-disable-next-line react-hooks/exhaustive-deps
39
+ }, [camera, downSamplingPass, normalPass, resolutionScale])
40
+ return <primitive ref={ref} object={effect} dispose={null} />
41
+ })
@@ -0,0 +1,7 @@
1
+ import { ScanlineEffect, BlendFunction } from 'postprocessing'
2
+ import { wrapEffect } from '../util.tsx'
3
+
4
+ export const Scanline = /* @__PURE__ */ wrapEffect(ScanlineEffect, {
5
+ blendFunction: BlendFunction.OVERLAY,
6
+ density: 1.25,
7
+ })
@@ -0,0 +1,126 @@
1
+ import { SelectiveBloomEffect, BlendFunction } from 'postprocessing'
2
+ import type { BloomEffectOptions } from 'postprocessing'
3
+ import React, { Ref, RefObject, forwardRef, useMemo, useEffect, useContext, useRef } from 'react'
4
+ import { Object3D } from 'three'
5
+ import { useThree } from '@react-three/fiber'
6
+ import { EffectComposerContext } from '../EffectComposer.tsx'
7
+ import { selectionContext } from '../Selection.tsx'
8
+ import { resolveRef } from '../util.tsx'
9
+
10
+ type ObjectRef = RefObject<Object3D>
11
+
12
+ export type SelectiveBloomProps = BloomEffectOptions &
13
+ Partial<{
14
+ lights: Object3D[] | ObjectRef[]
15
+ selection: Object3D | Object3D[] | ObjectRef | ObjectRef[]
16
+ selectionLayer: number
17
+ inverted: boolean
18
+ ignoreBackground: boolean
19
+ }>
20
+
21
+ const addLight = (light: Object3D, effect: SelectiveBloomEffect) => light.layers.enable(effect.selection.layer)
22
+ const removeLight = (light: Object3D, effect: SelectiveBloomEffect) => light.layers.disable(effect.selection.layer)
23
+
24
+ export const SelectiveBloom = /* @__PURE__ */ forwardRef(function SelectiveBloom(
25
+ {
26
+ selection = [],
27
+ selectionLayer = 10,
28
+ lights = [],
29
+ inverted = false,
30
+ ignoreBackground = false,
31
+ luminanceThreshold,
32
+ luminanceSmoothing,
33
+ intensity,
34
+ width,
35
+ height,
36
+ kernelSize,
37
+ mipmapBlur,
38
+
39
+ ...props
40
+ }: SelectiveBloomProps,
41
+ forwardRef: Ref<SelectiveBloomEffect>
42
+ ) {
43
+ if (lights.length === 0) {
44
+ console.warn('SelectiveBloom requires lights to work.')
45
+ }
46
+
47
+ const invalidate = useThree((state) => state.invalidate)
48
+ const { scene, camera } = useContext(EffectComposerContext)
49
+ const effect = useMemo(() => {
50
+ const effect = new SelectiveBloomEffect(scene, camera, {
51
+ blendFunction: BlendFunction.ADD,
52
+ luminanceThreshold,
53
+ luminanceSmoothing,
54
+ intensity,
55
+ width,
56
+ height,
57
+ kernelSize,
58
+ mipmapBlur,
59
+ ...props,
60
+ })
61
+ effect.inverted = inverted
62
+ effect.ignoreBackground = ignoreBackground
63
+ return effect
64
+ }, [
65
+ scene,
66
+ camera,
67
+ luminanceThreshold,
68
+ luminanceSmoothing,
69
+ intensity,
70
+ width,
71
+ height,
72
+ kernelSize,
73
+ mipmapBlur,
74
+ inverted,
75
+ ignoreBackground,
76
+ props,
77
+ ])
78
+
79
+ const api = useContext(selectionContext)
80
+
81
+ useEffect(() => {
82
+ // Do not allow array selection if declarative selection is active
83
+ // TODO: array selection should probably be deprecated altogether
84
+ if (!api && selection) {
85
+ effect.selection.set(
86
+ Array.isArray(selection) ? (selection as Object3D[]).map(resolveRef) : [resolveRef(selection) as Object3D]
87
+ )
88
+ invalidate()
89
+ return () => {
90
+ effect.selection.clear()
91
+ invalidate()
92
+ }
93
+ }
94
+ }, [effect, selection, api, invalidate])
95
+
96
+ useEffect(() => {
97
+ effect.selection.layer = selectionLayer
98
+ invalidate()
99
+ }, [effect, invalidate, selectionLayer])
100
+
101
+ useEffect(() => {
102
+ if (lights && lights.length > 0) {
103
+ lights.forEach((light) => addLight(resolveRef(light), effect))
104
+ invalidate()
105
+ return () => {
106
+ lights.forEach((light) => removeLight(resolveRef(light), effect))
107
+ invalidate()
108
+ }
109
+ }
110
+ }, [effect, invalidate, lights, selectionLayer])
111
+
112
+ useEffect(() => {
113
+ if (api && api.enabled) {
114
+ if (api.selected?.length) {
115
+ effect.selection.set(api.selected)
116
+ invalidate()
117
+ return () => {
118
+ effect.selection.clear()
119
+ invalidate()
120
+ }
121
+ }
122
+ }
123
+ }, [api, effect.selection, invalidate])
124
+
125
+ return <primitive ref={forwardRef} object={effect} dispose={null} />
126
+ })
@@ -0,0 +1,4 @@
1
+ import { SepiaEffect } from 'postprocessing'
2
+ import { wrapEffect } from '../util.tsx'
3
+
4
+ export const Sepia = /* @__PURE__ */ wrapEffect(SepiaEffect)
@@ -0,0 +1,4 @@
1
+ import { ShockWaveEffect } from 'postprocessing'
2
+ import { wrapEffect } from '../util.tsx'
3
+
4
+ export const ShockWave = /* @__PURE__ */ wrapEffect(ShockWaveEffect)
@@ -0,0 +1,23 @@
1
+ import { TextureEffect } from 'postprocessing'
2
+ import { Ref, forwardRef, useMemo, useLayoutEffect } from 'react'
3
+ import { useLoader } from '@react-three/fiber'
4
+ import { TextureLoader, SRGBColorSpace, RepeatWrapping } from 'three'
5
+
6
+ type TextureProps = ConstructorParameters<typeof TextureEffect>[0] & {
7
+ textureSrc: string
8
+ /** opacity of provided texture */
9
+ opacity?: number
10
+ }
11
+
12
+ export const Texture = /* @__PURE__ */ forwardRef<TextureEffect, TextureProps>(function Texture(
13
+ { textureSrc, texture, opacity = 1, ...props }: TextureProps,
14
+ ref: Ref<TextureEffect>
15
+ ) {
16
+ const t = useLoader(TextureLoader, textureSrc)
17
+ useLayoutEffect(() => {
18
+ t.colorSpace = SRGBColorSpace
19
+ t.wrapS = t.wrapT = RepeatWrapping
20
+ }, [t])
21
+ const effect = useMemo(() => new TextureEffect({ ...props, texture: t || texture }), [props, t, texture])
22
+ return <primitive ref={ref} object={effect} blendMode-opacity-value={opacity} dispose={null} />
23
+ })
@@ -0,0 +1,4 @@
1
+ import { TiltShiftEffect, BlendFunction } from 'postprocessing'
2
+ import { wrapEffect } from '../util.tsx'
3
+
4
+ export const TiltShift = /* @__PURE__ */ wrapEffect(TiltShiftEffect, { blendFunction: BlendFunction.ADD })