@react-three/postprocessing 3.0.4 → 3.1.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 (114) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +80 -81
  3. package/dist/EffectComposer.d.ts +14 -6
  4. package/dist/EffectGroup.d.ts +9 -0
  5. package/dist/Selection.d.ts +8 -8
  6. package/dist/createEffectComponent.d.ts +30 -0
  7. package/dist/effects/ASCII.d.ts +29 -7
  8. package/dist/effects/Autofocus.d.ts +8 -7
  9. package/dist/effects/Bloom.d.ts +10 -5
  10. package/dist/effects/BrightnessContrast.d.ts +15 -5
  11. package/dist/effects/ChromaticAberration.d.ts +30 -7
  12. package/dist/effects/ColorAverage.d.ts +7 -8
  13. package/dist/effects/ColorDepth.d.ts +8 -5
  14. package/dist/effects/Depth.d.ts +13 -5
  15. package/dist/effects/DepthOfField.d.ts +7 -18
  16. package/dist/effects/DotScreen.d.ts +15 -5
  17. package/dist/effects/FXAA.d.ts +11 -5
  18. package/dist/effects/Glitch.d.ts +17 -29
  19. package/dist/effects/GodRays.d.ts +7 -19
  20. package/dist/effects/Grid.d.ts +8 -8
  21. package/dist/effects/HueSaturation.d.ts +15 -5
  22. package/dist/effects/LUT.d.ts +4 -3
  23. package/dist/effects/LensFlare.d.ts +52 -11
  24. package/dist/effects/Noise.d.ts +8 -5
  25. package/dist/effects/Outline.d.ts +9 -25
  26. package/dist/effects/Pixelation.d.ts +3 -2
  27. package/dist/effects/Ramp.d.ts +58 -10
  28. package/dist/effects/SMAA.d.ts +10 -5
  29. package/dist/effects/SSAO.d.ts +7 -30
  30. package/dist/effects/ScanlineEffect.d.ts +13 -5
  31. package/dist/effects/SelectiveBloom.d.ts +5 -10
  32. package/dist/effects/Sepia.d.ts +13 -5
  33. package/dist/effects/ShockWave.d.ts +12 -5
  34. package/dist/effects/Texture.d.ts +7 -8
  35. package/dist/effects/TiltShift.d.ts +10 -5
  36. package/dist/effects/TiltShift2.d.ts +44 -8
  37. package/dist/effects/ToneMapping.d.ts +9 -7
  38. package/dist/effects/Vignette.d.ts +19 -5
  39. package/dist/effects/Water.d.ts +17 -5
  40. package/dist/index.d.ts +15 -11
  41. package/dist/index.js +1841 -45
  42. package/dist/index.js.map +1 -1
  43. package/dist/passes/DepthPicking.d.ts +11 -0
  44. package/dist/{effects → passes}/N8AO.d.ts +5 -2
  45. package/dist/util.d.ts +19 -17
  46. package/dist/wrapEffect.d.ts +12 -0
  47. package/package.json +74 -67
  48. package/src/EffectComposer.tsx +379 -200
  49. package/src/EffectGroup.tsx +74 -0
  50. package/src/Selection.tsx +86 -46
  51. package/src/createEffectComponent.tsx +71 -0
  52. package/src/effects/ASCII.tsx +183 -135
  53. package/src/effects/Autofocus.tsx +122 -153
  54. package/src/effects/Bloom.tsx +34 -6
  55. package/src/effects/BrightnessContrast.tsx +7 -4
  56. package/src/effects/ChromaticAberration.tsx +22 -5
  57. package/src/effects/ColorAverage.tsx +4 -15
  58. package/src/effects/ColorDepth.tsx +25 -4
  59. package/src/effects/Depth.tsx +6 -4
  60. package/src/effects/DepthOfField.tsx +109 -89
  61. package/src/effects/DotScreen.tsx +7 -4
  62. package/src/effects/FXAA.tsx +6 -4
  63. package/src/effects/Glitch.tsx +32 -40
  64. package/src/effects/GodRays.tsx +104 -16
  65. package/src/effects/Grid.tsx +27 -21
  66. package/src/effects/HueSaturation.tsx +7 -4
  67. package/src/effects/LUT.tsx +25 -26
  68. package/src/effects/LensFlare.tsx +765 -611
  69. package/src/effects/Noise.tsx +16 -4
  70. package/src/effects/Outline.tsx +84 -117
  71. package/src/effects/Pixelation.tsx +20 -15
  72. package/src/effects/Ramp.tsx +239 -150
  73. package/src/effects/SMAA.tsx +20 -4
  74. package/src/effects/SSAO.tsx +152 -41
  75. package/src/effects/ScanlineEffect.tsx +7 -7
  76. package/src/effects/SelectiveBloom.tsx +98 -126
  77. package/src/effects/Sepia.tsx +6 -4
  78. package/src/effects/ShockWave.tsx +32 -4
  79. package/src/effects/Texture.tsx +28 -23
  80. package/src/effects/TiltShift.tsx +32 -4
  81. package/src/effects/TiltShift2.tsx +156 -90
  82. package/src/effects/ToneMapping.tsx +19 -6
  83. package/src/effects/Vignette.tsx +7 -4
  84. package/src/effects/Water.tsx +50 -35
  85. package/src/index.ts +43 -40
  86. package/src/passes/DepthPicking.tsx +63 -0
  87. package/src/passes/N8AO.tsx +105 -0
  88. package/src/tests/Autofocus.test.tsx +38 -0
  89. package/src/tests/Bloom.test.tsx +76 -0
  90. package/src/tests/ChromaticAberration.test.tsx +81 -0
  91. package/src/tests/ColorDepth.test.tsx +71 -0
  92. package/src/tests/DepthOfField.test.tsx +130 -0
  93. package/src/tests/DepthPicking.test.tsx +250 -0
  94. package/src/tests/EffectComposer.test.tsx +1404 -0
  95. package/src/tests/EffectGroup.test.tsx +337 -0
  96. package/src/tests/Glitch.test.tsx +56 -0
  97. package/src/tests/GodRays.test.tsx +101 -0
  98. package/src/tests/Grid.test.tsx +34 -0
  99. package/src/tests/LUT.test.tsx +64 -0
  100. package/src/tests/N8AO.test.tsx +92 -0
  101. package/src/tests/Outline.test.tsx +211 -0
  102. package/src/tests/SSAO.test.tsx +140 -0
  103. package/src/tests/Selection.test.tsx +324 -0
  104. package/src/tests/SelectiveBloom.test.tsx +166 -0
  105. package/src/tests/ShockWave.test.tsx +95 -0
  106. package/src/tests/TiltShift.test.tsx +76 -0
  107. package/src/tests/createEffectComponent.test.tsx +286 -0
  108. package/src/tests/effects.smoke.test.tsx +238 -0
  109. package/src/tests/test-utils.tsx +96 -0
  110. package/src/tests/wrapEffect.test.tsx +209 -0
  111. package/src/util.tsx +221 -55
  112. package/src/wrapEffect.tsx +123 -0
  113. package/src/EffectComposer.test.tsx +0 -126
  114. package/src/effects/N8AO.tsx +0 -81
