@react-three/postprocessing 3.0.2 → 3.0.4

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 (82) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +81 -81
  3. package/dist/EffectComposer.d.ts +27 -0
  4. package/dist/Selection.d.ts +17 -0
  5. package/dist/effects/ASCII.d.ts +18 -0
  6. package/dist/effects/Autofocus.d.ts +22 -0
  7. package/dist/effects/Bloom.d.ts +5 -0
  8. package/dist/effects/BrightnessContrast.d.ts +5 -0
  9. package/dist/effects/ChromaticAberration.d.ts +8 -0
  10. package/dist/effects/ColorAverage.d.ts +8 -0
  11. package/dist/effects/ColorDepth.d.ts +5 -0
  12. package/dist/effects/Depth.d.ts +5 -0
  13. package/dist/effects/DepthOfField.d.ts +25 -0
  14. package/dist/effects/DotScreen.d.ts +5 -0
  15. package/dist/effects/FXAA.d.ts +5 -0
  16. package/dist/effects/Glitch.d.ts +30 -0
  17. package/dist/effects/GodRays.d.ts +21 -0
  18. package/dist/effects/Grid.d.ts +12 -0
  19. package/dist/effects/HueSaturation.d.ts +5 -0
  20. package/dist/effects/LUT.d.ts +9 -0
  21. package/dist/effects/LensFlare.d.ts +54 -0
  22. package/dist/effects/N8AO.d.ts +17 -0
  23. package/dist/effects/Noise.d.ts +5 -0
  24. package/dist/effects/Outline.d.ts +30 -0
  25. package/dist/effects/Pixelation.d.ts +6 -0
  26. package/dist/effects/Ramp.d.ts +78 -0
  27. package/dist/effects/SMAA.d.ts +5 -0
  28. package/dist/effects/SSAO.d.ts +30 -0
  29. package/dist/effects/ScanlineEffect.d.ts +5 -0
  30. package/dist/effects/SelectiveBloom.d.ts +20 -0
  31. package/dist/effects/Sepia.d.ts +5 -0
  32. package/dist/effects/ShockWave.d.ts +5 -0
  33. package/dist/effects/Texture.d.ts +11 -0
  34. package/dist/effects/TiltShift.d.ts +5 -0
  35. package/dist/effects/TiltShift2.d.ts +22 -0
  36. package/dist/effects/ToneMapping.d.ts +8 -0
  37. package/dist/effects/Vignette.d.ts +5 -0
  38. package/dist/effects/Water.d.ts +12 -0
  39. package/dist/index.d.ts +37 -0
  40. package/dist/index.js +555 -0
  41. package/dist/index.js.map +1 -0
  42. package/dist/util.d.ts +17 -0
  43. package/package.json +67 -68
  44. package/src/EffectComposer.test.tsx +126 -126
  45. package/src/EffectComposer.tsx +200 -200
  46. package/src/Selection.tsx +46 -46
  47. package/src/effects/ASCII.tsx +135 -135
  48. package/src/effects/Autofocus.tsx +153 -153
  49. package/src/effects/Bloom.tsx +6 -6
  50. package/src/effects/BrightnessContrast.tsx +4 -4
  51. package/src/effects/ChromaticAberration.tsx +5 -5
  52. package/src/effects/ColorAverage.tsx +15 -15
  53. package/src/effects/ColorDepth.tsx +4 -4
  54. package/src/effects/Depth.tsx +4 -4
  55. package/src/effects/DepthOfField.tsx +89 -89
  56. package/src/effects/DotScreen.tsx +4 -4
  57. package/src/effects/FXAA.tsx +4 -4
  58. package/src/effects/Glitch.tsx +40 -40
  59. package/src/effects/GodRays.tsx +16 -16
  60. package/src/effects/Grid.tsx +21 -21
  61. package/src/effects/HueSaturation.tsx +4 -4
  62. package/src/effects/LUT.tsx +26 -26
  63. package/src/effects/LensFlare.tsx +611 -611
  64. package/src/effects/N8AO.tsx +81 -81
  65. package/src/effects/Noise.tsx +4 -4
  66. package/src/effects/Outline.tsx +117 -117
  67. package/src/effects/Pixelation.tsx +15 -15
  68. package/src/effects/Ramp.tsx +150 -150
  69. package/src/effects/SMAA.tsx +4 -4
  70. package/src/effects/SSAO.tsx +41 -41
  71. package/src/effects/ScanlineEffect.tsx +7 -7
  72. package/src/effects/SelectiveBloom.tsx +126 -126
  73. package/src/effects/Sepia.tsx +4 -4
  74. package/src/effects/ShockWave.tsx +4 -4
  75. package/src/effects/Texture.tsx +23 -23
  76. package/src/effects/TiltShift.tsx +4 -4
  77. package/src/effects/TiltShift2.tsx +90 -90
  78. package/src/effects/ToneMapping.tsx +6 -6
  79. package/src/effects/Vignette.tsx +4 -4
  80. package/src/effects/Water.tsx +35 -35
  81. package/src/index.ts +40 -40
  82. package/src/util.tsx +55 -55