package/dist/index.js CHANGED
@@ -1,4 +1,1027 @@
1
- import{jsx as w,jsxs as K,Fragment as Q}from"react/jsx-runtime";import ee,{createContext as te,useState as j,useMemo as z,useRef as O,useContext as M,useEffect as A,memo as he,forwardRef as B,useLayoutEffect as L,useImperativeHandle as oe,useCallback as ae}from"react";import*as h from"three";import{NoToneMapping as _e,HalfFloatType as xe,Vector3 as ge,Uniform as y,TextureLoader as we,SRGBColorSpace as Se,RepeatWrapping as Y,Texture as ye,Color as Pe,CanvasTexture as be,NearestFilter as re}from"three";import{useThree as V,useFrame as J,extend as Ee,createPortal as Re,useLoader as Ue,applyProps as Ce}from"@react-three/fiber";import{EffectComposer as ze,RenderPass as Te,NormalPass as Ae,DepthDownsamplingPass as Be,Effect as W,EffectPass as Ve,Pass as Fe,DepthOfFieldEffect as Me,MaskFunction as De,DepthPickingPass as ke,CopyPass as Ge,BloomEffect as Ie,BrightnessContrastEffect as Le,ChromaticAberrationEffect as Ne,ColorAverageEffect as je,ColorDepthEffect as Oe,DepthEffect as We,DotScreenEffect as Xe,GlitchEffect as qe,GlitchMode as ne,GodRaysEffect as He,GridEffect as Ze,HueSaturationEffect as $e,NoiseEffect as Ke,OutlineEffect as Ye,PixelationEffect as Je,ScanlineEffect as Qe,SelectiveBloomEffect as et,SepiaEffect as tt,SSAOEffect as ot,SMAAEffect as at,FXAAEffect as rt,TextureEffect as nt,ToneMappingEffect as st,VignetteEffect as it,ShockWaveEffect as lt,LUT3DEffect as ct,TiltShiftEffect as ft}from"postprocessing";import{easing as se}from"maath";import{N8AOPostPass as ut}from"n8ao";const H=/*@__PURE__*/te(null);function pt({children:e,enabled:t=!0}){const[o,r]=j([]),a=z(()=>({selected:o,select:r,enabled:t}),[o,r,t]);return /*@__PURE__*/w(H.Provider,{value:a,children:e})}function mt({enabled:e=!1,children:t,...o}){const r=O(null),a=M(H);return A(()=>{if(a&&e){let n=!1;const i=[];if(r.current.traverse(s=>{s.type==="Mesh"&&i.push(s),a.selected.indexOf(s)===-1&&(n=!0)}),n)return a.select(s=>[...s,...i]),()=>{a.select(s=>s.filter(l=>!i.includes(l)))}}},[e,t,a]),/*@__PURE__*/w("group",{ref:r,...o,children:t})}const D=/*@__PURE__*/te(null),ie=e=>(e.getAttributes()&2)===2,dt=/*@__PURE__*/he(/*@__PURE__*/B(({children:e,camera:t,scene:o,resolutionScale:r,enabled:a=!0,renderPriority:n=1,autoClear:i=!0,depthBuffer:s,enableNormalPass:l,stencilBuffer:p,multisampling:_=8,frameBufferType:S=xe},g)=>{const{gl:d,scene:m,camera:v,size:x}=V(),f=o||m,u=t||v,[c,U,b]=z(()=>{const C=new ze(d,{depthBuffer:s,stencilBuffer:p,multisampling:_,frameBufferType:S});C.addPass(new Te(f,u));let R=null,E=null;return l&&(E=new Ae(f,u),E.enabled=!1,C.addPass(E),r!==void 0&&(R=new Be({normalBuffer:E.texture,resolutionScale:r}),R.enabled=!1,C.addPass(R))),[C,E,R]},[u,d,s,p,_,S,f,l,r]);A(()=>c?.setSize(x.width,x.height),[c,x]),J((C,R)=>{if(a){const E=d.autoClear;d.autoClear=i,p&&!i&&d.clearStencil(),c.render(R),d.autoClear=E}},a?n:0);const F=O(null);L(()=>{const C=[],R=F.current.__r3f;if(R&&c){const E=R.children;for(let T=0;T<E.length;T++){const N=E[T].object;if(N instanceof W){const q=[N];if(!ie(N)){let G=null;for(;(G=E[T+1]?.object)instanceof W&&!ie(G);)q.push(G),T++}const $=new Ve(u,...q);C.push($)}else N instanceof Fe&&C.push(N)}for(const T of C)c?.addPass(T);U&&(U.enabled=!0),b&&(b.enabled=!0)}return()=>{for(const E of C)c?.removePass(E);U&&(U.enabled=!1),b&&(b.enabled=!1)}},[c,e,u,U,b]),A(()=>{const C=d.toneMapping;return d.toneMapping=_e,()=>{d.toneMapping=C}},[d]);const X=z(()=>({composer:c,normalPass:U,downSamplingPass:b,resolutionScale:r,camera:u,scene:f}),[c,U,b,r,u,f]);return oe(g,()=>c,[c]),/*@__PURE__*/w(D.Provider,{value:X,children:/*@__PURE__*/w("group",{ref:F,children:e})})})),k=e=>typeof e=="object"&&e!=null&&"current"in e?e.current:e;let vt=0;const le=/*@__PURE__*/new WeakMap,P=(e,t)=>function({blendFunction:o=t?.blendFunction,opacity:r=t?.opacity,...a}){let n=le.get(e);if(!n){const l=`@react-three/postprocessing/${e.name}-${vt++}`;Ee({[l]:e}),le.set(e,n=l)}const i=V(l=>l.camera),s=ee.useMemo(()=>[...t?.args??[],...a.args??[{...t,...a}]],[JSON.stringify(a)]);return /*@__PURE__*/w(n,{camera:i,"blendMode-blendFunction":o,"blendMode-opacity-value":r,...a,args:s})},Z=(e,t)=>{const o=e[t];return ee.useMemo(()=>typeof o=="number"?new h.Vector2(o,o):o?new h.Vector2(...o):new h.Vector2,[o])},ce=/*@__PURE__*/B(function({blendFunction:e,worldFocusDistance:t,worldFocusRange:o,focusDistance:r,focusRange:a,focalLength:n,bokehScale:i,resolutionScale:s,resolutionX:l,resolutionY:p,width:_,height:S,target:g,depthTexture:d,...m},v){const{camera:x}=M(D),f=g!=null,u=z(()=>{const c=new Me(x,{blendFunction:e,worldFocusDistance:t,worldFocusRange:o,focusDistance:r,focusRange:a,focalLength:n,bokehScale:i,resolutionScale:s,resolutionX:l,resolutionY:p,width:_,height:S});f&&(c.target=new ge),d&&c.setDepthTexture(d.texture,d.packing);const U=c.maskPass;return U.maskFunction=De.MULTIPLY_RGB_SET_ALPHA,c},[x,e,t,o,r,a,n,i,s,l,p,_,S,f,d]);return A(()=>()=>{u.dispose()},[u]),/*@__PURE__*/w("primitive",{...m,ref:v,object:u,target:g})}),ht=/*@__PURE__*/B(({target:e=void 0,mouse:t=!1,debug:o=void 0,manual:r=!1,smoothTime:a=.25,...n},i)=>{const s=O(null),l=O(null),p=O(null),_=V(({scene:b})=>b),S=V(({pointer:b})=>b),{composer:g,camera:d}=M(D),[m]=j(()=>new ke),[v]=j(()=>new Ge);A(()=>(g.addPass(m),g.addPass(v),()=>{g.removePass(m),g.removePass(v)}),[g,m,v]),A(()=>()=>{m.dispose(),v.dispose()},[m,v]);const[x]=j(()=>new h.Vector3(0,0,0)),[f]=j(()=>new h.Vector3(0,0,0)),u=ae(async(b,F)=>(f.x=b,f.y=F,f.z=await m.readDepth(f),f.z=f.z*2-1,1-f.z>1e-7?f.unproject(d):!1),[f,m,d]),c=ae(async(b,F=!0)=>{if(e)x.set(...e);else{const{x:X,y:C}=t?S:{x:0,y:0},R=await u(X,C);R&&x.copy(R)}F&&s.current?.target&&(a>0&&b>0?se.damp3(s.current.target,x,a,b):s.current.target.copy(x))},[e,x,t,u,a,S]);J(async(b,F)=>{r||c(F),l.current&&l.current.position.copy(x),p.current&&s.current?.target&&p.current.position.copy(s.current.target)});const U=z(()=>({dofRef:s,hitpoint:x,update:c}),[x,c]);return oe(i,()=>U,[U]),/*@__PURE__*/K(Q,{children:[o?Re(/*@__PURE__*/K(Q,{children:[/*@__PURE__*/K("mesh",{ref:l,children:[/*@__PURE__*/w("sphereGeometry",{args:[o,16,16]}),/*@__PURE__*/w("meshBasicMaterial",{color:"#00ff00",opacity:1,transparent:!0,depthWrite:!1})]}),/*@__PURE__*/K("mesh",{ref:p,children:[/*@__PURE__*/w("sphereGeometry",{args:[o/2,16,16]}),/*@__PURE__*/w("meshBasicMaterial",{color:"#00ff00",opacity:.5,transparent:!0,depthWrite:!1})]})]}),_):null,/*@__PURE__*/w(ce,{ref:s,...n,target:x})]})}),_t={fragmentShader:`
1
+ import { applyProps, createPortal, extend, useFrame, useLoader, useThree } from "@react-three/fiber";
2
+ import { createContext, memo, use, useCallback, useContext, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useReducer, useRef, useState } from "react";
3
+ import { CanvasTexture, Color, HalfFloatType, Mesh, NearestFilter, NoToneMapping, RepeatWrapping, SRGBColorSpace, Texture as Texture$1, TextureLoader, Uniform, Vector2, Vector3 } from "three";
4
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
+ import { BloomEffect, BrightnessContrastEffect, ChromaticAberrationEffect, ColorAverageEffect, ColorDepthEffect, CopyPass, DepthDownsamplingPass, DepthEffect, DepthOfFieldEffect, DepthPickingPass, DotScreenEffect, Effect, EffectComposer as EffectComposer$1, EffectPass, FXAAEffect, GlitchEffect, GlitchMode, GodRaysEffect, GridEffect, HueSaturationEffect, LUT3DEffect, MaskFunction, NoiseEffect, NormalPass, OutlineEffect, Pass, PixelationEffect, RenderPass, SMAAEffect, SSAOEffect, ScanlineEffect, SelectiveBloomEffect, SepiaEffect, ShockWaveEffect, TextureEffect, TiltShiftEffect as TiltShiftEffect$1, ToneMappingEffect, VignetteEffect } from "postprocessing";
6
+ import { easing } from "maath";
7
+ import { N8AOPostPass } from "n8ao";
8
+ //#region src/Selection.tsx
9
+ var selectionContext = /* @__PURE__ */ createContext(null);
10
+ function Selection({ children, enabled = true }) {
11
+ const [selected, select] = useState([]);
12
+ const value = useMemo(() => ({
13
+ selected,
14
+ select,
15
+ enabled
16
+ }), [
17
+ selected,
18
+ select,
19
+ enabled
20
+ ]);
21
+ return /* @__PURE__ */ jsx(selectionContext.Provider, {
22
+ value,
23
+ children
24
+ });
25
+ }
26
+ function isSelectable(object) {
27
+ const o = object;
28
+ return !!(o.isMesh || o.isLine || o.isPoints);
29
+ }
30
+ function Select({ enabled = false, children, ...props }) {
31
+ const group = useRef(null);
32
+ const select = use(selectionContext)?.select;
33
+ const claimed = useRef([]);
34
+ useEffect(() => {
35
+ if (!select) return;
36
+ const current = [];
37
+ if (enabled) group.current.traverse((o) => {
38
+ if (isSelectable(o)) current.push(o);
39
+ });
40
+ const previouslyClaimed = claimed.current;
41
+ claimed.current = current;
42
+ select((prev) => {
43
+ const prevSet = new Set(prev);
44
+ const currentSet = new Set(current);
45
+ const toAdd = current.filter((o) => !prevSet.has(o));
46
+ const toRemove = previouslyClaimed.filter((o) => !currentSet.has(o) && prevSet.has(o));
47
+ if (!toAdd.length && !toRemove.length) return prev;
48
+ const toRemoveSet = toRemove.length ? new Set(toRemove) : null;
49
+ const kept = toRemoveSet ? prev.filter((o) => !toRemoveSet.has(o)) : prev;
50
+ return toAdd.length ? [...kept, ...toAdd] : kept;
51
+ });
52
+ }, [
53
+ enabled,
54
+ children,
55
+ select
56
+ ]);
57
+ useEffect(() => {
58
+ return () => {
59
+ if (!select || !claimed.current.length) return;
60
+ const stillClaimed = new Set(claimed.current);
61
+ select((prev) => {
62
+ const next = prev.filter((o) => !stillClaimed.has(o));
63
+ return next.length !== prev.length ? next : prev;
64
+ });
65
+ };
66
+ }, [select]);
67
+ return /* @__PURE__ */ jsx("group", {
68
+ ref: group,
69
+ ...props,
70
+ children
71
+ });
72
+ }
73
+ //#endregion
74
+ //#region src/util.tsx
75
+ var EMPTY_ARRAY = [];
76
+ var resolveRef = (ref) => typeof ref === "object" && ref != null && "current" in ref ? ref.current : ref;
77
+ function useMergeRefs(localRef, outerRef) {
78
+ return useCallback((instance) => {
79
+ localRef.current = instance;
80
+ if (typeof outerRef !== "function") {
81
+ if (outerRef) outerRef.current = instance;
82
+ return;
83
+ }
84
+ const cleanup = outerRef(instance);
85
+ if (typeof cleanup !== "function") return;
86
+ return () => {
87
+ localRef.current = null;
88
+ cleanup();
89
+ };
90
+ }, [localRef, outerRef]);
91
+ }
92
+ function readGroupChildren(group, filter) {
93
+ const groupInstance = group.__r3f;
94
+ return groupInstance ? groupInstance.children.map((child) => child.object).filter(filter) : [];
95
+ }
96
+ function updateIfChanged(ref, next) {
97
+ const previous = ref.current;
98
+ if (next.length === previous.length && next.every((item, i) => item === previous[i])) return false;
99
+ ref.current = next;
100
+ return true;
101
+ }
102
+ function useSelectionSync(effect, selection, selectionLayer) {
103
+ const invalidate = useThree((state) => state.invalidate);
104
+ const api = use(selectionContext);
105
+ useEffect(() => {
106
+ effect.selection.layer = selectionLayer;
107
+ invalidate();
108
+ }, [
109
+ effect,
110
+ invalidate,
111
+ selectionLayer
112
+ ]);
113
+ useEffect(() => {
114
+ if (api) return;
115
+ const resolved = (Array.isArray(selection) ? selection.map((o) => resolveRef(o)) : [resolveRef(selection)]).filter((o) => o != null);
116
+ if (!resolved.length) return;
117
+ effect.selection.set(resolved);
118
+ invalidate();
119
+ return () => {
120
+ effect.selection.clear();
121
+ invalidate();
122
+ };
123
+ }, [
124
+ effect,
125
+ selection,
126
+ api,
127
+ invalidate
128
+ ]);
129
+ useEffect(() => {
130
+ if (api && api.enabled && api.selected?.length) {
131
+ effect.selection.set(api.selected);
132
+ invalidate();
133
+ return () => {
134
+ effect.selection.clear();
135
+ invalidate();
136
+ };
137
+ }
138
+ }, [
139
+ api,
140
+ effect.selection,
141
+ invalidate
142
+ ]);
143
+ }
144
+ var useDispose = (instance) => {
145
+ useEffect(() => {
146
+ return () => {
147
+ instance?.dispose?.();
148
+ };
149
+ }, [instance]);
150
+ };
151
+ function readPierced(instance, key) {
152
+ let target = instance;
153
+ for (const part of key.split("-")) {
154
+ if (target == null) return void 0;
155
+ target = target[part];
156
+ }
157
+ return target;
158
+ }
159
+ function applyPierced(instance, key, value) {
160
+ const parts = key.split("-");
161
+ let target = instance;
162
+ for (let idx = 0; idx < parts.length - 1; idx++) {
163
+ if (target == null) return;
164
+ target = target[parts[idx]];
165
+ }
166
+ if (target == null) return;
167
+ target[parts[parts.length - 1]] = value;
168
+ }
169
+ function useLiveDefaults(instance, values, keys, get = readPierced, set = applyPierced) {
170
+ const snapshotRef = useRef(null);
171
+ const invalidate = useThree((state) => state.invalidate);
172
+ useLayoutEffect(() => {
173
+ const resolved = resolveRef(instance);
174
+ if (!resolved) return;
175
+ if (snapshotRef.current?.instance !== resolved) snapshotRef.current = {
176
+ instance: resolved,
177
+ defaults: /* @__PURE__ */ new Map(),
178
+ applied: /* @__PURE__ */ new Map()
179
+ };
180
+ const { defaults, applied } = snapshotRef.current;
181
+ let changed = false;
182
+ for (const key of keys) {
183
+ if (!defaults.has(key)) {
184
+ const current = get(resolved, key);
185
+ defaults.set(key, current);
186
+ applied.set(key, current);
187
+ }
188
+ const next = values[key] !== void 0 ? values[key] : defaults.get(key);
189
+ if (Object.is(applied.get(key), next)) continue;
190
+ set(resolved, key, next);
191
+ applied.set(key, next);
192
+ changed = true;
193
+ }
194
+ if (changed) invalidate();
195
+ });
196
+ }
197
+ var useVector2 = (props, key) => {
198
+ const value = props[key];
199
+ return useMemo(() => {
200
+ if (typeof value === "number") return new Vector2(value, value);
201
+ if (value instanceof Vector2) return value;
202
+ if (value) return new Vector2(...value);
203
+ return new Vector2();
204
+ }, [value]);
205
+ };
206
+ var useVector3 = (props, key) => {
207
+ const value = props[key];
208
+ return useMemo(() => {
209
+ if (typeof value === "number") return new Vector3(value, value, value);
210
+ if (value instanceof Vector3) return value;
211
+ if (value) return new Vector3(...value);
212
+ return new Vector3();
213
+ }, [value]);
214
+ };
215
+ //#endregion
216
+ //#region src/createEffectComponent.tsx
217
+ var components$1 = /* @__PURE__ */ new WeakMap();
218
+ var i$1 = 0;
219
+ var BLEND_KEYS = ["blendMode-blendFunction", "blendMode-opacity-value"];
220
+ /**
221
+ * Registers `effect` as a JSX intrinsic once per class and returns a
222
+ * component that renders it. Everything else - construction from `args`,
223
+ * live prop application (with the same Color/Vector coercion and reset-
224
+ * to-default on removal any r3f element gets), disposal - is r3f's own
225
+ * reconciler, same rules as `<mesh>`/`<meshStandardMaterial>`. Only fits
226
+ * effects whose constructor works with zero arguments (`new Effect()`) -
227
+ * r3f's own reset-on-removal falls back to `0` otherwise, which is wrong
228
+ * for anything non-numeric. Effects that require e.g. scene/camera stay
229
+ * hand-rolled (see Outline.tsx, SelectiveBloom.tsx, ShockWave.tsx).
230
+ *
231
+ * `blendFunction`/`opacity` are pierced through to `blendMode-*` - every
232
+ * `Effect` has them on a nested `blendMode`, not on the effect itself, so a
233
+ * plain top-level prop would silently land on a stray, unread property.
234
+ * Applied via useLiveDefaults, not as plain JSX props: BlendMode's own
235
+ * constructor requires `blendFunction` (no default), so its constructor
236
+ * length isn't 0 either, and r3f's native reset-on-removal falls back to
237
+ * `changedProps[prop] = 0` - which is 9, not a merely
238
+ * "wrong" blend function but one that hides the effect entirely.
239
+ */
240
+ function createEffectComponent(effect) {
241
+ return function EffectComponent({ blendFunction, opacity, ref, ...props }) {
242
+ let Component = components$1.get(effect);
243
+ if (!Component) {
244
+ const key = `@react-three/postprocessing/${effect.name}-${i$1++}`;
245
+ extend({ [key]: effect });
246
+ components$1.set(effect, Component = key);
247
+ }
248
+ const camera = useThree((state) => state.camera);
249
+ const localRef = useRef(null);
250
+ const setRef = useMergeRefs(localRef, ref);
251
+ useLiveDefaults(localRef, {
252
+ "blendMode-blendFunction": blendFunction,
253
+ "blendMode-opacity-value": opacity
254
+ }, BLEND_KEYS);
255
+ return /* @__PURE__ */ jsx(Component, {
256
+ ref: setRef,
257
+ camera,
258
+ ...props
259
+ });
260
+ };
261
+ }
262
+ //#endregion
263
+ //#region src/EffectComposer.tsx
264
+ var EffectComposerContext = /* @__PURE__ */ createContext(null);
265
+ var isConvolution = (effect) => (effect.getAttributes() & 2) === 2;
266
+ function createRendererPropertyGuard(property) {
267
+ const refs = /* @__PURE__ */ new WeakMap();
268
+ return {
269
+ acquire(gl, forcedValue) {
270
+ const existing = refs.get(gl);
271
+ if (existing) {
272
+ existing.count++;
273
+ existing.forcedValue = forcedValue;
274
+ } else refs.set(gl, {
275
+ count: 1,
276
+ original: gl[property],
277
+ forcedValue
278
+ });
279
+ },
280
+ release(gl) {
281
+ const entry = refs.get(gl);
282
+ if (!entry) return;
283
+ if (--entry.count <= 0) {
284
+ if (gl[property] === entry.forcedValue) gl[property] = entry.original;
285
+ refs.delete(gl);
286
+ }
287
+ }
288
+ };
289
+ }
290
+ var autoClearGuard = /* @__PURE__ */ createRendererPropertyGuard("autoClear");
291
+ var toneMappingGuard = /* @__PURE__ */ createRendererPropertyGuard("toneMapping");
292
+ var glSize = /* @__PURE__ */ new Vector2();
293
+ var defaultRenderPass = (scene, camera) => new RenderPass(scene, camera);
294
+ var generatedPasses = /* @__PURE__ */ new WeakSet();
295
+ var groupPasses = /* @__PURE__ */ new WeakSet();
296
+ function disposePassWithoutEffects(pass) {
297
+ if (pass instanceof EffectPass) pass.setEffects([]);
298
+ Pass.prototype.dispose.call(pass);
299
+ }
300
+ function disposeGeneratedPass(pass) {
301
+ if (!generatedPasses.has(pass)) return;
302
+ disposePassWithoutEffects(pass);
303
+ }
304
+ function buildPasses(nodes, camera, mergeMode) {
305
+ const passes = [];
306
+ for (let i = 0; i < nodes.length; i++) {
307
+ const node = nodes[i];
308
+ if (node instanceof Effect) {
309
+ const effects = [node];
310
+ let hasConvolution = isConvolution(node);
311
+ if (mergeMode !== "none") {
312
+ let next;
313
+ while ((next = nodes[i + 1]) instanceof Effect) {
314
+ const nextIsConvolution = isConvolution(next);
315
+ if (mergeMode === "auto" && hasConvolution && nextIsConvolution) break;
316
+ effects.push(next);
317
+ hasConvolution ||= nextIsConvolution;
318
+ i++;
319
+ }
320
+ }
321
+ const pass = new EffectPass(camera, ...effects);
322
+ generatedPasses.add(pass);
323
+ passes.push(pass);
324
+ } else if (node instanceof Pass) passes.push(node);
325
+ }
326
+ return passes;
327
+ }
328
+ var EffectComposer = /* @__PURE__ */ memo(function EffectComposer({ children, camera: _camera, scene: _scene, resolutionScale, enabled = true, renderPriority = 1, autoClear = true, autoRenderToScreen = true, depthBuffer, enableNormalPass, stencilBuffer, multisampling = 8, frameBufferType = HalfFloatType, renderPass = defaultRenderPass, mergeMode = "auto", ref }) {
329
+ const { gl, scene: defaultScene, camera: defaultCamera } = useThree();
330
+ const scene = _scene || defaultScene;
331
+ const camera = _camera || defaultCamera;
332
+ gl.getSize(glSize);
333
+ const [composerState, setComposerState] = useState(null);
334
+ const [, requestRebuild] = useReducer((c) => c + 1, 0);
335
+ useEffect(() => {
336
+ autoClearGuard.acquire(gl, false);
337
+ const effectComposer = new EffectComposer$1(gl, {
338
+ depthBuffer,
339
+ stencilBuffer,
340
+ multisampling,
341
+ frameBufferType
342
+ });
343
+ effectComposer.autoRenderToScreen = autoRenderToScreen;
344
+ effectComposer.addPass(renderPass(scene, camera));
345
+ let normalPass = null;
346
+ let downSamplingPass = null;
347
+ if (enableNormalPass) {
348
+ normalPass = new NormalPass(scene, camera);
349
+ normalPass.enabled = false;
350
+ effectComposer.addPass(normalPass);
351
+ if (resolutionScale !== void 0) {
352
+ downSamplingPass = new DepthDownsamplingPass({
353
+ normalBuffer: normalPass.texture,
354
+ resolutionScale
355
+ });
356
+ downSamplingPass.enabled = false;
357
+ effectComposer.addPass(downSamplingPass);
358
+ }
359
+ }
360
+ effectComposer.setSize(glSize.width, glSize.height);
361
+ setComposerState({
362
+ composer: effectComposer,
363
+ normalPass,
364
+ downSamplingPass
365
+ });
366
+ return () => {
367
+ for (const pass of effectComposer.passes) disposeGeneratedPass(pass);
368
+ effectComposer.dispose();
369
+ autoClearGuard.release(gl);
370
+ };
371
+ }, [
372
+ camera,
373
+ gl,
374
+ depthBuffer,
375
+ stencilBuffer,
376
+ multisampling,
377
+ frameBufferType,
378
+ autoRenderToScreen,
379
+ renderPass,
380
+ scene,
381
+ enableNormalPass,
382
+ resolutionScale
383
+ ]);
384
+ const appliedSizeRef = useRef({
385
+ width: -1,
386
+ height: -1
387
+ });
388
+ useFrame((_, delta) => {
389
+ if (!enabled || !composerState) return;
390
+ const { composer } = composerState;
391
+ gl.getSize(glSize);
392
+ if (glSize.width !== appliedSizeRef.current.width || glSize.height !== appliedSizeRef.current.height) {
393
+ composer.setSize(glSize.width, glSize.height);
394
+ appliedSizeRef.current.width = glSize.width;
395
+ appliedSizeRef.current.height = glSize.height;
396
+ }
397
+ const currentAutoClear = gl.autoClear;
398
+ gl.autoClear = autoClear;
399
+ if (stencilBuffer && !autoClear) gl.clearStencil();
400
+ composer.render(delta);
401
+ gl.autoClear = currentAutoClear;
402
+ }, enabled ? renderPriority : 0);
403
+ const group = useRef(null);
404
+ const nodesRef = useRef([]);
405
+ const [nodesVersion, setNodesVersion] = useState(0);
406
+ useLayoutEffect(() => {
407
+ if (!composerState) return;
408
+ const nodes = readGroupChildren(group.current, (object) => object instanceof Effect || object instanceof Pass);
409
+ if (updateIfChanged(nodesRef, nodes)) setNodesVersion((v) => v + 1);
410
+ });
411
+ useLayoutEffect(() => {
412
+ if (!composerState) return;
413
+ const { composer, normalPass, downSamplingPass } = composerState;
414
+ const passes = buildPasses(nodesRef.current, camera, mergeMode);
415
+ if (passes.some((pass) => groupPasses.has(pass))) {
416
+ const trailingCopyPass = new CopyPass();
417
+ generatedPasses.add(trailingCopyPass);
418
+ passes.push(trailingCopyPass);
419
+ }
420
+ for (const pass of passes) composer.addPass(pass);
421
+ if (passes.length) {
422
+ if (normalPass) normalPass.enabled = true;
423
+ if (downSamplingPass) downSamplingPass.enabled = true;
424
+ }
425
+ return () => {
426
+ for (const pass of passes) {
427
+ composer.removePass(pass);
428
+ disposeGeneratedPass(pass);
429
+ }
430
+ if (normalPass) normalPass.enabled = false;
431
+ if (downSamplingPass) downSamplingPass.enabled = false;
432
+ };
433
+ }, [
434
+ composerState,
435
+ nodesVersion,
436
+ camera,
437
+ mergeMode
438
+ ]);
439
+ useEffect(() => {
440
+ toneMappingGuard.acquire(gl, NoToneMapping);
441
+ gl.toneMapping = NoToneMapping;
442
+ return () => {
443
+ toneMappingGuard.release(gl);
444
+ };
445
+ }, [gl]);
446
+ const state = useMemo(() => composerState ? {
447
+ composer: composerState.composer,
448
+ normalPass: composerState.normalPass,
449
+ downSamplingPass: composerState.downSamplingPass,
450
+ resolutionScale,
451
+ camera,
452
+ scene,
453
+ requestRebuild,
454
+ autoClear
455
+ } : null, [
456
+ composerState,
457
+ resolutionScale,
458
+ camera,
459
+ scene,
460
+ requestRebuild,
461
+ autoClear
462
+ ]);
463
+ useImperativeHandle(ref, () => composerState?.composer, [composerState]);
464
+ if (!state) return null;
465
+ return /* @__PURE__ */ jsx(EffectComposerContext.Provider, {
466
+ value: state,
467
+ children: /* @__PURE__ */ jsx("group", {
468
+ ref: group,
469
+ children
470
+ })
471
+ });
472
+ });
473
+ //#endregion
474
+ //#region src/EffectGroup.tsx
475
+ function EffectGroup({ enabled = true, children, ref }) {
476
+ const { camera, requestRebuild } = use(EffectComposerContext);
477
+ const group = useRef(null);
478
+ const effectsRef = useRef([]);
479
+ const [pass, setPass] = useState(null);
480
+ useLayoutEffect(() => {
481
+ const effects = readGroupChildren(group.current, (object) => object instanceof Effect);
482
+ if (!updateIfChanged(effectsRef, effects)) return;
483
+ if (!effects.length) {
484
+ setPass(null);
485
+ return;
486
+ }
487
+ const newPass = new EffectPass(camera, ...effects);
488
+ groupPasses.add(newPass);
489
+ setPass(newPass);
490
+ });
491
+ useLayoutEffect(() => {
492
+ if (pass) pass.enabled = enabled;
493
+ }, [pass, enabled]);
494
+ useLayoutEffect(() => {
495
+ requestRebuild();
496
+ }, [pass, requestRebuild]);
497
+ useLayoutEffect(() => {
498
+ return () => {
499
+ if (pass) disposePassWithoutEffects(pass);
500
+ };
501
+ }, [pass]);
502
+ useImperativeHandle(ref, () => pass, [pass]);
503
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("group", {
504
+ ref: group,
505
+ children
506
+ }), pass && /* @__PURE__ */ jsx("primitive", { object: pass })] });
507
+ }
508
+ //#endregion
509
+ //#region src/wrapEffect.tsx
510
+ var i = 0;
511
+ var components = /* @__PURE__ */ new WeakMap();
512
+ var identityTokens = /* @__PURE__ */ new WeakMap();
513
+ var nextIdentityToken = 0;
514
+ function identityOf(value) {
515
+ let token = identityTokens.get(value);
516
+ if (token === void 0) {
517
+ token = nextIdentityToken++;
518
+ identityTokens.set(value, token);
519
+ }
520
+ return token;
521
+ }
522
+ function fingerprint(value, seen) {
523
+ if (value === null || typeof value !== "object") return value;
524
+ if (seen.has(value)) return "[Circular]";
525
+ if (ArrayBuffer.isView(value) || value instanceof ArrayBuffer) return identityOf(value);
526
+ seen.add(value);
527
+ if (Array.isArray(value)) return value.map((item) => fingerprint(item, seen));
528
+ const out = {};
529
+ for (const key of Object.keys(value).sort()) out[key] = fingerprint(value[key], seen);
530
+ return out;
531
+ }
532
+ function stableStringify(value) {
533
+ return JSON.stringify(fingerprint(value, /* @__PURE__ */ new WeakSet()));
534
+ }
535
+ function wrapEffect(effect, defaults) {
536
+ return function WrappedEffect({ ref, blendFunction = defaults?.blendFunction, opacity = defaults?.opacity, ...props }) {
537
+ let Component = components.get(effect);
538
+ if (!Component) {
539
+ const key = `@react-three/postprocessing/${effect.name}-${i++}`;
540
+ extend({ [key]: effect });
541
+ components.set(effect, Component = key);
542
+ }
543
+ const camera = useThree((state) => state.camera);
544
+ const args = useMemo(() => [...defaults?.args ?? [], ...props.args ?? [{
545
+ ...defaults,
546
+ ...props
547
+ }]], [stableStringify(props)]);
548
+ return /* @__PURE__ */ jsx(Component, {
549
+ camera,
550
+ "blendMode-blendFunction": blendFunction,
551
+ "blendMode-opacity-value": opacity,
552
+ ...props,
553
+ args,
554
+ ref
555
+ });
556
+ };
557
+ }
558
+ //#endregion
559
+ //#region src/effects/ASCII.tsx
560
+ var fragment = `
561
+ uniform sampler2D uCharacters;
562
+ uniform float uCharactersCount;
563
+ uniform float uCellSize;
564
+ uniform bool uInvert;
565
+ uniform vec3 uColor;
566
+
567
+ const vec2 SIZE = vec2(16.);
568
+
569
+ vec3 greyscale(vec3 color, float strength) {
570
+ float g = dot(color, vec3(0.299, 0.587, 0.114));
571
+ return mix(color, vec3(g), strength);
572
+ }
573
+
574
+ vec3 greyscale(vec3 color) {
575
+ return greyscale(color, 1.0);
576
+ }
577
+
578
+ void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
579
+ vec2 cell = resolution / uCellSize;
580
+ vec2 grid = 1.0 / cell;
581
+ vec2 pixelizedUV = grid * (0.5 + floor(uv / grid));
582
+ vec4 pixelized = texture2D(inputBuffer, pixelizedUV);
583
+ float greyscaled = greyscale(pixelized.rgb).r;
584
+
585
+ if (uInvert) {
586
+ greyscaled = 1.0 - greyscaled;
587
+ }
588
+
589
+ float characterIndex = floor((uCharactersCount - 1.0) * greyscaled);
590
+ vec2 characterPosition = vec2(mod(characterIndex, SIZE.x), floor(characterIndex / SIZE.y));
591
+ vec2 offset = vec2(characterPosition.x, -characterPosition.y) / SIZE;
592
+ vec2 charUV = mod(uv * (cell / SIZE), 1.0 / SIZE) - vec2(0., 1.0 / SIZE) + offset;
593
+ vec4 asciiCharacter = texture2D(uCharacters, charUV);
594
+
595
+ asciiCharacter.rgb = uColor * asciiCharacter.r;
596
+ asciiCharacter.a = pixelized.a;
597
+ outputColor = asciiCharacter;
598
+ }
599
+ `;
600
+ var ASCIIEffect = class extends Effect {
601
+ constructor({ font = "arial", characters = ` .:,'-^=*+?!|0#X%WM@`, fontSize = 54, cellSize = 16, color = "#ffffff", invert = false } = {}) {
602
+ const uniforms = /* @__PURE__ */ new Map([
603
+ ["uCharacters", new Uniform(new Texture$1())],
604
+ ["uCellSize", new Uniform(cellSize)],
605
+ ["uCharactersCount", new Uniform(characters.length)],
606
+ ["uColor", new Uniform(new Color(color))],
607
+ ["uInvert", new Uniform(invert)]
608
+ ]);
609
+ super("ASCIIEffect", fragment, { uniforms });
610
+ this._font = font;
611
+ this._characters = characters;
612
+ this._fontSize = fontSize;
613
+ this.updateCharactersTexture();
614
+ }
615
+ get cellSize() {
616
+ return this.uniforms.get("uCellSize").value;
617
+ }
618
+ set cellSize(value) {
619
+ this.uniforms.get("uCellSize").value = value;
620
+ }
621
+ get invert() {
622
+ return this.uniforms.get("uInvert").value;
623
+ }
624
+ set invert(value) {
625
+ this.uniforms.get("uInvert").value = value;
626
+ }
627
+ get color() {
628
+ return this.uniforms.get("uColor").value;
629
+ }
630
+ set color(value) {
631
+ this.uniforms.get("uColor").value.set(value);
632
+ }
633
+ get font() {
634
+ return this._font;
635
+ }
636
+ set font(value) {
637
+ this._font = value;
638
+ this.updateCharactersTexture();
639
+ }
640
+ get characters() {
641
+ return this._characters;
642
+ }
643
+ set characters(value) {
644
+ this._characters = value;
645
+ this.uniforms.get("uCharactersCount").value = value.length;
646
+ this.updateCharactersTexture();
647
+ }
648
+ get fontSize() {
649
+ return this._fontSize;
650
+ }
651
+ set fontSize(value) {
652
+ this._fontSize = value;
653
+ this.updateCharactersTexture();
654
+ }
655
+ updateCharactersTexture() {
656
+ const uniform = this.uniforms.get("uCharacters");
657
+ const previous = uniform.value;
658
+ uniform.value = this.createCharactersTexture(this._characters, this._font, this._fontSize);
659
+ previous.dispose();
660
+ }
661
+ /** Draws the characters on a Canvas and returns a texture */
662
+ createCharactersTexture(characters, font, fontSize) {
663
+ const canvas = document.createElement("canvas");
664
+ const SIZE = 1024;
665
+ const MAX_PER_ROW = 16;
666
+ const CELL = SIZE / MAX_PER_ROW;
667
+ canvas.width = canvas.height = SIZE;
668
+ const texture = new CanvasTexture(canvas, void 0, RepeatWrapping, RepeatWrapping, NearestFilter, NearestFilter);
669
+ const context = canvas.getContext("2d");
670
+ if (!context) throw new Error("Context not available");
671
+ context.clearRect(0, 0, SIZE, SIZE);
672
+ context.font = `${fontSize}px ${font}`;
673
+ context.textAlign = "center";
674
+ context.textBaseline = "middle";
675
+ context.fillStyle = "#fff";
676
+ for (let i = 0; i < characters.length; i++) {
677
+ const char = characters[i];
678
+ const x = i % MAX_PER_ROW;
679
+ const y = Math.floor(i / MAX_PER_ROW);
680
+ context.fillText(char, x * CELL + CELL / 2, y * CELL + CELL / 2);
681
+ }
682
+ texture.needsUpdate = true;
683
+ return texture;
684
+ }
685
+ };
686
+ var ASCII = /* @__PURE__ */ createEffectComponent(ASCIIEffect);
687
+ //#endregion
688
+ //#region src/passes/DepthPicking.tsx
689
+ function DepthPicking({ ref }) {
690
+ const { composer } = use(EffectComposerContext);
691
+ const [depthPickingPass] = useState(() => new DepthPickingPass());
692
+ const [copyPass] = useState(() => new CopyPass());
693
+ useEffect(() => {
694
+ composer.addPass(depthPickingPass);
695
+ composer.addPass(copyPass);
696
+ return () => {
697
+ composer.removePass(depthPickingPass);
698
+ composer.removePass(copyPass);
699
+ };
700
+ }, [
701
+ composer,
702
+ depthPickingPass,
703
+ copyPass
704
+ ]);
705
+ useDispose(depthPickingPass);
706
+ useDispose(copyPass);
707
+ useImperativeHandle(ref, () => ({ readDepth: (ndc) => depthPickingPass.readDepth(ndc) }), [depthPickingPass]);
708
+ return null;
709
+ }
710
+ function useDepthPicking(pass, camera) {
711
+ const composerCamera = use(EffectComposerContext)?.camera;
712
+ const defaultCamera = useThree((state) => state.camera);
713
+ const resolvedCamera = camera ?? composerCamera ?? defaultCamera;
714
+ const [ndc] = useState(() => new Vector3());
715
+ return useCallback(async (x, y) => {
716
+ if (!pass.current) return false;
717
+ ndc.x = x;
718
+ ndc.y = y;
719
+ ndc.z = await pass.current.readDepth(ndc);
720
+ ndc.z = ndc.z * 2 - 1;
721
+ return 1 - ndc.z > 1e-7 ? ndc.clone().unproject(resolvedCamera) : false;
722
+ }, [
723
+ pass,
724
+ resolvedCamera,
725
+ ndc
726
+ ]);
727
+ }
728
+ //#endregion
729
+ //#region src/effects/DepthOfField.tsx
730
+ var LIVE_KEYS$6 = [
731
+ "blendMode-blendFunction",
732
+ "bokehScale",
733
+ "cocMaterial-focusDistance",
734
+ "cocMaterial-focusRange",
735
+ "depthTexture"
736
+ ];
737
+ function get$2(effect, key) {
738
+ if (key !== "depthTexture") return readPierced(effect, key);
739
+ const texture = effect.cocMaterial.uniforms.depthBuffer.value;
740
+ return texture ? { texture } : void 0;
741
+ }
742
+ function set$3(effect, key, value) {
743
+ if (key === "depthTexture") {
744
+ const dt = value;
745
+ effect.setDepthTexture(dt?.texture, dt?.packing);
746
+ } else applyPierced(effect, key, value);
747
+ }
748
+ function DepthOfField({ ref, blendFunction, worldFocusDistance, worldFocusRange, focusDistance, focusRange, focalLength, bokehScale, resolutionScale, resolutionX, resolutionY, width, height, target, depthTexture, ...props }) {
749
+ const { camera } = use(EffectComposerContext);
750
+ const autoFocus = target != null;
751
+ const effect = useMemo(() => {
752
+ const effect = new DepthOfFieldEffect(camera, {
753
+ worldFocusDistance,
754
+ worldFocusRange,
755
+ focalLength,
756
+ resolutionScale,
757
+ resolutionX,
758
+ resolutionY,
759
+ width,
760
+ height
761
+ });
762
+ if (autoFocus) effect.target = new Vector3();
763
+ effect.maskFunction = MaskFunction.MULTIPLY_RGB_SET_ALPHA;
764
+ return effect;
765
+ }, [
766
+ camera,
767
+ worldFocusDistance,
768
+ worldFocusRange,
769
+ focalLength,
770
+ resolutionScale,
771
+ resolutionX,
772
+ resolutionY,
773
+ width,
774
+ height,
775
+ autoFocus
776
+ ]);
777
+ useLiveDefaults(effect, {
778
+ "blendMode-blendFunction": blendFunction,
779
+ bokehScale,
780
+ "cocMaterial-focusDistance": focusDistance,
781
+ "cocMaterial-focusRange": focusRange,
782
+ depthTexture
783
+ }, LIVE_KEYS$6, get$2, set$3);
784
+ useDispose(effect);
785
+ return /* @__PURE__ */ jsx("primitive", {
786
+ ...props,
787
+ object: effect,
788
+ ref,
789
+ target
790
+ });
791
+ }
792
+ //#endregion
793
+ //#region src/effects/Autofocus.tsx
794
+ function Autofocus({ target = void 0, mouse: followMouse = false, debug = void 0, manual = false, smoothTime = .25, ref, ...props }) {
795
+ const dofRef = useRef(null);
796
+ const pickRef = useRef(null);
797
+ const getHit = useDepthPicking(pickRef);
798
+ const hitpointMarkerRef = useRef(null);
799
+ const dofTargetMarkerRef = useRef(null);
800
+ const scene = useThree(({ scene }) => scene);
801
+ const pointer = useThree(({ pointer }) => pointer);
802
+ const [autoFocusMarker] = useState(() => new Vector3());
803
+ const [hitpoint] = useState(() => new Vector3());
804
+ const update = useCallback(async (delta, updateTarget = true) => {
805
+ if (target) hitpoint.set(...target);
806
+ else {
807
+ const { x, y } = followMouse ? pointer : {
808
+ x: 0,
809
+ y: 0
810
+ };
811
+ const hit = await getHit(x, y);
812
+ if (hit) hitpoint.copy(hit);
813
+ }
814
+ if (updateTarget && dofRef.current?.target) {
815
+ if (smoothTime > 0 && delta > 0) easing.damp3(dofRef.current.target, hitpoint, smoothTime, delta);
816
+ else dofRef.current.target.copy(hitpoint);
817
+ }
818
+ }, [
819
+ target,
820
+ hitpoint,
821
+ followMouse,
822
+ pointer,
823
+ getHit,
824
+ smoothTime
825
+ ]);
826
+ useFrame((_, delta) => {
827
+ if (!manual) update(delta);
828
+ if (hitpointMarkerRef.current) hitpointMarkerRef.current.position.copy(hitpoint);
829
+ if (dofTargetMarkerRef.current && dofRef.current?.target) dofTargetMarkerRef.current.position.copy(dofRef.current.target);
830
+ });
831
+ const api = useMemo(() => ({
832
+ dofRef,
833
+ hitpoint,
834
+ update
835
+ }), [hitpoint, update]);
836
+ useImperativeHandle(ref, () => api, [api]);
837
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
838
+ /* @__PURE__ */ jsx(DepthPicking, { ref: pickRef }),
839
+ debug ? createPortal(/* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("mesh", {
840
+ ref: hitpointMarkerRef,
841
+ children: [/* @__PURE__ */ jsx("sphereGeometry", { args: [
842
+ debug,
843
+ 16,
844
+ 16
845
+ ] }), /* @__PURE__ */ jsx("meshBasicMaterial", {
846
+ color: "#00ff00",
847
+ opacity: 1,
848
+ transparent: true,
849
+ depthWrite: false
850
+ })]
851
+ }), /* @__PURE__ */ jsxs("mesh", {
852
+ ref: dofTargetMarkerRef,
853
+ children: [/* @__PURE__ */ jsx("sphereGeometry", { args: [
854
+ debug / 2,
855
+ 16,
856
+ 16
857
+ ] }), /* @__PURE__ */ jsx("meshBasicMaterial", {
858
+ color: "#00ff00",
859
+ opacity: .5,
860
+ transparent: true,
861
+ depthWrite: false
862
+ })]
863
+ })] }), scene) : null,
864
+ /* @__PURE__ */ jsx(DepthOfField, {
865
+ ref: dofRef,
866
+ ...props,
867
+ target: autoFocusMarker
868
+ })
869
+ ] });
870
+ }
871
+ //#endregion
872
+ //#region src/effects/Bloom.tsx
873
+ var BloomImpl = /* @__PURE__ */ createEffectComponent(BloomEffect);
874
+ function Bloom({ blendFunction = 0, luminanceThreshold, luminanceSmoothing, mipmapBlur, radius, levels, resolutionScale, resolutionX, resolutionY, ...liveProps }) {
875
+ const args = useMemo(() => [{
876
+ luminanceThreshold,
877
+ luminanceSmoothing,
878
+ mipmapBlur,
879
+ radius,
880
+ levels,
881
+ resolutionScale,
882
+ resolutionX,
883
+ resolutionY
884
+ }], [
885
+ luminanceThreshold,
886
+ luminanceSmoothing,
887
+ mipmapBlur,
888
+ radius,
889
+ levels,
890
+ resolutionScale,
891
+ resolutionX,
892
+ resolutionY
893
+ ]);
894
+ return /* @__PURE__ */ jsx(BloomImpl, {
895
+ blendFunction,
896
+ args,
897
+ ...liveProps
898
+ });
899
+ }
900
+ //#endregion
901
+ //#region src/effects/BrightnessContrast.tsx
902
+ var BrightnessContrast = /* @__PURE__ */ createEffectComponent(BrightnessContrastEffect);
903
+ //#endregion
904
+ //#region src/effects/ChromaticAberration.tsx
905
+ var ChromaticAberration = /* @__PURE__ */ createEffectComponent(ChromaticAberrationEffect);
906
+ //#endregion
907
+ //#region src/effects/ColorAverage.tsx
908
+ var ColorAverage = /* @__PURE__ */ createEffectComponent(ColorAverageEffect);
909
+ //#endregion
910
+ //#region src/effects/ColorDepth.tsx
911
+ var ColorDepthImpl = /* @__PURE__ */ createEffectComponent(ColorDepthEffect);
912
+ function ColorDepth({ bits, ...props }) {
913
+ if (bits !== void 0) props.bitDepth = bits;
914
+ return /* @__PURE__ */ jsx(ColorDepthImpl, { ...props });
915
+ }
916
+ //#endregion
917
+ //#region src/effects/Depth.tsx
918
+ var Depth = /* @__PURE__ */ createEffectComponent(DepthEffect);
919
+ //#endregion
920
+ //#region src/effects/DotScreen.tsx
921
+ var DotScreen = /* @__PURE__ */ createEffectComponent(DotScreenEffect);
922
+ //#endregion
923
+ //#region src/effects/FXAA.tsx
924
+ var FXAA = /* @__PURE__ */ createEffectComponent(FXAAEffect);
925
+ //#endregion
926
+ //#region src/effects/Glitch.tsx
927
+ var GlitchImpl = /* @__PURE__ */ createEffectComponent(GlitchEffect);
928
+ function Glitch({ active = true, mode = GlitchMode.SPORADIC, dtSize, ...props }) {
929
+ const args = useMemo(() => [{ dtSize }], [dtSize]);
930
+ return /* @__PURE__ */ jsx(GlitchImpl, {
931
+ args,
932
+ mode: active ? mode : GlitchMode.DISABLED,
933
+ ...props
934
+ });
935
+ }
936
+ //#endregion
937
+ //#region src/effects/GodRays.tsx
938
+ var LIVE_KEYS$5 = [
939
+ "blendMode-blendFunction",
940
+ "godRaysMaterial-density",
941
+ "godRaysMaterial-decay",
942
+ "godRaysMaterial-weight",
943
+ "godRaysMaterial-exposure",
944
+ "clampMax",
945
+ "blur",
946
+ "kernelSize",
947
+ "samples",
948
+ "width",
949
+ "height"
950
+ ];
951
+ function get$1(effect, key) {
952
+ return key === "clampMax" ? effect.godRaysMaterial.maxIntensity : readPierced(effect, key);
953
+ }
954
+ function set$2(effect, key, value) {
955
+ if (key === "clampMax") effect.godRaysMaterial.maxIntensity = value;
956
+ else applyPierced(effect, key, value);
957
+ }
958
+ function GodRays({ sun, blendFunction, density, decay, weight, exposure, clampMax, blur, kernelSize, samples, width, height, resolutionScale, resolutionX, resolutionY, ref }) {
959
+ const { camera, autoClear } = use(EffectComposerContext);
960
+ const invalidate = useThree((state) => state.invalidate);
961
+ const effect = useMemo(() => new GodRaysEffect(camera, resolveRef(sun), {
962
+ resolutionScale,
963
+ resolutionX,
964
+ resolutionY
965
+ }), [
966
+ camera,
967
+ resolutionScale,
968
+ resolutionX,
969
+ resolutionY
970
+ ]);
971
+ useEffect(() => {
972
+ if (autoClear !== false) console.warn("GodRays renders an internal extra pass that needs <EffectComposer autoClear={false}> - without it, occlusion by other objects will look wrong.");
973
+ }, [autoClear]);
974
+ useLayoutEffect(() => {
975
+ effect.lightSource = resolveRef(sun);
976
+ invalidate();
977
+ }, [
978
+ effect,
979
+ sun,
980
+ invalidate
981
+ ]);
982
+ useLiveDefaults(effect, {
983
+ "blendMode-blendFunction": blendFunction,
984
+ "godRaysMaterial-density": density,
985
+ "godRaysMaterial-decay": decay,
986
+ "godRaysMaterial-weight": weight,
987
+ "godRaysMaterial-exposure": exposure,
988
+ clampMax,
989
+ blur,
990
+ kernelSize,
991
+ samples,
992
+ width,
993
+ height
994
+ }, LIVE_KEYS$5, get$1, set$2);
995
+ useDispose(effect);
996
+ return /* @__PURE__ */ jsx("primitive", {
997
+ ref,
998
+ object: effect
999
+ });
1000
+ }
1001
+ //#endregion
1002
+ //#region src/effects/Grid.tsx
1003
+ var GridImpl = /* @__PURE__ */ createEffectComponent(GridEffect);
1004
+ function Grid({ size, ref, ...props }) {
1005
+ const invalidate = useThree((state) => state.invalidate);
1006
+ const localRef = useRef(null);
1007
+ useImperativeHandle(ref, () => localRef.current, []);
1008
+ useLayoutEffect(() => {
1009
+ if (size) {
1010
+ localRef.current?.setSize(size.width, size.height);
1011
+ invalidate();
1012
+ }
1013
+ }, [size, invalidate]);
1014
+ return /* @__PURE__ */ jsx(GridImpl, {
1015
+ ref: localRef,
1016
+ ...props
1017
+ });
1018
+ }
1019
+ //#endregion
1020
+ //#region src/effects/HueSaturation.tsx
1021
+ var HueSaturation = /* @__PURE__ */ createEffectComponent(HueSaturationEffect);
1022
+ //#endregion
1023
+ //#region src/effects/LensFlare.tsx
1024
+ var LensFlareShader = { fragmentShader: `
2
1025
  uniform float time;
3
1026
  uniform vec2 lensPosition;
4
1027
  uniform vec2 screenRes;
@@ -382,7 +1405,312 @@ import{jsx as w,jsxs as K,Fragment as Q}from"react/jsx-runtime";import ee,{creat
382
1405
  outputColor = vec4(inputColor);
383
1406
  }
384
1407
  }
385
- `};class fe extends W{constructor({blendFunction:t,enabled:o,glareSize:r,lensPosition:a,screenRes:n,starPoints:i,flareSize:s,flareSpeed:l,flareShape:p,animated:_,anamorphic:S,colorGain:g,lensDirtTexture:d,haloScale:m,secondaryGhosts:v,aditionalStreaks:x,ghostScale:f,opacity:u,starBurst:c}){super("LensFlareEffect",_t.fragmentShader,{blendFunction:t,uniforms:/*@__PURE__*/new Map([["enabled",new h.Uniform(o)],["glareSize",new h.Uniform(r)],["lensPosition",new h.Uniform(a)],["time",new h.Uniform(0)],["screenRes",new h.Uniform(n)],["starPoints",new h.Uniform(i)],["flareSize",new h.Uniform(s)],["flareSpeed",new h.Uniform(l)],["flareShape",new h.Uniform(p)],["animated",new h.Uniform(_)],["anamorphic",new h.Uniform(S)],["colorGain",new h.Uniform(g)],["lensDirtTexture",new h.Uniform(d)],["haloScale",new h.Uniform(m)],["secondaryGhosts",new h.Uniform(v)],["aditionalStreaks",new h.Uniform(x)],["ghostScale",new h.Uniform(f)],["starBurst",new h.Uniform(c)],["opacity",new h.Uniform(u)]])})}update(t,o,r){const a=this.uniforms.get("time");a&&(a.value+=r)}}const xt=/*@__PURE__*/P(fe),gt=({smoothTime:e=.07,blendFunction:t=23,enabled:o=!0,glareSize:r=.2,lensPosition:a=new h.Vector3(-25,6,-60),screenRes:n=new h.Vector2(0,0),starPoints:i=6,flareSize:s=.01,flareSpeed:l=.01,flareShape:p=.01,animated:_=!0,anamorphic:S=!1,colorGain:g=new h.Color(20,20,20),lensDirtTexture:d=null,haloScale:m=.5,secondaryGhosts:v=!0,aditionalStreaks:x=!0,ghostScale:f=0,opacity:u=1,starBurst:c=!1})=>{const U=V(({viewport:T})=>T),b=V(({raycaster:T})=>T),{scene:F,camera:X}=M(D),[C]=j(()=>new h.Vector2),[R]=j(()=>new h.Vector3),E=O(null);return J((T,N)=>{if(!E?.current)return;const q=E.current.uniforms.get("lensPosition"),$=E.current.uniforms.get("opacity");if(!q||!$)return;let G=1;if(R.copy(a).project(X),R.z>1)return;q.value.x=R.x,q.value.y=R.y,C.x=R.x,C.y=R.y,b.setFromCamera(C,X);const ve=b.intersectObjects(F.children,!0),{object:I}=ve[0]||{};I&&(I.userData?.lensflare==="no-occlusion"?G=0:I instanceof h.Mesh&&(I.material.uniforms?._transmission?.value>.2||I.material._transmission&&I.material._transmission>.2?G=.2:I.material.transparent&&(G=I.material.opacity))),se.damp($,"value",G,e,N)}),A(()=>{if(!E?.current)return;const T=E.current.uniforms.get("screenRes");T&&(T.value.x=U.width,T.value.y=U.height)},[U]),/*@__PURE__*/w(xt,{ref:E,blendFunction:t,enabled:o,glareSize:r,lensPosition:a,screenRes:n,starPoints:i,flareSize:s,flareSpeed:l,flareShape:p,animated:_,anamorphic:S,colorGain:g,lensDirtTexture:d,haloScale:m,secondaryGhosts:v,aditionalStreaks:x,ghostScale:f,opacity:u,starBurst:c})},wt=/*@__PURE__*/P(Ie,{blendFunction:0}),St=/*@__PURE__*/P(Le),yt=/*@__PURE__*/P(Ne),Pt=/*@__PURE__*/B(function({blendFunction:e=23},t){const o=z(()=>new je(e),[e]);return /*@__PURE__*/w("primitive",{ref:t,object:o,dispose:null})}),bt=/*@__PURE__*/P(Oe),Et=/*@__PURE__*/P(We),Rt=/*@__PURE__*/P(Xe),Ut=/*@__PURE__*/B(function({active:e=!0,...t},o){const r=V(p=>p.invalidate),a=Z(t,"delay"),n=Z(t,"duration"),i=Z(t,"strength"),s=Z(t,"chromaticAberrationOffset"),l=z(()=>new qe({...t,delay:a,duration:n,strength:i,chromaticAberrationOffset:s}),[a,n,t,i,s]);return L(()=>{l.mode=e?t.mode||ne.SPORADIC:ne.DISABLED,r()},[e,l,r,t.mode]),A(()=>()=>{l.dispose?.()},[l]),/*@__PURE__*/w("primitive",{ref:o,object:l,dispose:null})}),Ct=/*@__PURE__*/B(function(e,t){const{camera:o}=M(D),r=z(()=>new He(o,k(e.sun),e),[o,e]);return L(()=>void(r.lightSource=k(e.sun)),[r,e.sun]),/*@__PURE__*/w("primitive",{ref:t,object:r,dispose:null})}),zt=/*@__PURE__*/B(function({size:e,...t},o){const r=V(n=>n.invalidate),a=z(()=>new Ze(t),[t]);return L(()=>{e&&a.setSize(e.width,e.height),r()},[a,e,r]),/*@__PURE__*/w("primitive",{ref:o,object:a,dispose:null})}),Tt=/*@__PURE__*/P($e),At=/*@__PURE__*/P(Ke,{blendFunction:5}),Bt=/*@__PURE__*/B(function({selection:e=[],selectionLayer:t=10,blendFunction:o,patternTexture:r,edgeStrength:a,pulseSpeed:n,visibleEdgeColor:i,hiddenEdgeColor:s,width:l,height:p,kernelSize:_,blur:S,xRay:g,...d},m){const v=V(U=>U.invalidate),{scene:x,camera:f}=M(D),u=z(()=>new Ye(x,f,{blendFunction:o,patternTexture:r,edgeStrength:a,pulseSpeed:n,visibleEdgeColor:i,hiddenEdgeColor:s,width:l,height:p,kernelSize:_,blur:S,xRay:g,...d}),[o,S,f,a,p,s,_,r,n,x,i,l,g]),c=M(H);return A(()=>{if(!c&&e)return u.selection.set(Array.isArray(e)?e.map(k):[k(e)]),v(),()=>{u.selection.clear(),v()}},[u,e,c,v]),A(()=>{u.selectionLayer=t,v()},[u,v,t]),O(void 0),A(()=>{if(c&&c.enabled&&c.selected?.length)return u.selection.set(c.selected),v(),()=>{u.selection.clear(),v()}},[c,u.selection,v]),A(()=>()=>{u.dispose()},[u]),/*@__PURE__*/w("primitive",{ref:m,object:u})}),Vt=/*@__PURE__*/B(function({granularity:e=5},t){const o=z(()=>new Je(e),[e]);return /*@__PURE__*/w("primitive",{ref:t,object:o,dispose:null})}),Ft=/*@__PURE__*/P(Qe,{blendFunction:24,density:1.25}),Mt=(e,t)=>e.layers.enable(t.selection.layer),Dt=(e,t)=>e.layers.disable(t.selection.layer),kt=/*@__PURE__*/B(function({selection:e=[],selectionLayer:t=10,lights:o=[],inverted:r=!1,ignoreBackground:a=!1,luminanceThreshold:n,luminanceSmoothing:i,intensity:s,width:l,height:p,kernelSize:_,mipmapBlur:S,...g},d){o.length===0&&console.warn("SelectiveBloom requires lights to work.");const m=V(c=>c.invalidate),{scene:v,camera:x}=M(D),f=z(()=>{const c=new et(v,x,{blendFunction:0,luminanceThreshold:n,luminanceSmoothing:i,intensity:s,width:l,height:p,kernelSize:_,mipmapBlur:S,...g});return c.inverted=r,c.ignoreBackground=a,c},[v,x,n,i,s,l,p,_,S,r,a,g]),u=M(H);return A(()=>{if(!u&&e)return f.selection.set(Array.isArray(e)?e.map(k):[k(e)]),m(),()=>{f.selection.clear(),m()}},[f,e,u,m]),A(()=>{f.selection.layer=t,m()},[f,m,t]),A(()=>{if(o&&o.length>0)return o.forEach(c=>Mt(k(c),f)),m(),()=>{o.forEach(c=>Dt(k(c),f)),m()}},[f,m,o,t]),A(()=>{if(u&&u.enabled&&u.selected?.length)return f.selection.set(u.selected),m(),()=>{f.selection.clear(),m()}},[u,f.selection,m]),/*@__PURE__*/w("primitive",{ref:d,object:f,dispose:null})}),Gt=/*@__PURE__*/P(tt),It=/*@__PURE__*/B(function(e,t){const{camera:o,normalPass:r,downSamplingPass:a,resolutionScale:n}=M(D),i=z(()=>r===null&&a===null?(console.error("Please enable the NormalPass in the EffectComposer in order to use SSAO."),{}):new ot(o,r&&!a?r.texture:null,{blendFunction:21,samples:30,rings:4,distanceThreshold:1,distanceFalloff:0,rangeThreshold:.5,rangeFalloff:.1,luminanceInfluence:.9,radius:20,bias:.5,intensity:1,color:void 0,normalDepthBuffer:a?a.texture:null,resolutionScale:n??1,depthAwareUpsampling:!0,...e}),[o,a,r,n]);return /*@__PURE__*/w("primitive",{ref:t,object:i,dispose:null})}),Lt=/*@__PURE__*/P(at),Nt=/*@__PURE__*/P(rt),jt={fragmentShader:`
1408
+ ` };
1409
+ var LensFlareEffect = class extends Effect {
1410
+ constructor({ blendFunction = 23, enabled = true, glareSize = .2, lensPosition = new Vector3(-25, 6, -60), screenRes = new Vector2(0, 0), starPoints = 6, flareSize = .01, flareSpeed = .01, flareShape = .01, animated = true, anamorphic = false, colorGain = new Color(20, 20, 20), lensDirtTexture = null, haloScale = .5, secondaryGhosts = true, aditionalStreaks = true, ghostScale = 0, opacity = 1, starBurst = false } = {}) {
1411
+ super("LensFlareEffect", LensFlareShader.fragmentShader, {
1412
+ blendFunction,
1413
+ uniforms: /* @__PURE__ */ new Map([
1414
+ ["enabled", new Uniform(enabled)],
1415
+ ["glareSize", new Uniform(glareSize)],
1416
+ ["lensPosition", new Uniform(lensPosition)],
1417
+ ["time", new Uniform(0)],
1418
+ ["screenRes", new Uniform(screenRes)],
1419
+ ["starPoints", new Uniform(starPoints)],
1420
+ ["flareSize", new Uniform(flareSize)],
1421
+ ["flareSpeed", new Uniform(flareSpeed)],
1422
+ ["flareShape", new Uniform(flareShape)],
1423
+ ["animated", new Uniform(animated)],
1424
+ ["anamorphic", new Uniform(anamorphic)],
1425
+ ["colorGain", new Uniform(colorGain)],
1426
+ ["lensDirtTexture", new Uniform(lensDirtTexture)],
1427
+ ["haloScale", new Uniform(haloScale)],
1428
+ ["secondaryGhosts", new Uniform(secondaryGhosts)],
1429
+ ["aditionalStreaks", new Uniform(aditionalStreaks)],
1430
+ ["ghostScale", new Uniform(ghostScale)],
1431
+ ["starBurst", new Uniform(starBurst)],
1432
+ ["opacity", new Uniform(opacity)]
1433
+ ])
1434
+ });
1435
+ }
1436
+ update(_renderer, _inputBuffer, deltaTime) {
1437
+ const time = this.uniforms.get("time");
1438
+ if (time) time.value += deltaTime;
1439
+ }
1440
+ u(name) {
1441
+ return this.uniforms.get(name).value;
1442
+ }
1443
+ setU(name, value) {
1444
+ this.uniforms.get(name).value = value;
1445
+ }
1446
+ get enabled() {
1447
+ return this.u("enabled");
1448
+ }
1449
+ set enabled(value) {
1450
+ this.setU("enabled", value);
1451
+ }
1452
+ get glareSize() {
1453
+ return this.u("glareSize");
1454
+ }
1455
+ set glareSize(value) {
1456
+ this.setU("glareSize", value);
1457
+ }
1458
+ get lensPosition() {
1459
+ return this.u("lensPosition");
1460
+ }
1461
+ set lensPosition(value) {
1462
+ this.setU("lensPosition", value);
1463
+ }
1464
+ get screenRes() {
1465
+ return this.u("screenRes");
1466
+ }
1467
+ set screenRes(value) {
1468
+ this.setU("screenRes", value);
1469
+ }
1470
+ get starPoints() {
1471
+ return this.u("starPoints");
1472
+ }
1473
+ set starPoints(value) {
1474
+ this.setU("starPoints", value);
1475
+ }
1476
+ get flareSize() {
1477
+ return this.u("flareSize");
1478
+ }
1479
+ set flareSize(value) {
1480
+ this.setU("flareSize", value);
1481
+ }
1482
+ get flareSpeed() {
1483
+ return this.u("flareSpeed");
1484
+ }
1485
+ set flareSpeed(value) {
1486
+ this.setU("flareSpeed", value);
1487
+ }
1488
+ get flareShape() {
1489
+ return this.u("flareShape");
1490
+ }
1491
+ set flareShape(value) {
1492
+ this.setU("flareShape", value);
1493
+ }
1494
+ get animated() {
1495
+ return this.u("animated");
1496
+ }
1497
+ set animated(value) {
1498
+ this.setU("animated", value);
1499
+ }
1500
+ get anamorphic() {
1501
+ return this.u("anamorphic");
1502
+ }
1503
+ set anamorphic(value) {
1504
+ this.setU("anamorphic", value);
1505
+ }
1506
+ get colorGain() {
1507
+ return this.u("colorGain");
1508
+ }
1509
+ set colorGain(value) {
1510
+ this.setU("colorGain", value);
1511
+ }
1512
+ get lensDirtTexture() {
1513
+ return this.u("lensDirtTexture");
1514
+ }
1515
+ set lensDirtTexture(value) {
1516
+ this.setU("lensDirtTexture", value);
1517
+ }
1518
+ get haloScale() {
1519
+ return this.u("haloScale");
1520
+ }
1521
+ set haloScale(value) {
1522
+ this.setU("haloScale", value);
1523
+ }
1524
+ get secondaryGhosts() {
1525
+ return this.u("secondaryGhosts");
1526
+ }
1527
+ set secondaryGhosts(value) {
1528
+ this.setU("secondaryGhosts", value);
1529
+ }
1530
+ get aditionalStreaks() {
1531
+ return this.u("aditionalStreaks");
1532
+ }
1533
+ set aditionalStreaks(value) {
1534
+ this.setU("aditionalStreaks", value);
1535
+ }
1536
+ get ghostScale() {
1537
+ return this.u("ghostScale");
1538
+ }
1539
+ set ghostScale(value) {
1540
+ this.setU("ghostScale", value);
1541
+ }
1542
+ get starBurst() {
1543
+ return this.u("starBurst");
1544
+ }
1545
+ set starBurst(value) {
1546
+ this.setU("starBurst", value);
1547
+ }
1548
+ get opacity() {
1549
+ return this.u("opacity");
1550
+ }
1551
+ set opacity(value) {
1552
+ this.setU("opacity", value);
1553
+ }
1554
+ };
1555
+ var LensFlareWrapped = /* @__PURE__ */ createEffectComponent(LensFlareEffect);
1556
+ var DEFAULT_SCREEN_RES = /* @__PURE__ */ new Vector2(0, 0);
1557
+ var DEFAULT_LENS_POSITION = /* @__PURE__ */ new Vector3(-25, 6, -60);
1558
+ var LensFlare = (props) => {
1559
+ const { ref: forwardedRef, smoothTime = .07, blendFunction = 23, enabled = true, glareSize = .2, screenRes, starPoints = 6, flareSize = .01, flareSpeed = .01, flareShape = .01, animated = true, anamorphic = false, colorGain = new Color(20, 20, 20), lensDirtTexture = null, haloScale = .5, secondaryGhosts = true, aditionalStreaks = true, ghostScale = 0, opacity = 1, starBurst = false } = props;
1560
+ const lensPosition = useVector3({ lensPosition: props.lensPosition ?? DEFAULT_LENS_POSITION }, "lensPosition");
1561
+ const viewport = useThree(({ viewport }) => viewport);
1562
+ const raycaster = useThree(({ raycaster }) => raycaster);
1563
+ const { scene, camera } = useContext(EffectComposerContext);
1564
+ const [raycasterPos] = useState(() => new Vector2());
1565
+ const [projectedPosition] = useState(() => new Vector3());
1566
+ const ref = useRef(null);
1567
+ const setRef = useMergeRefs(ref, forwardedRef);
1568
+ useFrame((_, delta) => {
1569
+ if (!ref?.current) return;
1570
+ const uLensPosition = ref.current.uniforms.get("lensPosition");
1571
+ const uOpacity = ref.current.uniforms.get("opacity");
1572
+ if (!uLensPosition || !uOpacity) return;
1573
+ let target = 0;
1574
+ projectedPosition.copy(lensPosition).project(camera);
1575
+ if (projectedPosition.z > 1) return;
1576
+ uLensPosition.value.x = projectedPosition.x;
1577
+ uLensPosition.value.y = projectedPosition.y;
1578
+ raycasterPos.x = projectedPosition.x;
1579
+ raycasterPos.y = projectedPosition.y;
1580
+ raycaster.setFromCamera(raycasterPos, camera);
1581
+ const { object } = raycaster.intersectObjects(scene.children, true)[0] || {};
1582
+ if (object) {
1583
+ target = 1;
1584
+ if (object.userData?.lensflare === "no-occlusion") target = 0;
1585
+ else if (object instanceof Mesh) {
1586
+ if (object.material.uniforms?._transmission?.value > .2) target = .2;
1587
+ else if (object.material._transmission && object.material._transmission > .2) target = .2;
1588
+ else if (object.material.transparent) target = object.material.opacity;
1589
+ }
1590
+ }
1591
+ easing.damp(uOpacity, "value", target, smoothTime, delta);
1592
+ });
1593
+ useEffect(() => {
1594
+ if (!ref?.current) return;
1595
+ const screenRes = ref.current.uniforms.get("screenRes");
1596
+ if (screenRes) {
1597
+ screenRes.value.x = viewport.width;
1598
+ screenRes.value.y = viewport.height;
1599
+ }
1600
+ }, [viewport]);
1601
+ return /* @__PURE__ */ jsx(LensFlareWrapped, {
1602
+ ref: setRef,
1603
+ blendFunction,
1604
+ enabled,
1605
+ glareSize,
1606
+ lensPosition,
1607
+ screenRes: screenRes ?? DEFAULT_SCREEN_RES,
1608
+ starPoints,
1609
+ flareSize,
1610
+ flareSpeed,
1611
+ flareShape,
1612
+ animated,
1613
+ anamorphic,
1614
+ colorGain,
1615
+ lensDirtTexture,
1616
+ haloScale,
1617
+ secondaryGhosts,
1618
+ aditionalStreaks,
1619
+ ghostScale,
1620
+ opacity,
1621
+ starBurst
1622
+ });
1623
+ };
1624
+ //#endregion
1625
+ //#region src/effects/LUT.tsx
1626
+ var LIVE_KEYS$4 = [
1627
+ "blendMode-blendFunction",
1628
+ "lut",
1629
+ "tetrahedralInterpolation"
1630
+ ];
1631
+ function LUT({ lut, blendFunction, tetrahedralInterpolation, ref }) {
1632
+ const effect = useMemo(() => new LUT3DEffect(lut), []);
1633
+ useLiveDefaults(effect, {
1634
+ "blendMode-blendFunction": blendFunction,
1635
+ lut,
1636
+ tetrahedralInterpolation
1637
+ }, LIVE_KEYS$4);
1638
+ useDispose(effect);
1639
+ return /* @__PURE__ */ jsx("primitive", {
1640
+ ref,
1641
+ object: effect
1642
+ });
1643
+ }
1644
+ //#endregion
1645
+ //#region src/effects/Noise.tsx
1646
+ var NoiseImpl = /* @__PURE__ */ createEffectComponent(NoiseEffect);
1647
+ function Noise({ blendFunction = 5, ...props }) {
1648
+ return /* @__PURE__ */ jsx(NoiseImpl, {
1649
+ blendFunction,
1650
+ ...props
1651
+ });
1652
+ }
1653
+ //#endregion
1654
+ //#region src/effects/Outline.tsx
1655
+ var LIVE_KEYS$3 = [
1656
+ "patternTexture",
1657
+ "patternScale",
1658
+ "edgeStrength",
1659
+ "pulseSpeed",
1660
+ "visibleEdgeColor",
1661
+ "hiddenEdgeColor",
1662
+ "multisampling",
1663
+ "width",
1664
+ "height",
1665
+ "kernelSize",
1666
+ "blur",
1667
+ "xRay",
1668
+ "dithering",
1669
+ "blendMode-blendFunction"
1670
+ ];
1671
+ function set$1(effect, key, value) {
1672
+ if (key === "visibleEdgeColor" || key === "hiddenEdgeColor") applyPierced(effect, key, new Color(value));
1673
+ else applyPierced(effect, key, value);
1674
+ }
1675
+ function Outline({ selection = EMPTY_ARRAY, selectionLayer = 10, blendFunction, resolutionScale, resolutionX, resolutionY, ref, ...liveProps }) {
1676
+ const { scene, camera, autoClear } = use(EffectComposerContext);
1677
+ const effect = useMemo(() => new OutlineEffect(scene, camera, {
1678
+ resolutionScale,
1679
+ resolutionX,
1680
+ resolutionY
1681
+ }), [
1682
+ scene,
1683
+ camera,
1684
+ resolutionScale,
1685
+ resolutionX,
1686
+ resolutionY
1687
+ ]);
1688
+ useEffect(() => {
1689
+ if (autoClear !== false) console.warn("Outline requires <EffectComposer autoClear={false}> to render correctly.");
1690
+ }, [autoClear]);
1691
+ useLiveDefaults(effect, {
1692
+ ...liveProps,
1693
+ "blendMode-blendFunction": blendFunction
1694
+ }, LIVE_KEYS$3, readPierced, set$1);
1695
+ useSelectionSync(effect, selection, selectionLayer);
1696
+ useDispose(effect);
1697
+ return /* @__PURE__ */ jsx("primitive", {
1698
+ ref,
1699
+ object: effect
1700
+ });
1701
+ }
1702
+ //#endregion
1703
+ //#region src/effects/Pixelation.tsx
1704
+ var PixelationImpl = /* @__PURE__ */ createEffectComponent(PixelationEffect);
1705
+ function Pixelation({ granularity = 5, ref }) {
1706
+ return /* @__PURE__ */ jsx(PixelationImpl, {
1707
+ granularity,
1708
+ ref
1709
+ });
1710
+ }
1711
+ //#endregion
1712
+ //#region src/effects/Ramp.tsx
1713
+ var RampShader = { fragmentShader: `
386
1714
  uniform int rampType;
387
1715
 
388
1716
  uniform vec2 rampStart;
@@ -442,7 +1770,354 @@ import{jsx as w,jsxs as K,Fragment as Q}from"react/jsx-runtime";import ee,{creat
442
1770
  outputColor = mix(startColor, endColor, rampAlpha);
443
1771
  }
444
1772
  }
445
- `};var ue=/*@__PURE__*/(e=>(e[e.Linear=0]="Linear",e[e.Radial=1]="Radial",e[e.MirroredLinear=2]="MirroredLinear",e))(ue||{});class pe extends W{constructor({rampType:t=0,rampStart:o=[.5,.5],rampEnd:r=[1,1],startColor:a=[0,0,0,1],endColor:n=[1,1,1,1],rampBias:i=.5,rampGain:s=.5,rampMask:l=!1,rampInvert:p=!1,..._}={}){super("RampEffect",jt.fragmentShader,{..._,uniforms:/*@__PURE__*/new Map([["rampType",new y(t)],["rampStart",new y(o)],["rampEnd",new y(r)],["startColor",new y(a)],["endColor",new y(n)],["rampBias",new y(i)],["rampGain",new y(s)],["rampMask",new y(l)],["rampInvert",new y(p)]])})}}const Ot=/*@__PURE__*/P(pe),Wt=/*@__PURE__*/B(function({textureSrc:e,texture:t,opacity:o=1,...r},a){const n=Ue(we,e);L(()=>{n.colorSpace=Se,n.wrapS=n.wrapT=Y},[n]);const i=z(()=>new nt({...r,texture:n||t}),[r,n,t]);return /*@__PURE__*/w("primitive",{ref:a,object:i,"blendMode-opacity-value":o,dispose:null})}),Xt=/*@__PURE__*/P(st),qt=/*@__PURE__*/P(it),Ht=/*@__PURE__*/P(lt),Zt=/*@__PURE__*/B(function({lut:e,tetrahedralInterpolation:t,...o},r){const a=z(()=>new ct(e,o),[e,o]),n=V(i=>i.invalidate);return L(()=>{t&&(a.tetrahedralInterpolation=t),e&&(a.lut=e),n()},[a,n,e,t]),/*@__PURE__*/w("primitive",{ref:r,object:a,dispose:null})}),$t=/*@__PURE__*/P(ft,{blendFunction:0}),Kt={fragmentShader:`
1773
+ ` };
1774
+ var RampType = /* @__PURE__ */ function(RampType) {
1775
+ RampType[RampType["Linear"] = 0] = "Linear";
1776
+ RampType[RampType["Radial"] = 1] = "Radial";
1777
+ RampType[RampType["MirroredLinear"] = 2] = "MirroredLinear";
1778
+ return RampType;
1779
+ }({});
1780
+ var RampEffect = class extends Effect {
1781
+ constructor({ rampType = 0, rampStart = [.5, .5], rampEnd = [1, 1], startColor = [
1782
+ 0,
1783
+ 0,
1784
+ 0,
1785
+ 1
1786
+ ], endColor = [
1787
+ 1,
1788
+ 1,
1789
+ 1,
1790
+ 1
1791
+ ], rampBias = .5, rampGain = .5, rampMask = false, rampInvert = false, ...params } = {}) {
1792
+ super("RampEffect", RampShader.fragmentShader, {
1793
+ ...params,
1794
+ uniforms: /* @__PURE__ */ new Map([
1795
+ ["rampType", new Uniform(rampType)],
1796
+ ["rampStart", new Uniform(rampStart)],
1797
+ ["rampEnd", new Uniform(rampEnd)],
1798
+ ["startColor", new Uniform(startColor)],
1799
+ ["endColor", new Uniform(endColor)],
1800
+ ["rampBias", new Uniform(rampBias)],
1801
+ ["rampGain", new Uniform(rampGain)],
1802
+ ["rampMask", new Uniform(rampMask)],
1803
+ ["rampInvert", new Uniform(rampInvert)]
1804
+ ])
1805
+ });
1806
+ }
1807
+ u(name) {
1808
+ return this.uniforms.get(name).value;
1809
+ }
1810
+ setU(name, value) {
1811
+ this.uniforms.get(name).value = value;
1812
+ }
1813
+ get rampType() {
1814
+ return this.u("rampType");
1815
+ }
1816
+ set rampType(value) {
1817
+ this.setU("rampType", value);
1818
+ }
1819
+ get rampStart() {
1820
+ return this.u("rampStart");
1821
+ }
1822
+ set rampStart(value) {
1823
+ this.setU("rampStart", value);
1824
+ }
1825
+ get rampEnd() {
1826
+ return this.u("rampEnd");
1827
+ }
1828
+ set rampEnd(value) {
1829
+ this.setU("rampEnd", value);
1830
+ }
1831
+ get startColor() {
1832
+ return this.u("startColor");
1833
+ }
1834
+ set startColor(value) {
1835
+ this.setU("startColor", value);
1836
+ }
1837
+ get endColor() {
1838
+ return this.u("endColor");
1839
+ }
1840
+ set endColor(value) {
1841
+ this.setU("endColor", value);
1842
+ }
1843
+ get rampBias() {
1844
+ return this.u("rampBias");
1845
+ }
1846
+ set rampBias(value) {
1847
+ this.setU("rampBias", value);
1848
+ }
1849
+ get rampGain() {
1850
+ return this.u("rampGain");
1851
+ }
1852
+ set rampGain(value) {
1853
+ this.setU("rampGain", value);
1854
+ }
1855
+ get rampMask() {
1856
+ return this.u("rampMask");
1857
+ }
1858
+ set rampMask(value) {
1859
+ this.setU("rampMask", value);
1860
+ }
1861
+ get rampInvert() {
1862
+ return this.u("rampInvert");
1863
+ }
1864
+ set rampInvert(value) {
1865
+ this.setU("rampInvert", value);
1866
+ }
1867
+ };
1868
+ var Ramp = /* @__PURE__ */ createEffectComponent(RampEffect);
1869
+ //#endregion
1870
+ //#region src/effects/ScanlineEffect.tsx
1871
+ var Scanline = /* @__PURE__ */ createEffectComponent(ScanlineEffect);
1872
+ //#endregion
1873
+ //#region src/effects/SelectiveBloom.tsx
1874
+ var addLight = (light, effect) => light.layers.enable(effect.selection.layer);
1875
+ var removeLight = (light, effect) => light.layers.disable(effect.selection.layer);
1876
+ var LIVE_KEYS$2 = [
1877
+ "width",
1878
+ "height",
1879
+ "kernelSize",
1880
+ "intensity",
1881
+ "inverted",
1882
+ "ignoreBackground"
1883
+ ];
1884
+ function SelectiveBloom({ selection = EMPTY_ARRAY, selectionLayer = 10, lights = EMPTY_ARRAY, luminanceThreshold, luminanceSmoothing, mipmapBlur, radius, levels, resolutionScale, resolutionX, resolutionY, ref, ...liveProps }) {
1885
+ const { scene, camera } = use(EffectComposerContext);
1886
+ const invalidate = useThree((state) => state.invalidate);
1887
+ const effect = useMemo(() => new SelectiveBloomEffect(scene, camera, {
1888
+ blendFunction: 0,
1889
+ luminanceThreshold,
1890
+ luminanceSmoothing,
1891
+ mipmapBlur,
1892
+ radius,
1893
+ levels,
1894
+ resolutionScale,
1895
+ resolutionX,
1896
+ resolutionY
1897
+ }), [
1898
+ scene,
1899
+ camera,
1900
+ luminanceThreshold,
1901
+ luminanceSmoothing,
1902
+ mipmapBlur,
1903
+ radius,
1904
+ levels,
1905
+ resolutionScale,
1906
+ resolutionX,
1907
+ resolutionY
1908
+ ]);
1909
+ useLiveDefaults(effect, liveProps, LIVE_KEYS$2);
1910
+ useSelectionSync(effect, selection, selectionLayer);
1911
+ useEffect(() => {
1912
+ if (lights.length === 0) {
1913
+ console.warn("SelectiveBloom requires lights to work.");
1914
+ return;
1915
+ }
1916
+ const resolvedLights = lights.map((light) => resolveRef(light)).filter((light) => light != null);
1917
+ if (resolvedLights.length === 0) return;
1918
+ resolvedLights.forEach((light) => addLight(light, effect));
1919
+ invalidate();
1920
+ return () => {
1921
+ resolvedLights.forEach((light) => removeLight(light, effect));
1922
+ invalidate();
1923
+ };
1924
+ }, [
1925
+ effect,
1926
+ invalidate,
1927
+ lights,
1928
+ selectionLayer
1929
+ ]);
1930
+ useDispose(effect);
1931
+ return /* @__PURE__ */ jsx("primitive", {
1932
+ ref,
1933
+ object: effect
1934
+ });
1935
+ }
1936
+ //#endregion
1937
+ //#region src/effects/Sepia.tsx
1938
+ var Sepia = /* @__PURE__ */ createEffectComponent(SepiaEffect);
1939
+ //#endregion
1940
+ //#region src/effects/ShockWave.tsx
1941
+ var LIVE_KEYS$1 = [
1942
+ "position",
1943
+ "speed",
1944
+ "maxRadius",
1945
+ "waveSize",
1946
+ "amplitude"
1947
+ ];
1948
+ function ShockWave(props) {
1949
+ const { speed, maxRadius, waveSize, amplitude, ref } = props;
1950
+ const { camera } = use(EffectComposerContext);
1951
+ const effect = useMemo(() => new ShockWaveEffect(camera), [camera]);
1952
+ useLiveDefaults(effect, {
1953
+ position: useVector3(props, "position"),
1954
+ speed,
1955
+ maxRadius,
1956
+ waveSize,
1957
+ amplitude
1958
+ }, LIVE_KEYS$1);
1959
+ useDispose(effect);
1960
+ return /* @__PURE__ */ jsx("primitive", {
1961
+ ref,
1962
+ object: effect
1963
+ });
1964
+ }
1965
+ //#endregion
1966
+ //#region src/effects/SMAA.tsx
1967
+ var SMAAImpl = /* @__PURE__ */ createEffectComponent(SMAAEffect);
1968
+ function SMAA({ preset, edgeDetectionMode, predicationMode, ...liveProps }) {
1969
+ const args = useMemo(() => [{
1970
+ preset,
1971
+ edgeDetectionMode,
1972
+ predicationMode
1973
+ }], [
1974
+ preset,
1975
+ edgeDetectionMode,
1976
+ predicationMode
1977
+ ]);
1978
+ return /* @__PURE__ */ jsx(SMAAImpl, {
1979
+ args,
1980
+ ...liveProps
1981
+ });
1982
+ }
1983
+ //#endregion
1984
+ //#region src/effects/SSAO.tsx
1985
+ var LIVE_KEYS = [
1986
+ "blendMode-blendFunction",
1987
+ "normalBuffer",
1988
+ "samples",
1989
+ "rings",
1990
+ "radius",
1991
+ "depthAwareUpsampling",
1992
+ "color",
1993
+ "luminanceInfluence",
1994
+ "intensity",
1995
+ "ssaoMaterial-bias",
1996
+ "ssaoMaterial-fade",
1997
+ "ssaoMaterial-minRadiusScale",
1998
+ "ssaoMaterial-distanceThreshold",
1999
+ "ssaoMaterial-distanceFalloff",
2000
+ "ssaoMaterial-worldDistanceThreshold",
2001
+ "ssaoMaterial-worldDistanceFalloff",
2002
+ "rangeThreshold",
2003
+ "rangeFalloff",
2004
+ "ssaoMaterial-worldProximityThreshold",
2005
+ "ssaoMaterial-worldProximityFalloff"
2006
+ ];
2007
+ function get(effect, key) {
2008
+ if (key === "rangeThreshold") return effect.ssaoMaterial.proximityThreshold;
2009
+ if (key === "rangeFalloff") return effect.ssaoMaterial.proximityFalloff;
2010
+ return readPierced(effect, key);
2011
+ }
2012
+ function set(effect, key, value) {
2013
+ if (key === "rangeThreshold") effect.ssaoMaterial.proximityThreshold = value;
2014
+ else if (key === "rangeFalloff") effect.ssaoMaterial.proximityFalloff = value;
2015
+ else applyPierced(effect, key, value);
2016
+ }
2017
+ function SSAO({ blendFunction = 21, samples = 30, rings = 4, distanceThreshold = 1, distanceFalloff = 0, rangeThreshold = .5, rangeFalloff = .1, luminanceInfluence = .9, radius = 20, bias = .5, intensity = 1, color, worldDistanceThreshold, worldDistanceFalloff, worldProximityThreshold, worldProximityFalloff, minRadiusScale, fade, depthAwareUpsampling = true, resolutionScale, resolutionX, resolutionY, width, height, ref }) {
2018
+ const { camera, normalPass, downSamplingPass, resolutionScale: composerResolutionScale } = use(EffectComposerContext);
2019
+ const effect = useMemo(() => {
2020
+ if (normalPass === null && downSamplingPass === null) {
2021
+ console.error("Please enable the NormalPass in the EffectComposer in order to use SSAO.");
2022
+ return {};
2023
+ }
2024
+ return new SSAOEffect(camera, normalPass && !downSamplingPass ? normalPass.texture : null, {
2025
+ blendFunction,
2026
+ samples,
2027
+ rings,
2028
+ distanceThreshold,
2029
+ distanceFalloff,
2030
+ rangeThreshold,
2031
+ rangeFalloff,
2032
+ luminanceInfluence,
2033
+ radius,
2034
+ bias,
2035
+ intensity,
2036
+ normalDepthBuffer: downSamplingPass ? downSamplingPass.texture : null,
2037
+ resolutionScale: resolutionScale ?? composerResolutionScale ?? 1,
2038
+ resolutionX,
2039
+ resolutionY,
2040
+ width,
2041
+ height,
2042
+ depthAwareUpsampling
2043
+ });
2044
+ }, [
2045
+ camera,
2046
+ downSamplingPass,
2047
+ normalPass,
2048
+ resolutionScale,
2049
+ composerResolutionScale,
2050
+ resolutionX,
2051
+ resolutionY,
2052
+ width,
2053
+ height
2054
+ ]);
2055
+ useLiveDefaults(effect instanceof SSAOEffect ? effect : null, {
2056
+ "blendMode-blendFunction": blendFunction,
2057
+ samples,
2058
+ rings,
2059
+ radius,
2060
+ depthAwareUpsampling,
2061
+ color,
2062
+ luminanceInfluence,
2063
+ intensity,
2064
+ "ssaoMaterial-bias": bias,
2065
+ "ssaoMaterial-fade": fade,
2066
+ "ssaoMaterial-minRadiusScale": minRadiusScale,
2067
+ "ssaoMaterial-distanceThreshold": distanceThreshold,
2068
+ "ssaoMaterial-distanceFalloff": distanceFalloff,
2069
+ "ssaoMaterial-worldDistanceThreshold": worldDistanceThreshold,
2070
+ "ssaoMaterial-worldDistanceFalloff": worldDistanceFalloff,
2071
+ rangeThreshold,
2072
+ rangeFalloff,
2073
+ "ssaoMaterial-worldProximityThreshold": worldProximityThreshold,
2074
+ "ssaoMaterial-worldProximityFalloff": worldProximityFalloff
2075
+ }, LIVE_KEYS, get, set);
2076
+ useDispose(effect);
2077
+ return /* @__PURE__ */ jsx("primitive", {
2078
+ ref,
2079
+ object: effect
2080
+ });
2081
+ }
2082
+ //#endregion
2083
+ //#region src/effects/Texture.tsx
2084
+ var TextureImpl = /* @__PURE__ */ createEffectComponent(TextureEffect);
2085
+ function Texture({ textureSrc, texture, opacity = 1, ...props }) {
2086
+ const t = useLoader(TextureLoader, textureSrc);
2087
+ useLayoutEffect(() => {
2088
+ t.colorSpace = SRGBColorSpace;
2089
+ t.wrapS = t.wrapT = RepeatWrapping;
2090
+ }, [t]);
2091
+ return /* @__PURE__ */ jsx(TextureImpl, {
2092
+ ...props,
2093
+ texture: texture ?? t,
2094
+ opacity
2095
+ });
2096
+ }
2097
+ //#endregion
2098
+ //#region src/effects/TiltShift.tsx
2099
+ var TiltShiftImpl = /* @__PURE__ */ createEffectComponent(TiltShiftEffect$1);
2100
+ function TiltShift({ blendFunction = 0, kernelSize, resolutionScale, resolutionX, resolutionY, ...liveProps }) {
2101
+ const args = useMemo(() => [{
2102
+ kernelSize,
2103
+ resolutionScale,
2104
+ resolutionX,
2105
+ resolutionY
2106
+ }], [
2107
+ kernelSize,
2108
+ resolutionScale,
2109
+ resolutionX,
2110
+ resolutionY
2111
+ ]);
2112
+ return /* @__PURE__ */ jsx(TiltShiftImpl, {
2113
+ blendFunction,
2114
+ args,
2115
+ ...liveProps
2116
+ });
2117
+ }
2118
+ //#endregion
2119
+ //#region src/effects/TiltShift2.tsx
2120
+ var TiltShiftShader = { fragmentShader: `
446
2121
 
447
2122
  // original shader by Evan Wallace
448
2123
 
@@ -498,58 +2173,179 @@ import{jsx as w,jsxs as K,Fragment as Q}from"react/jsx-runtime";import ee,{creat
498
2173
  /* switch back from pre-multiplied alpha */
499
2174
  outputColor.rgb /= outputColor.a + 0.00001;
500
2175
  }
501
- `};class me extends W{constructor({blendFunction:t=23,blur:o=.15,taper:r=.5,start:a=[.5,0],end:n=[.5,1],samples:i=10,direction:s=[1,1]}={}){super("TiltShiftEffect",Kt.fragmentShader,{blendFunction:t,attributes:2,uniforms:/*@__PURE__*/new Map([["blur",new y(o)],["taper",new y(r)],["start",new y(a)],["end",new y(n)],["samples",new y(i)],["direction",new y(s)]])})}}const Yt=/*@__PURE__*/P(me,{blendFunction:23}),Jt=`
502
- uniform sampler2D uCharacters;
503
- uniform float uCharactersCount;
504
- uniform float uCellSize;
505
- uniform bool uInvert;
506
- uniform vec3 uColor;
507
-
508
- const vec2 SIZE = vec2(16.);
509
-
510
- vec3 greyscale(vec3 color, float strength) {
511
- float g = dot(color, vec3(0.299, 0.587, 0.114));
512
- return mix(color, vec3(g), strength);
513
- }
514
-
515
- vec3 greyscale(vec3 color) {
516
- return greyscale(color, 1.0);
517
- }
518
-
519
- void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
520
- vec2 cell = resolution / uCellSize;
521
- vec2 grid = 1.0 / cell;
522
- vec2 pixelizedUV = grid * (0.5 + floor(uv / grid));
523
- vec4 pixelized = texture2D(inputBuffer, pixelizedUV);
524
- float greyscaled = greyscale(pixelized.rgb).r;
525
-
526
- if (uInvert) {
527
- greyscaled = 1.0 - greyscaled;
528
- }
529
-
530
- float characterIndex = floor((uCharactersCount - 1.0) * greyscaled);
531
- vec2 characterPosition = vec2(mod(characterIndex, SIZE.x), floor(characterIndex / SIZE.y));
532
- vec2 offset = vec2(characterPosition.x, -characterPosition.y) / SIZE;
533
- vec2 charUV = mod(uv * (cell / SIZE), 1.0 / SIZE) - vec2(0., 1.0 / SIZE) + offset;
534
- vec4 asciiCharacter = texture2D(uCharacters, charUV);
535
-
536
- asciiCharacter.rgb = uColor * asciiCharacter.r;
537
- asciiCharacter.a = pixelized.a;
538
- outputColor = asciiCharacter;
2176
+ ` };
2177
+ var TiltShiftEffect = class extends Effect {
2178
+ constructor({ blendFunction = 23, blur = .15, taper = .5, start = [.5, 0], end = [.5, 1], samples = 10, direction = [1, 1] } = {}) {
2179
+ super("TiltShiftEffect", TiltShiftShader.fragmentShader, {
2180
+ blendFunction,
2181
+ attributes: 2,
2182
+ uniforms: /* @__PURE__ */ new Map([
2183
+ ["blur", new Uniform(blur)],
2184
+ ["taper", new Uniform(taper)],
2185
+ ["start", new Uniform(start)],
2186
+ ["end", new Uniform(end)],
2187
+ ["samples", new Uniform(samples)],
2188
+ ["direction", new Uniform(direction)]
2189
+ ])
2190
+ });
2191
+ }
2192
+ u(name) {
2193
+ return this.uniforms.get(name).value;
2194
+ }
2195
+ setU(name, value) {
2196
+ this.uniforms.get(name).value = value;
2197
+ }
2198
+ get blur() {
2199
+ return this.u("blur");
2200
+ }
2201
+ set blur(value) {
2202
+ this.setU("blur", value);
2203
+ }
2204
+ get taper() {
2205
+ return this.u("taper");
2206
+ }
2207
+ set taper(value) {
2208
+ this.setU("taper", value);
2209
+ }
2210
+ get start() {
2211
+ return this.u("start");
2212
+ }
2213
+ set start(value) {
2214
+ this.setU("start", value);
2215
+ }
2216
+ get end() {
2217
+ return this.u("end");
2218
+ }
2219
+ set end(value) {
2220
+ this.setU("end", value);
2221
+ }
2222
+ get samples() {
2223
+ return this.u("samples");
2224
+ }
2225
+ set samples(value) {
2226
+ this.setU("samples", value);
2227
+ }
2228
+ get direction() {
2229
+ return this.u("direction");
2230
+ }
2231
+ set direction(value) {
2232
+ this.setU("direction", value);
2233
+ }
2234
+ };
2235
+ var TiltShift2 = /* @__PURE__ */ createEffectComponent(TiltShiftEffect);
2236
+ //#endregion
2237
+ //#region src/effects/ToneMapping.tsx
2238
+ var ToneMappingImpl = /* @__PURE__ */ createEffectComponent(ToneMappingEffect);
2239
+ function ToneMapping({ minLuminance, maxLuminance, ...liveProps }) {
2240
+ const args = useMemo(() => [{
2241
+ minLuminance,
2242
+ maxLuminance
2243
+ }], [minLuminance, maxLuminance]);
2244
+ return /* @__PURE__ */ jsx(ToneMappingImpl, {
2245
+ args,
2246
+ ...liveProps
2247
+ });
539
2248
  }
540
- `;class Qt extends W{constructor({font:t="arial",characters:o=" .:,'-^=*+?!|0#X%WM@",fontSize:r=54,cellSize:a=16,color:n="#ffffff",invert:i=!1}={}){const s=/*@__PURE__*/new Map([["uCharacters",new y(new ye)],["uCellSize",new y(a)],["uCharactersCount",new y(o.length)],["uColor",new y(new Pe(n))],["uInvert",new y(i)]]);super("ASCIIEffect",Jt,{uniforms:s});const l=this.uniforms.get("uCharacters");l&&(l.value=this.createCharactersTexture(o,t,r))}createCharactersTexture(t,o,r){const a=document.createElement("canvas"),n=1024,i=16,s=n/i;a.width=a.height=n;const l=new be(a,void 0,Y,Y,re,re),p=a.getContext("2d");if(!p)throw new Error("Context not available");p.clearRect(0,0,n,n),p.font=`${r}px ${o}`,p.textAlign="center",p.textBaseline="middle",p.fillStyle="#fff";for(let _=0;_<t.length;_++){const S=t[_],g=_%i,d=Math.floor(_/i);p.fillText(S,g*s+s/2,d*s+s/2)}return l.needsUpdate=!0,l}}const eo=/*@__PURE__*/B(({font:e="arial",characters:t=" .:,'-^=*+?!|0#X%WM@",fontSize:o=54,cellSize:r=16,color:a="#ffffff",invert:n=!1},i)=>{const s=z(()=>new Qt({characters:t,font:e,fontSize:o,cellSize:r,color:a,invert:n}),[t,o,r,a,n,e]);return /*@__PURE__*/w("primitive",{ref:i,object:s})}),to={fragmentShader:`
2249
+ //#endregion
2250
+ //#region src/effects/Vignette.tsx
2251
+ var Vignette = /* @__PURE__ */ createEffectComponent(VignetteEffect);
2252
+ //#endregion
2253
+ //#region src/effects/Water.tsx
2254
+ var WaterShader = { fragmentShader: `
541
2255
  uniform float factor;
542
2256
 
543
2257
  void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
544
2258
  vec2 vUv = uv;
545
2259
  float frequency = 6.0 * factor;
546
2260
  float amplitude = 0.015 * factor;
547
- float x = vUv.y * frequency + time * 0.7;
2261
+ float x = vUv.y * frequency + time * 0.7;
548
2262
  float y = vUv.x * frequency + time * 0.3;
549
2263
  vUv.x += cos(x + y) * amplitude * cos(y);
550
2264
  vUv.y += sin(x - y) * amplitude * cos(y);
551
2265
  vec4 rgba = texture(inputBuffer, vUv);
552
2266
  outputColor = rgba;
553
2267
  }
554
- `};class de extends W{constructor({blendFunction:t=23,factor:o=0}={}){super("WaterEffect",to.fragmentShader,{blendFunction:t,attributes:2,uniforms:/*@__PURE__*/new Map([["factor",new y(o)]])})}}const oo=/*@__PURE__*/P(de,{blendFunction:23}),ao=/*@__PURE__*/B(({halfRes:e,screenSpaceRadius:t,quality:o,depthAwareUpsampling:r=!0,aoRadius:a=5,aoSamples:n=16,denoiseSamples:i=4,denoiseRadius:s=12,distanceFalloff:l=1,intensity:p=1,color:_,renderMode:S=0},g)=>{const{camera:d,scene:m}=V(),v=z(()=>new ut(m,d),[d,m]);return L(()=>{Ce(v.configuration,{color:_,aoRadius:a,distanceFalloff:l,intensity:p,aoSamples:n,denoiseSamples:i,denoiseRadius:s,screenSpaceRadius:t,renderMode:S,halfRes:e,depthAwareUpsampling:r})},[t,_,a,l,p,n,i,s,S,e,r,v]),L(()=>{o&&v.setQualityMode(o.charAt(0).toUpperCase()+o.slice(1))},[v,o]),/*@__PURE__*/w("primitive",{ref:g,object:v})});export{eo as ASCII,ht as Autofocus,wt as Bloom,St as BrightnessContrast,yt as ChromaticAberration,Pt as ColorAverage,bt as ColorDepth,Et as Depth,ce as DepthOfField,Rt as DotScreen,dt as EffectComposer,D as EffectComposerContext,Nt as FXAA,Ut as Glitch,Ct as GodRays,zt as Grid,Tt as HueSaturation,Zt as LUT,gt as LensFlare,fe as LensFlareEffect,ao as N8AO,At as Noise,Bt as Outline,Vt as Pixelation,Ot as Ramp,pe as RampEffect,ue as RampType,Lt as SMAA,It as SSAO,Ft as Scanline,mt as Select,pt as Selection,kt as SelectiveBloom,Gt as Sepia,Ht as ShockWave,Wt as Texture,$t as TiltShift,Yt as TiltShift2,me as TiltShiftEffect,Xt as ToneMapping,qt as Vignette,oo as WaterEffect,de as WaterEffectImpl,k as resolveRef,H as selectionContext,Z as useVector2,P as wrapEffect};
555
- //# sourceMappingURL=index.js.map
2268
+ ` };
2269
+ var WaterEffectImpl = class extends Effect {
2270
+ constructor({ blendFunction = 23, factor = 0 } = {}) {
2271
+ super("WaterEffect", WaterShader.fragmentShader, {
2272
+ blendFunction,
2273
+ attributes: 2,
2274
+ uniforms: /* @__PURE__ */ new Map([["factor", new Uniform(factor)]])
2275
+ });
2276
+ }
2277
+ get factor() {
2278
+ return this.uniforms.get("factor").value;
2279
+ }
2280
+ set factor(value) {
2281
+ this.uniforms.get("factor").value = value;
2282
+ }
2283
+ };
2284
+ var WaterEffect = /* @__PURE__ */ createEffectComponent(WaterEffectImpl);
2285
+ //#endregion
2286
+ //#region src/passes/N8AO.tsx
2287
+ function N8AO({ enabled = true, halfRes, screenSpaceRadius, quality, depthAwareUpsampling = true, aoRadius = 5, aoSamples = 16, denoiseSamples = 4, denoiseRadius = 12, distanceFalloff = 1, intensity = 1, color, renderMode = 0, ref }) {
2288
+ const { camera, scene, invalidate } = useThree();
2289
+ const effect = useMemo(() => {
2290
+ const instance = new N8AOPostPass(scene, camera);
2291
+ groupPasses.add(instance);
2292
+ return instance;
2293
+ }, [camera, scene]);
2294
+ useDispose(effect);
2295
+ useLayoutEffect(() => {
2296
+ effect.enabled = enabled;
2297
+ invalidate();
2298
+ }, [
2299
+ effect,
2300
+ enabled,
2301
+ invalidate
2302
+ ]);
2303
+ useLayoutEffect(() => {
2304
+ applyProps(effect.configuration, {
2305
+ color,
2306
+ aoRadius,
2307
+ distanceFalloff,
2308
+ intensity,
2309
+ aoSamples,
2310
+ denoiseSamples,
2311
+ denoiseRadius,
2312
+ screenSpaceRadius,
2313
+ renderMode,
2314
+ halfRes,
2315
+ depthAwareUpsampling
2316
+ });
2317
+ invalidate();
2318
+ }, [
2319
+ screenSpaceRadius,
2320
+ color,
2321
+ aoRadius,
2322
+ distanceFalloff,
2323
+ intensity,
2324
+ aoSamples,
2325
+ denoiseSamples,
2326
+ denoiseRadius,
2327
+ renderMode,
2328
+ halfRes,
2329
+ depthAwareUpsampling,
2330
+ effect,
2331
+ invalidate
2332
+ ]);
2333
+ useLayoutEffect(() => {
2334
+ if (quality) {
2335
+ effect.setQualityMode(quality.charAt(0).toUpperCase() + quality.slice(1));
2336
+ invalidate();
2337
+ }
2338
+ }, [
2339
+ effect,
2340
+ quality,
2341
+ invalidate
2342
+ ]);
2343
+ return /* @__PURE__ */ jsx("primitive", {
2344
+ ref,
2345
+ object: effect
2346
+ });
2347
+ }
2348
+ //#endregion
2349
+ export { ASCII, Autofocus, Bloom, BrightnessContrast, ChromaticAberration, ColorAverage, ColorDepth, Depth, DepthOfField, DepthPicking, DotScreen, EMPTY_ARRAY, EffectComposer, EffectComposerContext, EffectGroup, FXAA, Glitch, GodRays, Grid, HueSaturation, LUT, LensFlare, LensFlareEffect, N8AO, Noise, Outline, Pixelation, Ramp, RampEffect, RampType, SMAA, SSAO, Scanline, Select, Selection, SelectiveBloom, Sepia, ShockWave, Texture, TiltShift, TiltShift2, TiltShiftEffect, ToneMapping, Vignette, WaterEffect, WaterEffectImpl, applyPierced, createEffectComponent, disposePassWithoutEffects, groupPasses, readGroupChildren, readPierced, resolveRef, selectionContext, updateIfChanged, useDepthPicking, useDispose, useLiveDefaults, useMergeRefs, useSelectionSync, useVector2, useVector3, wrapEffect };
2350
+
2351
+ //# sourceMappingURL=index.js.map