package/dist/util.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import React, { RefObject } from 'react';
2
+ import { Vector2 } from 'three';
3
+ import * as THREE from 'three';
4
+ import { type ThreeElement } from '@react-three/fiber';
5
+ import type { Effect, Pass, BlendFunction } from 'postprocessing';
6
+ export declare const resolveRef: <T>(ref: T | React.RefObject<T>) => T;
7
+ export type EffectConstructor = new (...args: any[]) => Effect | Pass;
8
+ export type EffectProps<T extends EffectConstructor> = ThreeElement<T> & ConstructorParameters<T>[0] & {
9
+ blendFunction?: BlendFunction;
10
+ opacity?: number;
11
+ };
12
+ export declare const wrapEffect: <T extends EffectConstructor>(effect: T, defaults?: EffectProps<T> | undefined) => ({ blendFunction, opacity, ...props }: {
13
+ [x: string]: any;
14
+ blendFunction?: any;
15
+ opacity?: any;
16
+ }) => import("react/jsx-runtime").JSX.Element;
17
+ export declare const useVector2: (props: Record<string, unknown>, key: string) => THREE.Vector2;
package/package.json CHANGED
@@ -1,68 +1,67 @@
1
- {
2
- "name": "@react-three/postprocessing",
3
- "version": "3.0.2",
4
- "description": "postprocessing wrapper for React and @react-three/fiber",
5
- "keywords": [
6
- "postprocessing",
7
- "react",
8
- "three",
9
- "@react-three/fiber",
10
- "webgl",
11
- "3d"
12
- ],
13
- "license": "MIT",
14
- "files": [
15
- "dist",
16
- "src"
17
- ],
18
- "type": "module",
19
- "main": "./dist/index.js",
20
- "exports": "./dist/index.js",
21
- "sideEffects": false,
22
- "repository": {
23
- "type": "git",
24
- "url": "git+https://github.com/pmndrs/react-postprocessing.git"
25
- },
26
- "scripts": {
27
- "build": "vite build",
28
- "eslint": "eslint . --fix --ext=js,ts,jsx,tsx",
29
- "eslint:ci": "eslint . --ext=js,ts,jsx,tsx",
30
- "test": "vitest run",
31
- "typecheck": "tsc",
32
- "release": "semantic-release"
33
- },
34
- "dependencies": {
35
- "maath": "^0.6.0",
36
- "n8ao": "^1.9.4",
37
- "postprocessing": "^6.36.6"
38
- },
39
- "devDependencies": {
40
- "@react-three/fiber": "^9.0.1",
41
- "@types/node": "^22.10.7",
42
- "@types/react": "^19.0.2",
43
- "@types/react-dom": "^19.0.2",
44
- "@types/three": "^0.156.0",
45
- "@typescript-eslint/eslint-plugin": "^5.59.1",
46
- "@typescript-eslint/parser": "^5.59.1",
47
- "eslint": "^8.39.0",
48
- "eslint-config-prettier": "^8.8.0",
49
- "eslint-import-resolver-alias": "^1.1.2",
50
- "eslint-plugin-import": "^2.27.5",
51
- "eslint-plugin-prettier": "^4.2.1",
52
- "eslint-plugin-react": "^7.32.2",
53
- "eslint-plugin-react-hooks": "^4.6.0",
54
- "prettier": "^2.8.8",
55
- "react": "^19.0.0",
56
- "react-dom": "^19.0.0",
57
- "semantic-release": "^21.0.2",
58
- "three": "^0.156.0",
59
- "typescript": "^5.0.4",
60
- "vite": "^4.3.5",
61
- "vitest": "^2.1.8"
62
- },
63
- "peerDependencies": {
64
- "@react-three/fiber": "^9.0.0",
65
- "react": "^19.0",
66
- "three": ">= 0.156.0"
67
- }
68
- }
1
+ {
2
+ "name": "@react-three/postprocessing",
3
+ "version": "3.0.4",
4
+ "description": "postprocessing wrapper for React and @react-three/fiber",
5
+ "keywords": [
6
+ "postprocessing",
7
+ "react",
8
+ "three",
9
+ "@react-three/fiber",
10
+ "webgl",
11
+ "3d"
12
+ ],
13
+ "license": "MIT",
14
+ "files": [
15
+ "dist",
16
+ "src"
17
+ ],
18
+ "type": "module",
19
+ "main": "./dist/index.js",
20
+ "exports": "./dist/index.js",
21
+ "sideEffects": false,
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/pmndrs/react-postprocessing.git"
25
+ },
26
+ "scripts": {
27
+ "build": "rimraf dist && vite build && tsc",
28
+ "eslint": "eslint . --fix --ext=js,ts,jsx,tsx",
29
+ "eslint:ci": "eslint . --ext=js,ts,jsx,tsx",
30
+ "test": "vitest run",
31
+ "typecheck": "tsc --noEmit"
32
+ },
33
+ "dependencies": {
34
+ "maath": "^0.6.0",
35
+ "n8ao": "^1.9.4",
36
+ "postprocessing": "^6.36.6"
37
+ },
38
+ "devDependencies": {
39
+ "@react-three/fiber": "^9.0.4",
40
+ "@types/node": "^22.10.7",
41
+ "@types/react": "^19.0.2",
42
+ "@types/react-dom": "^19.0.2",
43
+ "@types/three": "^0.156.0",
44
+ "@typescript-eslint/eslint-plugin": "^5.59.1",
45
+ "@typescript-eslint/parser": "^5.59.1",
46
+ "eslint": "^8.39.0",
47
+ "eslint-config-prettier": "^8.8.0",
48
+ "eslint-import-resolver-alias": "^1.1.2",
49
+ "eslint-plugin-import": "^2.27.5",
50
+ "eslint-plugin-prettier": "^4.2.1",
51
+ "eslint-plugin-react": "^7.32.2",
52
+ "eslint-plugin-react-hooks": "^4.6.0",
53
+ "prettier": "^2.8.8",
54
+ "react": "^19.0.0",
55
+ "react-dom": "^19.0.0",
56
+ "rimraf": "^6.0.1",
57
+ "three": "^0.156.0",
58
+ "typescript": "^5.0.4",
59
+ "vite": "^4.3.5",
60
+ "vitest": "^2.1.8"
61
+ },
62
+ "peerDependencies": {
63
+ "@react-three/fiber": "^9.0.0",
64
+ "react": "^19.0",
65
+ "three": ">= 0.156.0"
66
+ }
67
+ }
@@ -1,126 +1,126 @@
1
- import * as React from 'react'
2
- import * as THREE from 'three'
3
- import { vi, describe, it, expect } from 'vitest'
4
- import { extend, createRoot, act } from '@react-three/fiber'
5
- import { EffectComposer } from './EffectComposer'
6
- import { EffectComposer as EffectComposerImpl, RenderPass, Pass, Effect, EffectPass } from 'postprocessing'
7
-
8
- // Let React know that we'll be testing effectful components
9
- declare global {
10
- var IS_REACT_ACT_ENVIRONMENT: boolean
11
- }
12
- global.IS_REACT_ACT_ENVIRONMENT = true
13
-
14
- // Create virtual R3F root for testing
15
- extend(THREE as any)
16
- const root = createRoot({
17
- style: {} as CSSStyleDeclaration,
18
- addEventListener: (() => {}) as any,
19
- removeEventListener: (() => {}) as any,
20
- width: 1280,
21
- height: 800,
22
- clientWidth: 1280,
23
- clientHeight: 800,
24
- getContext: (() =>
25
- new Proxy(
26
- {},
27
- {
28
- get(_target, prop) {
29
- switch (prop) {
30
- case 'getParameter':
31
- return () => 'WebGL 2' // GL_VERSION
32
- case 'getExtension':
33
- return () => ({}) // EXT_blend_minmax
34
- case 'getContextAttributes':
35
- return () => ({ alpha: true })
36
- case 'getShaderPrecisionFormat':
37
- return () => ({ rangeMin: 1, rangeMax: 1, precision: 1 })
38
- default:
39
- return () => {}
40
- }
41
- },
42
- }
43
- )) as any,
44
- } satisfies Partial<HTMLCanvasElement> as HTMLCanvasElement)
45
- root.configure({ frameloop: 'never' })
46
-
47
- const EFFECT_SHADER = 'mainImage() {}'
48
-
49
- describe('EffectComposer', () => {
50
- it('should merge effects together', async () => {
51
- const composerRef = React.createRef<EffectComposerImpl>()
52
-
53
- const effectA = new Effect('A', EFFECT_SHADER)
54
- const effectB = new Effect('B', EFFECT_SHADER)
55
- const effectC = new Effect('C', EFFECT_SHADER)
56
- const passA = new Pass()
57
- const passB = new Pass()
58
-
59
- // Forward order
60
- await act(async () =>
61
- root.render(
62
- <EffectComposer ref={composerRef}>
63
- {/* EffectPass(effectA, effectB) */}
64
- <primitive object={effectA} />
65
- <primitive object={effectB} />
66
- {/* PassA */}
67
- <primitive object={passA} />
68
- {/* EffectPass(effectC) */}
69
- <primitive object={effectC} />
70
- {/* PassB */}
71
- <primitive object={passB} />
72
- </EffectComposer>
73
- )
74
- )
75
- expect(composerRef.current!.passes.map((p) => p.constructor)).toStrictEqual([
76
- RenderPass,
77
- EffectPass,
78
- Pass,
79
- EffectPass,
80
- Pass,
81
- ])
82
- // @ts-expect-error
83
- expect((composerRef.current!.passes[1] as EffectPass).effects).toStrictEqual([effectA, effectB])
84
- expect(composerRef.current!.passes[2]).toBe(passA)
85
- // @ts-expect-error
86
- expect((composerRef.current!.passes[3] as EffectPass).effects).toStrictEqual([effectC])
87
- expect(composerRef.current!.passes[4]).toBe(passB)
88
-
89
- // NOTE: instance children ordering is unstable until R3F v9, so we remount from scratch
90
- await act(async () => root.render(null))
91
-
92
- // Reverse order
93
- await act(async () =>
94
- root.render(
95
- <EffectComposer ref={composerRef}>
96
- {/* PassB */}
97
- <primitive object={passB} />
98
- {/* EffectPass(effectC) */}
99
- <primitive object={effectC} />
100
- {/* PassA */}
101
- <primitive object={passA} />
102
- {/* EffectPass(effectB, effectA) */}
103
- <primitive object={effectB} />
104
- <primitive object={effectA} />
105
- </EffectComposer>
106
- )
107
- )
108
- expect(composerRef.current!.passes.map((p) => p.constructor)).toStrictEqual([
109
- RenderPass,
110
- Pass,
111
- EffectPass,
112
- Pass,
113
- EffectPass,
114
- ])
115
- expect(composerRef.current!.passes[1]).toBe(passB)
116
- // @ts-expect-error
117
- expect((composerRef.current!.passes[2] as EffectPass).effects).toStrictEqual([effectC])
118
- expect(composerRef.current!.passes[3]).toBe(passA)
119
- // @ts-expect-error
120
- expect((composerRef.current!.passes[4] as EffectPass).effects).toStrictEqual([effectB, effectA])
121
- })
122
-
123
- it.skip('should split convolution effects', async () => {
124
- await act(async () => root.render(null))
125
- })
126
- })
1
+ import * as React from 'react'
2
+ import * as THREE from 'three'
3
+ import { vi, describe, it, expect } from 'vitest'
4
+ import { extend, createRoot, act } from '@react-three/fiber'
5
+ import { EffectComposer } from './EffectComposer'
6
+ import { EffectComposer as EffectComposerImpl, RenderPass, Pass, Effect, EffectPass } from 'postprocessing'
7
+
8
+ // Let React know that we'll be testing effectful components
9
+ declare global {
10
+ var IS_REACT_ACT_ENVIRONMENT: boolean
11
+ }
12
+ global.IS_REACT_ACT_ENVIRONMENT = true
13
+
14
+ // Create virtual R3F root for testing
15
+ extend(THREE as any)
16
+ const root = createRoot({
17
+ style: {} as CSSStyleDeclaration,
18
+ addEventListener: (() => {}) as any,
19
+ removeEventListener: (() => {}) as any,
20
+ width: 1280,
21
+ height: 800,
22
+ clientWidth: 1280,
23
+ clientHeight: 800,
24
+ getContext: (() =>
25
+ new Proxy(
26
+ {},
27
+ {
28
+ get(_target, prop) {
29
+ switch (prop) {
30
+ case 'getParameter':
31
+ return () => 'WebGL 2' // GL_VERSION
32
+ case 'getExtension':
33
+ return () => ({}) // EXT_blend_minmax
34
+ case 'getContextAttributes':
35
+ return () => ({ alpha: true })
36
+ case 'getShaderPrecisionFormat':
37
+ return () => ({ rangeMin: 1, rangeMax: 1, precision: 1 })
38
+ default:
39
+ return () => {}
40
+ }
41
+ },
42
+ }
43
+ )) as any,
44
+ } satisfies Partial<HTMLCanvasElement> as HTMLCanvasElement)
45
+ root.configure({ frameloop: 'never' })
46
+
47
+ const EFFECT_SHADER = 'mainImage() {}'
48
+
49
+ describe('EffectComposer', () => {
50
+ it('should merge effects together', async () => {
51
+ const composerRef = React.createRef<EffectComposerImpl>()
52
+
53
+ const effectA = new Effect('A', EFFECT_SHADER)
54
+ const effectB = new Effect('B', EFFECT_SHADER)
55
+ const effectC = new Effect('C', EFFECT_SHADER)
56
+ const passA = new Pass()
57
+ const passB = new Pass()
58
+
59
+ // Forward order
60
+ await act(async () =>
61
+ root.render(
62
+ <EffectComposer ref={composerRef}>
63
+ {/* EffectPass(effectA, effectB) */}
64
+ <primitive object={effectA} />
65
+ <primitive object={effectB} />
66
+ {/* PassA */}
67
+ <primitive object={passA} />
68
+ {/* EffectPass(effectC) */}
69
+ <primitive object={effectC} />
70
+ {/* PassB */}
71
+ <primitive object={passB} />
72
+ </EffectComposer>
73
+ )
74
+ )
75
+ expect(composerRef.current!.passes.map((p) => p.constructor)).toStrictEqual([
76
+ RenderPass,
77
+ EffectPass,
78
+ Pass,
79
+ EffectPass,
80
+ Pass,
81
+ ])
82
+ // @ts-expect-error
83
+ expect((composerRef.current!.passes[1] as EffectPass).effects).toStrictEqual([effectA, effectB])
84
+ expect(composerRef.current!.passes[2]).toBe(passA)
85
+ // @ts-expect-error
86
+ expect((composerRef.current!.passes[3] as EffectPass).effects).toStrictEqual([effectC])
87
+ expect(composerRef.current!.passes[4]).toBe(passB)
88
+
89
+ // NOTE: instance children ordering is unstable until R3F v9, so we remount from scratch
90
+ await act(async () => root.render(null))
91
+
92
+ // Reverse order
93
+ await act(async () =>
94
+ root.render(
95
+ <EffectComposer ref={composerRef}>
96
+ {/* PassB */}
97
+ <primitive object={passB} />
98
+ {/* EffectPass(effectC) */}
99
+ <primitive object={effectC} />
100
+ {/* PassA */}
101
+ <primitive object={passA} />
102
+ {/* EffectPass(effectB, effectA) */}
103
+ <primitive object={effectB} />
104
+ <primitive object={effectA} />
105
+ </EffectComposer>
106
+ )
107
+ )
108
+ expect(composerRef.current!.passes.map((p) => p.constructor)).toStrictEqual([
109
+ RenderPass,
110
+ Pass,
111
+ EffectPass,
112
+ Pass,
113
+ EffectPass,
114
+ ])
115
+ expect(composerRef.current!.passes[1]).toBe(passB)
116
+ // @ts-expect-error
117
+ expect((composerRef.current!.passes[2] as EffectPass).effects).toStrictEqual([effectC])
118
+ expect(composerRef.current!.passes[3]).toBe(passA)
119
+ // @ts-expect-error
120
+ expect((composerRef.current!.passes[4] as EffectPass).effects).toStrictEqual([effectB, effectA])
121
+ })
122
+
123
+ it.skip('should split convolution effects', async () => {
124
+ await act(async () => root.render(null))
125
+ })
126
+ })