@react-three/postprocessing 2.16.3 → 2.16.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.
- package/dist/EffectComposer.cjs +6 -5
- package/dist/EffectComposer.cjs.map +1 -1
- package/dist/EffectComposer.d.ts +1 -1
- package/dist/EffectComposer.js +7 -6
- package/dist/EffectComposer.js.map +1 -1
- package/dist/EffectComposer.test.d.ts +4 -0
- package/dist/effects/Autofocus.cjs.map +1 -1
- package/dist/effects/Autofocus.d.ts +1 -1
- package/dist/effects/Autofocus.js.map +1 -1
- package/dist/effects/Grid.cjs +1 -1
- package/dist/effects/Grid.cjs.map +1 -1
- package/dist/effects/Grid.js +1 -1
- package/dist/effects/Grid.js.map +1 -1
- package/dist/effects/N8AO/index.cjs +4 -3
- package/dist/effects/N8AO/index.cjs.map +1 -1
- package/dist/effects/N8AO/index.js +4 -3
- package/dist/effects/N8AO/index.js.map +1 -1
- package/dist/effects/Outline.cjs +2 -0
- package/dist/effects/Outline.cjs.map +1 -1
- package/dist/effects/Outline.js +2 -0
- package/dist/effects/Outline.js.map +1 -1
- package/dist/effects/SSAO.cjs +1 -1
- package/dist/effects/SSAO.cjs.map +1 -1
- package/dist/effects/SSAO.js +1 -1
- package/dist/effects/SSAO.js.map +1 -1
- package/dist/effects/SSR/index.cjs +2 -2
- package/dist/effects/SSR/index.cjs.map +1 -1
- package/dist/effects/SSR/index.js +2 -2
- package/dist/effects/SSR/index.js.map +1 -1
- package/dist/effects/ToneMapping.cjs +2 -46
- package/dist/effects/ToneMapping.cjs.map +1 -1
- package/dist/effects/ToneMapping.d.ts +2 -2
- package/dist/effects/ToneMapping.js +3 -47
- package/dist/effects/ToneMapping.js.map +1 -1
- package/dist/effects/Water.cjs +18 -13
- package/dist/effects/Water.cjs.map +1 -1
- package/dist/effects/Water.js +18 -13
- package/dist/effects/Water.js.map +1 -1
- package/package.json +4 -3
package/dist/EffectComposer.cjs
CHANGED
|
@@ -75,11 +75,12 @@ const EffectComposer = React.memo(
|
|
|
75
75
|
enabled ? renderPriority : 0
|
|
76
76
|
);
|
|
77
77
|
const group = React.useRef(null);
|
|
78
|
-
const instance = fiber.useInstanceHandle(group);
|
|
79
78
|
React.useLayoutEffect(() => {
|
|
79
|
+
var _a;
|
|
80
80
|
const passes = [];
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
const groupInstance = (_a = group.current) == null ? void 0 : _a.__r3f;
|
|
82
|
+
if (groupInstance && composer) {
|
|
83
|
+
const children2 = groupInstance.objects;
|
|
83
84
|
for (let i = 0; i < children2.length; i++) {
|
|
84
85
|
const child = children2[i];
|
|
85
86
|
if (child instanceof postprocessing.Effect) {
|
|
@@ -114,14 +115,14 @@ const EffectComposer = React.memo(
|
|
|
114
115
|
if (downSamplingPass)
|
|
115
116
|
downSamplingPass.enabled = false;
|
|
116
117
|
};
|
|
117
|
-
}, [composer, children, camera, normalPass, downSamplingPass
|
|
118
|
+
}, [composer, children, camera, normalPass, downSamplingPass]);
|
|
118
119
|
React.useEffect(() => {
|
|
119
120
|
const currentTonemapping = gl.toneMapping;
|
|
120
121
|
gl.toneMapping = THREE.NoToneMapping;
|
|
121
122
|
return () => {
|
|
122
123
|
gl.toneMapping = currentTonemapping;
|
|
123
124
|
};
|
|
124
|
-
}, []);
|
|
125
|
+
}, [gl]);
|
|
125
126
|
const state = React.useMemo(
|
|
126
127
|
() => ({ composer, normalPass, downSamplingPass, resolutionScale, camera, scene }),
|
|
127
128
|
[composer, normalPass, downSamplingPass, resolutionScale, camera, scene]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EffectComposer.cjs","sources":["../src/EffectComposer.tsx"],"sourcesContent":["import type { TextureDataType } from 'three'\nimport { HalfFloatType, NoToneMapping } from 'three'\nimport React, {\n forwardRef,\n useMemo,\n useEffect,\n useLayoutEffect,\n createContext,\n useRef,\n useImperativeHandle,\n} from 'react'\nimport { useThree, useFrame
|
|
1
|
+
{"version":3,"file":"EffectComposer.cjs","sources":["../src/EffectComposer.tsx"],"sourcesContent":["import type { TextureDataType } from 'three'\nimport { HalfFloatType, NoToneMapping } from 'three'\nimport React, {\n forwardRef,\n useMemo,\n useEffect,\n useLayoutEffect,\n createContext,\n useRef,\n useImperativeHandle,\n} from 'react'\nimport { useThree, useFrame } from '@react-three/fiber'\nimport {\n EffectComposer as EffectComposerImpl,\n RenderPass,\n EffectPass,\n NormalPass,\n // @ts-ignore\n DepthDownsamplingPass,\n Effect,\n Pass,\n EffectAttribute,\n} from 'postprocessing'\nimport { isWebGL2Available } from 'three-stdlib'\n\nexport const EffectComposerContext = createContext<{\n composer: EffectComposerImpl\n normalPass: NormalPass | null\n downSamplingPass: DepthDownsamplingPass | null\n camera: THREE.Camera\n scene: THREE.Scene\n resolutionScale?: number\n}>(null!)\n\nexport type EffectComposerProps = {\n enabled?: boolean\n children: JSX.Element | JSX.Element[]\n depthBuffer?: boolean\n /** Only used for SSGI currently, leave it disabled for everything else unless it's needed */\n enableNormalPass?: boolean\n stencilBuffer?: boolean\n autoClear?: boolean\n resolutionScale?: number\n multisampling?: number\n frameBufferType?: TextureDataType\n renderPriority?: number\n camera?: THREE.Camera\n scene?: THREE.Scene\n}\n\nconst isConvolution = (effect: Effect): boolean =>\n (effect.getAttributes() & EffectAttribute.CONVOLUTION) === EffectAttribute.CONVOLUTION\n\nexport const EffectComposer = React.memo(\n forwardRef<EffectComposerImpl, EffectComposerProps>(\n (\n {\n children,\n camera: _camera,\n scene: _scene,\n resolutionScale,\n enabled = true,\n renderPriority = 1,\n autoClear = true,\n depthBuffer,\n enableNormalPass,\n stencilBuffer,\n multisampling = 8,\n frameBufferType = HalfFloatType,\n },\n ref\n ) => {\n const { gl, scene: defaultScene, camera: defaultCamera, size } = useThree()\n const scene = _scene || defaultScene\n const camera = _camera || defaultCamera\n\n const [composer, normalPass, downSamplingPass] = useMemo(() => {\n const webGL2Available = isWebGL2Available()\n // Initialize composer\n const effectComposer = new EffectComposerImpl(gl, {\n depthBuffer,\n stencilBuffer,\n multisampling: multisampling > 0 && webGL2Available ? multisampling : 0,\n frameBufferType,\n })\n\n // Add render pass\n effectComposer.addPass(new RenderPass(scene, camera))\n\n // Create normal pass\n let downSamplingPass = null\n let normalPass = null\n if (enableNormalPass) {\n normalPass = new NormalPass(scene, camera)\n normalPass.enabled = false\n effectComposer.addPass(normalPass)\n if (resolutionScale !== undefined && webGL2Available) {\n downSamplingPass = new DepthDownsamplingPass({ normalBuffer: normalPass.texture, resolutionScale })\n downSamplingPass.enabled = false\n effectComposer.addPass(downSamplingPass)\n }\n }\n\n return [effectComposer, normalPass, downSamplingPass]\n }, [\n camera,\n gl,\n depthBuffer,\n stencilBuffer,\n multisampling,\n frameBufferType,\n scene,\n enableNormalPass,\n resolutionScale,\n ])\n\n useEffect(() => composer?.setSize(size.width, size.height), [composer, size])\n useFrame(\n (_, delta) => {\n if (enabled) {\n const currentAutoClear = gl.autoClear\n gl.autoClear = autoClear\n if (stencilBuffer && !autoClear) gl.clearStencil()\n composer.render(delta)\n gl.autoClear = currentAutoClear\n }\n },\n enabled ? renderPriority : 0\n )\n\n const group = useRef(null)\n useLayoutEffect(() => {\n const passes: Pass[] = []\n\n // TODO: rewrite all of this with R3F v9\n const groupInstance = (group.current as any)?.__r3f as { objects: unknown[] }\n\n if (groupInstance && composer) {\n const children = groupInstance.objects\n\n for (let i = 0; i < children.length; i++) {\n const child = children[i]\n\n if (child instanceof Effect) {\n const effects: Effect[] = [child]\n\n if (!isConvolution(child)) {\n let next: unknown = null\n while ((next = children[i + 1]) instanceof Effect) {\n if (isConvolution(next)) break\n effects.push(next)\n i++\n }\n }\n\n const pass = new EffectPass(camera, ...effects)\n passes.push(pass)\n } else if (child instanceof Pass) {\n passes.push(child)\n }\n }\n\n for (const pass of passes) composer?.addPass(pass)\n\n if (normalPass) normalPass.enabled = true\n if (downSamplingPass) downSamplingPass.enabled = true\n }\n\n return () => {\n for (const pass of passes) composer?.removePass(pass)\n if (normalPass) normalPass.enabled = false\n if (downSamplingPass) downSamplingPass.enabled = false\n }\n }, [composer, children, camera, normalPass, downSamplingPass])\n\n // Disable tone mapping because threejs disallows tonemapping on render targets\n useEffect(() => {\n const currentTonemapping = gl.toneMapping\n gl.toneMapping = NoToneMapping\n return () => {\n gl.toneMapping = currentTonemapping\n }\n }, [gl])\n\n // Memoize state, otherwise it would trigger all consumers on every render\n const state = useMemo(\n () => ({ composer, normalPass, downSamplingPass, resolutionScale, camera, scene }),\n [composer, normalPass, downSamplingPass, resolutionScale, camera, scene]\n )\n\n // Expose the composer\n useImperativeHandle(ref, () => composer, [composer])\n\n return (\n <EffectComposerContext.Provider value={state}>\n <group ref={group}>{children}</group>\n </EffectComposerContext.Provider>\n )\n }\n )\n)\n"],"names":["createContext","EffectAttribute","forwardRef","HalfFloatType","useThree","useMemo","isWebGL2Available","EffectComposerImpl","RenderPass","downSamplingPass","normalPass","NormalPass","DepthDownsamplingPass","useEffect","useFrame","useRef","useLayoutEffect","children","Effect","EffectPass","Pass","NoToneMapping","useImperativeHandle","jsx"],"mappings":";;;;;;;;AAyBa,MAAA,wBAAwBA,oBAOlC,IAAK;AAkBR,MAAM,gBAAgB,CAAC,YACpB,OAAO,cAAkB,IAAAC,+BAAgB,iBAAiBA,eAAgB,gBAAA;AAEtE,MAAM,iBAAiB,MAAM;AAAA,EAClCC,MAAA;AAAA,IACE,CACE;AAAA,MACE;AAAA,MACA,QAAQ;AAAA,MACR,OAAO;AAAA,MACP;AAAA,MACA,UAAU;AAAA,MACV,iBAAiB;AAAA,MACjB,YAAY;AAAA,MACZ;AAAA,MACA;AAAA,MACA;AAAA,MACA,gBAAgB;AAAA,MAChB,kBAAkBC,MAAA;AAAA,OAEpB,QACG;AACG,YAAA,EAAE,IAAI,OAAO,cAAc,QAAQ,eAAe,SAASC,MAAAA;AACjE,YAAM,QAAQ,UAAU;AACxB,YAAM,SAAS,WAAW;AAE1B,YAAM,CAAC,UAAU,YAAY,gBAAgB,IAAIC,cAAQ,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AAoB,KAAK,MAAM,UAAU,CAAC,QAAQ,CAAC;AAGjD,aAAAC,2BAAAA,IAAC,sBAAsB,UAAtB,EAA+B,OAAO,OACrC,UAAAA,2BAAA,IAAC,SAAM,EAAA,KAAK,OAAQ,SAAS,CAAA,EAC/B,CAAA;AAAA,IAEJ;AAAA,EACF;AACF;;;"}
|
package/dist/EffectComposer.d.ts
CHANGED
|
@@ -24,4 +24,4 @@ export type EffectComposerProps = {
|
|
|
24
24
|
camera?: THREE.Camera;
|
|
25
25
|
scene?: THREE.Scene;
|
|
26
26
|
};
|
|
27
|
-
export declare const EffectComposer: React.MemoExoticComponent<React.ForwardRefExoticComponent<EffectComposerProps & React.RefAttributes<
|
|
27
|
+
export declare const EffectComposer: React.MemoExoticComponent<React.ForwardRefExoticComponent<EffectComposerProps & React.RefAttributes<EffectComposerImpl>>>;
|
package/dist/EffectComposer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { NoToneMapping, HalfFloatType } from "three";
|
|
3
3
|
import React, { createContext, forwardRef, useMemo, useEffect, useRef, useLayoutEffect, useImperativeHandle } from "react";
|
|
4
|
-
import { useThree, useFrame
|
|
4
|
+
import { useThree, useFrame } from "@react-three/fiber";
|
|
5
5
|
import { EffectComposer as EffectComposer$1, RenderPass, NormalPass, DepthDownsamplingPass, Effect, EffectPass, EffectAttribute, Pass } from "postprocessing";
|
|
6
6
|
import { isWebGL2Available } from "three-stdlib";
|
|
7
7
|
const EffectComposerContext = createContext(null);
|
|
@@ -73,11 +73,12 @@ const EffectComposer = React.memo(
|
|
|
73
73
|
enabled ? renderPriority : 0
|
|
74
74
|
);
|
|
75
75
|
const group = useRef(null);
|
|
76
|
-
const instance = useInstanceHandle(group);
|
|
77
76
|
useLayoutEffect(() => {
|
|
77
|
+
var _a;
|
|
78
78
|
const passes = [];
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
const groupInstance = (_a = group.current) == null ? void 0 : _a.__r3f;
|
|
80
|
+
if (groupInstance && composer) {
|
|
81
|
+
const children2 = groupInstance.objects;
|
|
81
82
|
for (let i = 0; i < children2.length; i++) {
|
|
82
83
|
const child = children2[i];
|
|
83
84
|
if (child instanceof Effect) {
|
|
@@ -112,14 +113,14 @@ const EffectComposer = React.memo(
|
|
|
112
113
|
if (downSamplingPass)
|
|
113
114
|
downSamplingPass.enabled = false;
|
|
114
115
|
};
|
|
115
|
-
}, [composer, children, camera, normalPass, downSamplingPass
|
|
116
|
+
}, [composer, children, camera, normalPass, downSamplingPass]);
|
|
116
117
|
useEffect(() => {
|
|
117
118
|
const currentTonemapping = gl.toneMapping;
|
|
118
119
|
gl.toneMapping = NoToneMapping;
|
|
119
120
|
return () => {
|
|
120
121
|
gl.toneMapping = currentTonemapping;
|
|
121
122
|
};
|
|
122
|
-
}, []);
|
|
123
|
+
}, [gl]);
|
|
123
124
|
const state = useMemo(
|
|
124
125
|
() => ({ composer, normalPass, downSamplingPass, resolutionScale, camera, scene }),
|
|
125
126
|
[composer, normalPass, downSamplingPass, resolutionScale, camera, scene]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EffectComposer.js","sources":["../src/EffectComposer.tsx"],"sourcesContent":["import type { TextureDataType } from 'three'\nimport { HalfFloatType, NoToneMapping } from 'three'\nimport React, {\n forwardRef,\n useMemo,\n useEffect,\n useLayoutEffect,\n createContext,\n useRef,\n useImperativeHandle,\n} from 'react'\nimport { useThree, useFrame
|
|
1
|
+
{"version":3,"file":"EffectComposer.js","sources":["../src/EffectComposer.tsx"],"sourcesContent":["import type { TextureDataType } from 'three'\nimport { HalfFloatType, NoToneMapping } from 'three'\nimport React, {\n forwardRef,\n useMemo,\n useEffect,\n useLayoutEffect,\n createContext,\n useRef,\n useImperativeHandle,\n} from 'react'\nimport { useThree, useFrame } from '@react-three/fiber'\nimport {\n EffectComposer as EffectComposerImpl,\n RenderPass,\n EffectPass,\n NormalPass,\n // @ts-ignore\n DepthDownsamplingPass,\n Effect,\n Pass,\n EffectAttribute,\n} from 'postprocessing'\nimport { isWebGL2Available } from 'three-stdlib'\n\nexport const EffectComposerContext = createContext<{\n composer: EffectComposerImpl\n normalPass: NormalPass | null\n downSamplingPass: DepthDownsamplingPass | null\n camera: THREE.Camera\n scene: THREE.Scene\n resolutionScale?: number\n}>(null!)\n\nexport type EffectComposerProps = {\n enabled?: boolean\n children: JSX.Element | JSX.Element[]\n depthBuffer?: boolean\n /** Only used for SSGI currently, leave it disabled for everything else unless it's needed */\n enableNormalPass?: boolean\n stencilBuffer?: boolean\n autoClear?: boolean\n resolutionScale?: number\n multisampling?: number\n frameBufferType?: TextureDataType\n renderPriority?: number\n camera?: THREE.Camera\n scene?: THREE.Scene\n}\n\nconst isConvolution = (effect: Effect): boolean =>\n (effect.getAttributes() & EffectAttribute.CONVOLUTION) === EffectAttribute.CONVOLUTION\n\nexport const EffectComposer = React.memo(\n forwardRef<EffectComposerImpl, EffectComposerProps>(\n (\n {\n children,\n camera: _camera,\n scene: _scene,\n resolutionScale,\n enabled = true,\n renderPriority = 1,\n autoClear = true,\n depthBuffer,\n enableNormalPass,\n stencilBuffer,\n multisampling = 8,\n frameBufferType = HalfFloatType,\n },\n ref\n ) => {\n const { gl, scene: defaultScene, camera: defaultCamera, size } = useThree()\n const scene = _scene || defaultScene\n const camera = _camera || defaultCamera\n\n const [composer, normalPass, downSamplingPass] = useMemo(() => {\n const webGL2Available = isWebGL2Available()\n // Initialize composer\n const effectComposer = new EffectComposerImpl(gl, {\n depthBuffer,\n stencilBuffer,\n multisampling: multisampling > 0 && webGL2Available ? multisampling : 0,\n frameBufferType,\n })\n\n // Add render pass\n effectComposer.addPass(new RenderPass(scene, camera))\n\n // Create normal pass\n let downSamplingPass = null\n let normalPass = null\n if (enableNormalPass) {\n normalPass = new NormalPass(scene, camera)\n normalPass.enabled = false\n effectComposer.addPass(normalPass)\n if (resolutionScale !== undefined && webGL2Available) {\n downSamplingPass = new DepthDownsamplingPass({ normalBuffer: normalPass.texture, resolutionScale })\n downSamplingPass.enabled = false\n effectComposer.addPass(downSamplingPass)\n }\n }\n\n return [effectComposer, normalPass, downSamplingPass]\n }, [\n camera,\n gl,\n depthBuffer,\n stencilBuffer,\n multisampling,\n frameBufferType,\n scene,\n enableNormalPass,\n resolutionScale,\n ])\n\n useEffect(() => composer?.setSize(size.width, size.height), [composer, size])\n useFrame(\n (_, delta) => {\n if (enabled) {\n const currentAutoClear = gl.autoClear\n gl.autoClear = autoClear\n if (stencilBuffer && !autoClear) gl.clearStencil()\n composer.render(delta)\n gl.autoClear = currentAutoClear\n }\n },\n enabled ? renderPriority : 0\n )\n\n const group = useRef(null)\n useLayoutEffect(() => {\n const passes: Pass[] = []\n\n // TODO: rewrite all of this with R3F v9\n const groupInstance = (group.current as any)?.__r3f as { objects: unknown[] }\n\n if (groupInstance && composer) {\n const children = groupInstance.objects\n\n for (let i = 0; i < children.length; i++) {\n const child = children[i]\n\n if (child instanceof Effect) {\n const effects: Effect[] = [child]\n\n if (!isConvolution(child)) {\n let next: unknown = null\n while ((next = children[i + 1]) instanceof Effect) {\n if (isConvolution(next)) break\n effects.push(next)\n i++\n }\n }\n\n const pass = new EffectPass(camera, ...effects)\n passes.push(pass)\n } else if (child instanceof Pass) {\n passes.push(child)\n }\n }\n\n for (const pass of passes) composer?.addPass(pass)\n\n if (normalPass) normalPass.enabled = true\n if (downSamplingPass) downSamplingPass.enabled = true\n }\n\n return () => {\n for (const pass of passes) composer?.removePass(pass)\n if (normalPass) normalPass.enabled = false\n if (downSamplingPass) downSamplingPass.enabled = false\n }\n }, [composer, children, camera, normalPass, downSamplingPass])\n\n // Disable tone mapping because threejs disallows tonemapping on render targets\n useEffect(() => {\n const currentTonemapping = gl.toneMapping\n gl.toneMapping = NoToneMapping\n return () => {\n gl.toneMapping = currentTonemapping\n }\n }, [gl])\n\n // Memoize state, otherwise it would trigger all consumers on every render\n const state = useMemo(\n () => ({ composer, normalPass, downSamplingPass, resolutionScale, camera, scene }),\n [composer, normalPass, downSamplingPass, resolutionScale, camera, scene]\n )\n\n // Expose the composer\n useImperativeHandle(ref, () => composer, [composer])\n\n return (\n <EffectComposerContext.Provider value={state}>\n <group ref={group}>{children}</group>\n </EffectComposerContext.Provider>\n )\n }\n )\n)\n"],"names":["EffectComposerImpl","downSamplingPass","normalPass","children"],"mappings":";;;;;;AAyBa,MAAA,wBAAwB,cAOlC,IAAK;AAkBR,MAAM,gBAAgB,CAAC,YACpB,OAAO,cAAkB,IAAA,gBAAgB,iBAAiB,gBAAgB;AAEtE,MAAM,iBAAiB,MAAM;AAAA,EAClC;AAAA,IACE,CACE;AAAA,MACE;AAAA,MACA,QAAQ;AAAA,MACR,OAAO;AAAA,MACP;AAAA,MACA,UAAU;AAAA,MACV,iBAAiB;AAAA,MACjB,YAAY;AAAA,MACZ;AAAA,MACA;AAAA,MACA;AAAA,MACA,gBAAgB;AAAA,MAChB,kBAAkB;AAAA,OAEpB,QACG;AACG,YAAA,EAAE,IAAI,OAAO,cAAc,QAAQ,eAAe,SAAS;AACjE,YAAM,QAAQ,UAAU;AACxB,YAAM,SAAS,WAAW;AAE1B,YAAM,CAAC,UAAU,YAAY,gBAAgB,IAAI,QAAQ,MAAM;AAC7D,cAAM,kBAAkB;AAElB,cAAA,iBAAiB,IAAIA,iBAAmB,IAAI;AAAA,UAChD;AAAA,UACA;AAAA,UACA,eAAe,gBAAgB,KAAK,kBAAkB,gBAAgB;AAAA,UACtE;AAAA,QAAA,CACD;AAGD,uBAAe,QAAQ,IAAI,WAAW,OAAO,MAAM,CAAC;AAGpD,YAAIC,oBAAmB;AACvB,YAAIC,cAAa;AACjB,YAAI,kBAAkB;AACpBA,wBAAa,IAAI,WAAW,OAAO,MAAM;AACzCA,sBAAW,UAAU;AACrB,yBAAe,QAAQA,WAAU;AAC7B,cAAA,oBAAoB,UAAa,iBAAiB;AACpDD,gCAAmB,IAAI,sBAAsB,EAAE,cAAcC,YAAW,SAAS,iBAAiB;AAClG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AA,YACnB;AAAA,UACF;AAEA,qBAAW,QAAQ;AAAQ,iDAAU,QAAQ;AAEzC,cAAA;AAAY,uBAAW,UAAU;AACjC,cAAA;AAAkB,6BAAiB,UAAU;AAAA,QACnD;AAEA,eAAO,MAAM;AACX,qBAAW,QAAQ;AAAQ,iDAAU,WAAW;AAC5C,cAAA;AAAY,uBAAW,UAAU;AACjC,cAAA;AAAkB,6BAAiB,UAAU;AAAA,QAAA;AAAA,MACnD,GACC,CAAC,UAAU,UAAU,QAAQ,YAAY,gBAAgB,CAAC;AAG7D,gBAAU,MAAM;AACd,cAAM,qBAAqB,GAAG;AAC9B,WAAG,cAAc;AACjB,eAAO,MAAM;AACX,aAAG,cAAc;AAAA,QAAA;AAAA,MACnB,GACC,CAAC,EAAE,CAAC;AAGP,YAAM,QAAQ;AAAA,QACZ,OAAO,EAAE,UAAU,YAAY,kBAAkB,iBAAiB,QAAQ;QAC1E,CAAC,UAAU,YAAY,kBAAkB,iBAAiB,QAAQ,KAAK;AAAA,MAAA;AAIzE,0BAAoB,KAAK,MAAM,UAAU,CAAC,QAAQ,CAAC;AAGjD,aAAA,oBAAC,sBAAsB,UAAtB,EAA+B,OAAO,OACrC,UAAA,oBAAC,SAAM,EAAA,KAAK,OAAQ,SAAS,CAAA,EAC/B,CAAA;AAAA,IAEJ;AAAA,EACF;AACF;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Autofocus.cjs","sources":["../../src/effects/Autofocus.tsx"],"sourcesContent":["import * as THREE from 'three'\nimport React, {\n useRef,\n useContext,\n useState,\n useEffect,\n useCallback,\n forwardRef,\n useImperativeHandle,\n RefObject,\n useMemo,\n} from 'react'\nimport { useThree, useFrame, createPortal, Vector3 } from '@react-three/fiber'\nimport { CopyPass, DepthPickingPass, DepthOfFieldEffect } from 'postprocessing'\nimport { easing } from 'maath'\n\nimport { DepthOfField } from './DepthOfField'\nimport { EffectComposerContext } from '../EffectComposer'\n\nexport type AutofocusProps = React.ComponentProps<typeof DepthOfField> & {\n target?: Vector3\n /** should the target follow the pointer */\n mouse?: boolean\n /** size of the debug green point */\n debug?: number\n /** manual update */\n manual?: boolean\n /** approximate time to reach the target */\n smoothTime?: number\n}\n\nexport type AutofocusApi = {\n dofRef: RefObject<DepthOfFieldEffect>\n hitpoint: THREE.Vector3\n update: (delta: number, updateTarget: boolean) => void\n}\n\nexport const Autofocus = forwardRef<AutofocusApi, AutofocusProps>(\n (\n { target = undefined, mouse: followMouse = false, debug = undefined, manual = false, smoothTime = 0.25, ...props },\n fref\n ) => {\n const dofRef = useRef<DepthOfFieldEffect>(null)\n const hitpointRef = useRef<THREE.Mesh>(null)\n const targetRef = useRef<THREE.Mesh>(null)\n\n const scene = useThree(({ scene }) => scene)\n const pointer = useThree(({ pointer }) => pointer)\n const { composer, camera } = useContext(EffectComposerContext)\n\n // see: https://codesandbox.io/s/depthpickingpass-x130hg\n const [depthPickingPass] = useState(() => new DepthPickingPass())\n const [copyPass] = useState(() => new CopyPass())\n useEffect(() => {\n composer.addPass(depthPickingPass)\n composer.addPass(copyPass)\n return () => {\n composer.removePass(depthPickingPass)\n composer.removePass(copyPass)\n }\n }, [composer, depthPickingPass, copyPass])\n\n useEffect(() => {\n return () => {\n depthPickingPass.dispose()\n copyPass.dispose()\n }\n }, [depthPickingPass, copyPass])\n\n const [hitpoint] = useState(() => new THREE.Vector3(0, 0, 0))\n\n const [ndc] = useState(() => new THREE.Vector3(0, 0, 0))\n const getHit = useCallback(\n async (x: number, y: number) => {\n ndc.x = x\n ndc.y = y\n ndc.z = await depthPickingPass.readDepth(ndc)\n ndc.z = ndc.z * 2.0 - 1.0\n const hit = 1 - ndc.z > 0.0000001 // it is missed if ndc.z is close to 1\n return hit ? ndc.unproject(camera) : false\n },\n [ndc, depthPickingPass, camera]\n )\n\n const update = useCallback(\n async (delta: number, updateTarget = true) => {\n // Update hitpoint\n if (target) {\n hitpoint.set(...(target as [number, number, number]))\n } else {\n const { x, y } = followMouse ? pointer : { x: 0, y: 0 }\n const hit = await getHit(x, y)\n if (hit) hitpoint.copy(hit)\n }\n\n // Update target\n if (updateTarget && dofRef.current?.target) {\n if (smoothTime > 0 && delta > 0) {\n easing.damp3(dofRef.current.target, hitpoint, smoothTime, delta)\n } else {\n dofRef.current.target.copy(hitpoint)\n }\n }\n },\n [target, hitpoint, followMouse, getHit, smoothTime, pointer]\n )\n\n useFrame(async (_, delta) => {\n if (!manual) {\n update(delta)\n }\n if (hitpointRef.current) {\n hitpointRef.current.position.copy(hitpoint)\n }\n if (targetRef.current && dofRef.current?.target) {\n targetRef.current.position.copy(dofRef.current.target)\n }\n })\n\n // Ref API\n const api = useMemo<AutofocusApi>(\n () => ({\n dofRef,\n hitpoint,\n update,\n }),\n [hitpoint, update]\n )\n useImperativeHandle(fref, () => api, [api])\n\n return (\n <>\n {debug\n ? createPortal(\n <>\n <mesh ref={hitpointRef}>\n <sphereGeometry args={[debug, 16, 16]} />\n <meshBasicMaterial color=\"#00ff00\" opacity={1} transparent depthWrite={false} />\n </mesh>\n <mesh ref={targetRef}>\n <sphereGeometry args={[debug / 2, 16, 16]} />\n <meshBasicMaterial color=\"#00ff00\" opacity={0.5} transparent depthWrite={false} />\n </mesh>\n </>,\n scene\n )\n : null}\n\n <DepthOfField ref={dofRef} {...props} target={hitpoint} />\n </>\n )\n }\n)\n"],"names":["forwardRef","useRef","useThree","scene","pointer","useContext","EffectComposerContext","useState","DepthPickingPass","CopyPass","useEffect","THREE","useCallback","easing","useFrame","useMemo","useImperativeHandle","jsxs","Fragment","createPortal","jsx","DepthOfField"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCO,MAAM,YAAYA,MAAA;AAAA,EACvB,CACE,EAAE,SAAS,QAAW,OAAO,cAAc,OAAO,QAAQ,QAAW,SAAS,OAAO,aAAa,MAAM,GAAG,SAC3G,SACG;AACG,UAAA,SAASC,aAA2B,IAAI;AACxC,UAAA,cAAcA,aAAmB,IAAI;AACrC,UAAA,YAAYA,aA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AAA,QAAA,EAAK,KAAK,aACT,UAAA;AAAA,YAAAG,2BAAA,IAAC,oBAAe,MAAM,CAAC,OAAO,IAAI,EAAE,GAAG;AAAA,YACvCA,2BAAAA,IAAC,uBAAkB,OAAM,WAAU,SAAS,GAAG,aAAW,MAAC,YAAY,MAAO,CAAA;AAAA,UAAA,GAChF;AAAA,UACAH,2BAAAA,KAAC,QAAK,EAAA,KAAK,WACT,UAAA;AAAA,YAAAG,+BAAC,oBAAe,MAAM,CAAC,QAAQ,GAAG,IAAI,EAAE,GAAG;AAAA,YAC3CA,2BAAAA,IAAC,uBAAkB,OAAM,WAAU,SAAS,KAAK,aAAW,MAAC,YAAY,MAAO,CAAA;AAAA,UAAA,GAClF;AAAA,QAAA,GACF;AAAA,QACA;AAAA,MAAA,IAEF;AAAA,qCAEHC,aAAAA,cAAa,EAAA,KAAK,QAAS,GAAG,OAAO,QAAQ,UAAU;AAAA,IAC1D,EAAA,CAAA;AAAA,EAEJ;AACF;;"}
|
|
1
|
+
{"version":3,"file":"Autofocus.cjs","sources":["../../src/effects/Autofocus.tsx"],"sourcesContent":["import * as THREE from 'three'\nimport React, {\n useRef,\n useContext,\n useState,\n useEffect,\n useCallback,\n forwardRef,\n useImperativeHandle,\n RefObject,\n useMemo,\n} from 'react'\nimport { useThree, useFrame, createPortal, type Vector3 } from '@react-three/fiber'\nimport { CopyPass, DepthPickingPass, DepthOfFieldEffect } from 'postprocessing'\nimport { easing } from 'maath'\n\nimport { DepthOfField } from './DepthOfField'\nimport { EffectComposerContext } from '../EffectComposer'\n\nexport type AutofocusProps = React.ComponentProps<typeof DepthOfField> & {\n target?: Vector3\n /** should the target follow the pointer */\n mouse?: boolean\n /** size of the debug green point */\n debug?: number\n /** manual update */\n manual?: boolean\n /** approximate time to reach the target */\n smoothTime?: number\n}\n\nexport type AutofocusApi = {\n dofRef: RefObject<DepthOfFieldEffect>\n hitpoint: THREE.Vector3\n update: (delta: number, updateTarget: boolean) => void\n}\n\nexport const Autofocus = forwardRef<AutofocusApi, AutofocusProps>(\n (\n { target = undefined, mouse: followMouse = false, debug = undefined, manual = false, smoothTime = 0.25, ...props },\n fref\n ) => {\n const dofRef = useRef<DepthOfFieldEffect>(null)\n const hitpointRef = useRef<THREE.Mesh>(null)\n const targetRef = useRef<THREE.Mesh>(null)\n\n const scene = useThree(({ scene }) => scene)\n const pointer = useThree(({ pointer }) => pointer)\n const { composer, camera } = useContext(EffectComposerContext)\n\n // see: https://codesandbox.io/s/depthpickingpass-x130hg\n const [depthPickingPass] = useState(() => new DepthPickingPass())\n const [copyPass] = useState(() => new CopyPass())\n useEffect(() => {\n composer.addPass(depthPickingPass)\n composer.addPass(copyPass)\n return () => {\n composer.removePass(depthPickingPass)\n composer.removePass(copyPass)\n }\n }, [composer, depthPickingPass, copyPass])\n\n useEffect(() => {\n return () => {\n depthPickingPass.dispose()\n copyPass.dispose()\n }\n }, [depthPickingPass, copyPass])\n\n const [hitpoint] = useState(() => new THREE.Vector3(0, 0, 0))\n\n const [ndc] = useState(() => new THREE.Vector3(0, 0, 0))\n const getHit = useCallback(\n async (x: number, y: number) => {\n ndc.x = x\n ndc.y = y\n ndc.z = await depthPickingPass.readDepth(ndc)\n ndc.z = ndc.z * 2.0 - 1.0\n const hit = 1 - ndc.z > 0.0000001 // it is missed if ndc.z is close to 1\n return hit ? ndc.unproject(camera) : false\n },\n [ndc, depthPickingPass, camera]\n )\n\n const update = useCallback(\n async (delta: number, updateTarget = true) => {\n // Update hitpoint\n if (target) {\n hitpoint.set(...(target as [number, number, number]))\n } else {\n const { x, y } = followMouse ? pointer : { x: 0, y: 0 }\n const hit = await getHit(x, y)\n if (hit) hitpoint.copy(hit)\n }\n\n // Update target\n if (updateTarget && dofRef.current?.target) {\n if (smoothTime > 0 && delta > 0) {\n easing.damp3(dofRef.current.target, hitpoint, smoothTime, delta)\n } else {\n dofRef.current.target.copy(hitpoint)\n }\n }\n },\n [target, hitpoint, followMouse, getHit, smoothTime, pointer]\n )\n\n useFrame(async (_, delta) => {\n if (!manual) {\n update(delta)\n }\n if (hitpointRef.current) {\n hitpointRef.current.position.copy(hitpoint)\n }\n if (targetRef.current && dofRef.current?.target) {\n targetRef.current.position.copy(dofRef.current.target)\n }\n })\n\n // Ref API\n const api = useMemo<AutofocusApi>(\n () => ({\n dofRef,\n hitpoint,\n update,\n }),\n [hitpoint, update]\n )\n useImperativeHandle(fref, () => api, [api])\n\n return (\n <>\n {debug\n ? createPortal(\n <>\n <mesh ref={hitpointRef}>\n <sphereGeometry args={[debug, 16, 16]} />\n <meshBasicMaterial color=\"#00ff00\" opacity={1} transparent depthWrite={false} />\n </mesh>\n <mesh ref={targetRef}>\n <sphereGeometry args={[debug / 2, 16, 16]} />\n <meshBasicMaterial color=\"#00ff00\" opacity={0.5} transparent depthWrite={false} />\n </mesh>\n </>,\n scene\n )\n : null}\n\n <DepthOfField ref={dofRef} {...props} target={hitpoint} />\n </>\n )\n }\n)\n"],"names":["forwardRef","useRef","useThree","scene","pointer","useContext","EffectComposerContext","useState","DepthPickingPass","CopyPass","useEffect","THREE","useCallback","easing","useFrame","useMemo","useImperativeHandle","jsxs","Fragment","createPortal","jsx","DepthOfField"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCO,MAAM,YAAYA,MAAA;AAAA,EACvB,CACE,EAAE,SAAS,QAAW,OAAO,cAAc,OAAO,QAAQ,QAAW,SAAS,OAAO,aAAa,MAAM,GAAG,SAC3G,SACG;AACG,UAAA,SAASC,aAA2B,IAAI;AACxC,UAAA,cAAcA,aAAmB,IAAI;AACrC,UAAA,YAAYA,aAAmB,IAAI;AAEzC,UAAM,QAAQC,MAAAA,SAAS,CAAC,EAAE,OAAAC,OAAAA,MAAYA,MAAK;AAC3C,UAAM,UAAUD,MAAAA,SAAS,CAAC,EAAE,SAAAE,SAAAA,MAAcA,QAAO;AACjD,UAAM,EAAE,UAAU,OAAO,IAAIC,iBAAWC,eAAqB,qBAAA;AAG7D,UAAM,CAAC,gBAAgB,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AAA,KAAK,WACT,UAAA;AAAA,YAAAG,+BAAC,oBAAe,MAAM,CAAC,QAAQ,GAAG,IAAI,EAAE,GAAG;AAAA,YAC3CA,2BAAAA,IAAC,uBAAkB,OAAM,WAAU,SAAS,KAAK,aAAW,MAAC,YAAY,MAAO,CAAA;AAAA,UAAA,GAClF;AAAA,QAAA,GACF;AAAA,QACA;AAAA,MAAA,IAEF;AAAA,qCAEHC,aAAAA,cAAa,EAAA,KAAK,QAAS,GAAG,OAAO,QAAQ,UAAU;AAAA,IAC1D,EAAA,CAAA;AAAA,EAEJ;AACF;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
import React, { RefObject } from 'react';
|
|
3
|
-
import { Vector3 } from '@react-three/fiber';
|
|
3
|
+
import { type Vector3 } from '@react-three/fiber';
|
|
4
4
|
import { DepthOfFieldEffect } from 'postprocessing';
|
|
5
5
|
import { DepthOfField } from './DepthOfField';
|
|
6
6
|
export type AutofocusProps = React.ComponentProps<typeof DepthOfField> & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Autofocus.js","sources":["../../src/effects/Autofocus.tsx"],"sourcesContent":["import * as THREE from 'three'\nimport React, {\n useRef,\n useContext,\n useState,\n useEffect,\n useCallback,\n forwardRef,\n useImperativeHandle,\n RefObject,\n useMemo,\n} from 'react'\nimport { useThree, useFrame, createPortal, Vector3 } from '@react-three/fiber'\nimport { CopyPass, DepthPickingPass, DepthOfFieldEffect } from 'postprocessing'\nimport { easing } from 'maath'\n\nimport { DepthOfField } from './DepthOfField'\nimport { EffectComposerContext } from '../EffectComposer'\n\nexport type AutofocusProps = React.ComponentProps<typeof DepthOfField> & {\n target?: Vector3\n /** should the target follow the pointer */\n mouse?: boolean\n /** size of the debug green point */\n debug?: number\n /** manual update */\n manual?: boolean\n /** approximate time to reach the target */\n smoothTime?: number\n}\n\nexport type AutofocusApi = {\n dofRef: RefObject<DepthOfFieldEffect>\n hitpoint: THREE.Vector3\n update: (delta: number, updateTarget: boolean) => void\n}\n\nexport const Autofocus = forwardRef<AutofocusApi, AutofocusProps>(\n (\n { target = undefined, mouse: followMouse = false, debug = undefined, manual = false, smoothTime = 0.25, ...props },\n fref\n ) => {\n const dofRef = useRef<DepthOfFieldEffect>(null)\n const hitpointRef = useRef<THREE.Mesh>(null)\n const targetRef = useRef<THREE.Mesh>(null)\n\n const scene = useThree(({ scene }) => scene)\n const pointer = useThree(({ pointer }) => pointer)\n const { composer, camera } = useContext(EffectComposerContext)\n\n // see: https://codesandbox.io/s/depthpickingpass-x130hg\n const [depthPickingPass] = useState(() => new DepthPickingPass())\n const [copyPass] = useState(() => new CopyPass())\n useEffect(() => {\n composer.addPass(depthPickingPass)\n composer.addPass(copyPass)\n return () => {\n composer.removePass(depthPickingPass)\n composer.removePass(copyPass)\n }\n }, [composer, depthPickingPass, copyPass])\n\n useEffect(() => {\n return () => {\n depthPickingPass.dispose()\n copyPass.dispose()\n }\n }, [depthPickingPass, copyPass])\n\n const [hitpoint] = useState(() => new THREE.Vector3(0, 0, 0))\n\n const [ndc] = useState(() => new THREE.Vector3(0, 0, 0))\n const getHit = useCallback(\n async (x: number, y: number) => {\n ndc.x = x\n ndc.y = y\n ndc.z = await depthPickingPass.readDepth(ndc)\n ndc.z = ndc.z * 2.0 - 1.0\n const hit = 1 - ndc.z > 0.0000001 // it is missed if ndc.z is close to 1\n return hit ? ndc.unproject(camera) : false\n },\n [ndc, depthPickingPass, camera]\n )\n\n const update = useCallback(\n async (delta: number, updateTarget = true) => {\n // Update hitpoint\n if (target) {\n hitpoint.set(...(target as [number, number, number]))\n } else {\n const { x, y } = followMouse ? pointer : { x: 0, y: 0 }\n const hit = await getHit(x, y)\n if (hit) hitpoint.copy(hit)\n }\n\n // Update target\n if (updateTarget && dofRef.current?.target) {\n if (smoothTime > 0 && delta > 0) {\n easing.damp3(dofRef.current.target, hitpoint, smoothTime, delta)\n } else {\n dofRef.current.target.copy(hitpoint)\n }\n }\n },\n [target, hitpoint, followMouse, getHit, smoothTime, pointer]\n )\n\n useFrame(async (_, delta) => {\n if (!manual) {\n update(delta)\n }\n if (hitpointRef.current) {\n hitpointRef.current.position.copy(hitpoint)\n }\n if (targetRef.current && dofRef.current?.target) {\n targetRef.current.position.copy(dofRef.current.target)\n }\n })\n\n // Ref API\n const api = useMemo<AutofocusApi>(\n () => ({\n dofRef,\n hitpoint,\n update,\n }),\n [hitpoint, update]\n )\n useImperativeHandle(fref, () => api, [api])\n\n return (\n <>\n {debug\n ? createPortal(\n <>\n <mesh ref={hitpointRef}>\n <sphereGeometry args={[debug, 16, 16]} />\n <meshBasicMaterial color=\"#00ff00\" opacity={1} transparent depthWrite={false} />\n </mesh>\n <mesh ref={targetRef}>\n <sphereGeometry args={[debug / 2, 16, 16]} />\n <meshBasicMaterial color=\"#00ff00\" opacity={0.5} transparent depthWrite={false} />\n </mesh>\n </>,\n scene\n )\n : null}\n\n <DepthOfField ref={dofRef} {...props} target={hitpoint} />\n </>\n )\n }\n)\n"],"names":["scene","pointer"],"mappings":";;;;;;;;AAqCO,MAAM,YAAY;AAAA,EACvB,CACE,EAAE,SAAS,QAAW,OAAO,cAAc,OAAO,QAAQ,QAAW,SAAS,OAAO,aAAa,MAAM,GAAG,SAC3G,SACG;AACG,UAAA,SAAS,OAA2B,IAAI;AACxC,UAAA,cAAc,OAAmB,IAAI;AACrC,UAAA,YAAY,OAAmB,IAAI;AAEzC,UAAM,QAAQ,SAAS,CAAC,EAAE,OAAAA,OAAAA,MAAYA,MAAK;AAC3C,UAAM,UAAU,SAAS,CAAC,EAAE,SAAAC,SAAAA,MAAcA,QAAO;AACjD,UAAM,EAAE,UAAU,OAAO,IAAI,WAAW,qBAAqB;AAG7D,UAAM,CAAC,gBAAgB,IAAI,SAAS,MAAM,IAAI,iBAAkB,CAAA;AAChE,UAAM,CAAC,QAAQ,IAAI,SAAS,MAAM,IAAI,SAAU,CAAA;AAChD,cAAU,MAAM;AACd,eAAS,QA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QAAQ,UAAU;AAAA,IAC1D,EAAA,CAAA;AAAA,EAEJ;AACF;"}
|
|
1
|
+
{"version":3,"file":"Autofocus.js","sources":["../../src/effects/Autofocus.tsx"],"sourcesContent":["import * as THREE from 'three'\nimport React, {\n useRef,\n useContext,\n useState,\n useEffect,\n useCallback,\n forwardRef,\n useImperativeHandle,\n RefObject,\n useMemo,\n} from 'react'\nimport { useThree, useFrame, createPortal, type Vector3 } from '@react-three/fiber'\nimport { CopyPass, DepthPickingPass, DepthOfFieldEffect } from 'postprocessing'\nimport { easing } from 'maath'\n\nimport { DepthOfField } from './DepthOfField'\nimport { EffectComposerContext } from '../EffectComposer'\n\nexport type AutofocusProps = React.ComponentProps<typeof DepthOfField> & {\n target?: Vector3\n /** should the target follow the pointer */\n mouse?: boolean\n /** size of the debug green point */\n debug?: number\n /** manual update */\n manual?: boolean\n /** approximate time to reach the target */\n smoothTime?: number\n}\n\nexport type AutofocusApi = {\n dofRef: RefObject<DepthOfFieldEffect>\n hitpoint: THREE.Vector3\n update: (delta: number, updateTarget: boolean) => void\n}\n\nexport const Autofocus = forwardRef<AutofocusApi, AutofocusProps>(\n (\n { target = undefined, mouse: followMouse = false, debug = undefined, manual = false, smoothTime = 0.25, ...props },\n fref\n ) => {\n const dofRef = useRef<DepthOfFieldEffect>(null)\n const hitpointRef = useRef<THREE.Mesh>(null)\n const targetRef = useRef<THREE.Mesh>(null)\n\n const scene = useThree(({ scene }) => scene)\n const pointer = useThree(({ pointer }) => pointer)\n const { composer, camera } = useContext(EffectComposerContext)\n\n // see: https://codesandbox.io/s/depthpickingpass-x130hg\n const [depthPickingPass] = useState(() => new DepthPickingPass())\n const [copyPass] = useState(() => new CopyPass())\n useEffect(() => {\n composer.addPass(depthPickingPass)\n composer.addPass(copyPass)\n return () => {\n composer.removePass(depthPickingPass)\n composer.removePass(copyPass)\n }\n }, [composer, depthPickingPass, copyPass])\n\n useEffect(() => {\n return () => {\n depthPickingPass.dispose()\n copyPass.dispose()\n }\n }, [depthPickingPass, copyPass])\n\n const [hitpoint] = useState(() => new THREE.Vector3(0, 0, 0))\n\n const [ndc] = useState(() => new THREE.Vector3(0, 0, 0))\n const getHit = useCallback(\n async (x: number, y: number) => {\n ndc.x = x\n ndc.y = y\n ndc.z = await depthPickingPass.readDepth(ndc)\n ndc.z = ndc.z * 2.0 - 1.0\n const hit = 1 - ndc.z > 0.0000001 // it is missed if ndc.z is close to 1\n return hit ? ndc.unproject(camera) : false\n },\n [ndc, depthPickingPass, camera]\n )\n\n const update = useCallback(\n async (delta: number, updateTarget = true) => {\n // Update hitpoint\n if (target) {\n hitpoint.set(...(target as [number, number, number]))\n } else {\n const { x, y } = followMouse ? pointer : { x: 0, y: 0 }\n const hit = await getHit(x, y)\n if (hit) hitpoint.copy(hit)\n }\n\n // Update target\n if (updateTarget && dofRef.current?.target) {\n if (smoothTime > 0 && delta > 0) {\n easing.damp3(dofRef.current.target, hitpoint, smoothTime, delta)\n } else {\n dofRef.current.target.copy(hitpoint)\n }\n }\n },\n [target, hitpoint, followMouse, getHit, smoothTime, pointer]\n )\n\n useFrame(async (_, delta) => {\n if (!manual) {\n update(delta)\n }\n if (hitpointRef.current) {\n hitpointRef.current.position.copy(hitpoint)\n }\n if (targetRef.current && dofRef.current?.target) {\n targetRef.current.position.copy(dofRef.current.target)\n }\n })\n\n // Ref API\n const api = useMemo<AutofocusApi>(\n () => ({\n dofRef,\n hitpoint,\n update,\n }),\n [hitpoint, update]\n )\n useImperativeHandle(fref, () => api, [api])\n\n return (\n <>\n {debug\n ? createPortal(\n <>\n <mesh ref={hitpointRef}>\n <sphereGeometry args={[debug, 16, 16]} />\n <meshBasicMaterial color=\"#00ff00\" opacity={1} transparent depthWrite={false} />\n </mesh>\n <mesh ref={targetRef}>\n <sphereGeometry args={[debug / 2, 16, 16]} />\n <meshBasicMaterial color=\"#00ff00\" opacity={0.5} transparent depthWrite={false} />\n </mesh>\n </>,\n scene\n )\n : null}\n\n <DepthOfField ref={dofRef} {...props}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CAAC;AAE1C,WAEK,qBAAA,UAAA,EAAA,UAAA;AAAA,MACG,QAAA;AAAA,QAEI,qBAAA,UAAA,EAAA,UAAA;AAAA,UAAC,qBAAA,QAAA,EAAK,KAAK,aACT,UAAA;AAAA,YAAA,oBAAC,oBAAe,MAAM,CAAC,OAAO,IAAI,EAAE,GAAG;AAAA,YACvC,oBAAC,uBAAkB,OAAM,WAAU,SAAS,GAAG,aAAW,MAAC,YAAY,MAAO,CAAA;AAAA,UAAA,GAChF;AAAA,UACA,qBAAC,QAAK,EAAA,KAAK,WACT,UAAA;AAAA,YAAA,oBAAC,oBAAe,MAAM,CAAC,QAAQ,GAAG,IAAI,EAAE,GAAG;AAAA,YAC3C,oBAAC,uBAAkB,OAAM,WAAU,SAAS,KAAK,aAAW,MAAC,YAAY,MAAO,CAAA;AAAA,UAAA,GAClF;AAAA,QAAA,GACF;AAAA,QACA;AAAA,MAAA,IAEF;AAAA,0BAEH,cAAa,EAAA,KAAK,QAAS,GAAG,OAAO,QAAQ,UAAU;AAAA,IAC1D,EAAA,CAAA;AAAA,EAEJ;AACF;"}
|
package/dist/effects/Grid.cjs
CHANGED
|
@@ -11,7 +11,7 @@ const Grid = React.forwardRef(function Grid2({ size, ...props }, ref) {
|
|
|
11
11
|
if (size)
|
|
12
12
|
effect.setSize(size.width, size.height);
|
|
13
13
|
invalidate();
|
|
14
|
-
}, [effect, size]);
|
|
14
|
+
}, [effect, size, invalidate]);
|
|
15
15
|
return /* @__PURE__ */ jsxRuntime.jsx("primitive", { ref, object: effect, dispose: null });
|
|
16
16
|
});
|
|
17
17
|
exports.Grid = Grid;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Grid.cjs","sources":["../../src/effects/Grid.tsx"],"sourcesContent":["import React, { Ref, forwardRef, useMemo, useLayoutEffect } from 'react'\nimport { GridEffect } from 'postprocessing'\nimport { useThree } from '@react-three/fiber'\n\ntype GridProps = ConstructorParameters<typeof GridEffect>[0] &\n Partial<{\n size: {\n width: number\n height: number\n }\n }>\n\nexport const Grid = forwardRef(function Grid({ size, ...props }: GridProps, ref: Ref<GridEffect>) {\n const invalidate = useThree((state) => state.invalidate)\n const effect = useMemo(() => new GridEffect(props), [props])\n useLayoutEffect(() => {\n if (size) effect.setSize(size.width, size.height)\n invalidate()\n }, [effect, size])\n return <primitive ref={ref} object={effect} dispose={null} />\n})\n"],"names":["forwardRef","Grid","useThree","useMemo","GridEffect","useLayoutEffect"],"mappings":";;;;;;AAYa,MAAA,OAAOA,iBAAW,SAASC,MAAK,EAAE,MAAM,GAAG,MAAM,GAAc,KAAsB;AAChG,QAAM,aAAaC,MAAAA,SAAS,CAAC,UAAU,MAAM,UAAU;AACjD,QAAA,SAASC,cAAQ,MAAM,IAAIC,eAAAA,WAAW,KAAK,GAAG,CAAC,KAAK,CAAC;AAC3DC,QAAAA,gBAAgB,MAAM;AAChB,QAAA;AAAM,aAAO,QAAQ,KAAK,OAAO,KAAK,MAAM;AACrC;
|
|
1
|
+
{"version":3,"file":"Grid.cjs","sources":["../../src/effects/Grid.tsx"],"sourcesContent":["import React, { Ref, forwardRef, useMemo, useLayoutEffect } from 'react'\nimport { GridEffect } from 'postprocessing'\nimport { useThree } from '@react-three/fiber'\n\ntype GridProps = ConstructorParameters<typeof GridEffect>[0] &\n Partial<{\n size: {\n width: number\n height: number\n }\n }>\n\nexport const Grid = forwardRef(function Grid({ size, ...props }: GridProps, ref: Ref<GridEffect>) {\n const invalidate = useThree((state) => state.invalidate)\n const effect = useMemo(() => new GridEffect(props), [props])\n useLayoutEffect(() => {\n if (size) effect.setSize(size.width, size.height)\n invalidate()\n }, [effect, size, invalidate])\n return <primitive ref={ref} object={effect} dispose={null} />\n})\n"],"names":["forwardRef","Grid","useThree","useMemo","GridEffect","useLayoutEffect"],"mappings":";;;;;;AAYa,MAAA,OAAOA,iBAAW,SAASC,MAAK,EAAE,MAAM,GAAG,MAAM,GAAc,KAAsB;AAChG,QAAM,aAAaC,MAAAA,SAAS,CAAC,UAAU,MAAM,UAAU;AACjD,QAAA,SAASC,cAAQ,MAAM,IAAIC,eAAAA,WAAW,KAAK,GAAG,CAAC,KAAK,CAAC;AAC3DC,QAAAA,gBAAgB,MAAM;AAChB,QAAA;AAAM,aAAO,QAAQ,KAAK,OAAO,KAAK,MAAM;AACrC;EACV,GAAA,CAAC,QAAQ,MAAM,UAAU,CAAC;AAC7B,wCAAQ,aAAU,EAAA,KAAU,QAAQ,QAAQ,SAAS,KAAM,CAAA;AAC7D,CAAC;;"}
|
package/dist/effects/Grid.js
CHANGED
|
@@ -9,7 +9,7 @@ const Grid = forwardRef(function Grid2({ size, ...props }, ref) {
|
|
|
9
9
|
if (size)
|
|
10
10
|
effect.setSize(size.width, size.height);
|
|
11
11
|
invalidate();
|
|
12
|
-
}, [effect, size]);
|
|
12
|
+
}, [effect, size, invalidate]);
|
|
13
13
|
return /* @__PURE__ */ jsx("primitive", { ref, object: effect, dispose: null });
|
|
14
14
|
});
|
|
15
15
|
export {
|
package/dist/effects/Grid.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Grid.js","sources":["../../src/effects/Grid.tsx"],"sourcesContent":["import React, { Ref, forwardRef, useMemo, useLayoutEffect } from 'react'\nimport { GridEffect } from 'postprocessing'\nimport { useThree } from '@react-three/fiber'\n\ntype GridProps = ConstructorParameters<typeof GridEffect>[0] &\n Partial<{\n size: {\n width: number\n height: number\n }\n }>\n\nexport const Grid = forwardRef(function Grid({ size, ...props }: GridProps, ref: Ref<GridEffect>) {\n const invalidate = useThree((state) => state.invalidate)\n const effect = useMemo(() => new GridEffect(props), [props])\n useLayoutEffect(() => {\n if (size) effect.setSize(size.width, size.height)\n invalidate()\n }, [effect, size])\n return <primitive ref={ref} object={effect} dispose={null} />\n})\n"],"names":["Grid"],"mappings":";;;;AAYa,MAAA,OAAO,WAAW,SAASA,MAAK,EAAE,MAAM,GAAG,MAAM,GAAc,KAAsB;AAChG,QAAM,aAAa,SAAS,CAAC,UAAU,MAAM,UAAU;AACjD,QAAA,SAAS,QAAQ,MAAM,IAAI,WAAW,KAAK,GAAG,CAAC,KAAK,CAAC;AAC3D,kBAAgB,MAAM;AAChB,QAAA;AAAM,aAAO,QAAQ,KAAK,OAAO,KAAK,MAAM;AACrC;
|
|
1
|
+
{"version":3,"file":"Grid.js","sources":["../../src/effects/Grid.tsx"],"sourcesContent":["import React, { Ref, forwardRef, useMemo, useLayoutEffect } from 'react'\nimport { GridEffect } from 'postprocessing'\nimport { useThree } from '@react-three/fiber'\n\ntype GridProps = ConstructorParameters<typeof GridEffect>[0] &\n Partial<{\n size: {\n width: number\n height: number\n }\n }>\n\nexport const Grid = forwardRef(function Grid({ size, ...props }: GridProps, ref: Ref<GridEffect>) {\n const invalidate = useThree((state) => state.invalidate)\n const effect = useMemo(() => new GridEffect(props), [props])\n useLayoutEffect(() => {\n if (size) effect.setSize(size.width, size.height)\n invalidate()\n }, [effect, size, invalidate])\n return <primitive ref={ref} object={effect} dispose={null} />\n})\n"],"names":["Grid"],"mappings":";;;;AAYa,MAAA,OAAO,WAAW,SAASA,MAAK,EAAE,MAAM,GAAG,MAAM,GAAc,KAAsB;AAChG,QAAM,aAAa,SAAS,CAAC,UAAU,MAAM,UAAU;AACjD,QAAA,SAAS,QAAQ,MAAM,IAAI,WAAW,KAAK,GAAG,CAAC,KAAK,CAAC;AAC3D,kBAAgB,MAAM;AAChB,QAAA;AAAM,aAAO,QAAQ,KAAK,OAAO,KAAK,MAAM;AACrC;EACV,GAAA,CAAC,QAAQ,MAAM,UAAU,CAAC;AAC7B,6BAAQ,aAAU,EAAA,KAAU,QAAQ,QAAQ,SAAS,KAAM,CAAA;AAC7D,CAAC;"}
|
|
@@ -20,7 +20,7 @@ const N8AO = React.forwardRef(
|
|
|
20
20
|
renderMode = 0
|
|
21
21
|
}, ref) => {
|
|
22
22
|
const { camera, scene } = fiber.useThree();
|
|
23
|
-
const effect = React.useMemo(() => new N8AOPostPass.N8AOPostPass(scene, camera), []);
|
|
23
|
+
const effect = React.useMemo(() => new N8AOPostPass.N8AOPostPass(scene, camera), [camera, scene]);
|
|
24
24
|
React.useLayoutEffect(() => {
|
|
25
25
|
fiber.applyProps(effect.configuration, {
|
|
26
26
|
color,
|
|
@@ -46,12 +46,13 @@ const N8AO = React.forwardRef(
|
|
|
46
46
|
denoiseRadius,
|
|
47
47
|
renderMode,
|
|
48
48
|
halfRes,
|
|
49
|
-
depthAwareUpsampling
|
|
49
|
+
depthAwareUpsampling,
|
|
50
|
+
effect
|
|
50
51
|
]);
|
|
51
52
|
React.useLayoutEffect(() => {
|
|
52
53
|
if (quality)
|
|
53
54
|
effect.setQualityMode(quality.charAt(0).toUpperCase() + quality.slice(1));
|
|
54
|
-
}, [quality]);
|
|
55
|
+
}, [effect, quality]);
|
|
55
56
|
return /* @__PURE__ */ jsxRuntime.jsx("primitive", { ref, object: effect });
|
|
56
57
|
}
|
|
57
58
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../../src/effects/N8AO/index.tsx"],"sourcesContent":["// From https://github.com/N8python/n8ao\n// https://twitter.com/N8Programs/status/1660996748485984261\n\nimport { Ref, forwardRef, useLayoutEffect, useMemo } from 'react'\n/* @ts-ignore */\nimport { N8AOPostPass } from './N8AOPostPass'\nimport { useThree, ReactThreeFiber, applyProps } from '@react-three/fiber'\n\ntype N8AOProps = {\n aoRadius?: number\n distanceFalloff?: number\n intensity?: number\n quality?: 'performance' | 'low' | 'medium' | 'high' | 'ultra'\n aoSamples?: number\n denoiseSamples?: number\n denoiseRadius?: number\n color?: ReactThreeFiber.Color\n halfRes?: boolean\n depthAwareUpsampling?: boolean\n screenSpaceRadius?: boolean\n renderMode?: 0 | 1 | 2 | 3 | 4\n}\n\nexport const N8AO = forwardRef<N8AOPostPass, N8AOProps>(\n (\n {\n halfRes,\n screenSpaceRadius,\n quality,\n depthAwareUpsampling = true,\n aoRadius = 5,\n aoSamples = 16,\n denoiseSamples = 4,\n denoiseRadius = 12,\n distanceFalloff = 1,\n intensity = 1,\n color,\n renderMode = 0,\n },\n ref: Ref<N8AOPostPass>\n ) => {\n const { camera, scene } = useThree()\n const effect = useMemo(() => new N8AOPostPass(scene, camera), [])\n useLayoutEffect(() => {\n applyProps(effect.configuration, {\n color,\n aoRadius,\n distanceFalloff,\n intensity,\n aoSamples,\n denoiseSamples,\n denoiseRadius,\n screenSpaceRadius,\n renderMode,\n halfRes,\n depthAwareUpsampling,\n })\n }, [\n screenSpaceRadius,\n color,\n aoRadius,\n distanceFalloff,\n intensity,\n aoSamples,\n denoiseSamples,\n denoiseRadius,\n renderMode,\n halfRes,\n depthAwareUpsampling,\n ])\n useLayoutEffect(() => {\n if (quality) effect.setQualityMode(quality.charAt(0).toUpperCase() + quality.slice(1))\n }, [quality])\n return <primitive ref={ref} object={effect} />\n }\n)\n"],"names":["forwardRef","useThree","useMemo","N8AOPostPass","useLayoutEffect","applyProps","jsx"],"mappings":";;;;;;AAuBO,MAAM,OAAOA,MAAA;AAAA,EAClB,CACE;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA,uBAAuB;AAAA,IACvB,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,iBAAiB;AAAA,IACjB,gBAAgB;AAAA,IAChB,kBAAkB;AAAA,IAClB,YAAY;AAAA,IACZ;AAAA,IACA,aAAa;AAAA,KAEf,QACG;AACH,UAAM,EAAE,QAAQ,MAAM,IAAIC,MAAS,SAAA;AAC7B,UAAA,SAASC,
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../src/effects/N8AO/index.tsx"],"sourcesContent":["// From https://github.com/N8python/n8ao\n// https://twitter.com/N8Programs/status/1660996748485984261\n\nimport { Ref, forwardRef, useLayoutEffect, useMemo } from 'react'\n/* @ts-ignore */\nimport { N8AOPostPass } from './N8AOPostPass'\nimport { useThree, ReactThreeFiber, applyProps } from '@react-three/fiber'\n\ntype N8AOProps = {\n aoRadius?: number\n distanceFalloff?: number\n intensity?: number\n quality?: 'performance' | 'low' | 'medium' | 'high' | 'ultra'\n aoSamples?: number\n denoiseSamples?: number\n denoiseRadius?: number\n color?: ReactThreeFiber.Color\n halfRes?: boolean\n depthAwareUpsampling?: boolean\n screenSpaceRadius?: boolean\n renderMode?: 0 | 1 | 2 | 3 | 4\n}\n\nexport const N8AO = forwardRef<N8AOPostPass, N8AOProps>(\n (\n {\n halfRes,\n screenSpaceRadius,\n quality,\n depthAwareUpsampling = true,\n aoRadius = 5,\n aoSamples = 16,\n denoiseSamples = 4,\n denoiseRadius = 12,\n distanceFalloff = 1,\n intensity = 1,\n color,\n renderMode = 0,\n },\n ref: Ref<N8AOPostPass>\n ) => {\n const { camera, scene } = useThree()\n const effect = useMemo(() => new N8AOPostPass(scene, camera), [camera, scene])\n\n // TODO: implement dispose upstream; this effect has memory leaks without\n useLayoutEffect(() => {\n applyProps(effect.configuration, {\n color,\n aoRadius,\n distanceFalloff,\n intensity,\n aoSamples,\n denoiseSamples,\n denoiseRadius,\n screenSpaceRadius,\n renderMode,\n halfRes,\n depthAwareUpsampling,\n })\n }, [\n screenSpaceRadius,\n color,\n aoRadius,\n distanceFalloff,\n intensity,\n aoSamples,\n denoiseSamples,\n denoiseRadius,\n renderMode,\n halfRes,\n depthAwareUpsampling,\n effect,\n ])\n\n useLayoutEffect(() => {\n if (quality) effect.setQualityMode(quality.charAt(0).toUpperCase() + quality.slice(1))\n }, [effect, quality])\n\n return <primitive ref={ref} object={effect} />\n }\n)\n"],"names":["forwardRef","useThree","useMemo","N8AOPostPass","useLayoutEffect","applyProps","jsx"],"mappings":";;;;;;AAuBO,MAAM,OAAOA,MAAA;AAAA,EAClB,CACE;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA,uBAAuB;AAAA,IACvB,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,iBAAiB;AAAA,IACjB,gBAAgB;AAAA,IAChB,kBAAkB;AAAA,IAClB,YAAY;AAAA,IACZ;AAAA,IACA,aAAa;AAAA,KAEf,QACG;AACH,UAAM,EAAE,QAAQ,MAAM,IAAIC,MAAS,SAAA;AAC7B,UAAA,SAASC,MAAAA,QAAQ,MAAM,IAAIC,0BAAa,OAAO,MAAM,GAAG,CAAC,QAAQ,KAAK,CAAC;AAG7EC,UAAAA,gBAAgB,MAAM;AACpBC,YAAA,WAAW,OAAO,eAAe;AAAA,QAC/B;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MAAA,CACD;AAAA,IAAA,GACA;AAAA,MACD;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD;AAEDD,UAAAA,gBAAgB,MAAM;AAChB,UAAA;AAAgB,eAAA,eAAe,QAAQ,OAAO,CAAC,EAAE,gBAAgB,QAAQ,MAAM,CAAC,CAAC;AAAA,IAAA,GACpF,CAAC,QAAQ,OAAO,CAAC;AAEpB,WAAQE,2BAAAA,IAAA,aAAA,EAAU,KAAU,QAAQ,OAAQ,CAAA;AAAA,EAC9C;AACF;;"}
|
|
@@ -18,7 +18,7 @@ const N8AO = forwardRef(
|
|
|
18
18
|
renderMode = 0
|
|
19
19
|
}, ref) => {
|
|
20
20
|
const { camera, scene } = useThree();
|
|
21
|
-
const effect = useMemo(() => new N8AOPostPass(scene, camera), []);
|
|
21
|
+
const effect = useMemo(() => new N8AOPostPass(scene, camera), [camera, scene]);
|
|
22
22
|
useLayoutEffect(() => {
|
|
23
23
|
applyProps(effect.configuration, {
|
|
24
24
|
color,
|
|
@@ -44,12 +44,13 @@ const N8AO = forwardRef(
|
|
|
44
44
|
denoiseRadius,
|
|
45
45
|
renderMode,
|
|
46
46
|
halfRes,
|
|
47
|
-
depthAwareUpsampling
|
|
47
|
+
depthAwareUpsampling,
|
|
48
|
+
effect
|
|
48
49
|
]);
|
|
49
50
|
useLayoutEffect(() => {
|
|
50
51
|
if (quality)
|
|
51
52
|
effect.setQualityMode(quality.charAt(0).toUpperCase() + quality.slice(1));
|
|
52
|
-
}, [quality]);
|
|
53
|
+
}, [effect, quality]);
|
|
53
54
|
return /* @__PURE__ */ jsx("primitive", { ref, object: effect });
|
|
54
55
|
}
|
|
55
56
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/effects/N8AO/index.tsx"],"sourcesContent":["// From https://github.com/N8python/n8ao\n// https://twitter.com/N8Programs/status/1660996748485984261\n\nimport { Ref, forwardRef, useLayoutEffect, useMemo } from 'react'\n/* @ts-ignore */\nimport { N8AOPostPass } from './N8AOPostPass'\nimport { useThree, ReactThreeFiber, applyProps } from '@react-three/fiber'\n\ntype N8AOProps = {\n aoRadius?: number\n distanceFalloff?: number\n intensity?: number\n quality?: 'performance' | 'low' | 'medium' | 'high' | 'ultra'\n aoSamples?: number\n denoiseSamples?: number\n denoiseRadius?: number\n color?: ReactThreeFiber.Color\n halfRes?: boolean\n depthAwareUpsampling?: boolean\n screenSpaceRadius?: boolean\n renderMode?: 0 | 1 | 2 | 3 | 4\n}\n\nexport const N8AO = forwardRef<N8AOPostPass, N8AOProps>(\n (\n {\n halfRes,\n screenSpaceRadius,\n quality,\n depthAwareUpsampling = true,\n aoRadius = 5,\n aoSamples = 16,\n denoiseSamples = 4,\n denoiseRadius = 12,\n distanceFalloff = 1,\n intensity = 1,\n color,\n renderMode = 0,\n },\n ref: Ref<N8AOPostPass>\n ) => {\n const { camera, scene } = useThree()\n const effect = useMemo(() => new N8AOPostPass(scene, camera), [])\n useLayoutEffect(() => {\n applyProps(effect.configuration, {\n color,\n aoRadius,\n distanceFalloff,\n intensity,\n aoSamples,\n denoiseSamples,\n denoiseRadius,\n screenSpaceRadius,\n renderMode,\n halfRes,\n depthAwareUpsampling,\n })\n }, [\n screenSpaceRadius,\n color,\n aoRadius,\n distanceFalloff,\n intensity,\n aoSamples,\n denoiseSamples,\n denoiseRadius,\n renderMode,\n halfRes,\n depthAwareUpsampling,\n ])\n useLayoutEffect(() => {\n if (quality) effect.setQualityMode(quality.charAt(0).toUpperCase() + quality.slice(1))\n }, [quality])\n return <primitive ref={ref} object={effect} />\n }\n)\n"],"names":[],"mappings":";;;;AAuBO,MAAM,OAAO;AAAA,EAClB,CACE;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA,uBAAuB;AAAA,IACvB,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,iBAAiB;AAAA,IACjB,gBAAgB;AAAA,IAChB,kBAAkB;AAAA,IAClB,YAAY;AAAA,IACZ;AAAA,IACA,aAAa;AAAA,KAEf,QACG;AACH,UAAM,EAAE,QAAQ,MAAM,IAAI,SAAS;AAC7B,UAAA,SAAS,QAAQ,MAAM,IAAI,aAAa,OAAO,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/effects/N8AO/index.tsx"],"sourcesContent":["// From https://github.com/N8python/n8ao\n// https://twitter.com/N8Programs/status/1660996748485984261\n\nimport { Ref, forwardRef, useLayoutEffect, useMemo } from 'react'\n/* @ts-ignore */\nimport { N8AOPostPass } from './N8AOPostPass'\nimport { useThree, ReactThreeFiber, applyProps } from '@react-three/fiber'\n\ntype N8AOProps = {\n aoRadius?: number\n distanceFalloff?: number\n intensity?: number\n quality?: 'performance' | 'low' | 'medium' | 'high' | 'ultra'\n aoSamples?: number\n denoiseSamples?: number\n denoiseRadius?: number\n color?: ReactThreeFiber.Color\n halfRes?: boolean\n depthAwareUpsampling?: boolean\n screenSpaceRadius?: boolean\n renderMode?: 0 | 1 | 2 | 3 | 4\n}\n\nexport const N8AO = forwardRef<N8AOPostPass, N8AOProps>(\n (\n {\n halfRes,\n screenSpaceRadius,\n quality,\n depthAwareUpsampling = true,\n aoRadius = 5,\n aoSamples = 16,\n denoiseSamples = 4,\n denoiseRadius = 12,\n distanceFalloff = 1,\n intensity = 1,\n color,\n renderMode = 0,\n },\n ref: Ref<N8AOPostPass>\n ) => {\n const { camera, scene } = useThree()\n const effect = useMemo(() => new N8AOPostPass(scene, camera), [camera, scene])\n\n // TODO: implement dispose upstream; this effect has memory leaks without\n useLayoutEffect(() => {\n applyProps(effect.configuration, {\n color,\n aoRadius,\n distanceFalloff,\n intensity,\n aoSamples,\n denoiseSamples,\n denoiseRadius,\n screenSpaceRadius,\n renderMode,\n halfRes,\n depthAwareUpsampling,\n })\n }, [\n screenSpaceRadius,\n color,\n aoRadius,\n distanceFalloff,\n intensity,\n aoSamples,\n denoiseSamples,\n denoiseRadius,\n renderMode,\n halfRes,\n depthAwareUpsampling,\n effect,\n ])\n\n useLayoutEffect(() => {\n if (quality) effect.setQualityMode(quality.charAt(0).toUpperCase() + quality.slice(1))\n }, [effect, quality])\n\n return <primitive ref={ref} object={effect} />\n }\n)\n"],"names":[],"mappings":";;;;AAuBO,MAAM,OAAO;AAAA,EAClB,CACE;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA,uBAAuB;AAAA,IACvB,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,iBAAiB;AAAA,IACjB,gBAAgB;AAAA,IAChB,kBAAkB;AAAA,IAClB,YAAY;AAAA,IACZ;AAAA,IACA,aAAa;AAAA,KAEf,QACG;AACH,UAAM,EAAE,QAAQ,MAAM,IAAI,SAAS;AAC7B,UAAA,SAAS,QAAQ,MAAM,IAAI,aAAa,OAAO,MAAM,GAAG,CAAC,QAAQ,KAAK,CAAC;AAG7E,oBAAgB,MAAM;AACpB,iBAAW,OAAO,eAAe;AAAA,QAC/B;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MAAA,CACD;AAAA,IAAA,GACA;AAAA,MACD;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD;AAED,oBAAgB,MAAM;AAChB,UAAA;AAAgB,eAAA,eAAe,QAAQ,OAAO,CAAC,EAAE,gBAAgB,QAAQ,MAAM,CAAC,CAAC;AAAA,IAAA,GACpF,CAAC,QAAQ,OAAO,CAAC;AAEpB,WAAQ,oBAAA,aAAA,EAAU,KAAU,QAAQ,OAAQ,CAAA;AAAA,EAC9C;AACF;"}
|
package/dist/effects/Outline.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Outline.cjs","sources":["../../src/effects/Outline.tsx"],"sourcesContent":["import { OutlineEffect } from 'postprocessing'\nimport { Ref, MutableRefObject, forwardRef, useMemo, useEffect, useContext, useRef } from 'react'\nimport { Object3D } from 'three'\nimport { useThree } from '@react-three/fiber'\nimport { EffectComposerContext } from '../EffectComposer'\nimport { selectionContext } from '../Selection'\nimport { resolveRef } from '../util'\n\ntype ObjectRef = MutableRefObject<Object3D>\n\nexport type OutlineProps = ConstructorParameters<typeof OutlineEffect>[2] &\n Partial<{\n selection: Object3D | Object3D[] | ObjectRef | ObjectRef[]\n selectionLayer: number\n }>\n\nexport const Outline = forwardRef(function Outline(\n {\n selection = [],\n selectionLayer = 10,\n blendFunction,\n patternTexture,\n edgeStrength,\n pulseSpeed,\n visibleEdgeColor,\n hiddenEdgeColor,\n width,\n height,\n kernelSize,\n blur,\n xRay,\n ...props\n }: OutlineProps,\n forwardRef: Ref<OutlineEffect>\n) {\n const invalidate = useThree((state) => state.invalidate)\n const { scene, camera } = useContext(EffectComposerContext)\n\n const effect = useMemo(\n () =>\n new OutlineEffect(scene, camera, {\n blendFunction,\n patternTexture,\n edgeStrength,\n pulseSpeed,\n visibleEdgeColor,\n hiddenEdgeColor,\n width,\n height,\n kernelSize,\n blur,\n xRay,\n ...props,\n }),\n [\n blendFunction,\n blur,\n camera,\n edgeStrength,\n height,\n hiddenEdgeColor,\n kernelSize,\n patternTexture,\n pulseSpeed,\n scene,\n visibleEdgeColor,\n width,\n xRay,\n ]\n )\n\n const api = useContext(selectionContext)\n\n useEffect(() => {\n // Do not allow array selection if declarative selection is active\n // TODO: array selection should probably be deprecated altogether\n if (!api && selection) {\n effect.selection.set(\n Array.isArray(selection) ? (selection as Object3D[]).map(resolveRef) : [resolveRef(selection) as Object3D]\n )\n invalidate()\n return () => {\n effect.selection.clear()\n invalidate()\n }\n }\n }, [effect, selection, api, invalidate])\n\n useEffect(() => {\n effect.selectionLayer = selectionLayer\n invalidate()\n }, [effect, invalidate, selectionLayer])\n\n const ref = useRef<OutlineEffect>()\n useEffect(() => {\n if (api && api.enabled) {\n if (api.selected?.length) {\n effect.selection.set(api.selected)\n invalidate()\n return () => {\n effect.selection.clear()\n invalidate()\n }\n }\n }\n }, [api, effect.selection, invalidate])\n\n useEffect(() => {\n return () => {\n effect.dispose()\n }\n }, [effect])\n\n return <primitive ref={forwardRef} object={effect} />\n})\n"],"names":["forwardRef","Outline","useThree","useContext","EffectComposerContext","useMemo","OutlineEffect","selectionContext","useEffect","resolveRef","useRef","jsx"],"mappings":";;;;;;;;;AAgBa,MAAA,UAAUA,MAAAA,WAAW,SAASC,SACzC;AAAA,EACE,YAAY,CAAC;AAAA,EACb,iBAAiB;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GACAD,aACA;AACA,QAAM,aAAaE,MAAAA,SAAS,CAAC,UAAU,MAAM,UAAU;AACvD,QAAM,EAAE,OAAO,OAAO,IAAIC,iBAAWC,eAAqB,qBAAA;AAE1D,QAAM,SAASC,MAAA;AAAA,IACb,MACE,IAAIC,eAAAA,cAAc,OAAO,QAAQ;AAAA,MAC/B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IAAA,CACJ;AAAA,
|
|
1
|
+
{"version":3,"file":"Outline.cjs","sources":["../../src/effects/Outline.tsx"],"sourcesContent":["import { OutlineEffect } from 'postprocessing'\nimport { Ref, MutableRefObject, forwardRef, useMemo, useEffect, useContext, useRef } from 'react'\nimport { Object3D } from 'three'\nimport { useThree } from '@react-three/fiber'\nimport { EffectComposerContext } from '../EffectComposer'\nimport { selectionContext } from '../Selection'\nimport { resolveRef } from '../util'\n\ntype ObjectRef = MutableRefObject<Object3D>\n\nexport type OutlineProps = ConstructorParameters<typeof OutlineEffect>[2] &\n Partial<{\n selection: Object3D | Object3D[] | ObjectRef | ObjectRef[]\n selectionLayer: number\n }>\n\nexport const Outline = forwardRef(function Outline(\n {\n selection = [],\n selectionLayer = 10,\n blendFunction,\n patternTexture,\n edgeStrength,\n pulseSpeed,\n visibleEdgeColor,\n hiddenEdgeColor,\n width,\n height,\n kernelSize,\n blur,\n xRay,\n ...props\n }: OutlineProps,\n forwardRef: Ref<OutlineEffect>\n) {\n const invalidate = useThree((state) => state.invalidate)\n const { scene, camera } = useContext(EffectComposerContext)\n\n const effect = useMemo(\n () =>\n new OutlineEffect(scene, camera, {\n blendFunction,\n patternTexture,\n edgeStrength,\n pulseSpeed,\n visibleEdgeColor,\n hiddenEdgeColor,\n width,\n height,\n kernelSize,\n blur,\n xRay,\n ...props,\n }),\n // NOTE: `props` is an unstable reference, so we can't memoize it\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [\n blendFunction,\n blur,\n camera,\n edgeStrength,\n height,\n hiddenEdgeColor,\n kernelSize,\n patternTexture,\n pulseSpeed,\n scene,\n visibleEdgeColor,\n width,\n xRay,\n ]\n )\n\n const api = useContext(selectionContext)\n\n useEffect(() => {\n // Do not allow array selection if declarative selection is active\n // TODO: array selection should probably be deprecated altogether\n if (!api && selection) {\n effect.selection.set(\n Array.isArray(selection) ? (selection as Object3D[]).map(resolveRef) : [resolveRef(selection) as Object3D]\n )\n invalidate()\n return () => {\n effect.selection.clear()\n invalidate()\n }\n }\n }, [effect, selection, api, invalidate])\n\n useEffect(() => {\n effect.selectionLayer = selectionLayer\n invalidate()\n }, [effect, invalidate, selectionLayer])\n\n const ref = useRef<OutlineEffect>()\n useEffect(() => {\n if (api && api.enabled) {\n if (api.selected?.length) {\n effect.selection.set(api.selected)\n invalidate()\n return () => {\n effect.selection.clear()\n invalidate()\n }\n }\n }\n }, [api, effect.selection, invalidate])\n\n useEffect(() => {\n return () => {\n effect.dispose()\n }\n }, [effect])\n\n return <primitive ref={forwardRef} object={effect} />\n})\n"],"names":["forwardRef","Outline","useThree","useContext","EffectComposerContext","useMemo","OutlineEffect","selectionContext","useEffect","resolveRef","useRef","jsx"],"mappings":";;;;;;;;;AAgBa,MAAA,UAAUA,MAAAA,WAAW,SAASC,SACzC;AAAA,EACE,YAAY,CAAC;AAAA,EACb,iBAAiB;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GACAD,aACA;AACA,QAAM,aAAaE,MAAAA,SAAS,CAAC,UAAU,MAAM,UAAU;AACvD,QAAM,EAAE,OAAO,OAAO,IAAIC,iBAAWC,eAAqB,qBAAA;AAE1D,QAAM,SAASC,MAAA;AAAA,IACb,MACE,IAAIC,eAAAA,cAAc,OAAO,QAAQ;AAAA,MAC/B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IAAA,CACJ;AAAA;AAAA;AAAA,IAGH;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EAAA;AAGI,QAAA,MAAMH,iBAAWI,UAAAA,gBAAgB;AAEvCC,QAAAA,UAAU,MAAM;AAGV,QAAA,CAAC,OAAO,WAAW;AACrB,aAAO,UAAU;AAAA,QACf,MAAM,QAAQ,SAAS,IAAK,UAAyB,IAAIC,KAAAA,UAAU,IAAI,CAACA,gBAAW,SAAS,CAAa;AAAA,MAAA;AAEhG;AACX,aAAO,MAAM;AACX,eAAO,UAAU;AACN;MAAA;AAAA,IAEf;AAAA,KACC,CAAC,QAAQ,WAAW,KAAK,UAAU,CAAC;AAEvCD,QAAAA,UAAU,MAAM;AACd,WAAO,iBAAiB;AACb;EACV,GAAA,CAAC,QAAQ,YAAY,cAAc,CAAC;AAE3BE,eAAsB;AAClCF,QAAAA,UAAU,MAAM;;AACV,QAAA,OAAO,IAAI,SAAS;AAClB,WAAA,SAAI,aAAJ,mBAAc,QAAQ;AACjB,eAAA,UAAU,IAAI,IAAI,QAAQ;AACtB;AACX,eAAO,MAAM;AACX,iBAAO,UAAU;AACN;QAAA;AAAA,MAEf;AAAA,IACF;AAAA,KACC,CAAC,KAAK,OAAO,WAAW,UAAU,CAAC;AAEtCA,QAAAA,UAAU,MAAM;AACd,WAAO,MAAM;AACX,aAAO,QAAQ;AAAA,IAAA;AAAA,EACjB,GACC,CAAC,MAAM,CAAC;AAEX,SAAQG,2BAAAA,IAAA,aAAA,EAAU,KAAKX,aAAY,QAAQ,OAAQ,CAAA;AACrD,CAAC;;"}
|
package/dist/effects/Outline.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Outline.js","sources":["../../src/effects/Outline.tsx"],"sourcesContent":["import { OutlineEffect } from 'postprocessing'\nimport { Ref, MutableRefObject, forwardRef, useMemo, useEffect, useContext, useRef } from 'react'\nimport { Object3D } from 'three'\nimport { useThree } from '@react-three/fiber'\nimport { EffectComposerContext } from '../EffectComposer'\nimport { selectionContext } from '../Selection'\nimport { resolveRef } from '../util'\n\ntype ObjectRef = MutableRefObject<Object3D>\n\nexport type OutlineProps = ConstructorParameters<typeof OutlineEffect>[2] &\n Partial<{\n selection: Object3D | Object3D[] | ObjectRef | ObjectRef[]\n selectionLayer: number\n }>\n\nexport const Outline = forwardRef(function Outline(\n {\n selection = [],\n selectionLayer = 10,\n blendFunction,\n patternTexture,\n edgeStrength,\n pulseSpeed,\n visibleEdgeColor,\n hiddenEdgeColor,\n width,\n height,\n kernelSize,\n blur,\n xRay,\n ...props\n }: OutlineProps,\n forwardRef: Ref<OutlineEffect>\n) {\n const invalidate = useThree((state) => state.invalidate)\n const { scene, camera } = useContext(EffectComposerContext)\n\n const effect = useMemo(\n () =>\n new OutlineEffect(scene, camera, {\n blendFunction,\n patternTexture,\n edgeStrength,\n pulseSpeed,\n visibleEdgeColor,\n hiddenEdgeColor,\n width,\n height,\n kernelSize,\n blur,\n xRay,\n ...props,\n }),\n [\n blendFunction,\n blur,\n camera,\n edgeStrength,\n height,\n hiddenEdgeColor,\n kernelSize,\n patternTexture,\n pulseSpeed,\n scene,\n visibleEdgeColor,\n width,\n xRay,\n ]\n )\n\n const api = useContext(selectionContext)\n\n useEffect(() => {\n // Do not allow array selection if declarative selection is active\n // TODO: array selection should probably be deprecated altogether\n if (!api && selection) {\n effect.selection.set(\n Array.isArray(selection) ? (selection as Object3D[]).map(resolveRef) : [resolveRef(selection) as Object3D]\n )\n invalidate()\n return () => {\n effect.selection.clear()\n invalidate()\n }\n }\n }, [effect, selection, api, invalidate])\n\n useEffect(() => {\n effect.selectionLayer = selectionLayer\n invalidate()\n }, [effect, invalidate, selectionLayer])\n\n const ref = useRef<OutlineEffect>()\n useEffect(() => {\n if (api && api.enabled) {\n if (api.selected?.length) {\n effect.selection.set(api.selected)\n invalidate()\n return () => {\n effect.selection.clear()\n invalidate()\n }\n }\n }\n }, [api, effect.selection, invalidate])\n\n useEffect(() => {\n return () => {\n effect.dispose()\n }\n }, [effect])\n\n return <primitive ref={forwardRef} object={effect} />\n})\n"],"names":["Outline","forwardRef"],"mappings":";;;;;;;AAgBa,MAAA,UAAU,WAAW,SAASA,SACzC;AAAA,EACE,YAAY,CAAC;AAAA,EACb,iBAAiB;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GACAC,aACA;AACA,QAAM,aAAa,SAAS,CAAC,UAAU,MAAM,UAAU;AACvD,QAAM,EAAE,OAAO,OAAO,IAAI,WAAW,qBAAqB;AAE1D,QAAM,SAAS;AAAA,IACb,MACE,IAAI,cAAc,OAAO,QAAQ;AAAA,MAC/B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IAAA,CACJ;AAAA,
|
|
1
|
+
{"version":3,"file":"Outline.js","sources":["../../src/effects/Outline.tsx"],"sourcesContent":["import { OutlineEffect } from 'postprocessing'\nimport { Ref, MutableRefObject, forwardRef, useMemo, useEffect, useContext, useRef } from 'react'\nimport { Object3D } from 'three'\nimport { useThree } from '@react-three/fiber'\nimport { EffectComposerContext } from '../EffectComposer'\nimport { selectionContext } from '../Selection'\nimport { resolveRef } from '../util'\n\ntype ObjectRef = MutableRefObject<Object3D>\n\nexport type OutlineProps = ConstructorParameters<typeof OutlineEffect>[2] &\n Partial<{\n selection: Object3D | Object3D[] | ObjectRef | ObjectRef[]\n selectionLayer: number\n }>\n\nexport const Outline = forwardRef(function Outline(\n {\n selection = [],\n selectionLayer = 10,\n blendFunction,\n patternTexture,\n edgeStrength,\n pulseSpeed,\n visibleEdgeColor,\n hiddenEdgeColor,\n width,\n height,\n kernelSize,\n blur,\n xRay,\n ...props\n }: OutlineProps,\n forwardRef: Ref<OutlineEffect>\n) {\n const invalidate = useThree((state) => state.invalidate)\n const { scene, camera } = useContext(EffectComposerContext)\n\n const effect = useMemo(\n () =>\n new OutlineEffect(scene, camera, {\n blendFunction,\n patternTexture,\n edgeStrength,\n pulseSpeed,\n visibleEdgeColor,\n hiddenEdgeColor,\n width,\n height,\n kernelSize,\n blur,\n xRay,\n ...props,\n }),\n // NOTE: `props` is an unstable reference, so we can't memoize it\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [\n blendFunction,\n blur,\n camera,\n edgeStrength,\n height,\n hiddenEdgeColor,\n kernelSize,\n patternTexture,\n pulseSpeed,\n scene,\n visibleEdgeColor,\n width,\n xRay,\n ]\n )\n\n const api = useContext(selectionContext)\n\n useEffect(() => {\n // Do not allow array selection if declarative selection is active\n // TODO: array selection should probably be deprecated altogether\n if (!api && selection) {\n effect.selection.set(\n Array.isArray(selection) ? (selection as Object3D[]).map(resolveRef) : [resolveRef(selection) as Object3D]\n )\n invalidate()\n return () => {\n effect.selection.clear()\n invalidate()\n }\n }\n }, [effect, selection, api, invalidate])\n\n useEffect(() => {\n effect.selectionLayer = selectionLayer\n invalidate()\n }, [effect, invalidate, selectionLayer])\n\n const ref = useRef<OutlineEffect>()\n useEffect(() => {\n if (api && api.enabled) {\n if (api.selected?.length) {\n effect.selection.set(api.selected)\n invalidate()\n return () => {\n effect.selection.clear()\n invalidate()\n }\n }\n }\n }, [api, effect.selection, invalidate])\n\n useEffect(() => {\n return () => {\n effect.dispose()\n }\n }, [effect])\n\n return <primitive ref={forwardRef} object={effect} />\n})\n"],"names":["Outline","forwardRef"],"mappings":";;;;;;;AAgBa,MAAA,UAAU,WAAW,SAASA,SACzC;AAAA,EACE,YAAY,CAAC;AAAA,EACb,iBAAiB;AAAA,EACjB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,GACAC,aACA;AACA,QAAM,aA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,MAAM,CAAC;AAEX,SAAQ,oBAAA,aAAA,EAAU,KAAKA,aAAY,QAAQ,OAAQ,CAAA;AACrD,CAAC;"}
|
package/dist/effects/SSAO.cjs
CHANGED
|
@@ -30,7 +30,7 @@ const SSAO = React.forwardRef(function SSAO2(props, ref) {
|
|
|
30
30
|
depthAwareUpsampling: true,
|
|
31
31
|
...props
|
|
32
32
|
});
|
|
33
|
-
}, [camera, normalPass,
|
|
33
|
+
}, [camera, downSamplingPass, normalPass, resolutionScale]);
|
|
34
34
|
return /* @__PURE__ */ jsxRuntime.jsx("primitive", { ref, object: effect, dispose: null });
|
|
35
35
|
});
|
|
36
36
|
exports.SSAO = SSAO;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SSAO.cjs","sources":["../../src/effects/SSAO.tsx"],"sourcesContent":["import { Ref, forwardRef, useContext, useMemo } from 'react'\nimport { SSAOEffect, BlendFunction } from 'postprocessing'\nimport { EffectComposerContext } from '../EffectComposer'\n\n// first two args are camera and texture\ntype SSAOProps = ConstructorParameters<typeof SSAOEffect>[2]\n\nexport const SSAO = forwardRef<SSAOEffect, SSAOProps>(function SSAO(props: SSAOProps, ref: Ref<SSAOEffect>) {\n const { camera, normalPass, downSamplingPass, resolutionScale } = useContext(EffectComposerContext)\n const effect = useMemo<SSAOEffect | {}>(() => {\n if (normalPass === null && downSamplingPass === null) {\n console.error('Please enable the NormalPass in the EffectComposer in order to use SSAO.')\n return {}\n }\n return new SSAOEffect(camera, normalPass && !downSamplingPass ? (normalPass as any).texture : null, {\n blendFunction: BlendFunction.MULTIPLY,\n samples: 30,\n rings: 4,\n distanceThreshold: 1.0,\n distanceFalloff: 0.0,\n rangeThreshold: 0.5,\n rangeFalloff: 0.1,\n luminanceInfluence: 0.9,\n radius: 20,\n bias: 0.5,\n intensity: 1.0,\n color: undefined,\n // @ts-ignore\n normalDepthBuffer: downSamplingPass ? downSamplingPass.texture : null,\n resolutionScale: resolutionScale ?? 1,\n depthAwareUpsampling: true,\n ...props,\n })\n }, [camera, normalPass,
|
|
1
|
+
{"version":3,"file":"SSAO.cjs","sources":["../../src/effects/SSAO.tsx"],"sourcesContent":["import { Ref, forwardRef, useContext, useMemo } from 'react'\nimport { SSAOEffect, BlendFunction } from 'postprocessing'\nimport { EffectComposerContext } from '../EffectComposer'\n\n// first two args are camera and texture\ntype SSAOProps = ConstructorParameters<typeof SSAOEffect>[2]\n\nexport const SSAO = forwardRef<SSAOEffect, SSAOProps>(function SSAO(props: SSAOProps, ref: Ref<SSAOEffect>) {\n const { camera, normalPass, downSamplingPass, resolutionScale } = useContext(EffectComposerContext)\n const effect = useMemo<SSAOEffect | {}>(() => {\n if (normalPass === null && downSamplingPass === null) {\n console.error('Please enable the NormalPass in the EffectComposer in order to use SSAO.')\n return {}\n }\n return new SSAOEffect(camera, normalPass && !downSamplingPass ? (normalPass as any).texture : null, {\n blendFunction: BlendFunction.MULTIPLY,\n samples: 30,\n rings: 4,\n distanceThreshold: 1.0,\n distanceFalloff: 0.0,\n rangeThreshold: 0.5,\n rangeFalloff: 0.1,\n luminanceInfluence: 0.9,\n radius: 20,\n bias: 0.5,\n intensity: 1.0,\n color: undefined,\n // @ts-ignore\n normalDepthBuffer: downSamplingPass ? downSamplingPass.texture : null,\n resolutionScale: resolutionScale ?? 1,\n depthAwareUpsampling: true,\n ...props,\n })\n // NOTE: `props` is an unstable reference, so we can't memoize it\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [camera, downSamplingPass, normalPass, resolutionScale])\n return <primitive ref={ref} object={effect} dispose={null} />\n})\n"],"names":["forwardRef","SSAO","useContext","EffectComposerContext","useMemo","SSAOEffect","BlendFunction"],"mappings":";;;;;;AAOO,MAAM,OAAOA,MAAAA,WAAkC,SAASC,MAAK,OAAkB,KAAsB;AAC1G,QAAM,EAAE,QAAQ,YAAY,kBAAkB,oBAAoBC,MAAAA,WAAWC,eAAAA,qBAAqB;AAC5F,QAAA,SAASC,MAAAA,QAAyB,MAAM;AACxC,QAAA,eAAe,QAAQ,qBAAqB,MAAM;AACpD,cAAQ,MAAM,0EAA0E;AACxF,aAAO;IACT;AACO,WAAA,IAAIC,eAAAA,WAAW,QAAQ,cAAc,CAAC,mBAAoB,WAAmB,UAAU,MAAM;AAAA,MAClG,eAAeC,eAAc,cAAA;AAAA,MAC7B,SAAS;AAAA,MACT,OAAO;AAAA,MACP,mBAAmB;AAAA,MACnB,iBAAiB;AAAA,MACjB,gBAAgB;AAAA,MAChB,cAAc;AAAA,MACd,oBAAoB;AAAA,MACpB,QAAQ;AAAA,MACR,MAAM;AAAA,MACN,WAAW;AAAA,MACX,OAAO;AAAA;AAAA,MAEP,mBAAmB,mBAAmB,iBAAiB,UAAU;AAAA,MACjE,iBAAiB,4CAAmB;AAAA,MACpC,sBAAsB;AAAA,MACtB,GAAG;AAAA,IAAA,CACJ;AAAA,KAGA,CAAC,QAAQ,kBAAkB,YAAY,eAAe,CAAC;AAC1D,wCAAQ,aAAU,EAAA,KAAU,QAAQ,QAAQ,SAAS,KAAM,CAAA;AAC7D,CAAC;;"}
|
package/dist/effects/SSAO.js
CHANGED
|
@@ -28,7 +28,7 @@ const SSAO = forwardRef(function SSAO2(props, ref) {
|
|
|
28
28
|
depthAwareUpsampling: true,
|
|
29
29
|
...props
|
|
30
30
|
});
|
|
31
|
-
}, [camera, normalPass,
|
|
31
|
+
}, [camera, downSamplingPass, normalPass, resolutionScale]);
|
|
32
32
|
return /* @__PURE__ */ jsx("primitive", { ref, object: effect, dispose: null });
|
|
33
33
|
});
|
|
34
34
|
export {
|
package/dist/effects/SSAO.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SSAO.js","sources":["../../src/effects/SSAO.tsx"],"sourcesContent":["import { Ref, forwardRef, useContext, useMemo } from 'react'\nimport { SSAOEffect, BlendFunction } from 'postprocessing'\nimport { EffectComposerContext } from '../EffectComposer'\n\n// first two args are camera and texture\ntype SSAOProps = ConstructorParameters<typeof SSAOEffect>[2]\n\nexport const SSAO = forwardRef<SSAOEffect, SSAOProps>(function SSAO(props: SSAOProps, ref: Ref<SSAOEffect>) {\n const { camera, normalPass, downSamplingPass, resolutionScale } = useContext(EffectComposerContext)\n const effect = useMemo<SSAOEffect | {}>(() => {\n if (normalPass === null && downSamplingPass === null) {\n console.error('Please enable the NormalPass in the EffectComposer in order to use SSAO.')\n return {}\n }\n return new SSAOEffect(camera, normalPass && !downSamplingPass ? (normalPass as any).texture : null, {\n blendFunction: BlendFunction.MULTIPLY,\n samples: 30,\n rings: 4,\n distanceThreshold: 1.0,\n distanceFalloff: 0.0,\n rangeThreshold: 0.5,\n rangeFalloff: 0.1,\n luminanceInfluence: 0.9,\n radius: 20,\n bias: 0.5,\n intensity: 1.0,\n color: undefined,\n // @ts-ignore\n normalDepthBuffer: downSamplingPass ? downSamplingPass.texture : null,\n resolutionScale: resolutionScale ?? 1,\n depthAwareUpsampling: true,\n ...props,\n })\n }, [camera, normalPass,
|
|
1
|
+
{"version":3,"file":"SSAO.js","sources":["../../src/effects/SSAO.tsx"],"sourcesContent":["import { Ref, forwardRef, useContext, useMemo } from 'react'\nimport { SSAOEffect, BlendFunction } from 'postprocessing'\nimport { EffectComposerContext } from '../EffectComposer'\n\n// first two args are camera and texture\ntype SSAOProps = ConstructorParameters<typeof SSAOEffect>[2]\n\nexport const SSAO = forwardRef<SSAOEffect, SSAOProps>(function SSAO(props: SSAOProps, ref: Ref<SSAOEffect>) {\n const { camera, normalPass, downSamplingPass, resolutionScale } = useContext(EffectComposerContext)\n const effect = useMemo<SSAOEffect | {}>(() => {\n if (normalPass === null && downSamplingPass === null) {\n console.error('Please enable the NormalPass in the EffectComposer in order to use SSAO.')\n return {}\n }\n return new SSAOEffect(camera, normalPass && !downSamplingPass ? (normalPass as any).texture : null, {\n blendFunction: BlendFunction.MULTIPLY,\n samples: 30,\n rings: 4,\n distanceThreshold: 1.0,\n distanceFalloff: 0.0,\n rangeThreshold: 0.5,\n rangeFalloff: 0.1,\n luminanceInfluence: 0.9,\n radius: 20,\n bias: 0.5,\n intensity: 1.0,\n color: undefined,\n // @ts-ignore\n normalDepthBuffer: downSamplingPass ? downSamplingPass.texture : null,\n resolutionScale: resolutionScale ?? 1,\n depthAwareUpsampling: true,\n ...props,\n })\n // NOTE: `props` is an unstable reference, so we can't memoize it\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [camera, downSamplingPass, normalPass, resolutionScale])\n return <primitive ref={ref} object={effect} dispose={null} />\n})\n"],"names":["SSAO"],"mappings":";;;;AAOO,MAAM,OAAO,WAAkC,SAASA,MAAK,OAAkB,KAAsB;AAC1G,QAAM,EAAE,QAAQ,YAAY,kBAAkB,oBAAoB,WAAW,qBAAqB;AAC5F,QAAA,SAAS,QAAyB,MAAM;AACxC,QAAA,eAAe,QAAQ,qBAAqB,MAAM;AACpD,cAAQ,MAAM,0EAA0E;AACxF,aAAO;IACT;AACO,WAAA,IAAI,WAAW,QAAQ,cAAc,CAAC,mBAAoB,WAAmB,UAAU,MAAM;AAAA,MAClG,eAAe,cAAc;AAAA,MAC7B,SAAS;AAAA,MACT,OAAO;AAAA,MACP,mBAAmB;AAAA,MACnB,iBAAiB;AAAA,MACjB,gBAAgB;AAAA,MAChB,cAAc;AAAA,MACd,oBAAoB;AAAA,MACpB,QAAQ;AAAA,MACR,MAAM;AAAA,MACN,WAAW;AAAA,MACX,OAAO;AAAA;AAAA,MAEP,mBAAmB,mBAAmB,iBAAiB,UAAU;AAAA,MACjE,iBAAiB,4CAAmB;AAAA,MACpC,sBAAsB;AAAA,MACtB,GAAG;AAAA,IAAA,CACJ;AAAA,KAGA,CAAC,QAAQ,kBAAkB,YAAY,eAAe,CAAC;AAC1D,6BAAQ,aAAU,EAAA,KAAU,QAAQ,QAAQ,SAAS,KAAM,CAAA;AAC7D,CAAC;"}
|
|
@@ -7,7 +7,7 @@ const EffectComposer = require("../../EffectComposer.cjs");
|
|
|
7
7
|
const Selection = require("../../Selection.cjs");
|
|
8
8
|
const fiber = require("@react-three/fiber");
|
|
9
9
|
const SSR = React.forwardRef(function SSR2({ ENABLE_BLUR = true, USE_MRT = true, ...props }, ref) {
|
|
10
|
-
const
|
|
10
|
+
const invalidate = fiber.useThree((s) => s.invalidate);
|
|
11
11
|
const { scene, camera } = React.useContext(EffectComposer.EffectComposerContext);
|
|
12
12
|
const effect = React.useMemo(
|
|
13
13
|
() => new screenSpaceReflections.SSREffect(scene, camera, { ENABLE_BLUR, USE_MRT, ...props }),
|
|
@@ -26,7 +26,7 @@ const SSR = React.forwardRef(function SSR2({ ENABLE_BLUR = true, USE_MRT = true,
|
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
}, [api]);
|
|
29
|
+
}, [api, effect, invalidate]);
|
|
30
30
|
return /* @__PURE__ */ jsxRuntime.jsx("primitive", { ref, object: effect, ...props });
|
|
31
31
|
});
|
|
32
32
|
exports.SSR = SSR;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../../src/effects/SSR/index.tsx"],"sourcesContent":["import React, { Ref, forwardRef, useLayoutEffect, useEffect, useContext, useMemo } from 'react'\n/* @ts-ignore */\nimport { SSREffect } from './screen-space-reflections'\nimport { EffectComposerContext } from '../../EffectComposer'\nimport { selectionContext } from '../../Selection'\nimport { useThree } from '@react-three/fiber'\n\n// first two args are camera and texture\ntype SSRProps = {\n /** whether you want to use Temporal Resolving to re-use reflections from the last frames; this will reduce noise tremendously but may result in \"smearing\" */\n temporalResolve?: boolean\n /** a value between 0 and 1 to set how much the last frame's reflections should be blended in; higher values will result in less noisy reflections when moving the camera but a more smeary look */\n temporalResolveMix?: number\n /** a value between 0 and 1 to set how much the reprojected reflection should be corrected; higher values will reduce smearing but will result in less flickering at reflection edges */\n temporalResolveCorrectionMix?: number\n /** the maximum number of samples for reflections; settings it to 0 means unlimited samples; setting it to a value like 6 can help make camera movements less disruptive when calculating reflections */\n maxSamples?: number\n /** whether to blur the reflections and blend these blurred reflections with the raw ones depending on the blurMix value */\n ENABLE_BLUR?: boolean\n /** how much the blurred reflections should be mixed with the raw reflections */\n blurMix?: number\n /** the sharpness of the Bilateral Filter used to blur reflections */\n blurSharpness?: number\n /** the kernel size of the Bilateral Blur Filter; higher kernel sizes will result in blurrier reflections with more artifacts */\n blurKernelSize?: number\n /** how much the reflection ray should travel in each of its iteration; higher values will give deeper reflections but with more artifacts */\n rayStep?: number\n /** the intensity of the reflections */\n intensity?: number\n /** the maximum roughness a texel can have to have reflections calculated for it */\n maxRoughness?: number\n /** whether jittering is enabled; jittering will randomly jitter the reflections resulting in a more noisy but overall more realistic look, enabling jittering can be expensive depending on the view angle */\n ENABLE_JITTERING?: boolean\n /** how intense jittering should be */\n jitter?: number\n /** how much the jittered rays should be spread; higher values will give a rougher look regarding the reflections but are more expensive to compute with */\n jitterSpread?: number\n /** how intense jittering should be in relation to a material's roughness */\n jitterRough?: number\n /** the number of steps a reflection ray can maximally do to find an object it intersected (and thus reflects) */\n MAX_STEPS?: number\n /** once we had our ray intersect something, we need to find the exact point in space it intersected and thus it reflects; this can be done through binary search with the given number of maximum steps */\n NUM_BINARY_SEARCH_STEPS?: number\n /** the maximum depth difference between a ray and the particular depth at its screen position after refining with binary search; lower values will result in better performance */\n maxDepthDifference?: number\n /** the maximum depth for which reflections will be calculated */\n maxDepth?: number\n /** the maximum depth difference between a ray and the particular depth at its screen position before refining with binary search; lower values will result in better performance */\n thickness?: number\n /** Index of Refraction, used for calculating fresnel; reflections tend to be more intense the steeper the angle between them and the viewer is, the ior parameter set how much the intensity varies */\n ior?: number\n /** if there should still be reflections for rays for which a reflecting point couldn't be found; enabling this will result in stretched looking reflections which can look good or bad depending on the angle */\n STRETCH_MISSED_RAYS?: boolean\n /** WebGL2 only - whether to use multiple render targets when rendering the G-buffers (normals, depth and roughness); using them can improve performance as they will render all information to multiple buffers for each fragment in one run; this setting can't be changed during run-time */\n USE_MRT?: boolean\n /** if roughness maps should be taken account of when calculating reflections */\n USE_ROUGHNESSMAP?: boolean\n /** if normal maps should be taken account of when calculating reflections */\n USE_NORMALMAP?: boolean\n}\n\nexport const SSR = forwardRef<SSREffect, SSRProps>(function SSR(\n { ENABLE_BLUR = true, USE_MRT = true, ...props }: SSRProps,\n\n ref: Ref<SSREffect>\n) {\n const
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../src/effects/SSR/index.tsx"],"sourcesContent":["import React, { Ref, forwardRef, useLayoutEffect, useEffect, useContext, useMemo } from 'react'\n/* @ts-ignore */\nimport { SSREffect } from './screen-space-reflections'\nimport { EffectComposerContext } from '../../EffectComposer'\nimport { selectionContext } from '../../Selection'\nimport { useThree } from '@react-three/fiber'\n\n// first two args are camera and texture\ntype SSRProps = {\n /** whether you want to use Temporal Resolving to re-use reflections from the last frames; this will reduce noise tremendously but may result in \"smearing\" */\n temporalResolve?: boolean\n /** a value between 0 and 1 to set how much the last frame's reflections should be blended in; higher values will result in less noisy reflections when moving the camera but a more smeary look */\n temporalResolveMix?: number\n /** a value between 0 and 1 to set how much the reprojected reflection should be corrected; higher values will reduce smearing but will result in less flickering at reflection edges */\n temporalResolveCorrectionMix?: number\n /** the maximum number of samples for reflections; settings it to 0 means unlimited samples; setting it to a value like 6 can help make camera movements less disruptive when calculating reflections */\n maxSamples?: number\n /** whether to blur the reflections and blend these blurred reflections with the raw ones depending on the blurMix value */\n ENABLE_BLUR?: boolean\n /** how much the blurred reflections should be mixed with the raw reflections */\n blurMix?: number\n /** the sharpness of the Bilateral Filter used to blur reflections */\n blurSharpness?: number\n /** the kernel size of the Bilateral Blur Filter; higher kernel sizes will result in blurrier reflections with more artifacts */\n blurKernelSize?: number\n /** how much the reflection ray should travel in each of its iteration; higher values will give deeper reflections but with more artifacts */\n rayStep?: number\n /** the intensity of the reflections */\n intensity?: number\n /** the maximum roughness a texel can have to have reflections calculated for it */\n maxRoughness?: number\n /** whether jittering is enabled; jittering will randomly jitter the reflections resulting in a more noisy but overall more realistic look, enabling jittering can be expensive depending on the view angle */\n ENABLE_JITTERING?: boolean\n /** how intense jittering should be */\n jitter?: number\n /** how much the jittered rays should be spread; higher values will give a rougher look regarding the reflections but are more expensive to compute with */\n jitterSpread?: number\n /** how intense jittering should be in relation to a material's roughness */\n jitterRough?: number\n /** the number of steps a reflection ray can maximally do to find an object it intersected (and thus reflects) */\n MAX_STEPS?: number\n /** once we had our ray intersect something, we need to find the exact point in space it intersected and thus it reflects; this can be done through binary search with the given number of maximum steps */\n NUM_BINARY_SEARCH_STEPS?: number\n /** the maximum depth difference between a ray and the particular depth at its screen position after refining with binary search; lower values will result in better performance */\n maxDepthDifference?: number\n /** the maximum depth for which reflections will be calculated */\n maxDepth?: number\n /** the maximum depth difference between a ray and the particular depth at its screen position before refining with binary search; lower values will result in better performance */\n thickness?: number\n /** Index of Refraction, used for calculating fresnel; reflections tend to be more intense the steeper the angle between them and the viewer is, the ior parameter set how much the intensity varies */\n ior?: number\n /** if there should still be reflections for rays for which a reflecting point couldn't be found; enabling this will result in stretched looking reflections which can look good or bad depending on the angle */\n STRETCH_MISSED_RAYS?: boolean\n /** WebGL2 only - whether to use multiple render targets when rendering the G-buffers (normals, depth and roughness); using them can improve performance as they will render all information to multiple buffers for each fragment in one run; this setting can't be changed during run-time */\n USE_MRT?: boolean\n /** if roughness maps should be taken account of when calculating reflections */\n USE_ROUGHNESSMAP?: boolean\n /** if normal maps should be taken account of when calculating reflections */\n USE_NORMALMAP?: boolean\n}\n\nexport const SSR = forwardRef<SSREffect, SSRProps>(function SSR(\n { ENABLE_BLUR = true, USE_MRT = true, ...props }: SSRProps,\n\n ref: Ref<SSREffect>\n) {\n const invalidate = useThree((s) => s.invalidate)\n const { scene, camera } = useContext(EffectComposerContext)\n const effect = useMemo(\n () => new SSREffect(scene, camera, { ENABLE_BLUR, USE_MRT, ...props }),\n [scene, camera, ENABLE_BLUR, USE_MRT, props]\n )\n\n const api = useContext(selectionContext)\n useEffect(() => {\n if (api && api.enabled) {\n if (api.selected?.length) {\n effect.selection.set(api.selected)\n invalidate()\n return () => {\n effect.selection.clear()\n invalidate()\n }\n }\n }\n }, [api, effect, invalidate])\n\n return <primitive ref={ref} object={effect} {...props} />\n})\n"],"names":["forwardRef","SSR","useThree","useContext","EffectComposerContext","useMemo","SSREffect","selectionContext","useEffect"],"mappings":";;;;;;;;AA6DO,MAAM,MAAMA,MAAA,WAAgC,SAASC,KAC1D,EAAE,cAAc,MAAM,UAAU,MAAM,GAAG,MAAM,GAE/C,KACA;AACA,QAAM,aAAaC,MAAAA,SAAS,CAAC,MAAM,EAAE,UAAU;AAC/C,QAAM,EAAE,OAAO,OAAO,IAAIC,iBAAWC,eAAqB,qBAAA;AAC1D,QAAM,SAASC,MAAA;AAAA,IACb,MAAM,IAAIC,uBAAAA,UAAU,OAAO,QAAQ,EAAE,aAAa,SAAS,GAAG,OAAO;AAAA,IACrE,CAAC,OAAO,QAAQ,aAAa,SAAS,KAAK;AAAA,EAAA;AAGvC,QAAA,MAAMH,iBAAWI,UAAAA,gBAAgB;AACvCC,QAAAA,UAAU,MAAM;;AACV,QAAA,OAAO,IAAI,SAAS;AAClB,WAAA,SAAI,aAAJ,mBAAc,QAAQ;AACjB,eAAA,UAAU,IAAI,IAAI,QAAQ;AACtB;AACX,eAAO,MAAM;AACX,iBAAO,UAAU;AACN;QAAA;AAAA,MAEf;AAAA,IACF;AAAA,EACC,GAAA,CAAC,KAAK,QAAQ,UAAU,CAAC;AAE5B,wCAAQ,aAAU,EAAA,KAAU,QAAQ,QAAS,GAAG,MAAO,CAAA;AACzD,CAAC;;"}
|
|
@@ -5,7 +5,7 @@ import { EffectComposerContext } from "../../EffectComposer.js";
|
|
|
5
5
|
import { selectionContext } from "../../Selection.js";
|
|
6
6
|
import { useThree } from "@react-three/fiber";
|
|
7
7
|
const SSR = forwardRef(function SSR2({ ENABLE_BLUR = true, USE_MRT = true, ...props }, ref) {
|
|
8
|
-
const
|
|
8
|
+
const invalidate = useThree((s) => s.invalidate);
|
|
9
9
|
const { scene, camera } = useContext(EffectComposerContext);
|
|
10
10
|
const effect = useMemo(
|
|
11
11
|
() => new SSREffect(scene, camera, { ENABLE_BLUR, USE_MRT, ...props }),
|
|
@@ -24,7 +24,7 @@ const SSR = forwardRef(function SSR2({ ENABLE_BLUR = true, USE_MRT = true, ...pr
|
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
}, [api]);
|
|
27
|
+
}, [api, effect, invalidate]);
|
|
28
28
|
return /* @__PURE__ */ jsx("primitive", { ref, object: effect, ...props });
|
|
29
29
|
});
|
|
30
30
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/effects/SSR/index.tsx"],"sourcesContent":["import React, { Ref, forwardRef, useLayoutEffect, useEffect, useContext, useMemo } from 'react'\n/* @ts-ignore */\nimport { SSREffect } from './screen-space-reflections'\nimport { EffectComposerContext } from '../../EffectComposer'\nimport { selectionContext } from '../../Selection'\nimport { useThree } from '@react-three/fiber'\n\n// first two args are camera and texture\ntype SSRProps = {\n /** whether you want to use Temporal Resolving to re-use reflections from the last frames; this will reduce noise tremendously but may result in \"smearing\" */\n temporalResolve?: boolean\n /** a value between 0 and 1 to set how much the last frame's reflections should be blended in; higher values will result in less noisy reflections when moving the camera but a more smeary look */\n temporalResolveMix?: number\n /** a value between 0 and 1 to set how much the reprojected reflection should be corrected; higher values will reduce smearing but will result in less flickering at reflection edges */\n temporalResolveCorrectionMix?: number\n /** the maximum number of samples for reflections; settings it to 0 means unlimited samples; setting it to a value like 6 can help make camera movements less disruptive when calculating reflections */\n maxSamples?: number\n /** whether to blur the reflections and blend these blurred reflections with the raw ones depending on the blurMix value */\n ENABLE_BLUR?: boolean\n /** how much the blurred reflections should be mixed with the raw reflections */\n blurMix?: number\n /** the sharpness of the Bilateral Filter used to blur reflections */\n blurSharpness?: number\n /** the kernel size of the Bilateral Blur Filter; higher kernel sizes will result in blurrier reflections with more artifacts */\n blurKernelSize?: number\n /** how much the reflection ray should travel in each of its iteration; higher values will give deeper reflections but with more artifacts */\n rayStep?: number\n /** the intensity of the reflections */\n intensity?: number\n /** the maximum roughness a texel can have to have reflections calculated for it */\n maxRoughness?: number\n /** whether jittering is enabled; jittering will randomly jitter the reflections resulting in a more noisy but overall more realistic look, enabling jittering can be expensive depending on the view angle */\n ENABLE_JITTERING?: boolean\n /** how intense jittering should be */\n jitter?: number\n /** how much the jittered rays should be spread; higher values will give a rougher look regarding the reflections but are more expensive to compute with */\n jitterSpread?: number\n /** how intense jittering should be in relation to a material's roughness */\n jitterRough?: number\n /** the number of steps a reflection ray can maximally do to find an object it intersected (and thus reflects) */\n MAX_STEPS?: number\n /** once we had our ray intersect something, we need to find the exact point in space it intersected and thus it reflects; this can be done through binary search with the given number of maximum steps */\n NUM_BINARY_SEARCH_STEPS?: number\n /** the maximum depth difference between a ray and the particular depth at its screen position after refining with binary search; lower values will result in better performance */\n maxDepthDifference?: number\n /** the maximum depth for which reflections will be calculated */\n maxDepth?: number\n /** the maximum depth difference between a ray and the particular depth at its screen position before refining with binary search; lower values will result in better performance */\n thickness?: number\n /** Index of Refraction, used for calculating fresnel; reflections tend to be more intense the steeper the angle between them and the viewer is, the ior parameter set how much the intensity varies */\n ior?: number\n /** if there should still be reflections for rays for which a reflecting point couldn't be found; enabling this will result in stretched looking reflections which can look good or bad depending on the angle */\n STRETCH_MISSED_RAYS?: boolean\n /** WebGL2 only - whether to use multiple render targets when rendering the G-buffers (normals, depth and roughness); using them can improve performance as they will render all information to multiple buffers for each fragment in one run; this setting can't be changed during run-time */\n USE_MRT?: boolean\n /** if roughness maps should be taken account of when calculating reflections */\n USE_ROUGHNESSMAP?: boolean\n /** if normal maps should be taken account of when calculating reflections */\n USE_NORMALMAP?: boolean\n}\n\nexport const SSR = forwardRef<SSREffect, SSRProps>(function SSR(\n { ENABLE_BLUR = true, USE_MRT = true, ...props }: SSRProps,\n\n ref: Ref<SSREffect>\n) {\n const
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/effects/SSR/index.tsx"],"sourcesContent":["import React, { Ref, forwardRef, useLayoutEffect, useEffect, useContext, useMemo } from 'react'\n/* @ts-ignore */\nimport { SSREffect } from './screen-space-reflections'\nimport { EffectComposerContext } from '../../EffectComposer'\nimport { selectionContext } from '../../Selection'\nimport { useThree } from '@react-three/fiber'\n\n// first two args are camera and texture\ntype SSRProps = {\n /** whether you want to use Temporal Resolving to re-use reflections from the last frames; this will reduce noise tremendously but may result in \"smearing\" */\n temporalResolve?: boolean\n /** a value between 0 and 1 to set how much the last frame's reflections should be blended in; higher values will result in less noisy reflections when moving the camera but a more smeary look */\n temporalResolveMix?: number\n /** a value between 0 and 1 to set how much the reprojected reflection should be corrected; higher values will reduce smearing but will result in less flickering at reflection edges */\n temporalResolveCorrectionMix?: number\n /** the maximum number of samples for reflections; settings it to 0 means unlimited samples; setting it to a value like 6 can help make camera movements less disruptive when calculating reflections */\n maxSamples?: number\n /** whether to blur the reflections and blend these blurred reflections with the raw ones depending on the blurMix value */\n ENABLE_BLUR?: boolean\n /** how much the blurred reflections should be mixed with the raw reflections */\n blurMix?: number\n /** the sharpness of the Bilateral Filter used to blur reflections */\n blurSharpness?: number\n /** the kernel size of the Bilateral Blur Filter; higher kernel sizes will result in blurrier reflections with more artifacts */\n blurKernelSize?: number\n /** how much the reflection ray should travel in each of its iteration; higher values will give deeper reflections but with more artifacts */\n rayStep?: number\n /** the intensity of the reflections */\n intensity?: number\n /** the maximum roughness a texel can have to have reflections calculated for it */\n maxRoughness?: number\n /** whether jittering is enabled; jittering will randomly jitter the reflections resulting in a more noisy but overall more realistic look, enabling jittering can be expensive depending on the view angle */\n ENABLE_JITTERING?: boolean\n /** how intense jittering should be */\n jitter?: number\n /** how much the jittered rays should be spread; higher values will give a rougher look regarding the reflections but are more expensive to compute with */\n jitterSpread?: number\n /** how intense jittering should be in relation to a material's roughness */\n jitterRough?: number\n /** the number of steps a reflection ray can maximally do to find an object it intersected (and thus reflects) */\n MAX_STEPS?: number\n /** once we had our ray intersect something, we need to find the exact point in space it intersected and thus it reflects; this can be done through binary search with the given number of maximum steps */\n NUM_BINARY_SEARCH_STEPS?: number\n /** the maximum depth difference between a ray and the particular depth at its screen position after refining with binary search; lower values will result in better performance */\n maxDepthDifference?: number\n /** the maximum depth for which reflections will be calculated */\n maxDepth?: number\n /** the maximum depth difference between a ray and the particular depth at its screen position before refining with binary search; lower values will result in better performance */\n thickness?: number\n /** Index of Refraction, used for calculating fresnel; reflections tend to be more intense the steeper the angle between them and the viewer is, the ior parameter set how much the intensity varies */\n ior?: number\n /** if there should still be reflections for rays for which a reflecting point couldn't be found; enabling this will result in stretched looking reflections which can look good or bad depending on the angle */\n STRETCH_MISSED_RAYS?: boolean\n /** WebGL2 only - whether to use multiple render targets when rendering the G-buffers (normals, depth and roughness); using them can improve performance as they will render all information to multiple buffers for each fragment in one run; this setting can't be changed during run-time */\n USE_MRT?: boolean\n /** if roughness maps should be taken account of when calculating reflections */\n USE_ROUGHNESSMAP?: boolean\n /** if normal maps should be taken account of when calculating reflections */\n USE_NORMALMAP?: boolean\n}\n\nexport const SSR = forwardRef<SSREffect, SSRProps>(function SSR(\n { ENABLE_BLUR = true, USE_MRT = true, ...props }: SSRProps,\n\n ref: Ref<SSREffect>\n) {\n const invalidate = useThree((s) => s.invalidate)\n const { scene, camera } = useContext(EffectComposerContext)\n const effect = useMemo(\n () => new SSREffect(scene, camera, { ENABLE_BLUR, USE_MRT, ...props }),\n [scene, camera, ENABLE_BLUR, USE_MRT, props]\n )\n\n const api = useContext(selectionContext)\n useEffect(() => {\n if (api && api.enabled) {\n if (api.selected?.length) {\n effect.selection.set(api.selected)\n invalidate()\n return () => {\n effect.selection.clear()\n invalidate()\n }\n }\n }\n }, [api, effect, invalidate])\n\n return <primitive ref={ref} object={effect} {...props} />\n})\n"],"names":["SSR"],"mappings":";;;;;;AA6DO,MAAM,MAAM,WAAgC,SAASA,KAC1D,EAAE,cAAc,MAAM,UAAU,MAAM,GAAG,MAAM,GAE/C,KACA;AACA,QAAM,aAAa,SAAS,CAAC,MAAM,EAAE,UAAU;AAC/C,QAAM,EAAE,OAAO,OAAO,IAAI,WAAW,qBAAqB;AAC1D,QAAM,SAAS;AAAA,IACb,MAAM,IAAI,UAAU,OAAO,QAAQ,EAAE,aAAa,SAAS,GAAG,OAAO;AAAA,IACrE,CAAC,OAAO,QAAQ,aAAa,SAAS,KAAK;AAAA,EAAA;AAGvC,QAAA,MAAM,WAAW,gBAAgB;AACvC,YAAU,MAAM;;AACV,QAAA,OAAO,IAAI,SAAS;AAClB,WAAA,SAAI,aAAJ,mBAAc,QAAQ;AACjB,eAAA,UAAU,IAAI,IAAI,QAAQ;AACtB;AACX,eAAO,MAAM;AACX,iBAAO,UAAU;AACN;QAAA;AAAA,MAEf;AAAA,IACF;AAAA,EACC,GAAA,CAAC,KAAK,QAAQ,UAAU,CAAC;AAE5B,6BAAQ,aAAU,EAAA,KAAU,QAAQ,QAAS,GAAG,MAAO,CAAA;AACzD,CAAC;"}
|
|
@@ -1,51 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const jsxRuntime = require("react/jsx-runtime");
|
|
4
3
|
const postprocessing = require("postprocessing");
|
|
5
|
-
const
|
|
6
|
-
const ToneMapping =
|
|
7
|
-
blendFunction,
|
|
8
|
-
adaptive,
|
|
9
|
-
mode,
|
|
10
|
-
resolution,
|
|
11
|
-
maxLuminance,
|
|
12
|
-
whitePoint,
|
|
13
|
-
middleGrey,
|
|
14
|
-
minLuminance,
|
|
15
|
-
averageLuminance,
|
|
16
|
-
adaptationRate,
|
|
17
|
-
...props
|
|
18
|
-
}, ref) {
|
|
19
|
-
const effect = React.useMemo(
|
|
20
|
-
() => new postprocessing.ToneMappingEffect({
|
|
21
|
-
blendFunction,
|
|
22
|
-
adaptive,
|
|
23
|
-
mode,
|
|
24
|
-
resolution,
|
|
25
|
-
maxLuminance,
|
|
26
|
-
whitePoint,
|
|
27
|
-
middleGrey,
|
|
28
|
-
minLuminance,
|
|
29
|
-
averageLuminance,
|
|
30
|
-
adaptationRate
|
|
31
|
-
}),
|
|
32
|
-
[
|
|
33
|
-
blendFunction,
|
|
34
|
-
adaptive,
|
|
35
|
-
mode,
|
|
36
|
-
resolution,
|
|
37
|
-
maxLuminance,
|
|
38
|
-
whitePoint,
|
|
39
|
-
middleGrey,
|
|
40
|
-
minLuminance,
|
|
41
|
-
averageLuminance,
|
|
42
|
-
adaptationRate
|
|
43
|
-
]
|
|
44
|
-
);
|
|
45
|
-
React.useEffect(() => {
|
|
46
|
-
effect.dispose();
|
|
47
|
-
}, [effect]);
|
|
48
|
-
return /* @__PURE__ */ jsxRuntime.jsx("primitive", { ...props, ref, object: effect, attributes: postprocessing.EffectAttribute.CONVOLUTION });
|
|
49
|
-
});
|
|
4
|
+
const util = require("../util.cjs");
|
|
5
|
+
const ToneMapping = util.wrapEffect(postprocessing.ToneMappingEffect);
|
|
50
6
|
exports.ToneMapping = ToneMapping;
|
|
51
7
|
//# sourceMappingURL=ToneMapping.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToneMapping.cjs","sources":["../../src/effects/ToneMapping.tsx"],"sourcesContent":["import { ToneMappingEffect
|
|
1
|
+
{"version":3,"file":"ToneMapping.cjs","sources":["../../src/effects/ToneMapping.tsx"],"sourcesContent":["import { ToneMappingEffect } from 'postprocessing'\nimport { type EffectProps, wrapEffect } from '../util'\n\nexport type ToneMappingProps = EffectProps<typeof ToneMappingEffect>\n\nexport const ToneMapping = wrapEffect(ToneMappingEffect)\n"],"names":["wrapEffect","ToneMappingEffect"],"mappings":";;;;AAKa,MAAA,cAAcA,gBAAWC,eAAiB,iBAAA;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { ToneMappingEffect } from 'postprocessing';
|
|
3
|
-
import { EffectProps } from '../util';
|
|
3
|
+
import { type EffectProps } from '../util';
|
|
4
4
|
export type ToneMappingProps = EffectProps<typeof ToneMappingEffect>;
|
|
5
5
|
export declare const ToneMapping: import("react").ForwardRefExoticComponent<Omit<import("@react-three/fiber").ExtendedColors<import("@react-three/fiber").Overwrite<Partial<ToneMappingEffect>, import("@react-three/fiber").NodeProps<ToneMappingEffect, typeof ToneMappingEffect>>> & {
|
|
6
6
|
blendFunction?: import("postprocessing").BlendFunction | undefined;
|
|
@@ -16,4 +16,4 @@ export declare const ToneMapping: import("react").ForwardRefExoticComponent<Omit
|
|
|
16
16
|
} & {
|
|
17
17
|
blendFunction?: import("postprocessing").BlendFunction | undefined;
|
|
18
18
|
opacity?: number | undefined;
|
|
19
|
-
}, "ref"> & import("react").RefAttributes<ToneMappingEffect>>;
|
|
19
|
+
}, "ref"> & import("react").RefAttributes<typeof ToneMappingEffect>>;
|
|
@@ -1,50 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
const ToneMapping = forwardRef(function ToneMapping2({
|
|
5
|
-
blendFunction,
|
|
6
|
-
adaptive,
|
|
7
|
-
mode,
|
|
8
|
-
resolution,
|
|
9
|
-
maxLuminance,
|
|
10
|
-
whitePoint,
|
|
11
|
-
middleGrey,
|
|
12
|
-
minLuminance,
|
|
13
|
-
averageLuminance,
|
|
14
|
-
adaptationRate,
|
|
15
|
-
...props
|
|
16
|
-
}, ref) {
|
|
17
|
-
const effect = useMemo(
|
|
18
|
-
() => new ToneMappingEffect({
|
|
19
|
-
blendFunction,
|
|
20
|
-
adaptive,
|
|
21
|
-
mode,
|
|
22
|
-
resolution,
|
|
23
|
-
maxLuminance,
|
|
24
|
-
whitePoint,
|
|
25
|
-
middleGrey,
|
|
26
|
-
minLuminance,
|
|
27
|
-
averageLuminance,
|
|
28
|
-
adaptationRate
|
|
29
|
-
}),
|
|
30
|
-
[
|
|
31
|
-
blendFunction,
|
|
32
|
-
adaptive,
|
|
33
|
-
mode,
|
|
34
|
-
resolution,
|
|
35
|
-
maxLuminance,
|
|
36
|
-
whitePoint,
|
|
37
|
-
middleGrey,
|
|
38
|
-
minLuminance,
|
|
39
|
-
averageLuminance,
|
|
40
|
-
adaptationRate
|
|
41
|
-
]
|
|
42
|
-
);
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
effect.dispose();
|
|
45
|
-
}, [effect]);
|
|
46
|
-
return /* @__PURE__ */ jsx("primitive", { ...props, ref, object: effect, attributes: EffectAttribute.CONVOLUTION });
|
|
47
|
-
});
|
|
1
|
+
import { ToneMappingEffect } from "postprocessing";
|
|
2
|
+
import { wrapEffect } from "../util.js";
|
|
3
|
+
const ToneMapping = wrapEffect(ToneMappingEffect);
|
|
48
4
|
export {
|
|
49
5
|
ToneMapping
|
|
50
6
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToneMapping.js","sources":["../../src/effects/ToneMapping.tsx"],"sourcesContent":["import { ToneMappingEffect
|
|
1
|
+
{"version":3,"file":"ToneMapping.js","sources":["../../src/effects/ToneMapping.tsx"],"sourcesContent":["import { ToneMappingEffect } from 'postprocessing'\nimport { type EffectProps, wrapEffect } from '../util'\n\nexport type ToneMappingProps = EffectProps<typeof ToneMappingEffect>\n\nexport const ToneMapping = wrapEffect(ToneMappingEffect)\n"],"names":[],"mappings":";;AAKa,MAAA,cAAc,WAAW,iBAAiB;"}
|
package/dist/effects/Water.cjs
CHANGED
|
@@ -4,19 +4,24 @@ const THREE = require("three");
|
|
|
4
4
|
const postprocessing = require("postprocessing");
|
|
5
5
|
const util = require("../util.cjs");
|
|
6
6
|
const WaterShader = {
|
|
7
|
-
fragmentShader:
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
fragmentShader: (
|
|
8
|
+
/* glsl */
|
|
9
|
+
`
|
|
10
|
+
uniform float factor;
|
|
11
|
+
|
|
12
|
+
void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
|
|
13
|
+
vec2 vUv = uv;
|
|
14
|
+
float frequency = 6.0 * factor;
|
|
15
|
+
float amplitude = 0.015 * factor;
|
|
16
|
+
float x = vUv.y * frequency + time * 0.7;
|
|
17
|
+
float y = vUv.x * frequency + time * 0.3;
|
|
18
|
+
vUv.x += cos(x + y) * amplitude * cos(y);
|
|
19
|
+
vUv.y += sin(x - y) * amplitude * cos(y);
|
|
20
|
+
vec4 rgba = texture(inputBuffer, vUv);
|
|
21
|
+
outputColor = rgba;
|
|
22
|
+
}
|
|
23
|
+
`
|
|
24
|
+
)
|
|
20
25
|
};
|
|
21
26
|
class WaterEffectImpl extends postprocessing.Effect {
|
|
22
27
|
constructor({ blendFunction = postprocessing.BlendFunction.NORMAL, factor = 0 } = {}) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Water.cjs","sources":["../../src/effects/Water.tsx"],"sourcesContent":["import { Uniform } from 'three'\nimport { BlendFunction, Effect, EffectAttribute } from 'postprocessing'\nimport { wrapEffect } from '../util'\n\nconst WaterShader = {\n fragmentShader: `\n
|
|
1
|
+
{"version":3,"file":"Water.cjs","sources":["../../src/effects/Water.tsx"],"sourcesContent":["import { Uniform } from 'three'\nimport { BlendFunction, Effect, EffectAttribute } from 'postprocessing'\nimport { wrapEffect } from '../util'\n\nconst WaterShader = {\n fragmentShader: /* glsl */ `\n uniform float factor;\n\n void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {\n vec2 vUv = uv;\n float frequency = 6.0 * factor;\n float amplitude = 0.015 * factor;\n float x = vUv.y * frequency + time * 0.7; \n float y = vUv.x * frequency + time * 0.3;\n vUv.x += cos(x + y) * amplitude * cos(y);\n vUv.y += sin(x - y) * amplitude * cos(y);\n vec4 rgba = texture(inputBuffer, vUv);\n outputColor = rgba;\n }\n `,\n}\n\nexport class WaterEffectImpl extends Effect {\n constructor({ blendFunction = BlendFunction.NORMAL, factor = 0 } = {}) {\n super('WaterEffect', WaterShader.fragmentShader, {\n blendFunction,\n attributes: EffectAttribute.CONVOLUTION,\n uniforms: new Map<string, Uniform<number | number[]>>([['factor', new Uniform(factor)]]),\n })\n }\n}\n\nexport const WaterEffect = wrapEffect(WaterEffectImpl, { blendFunction: BlendFunction.NORMAL })\n"],"names":["Effect","BlendFunction","EffectAttribute","Uniform","wrapEffect"],"mappings":";;;;;AAIA,MAAM,cAAc;AAAA,EAClB;AAAA;AAAA,IAA2B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAe7B;AAEO,MAAM,wBAAwBA,eAAAA,OAAO;AAAA,EAC1C,YAAY,EAAE,gBAAgBC,eAAA,cAAc,QAAQ,SAAS,EAAM,IAAA,IAAI;AAC/D,UAAA,eAAe,YAAY,gBAAgB;AAAA,MAC/C;AAAA,MACA,YAAYC,eAAgB,gBAAA;AAAA,MAC5B,UAAc,oBAAA,IAAwC,CAAC,CAAC,UAAU,IAAIC,cAAQ,MAAM,CAAC,CAAC,CAAC;AAAA,IAAA,CACxF;AAAA,EACH;AACF;AAEO,MAAM,cAAcC,KAAW,WAAA,iBAAiB,EAAE,eAAeH,eAAAA,cAAc,OAAQ,CAAA;;;"}
|
package/dist/effects/Water.js
CHANGED
|
@@ -2,19 +2,24 @@ import { Uniform } from "three";
|
|
|
2
2
|
import { Effect, EffectAttribute, BlendFunction } from "postprocessing";
|
|
3
3
|
import { wrapEffect } from "../util.js";
|
|
4
4
|
const WaterShader = {
|
|
5
|
-
fragmentShader:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
5
|
+
fragmentShader: (
|
|
6
|
+
/* glsl */
|
|
7
|
+
`
|
|
8
|
+
uniform float factor;
|
|
9
|
+
|
|
10
|
+
void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
|
|
11
|
+
vec2 vUv = uv;
|
|
12
|
+
float frequency = 6.0 * factor;
|
|
13
|
+
float amplitude = 0.015 * factor;
|
|
14
|
+
float x = vUv.y * frequency + time * 0.7;
|
|
15
|
+
float y = vUv.x * frequency + time * 0.3;
|
|
16
|
+
vUv.x += cos(x + y) * amplitude * cos(y);
|
|
17
|
+
vUv.y += sin(x - y) * amplitude * cos(y);
|
|
18
|
+
vec4 rgba = texture(inputBuffer, vUv);
|
|
19
|
+
outputColor = rgba;
|
|
20
|
+
}
|
|
21
|
+
`
|
|
22
|
+
)
|
|
18
23
|
};
|
|
19
24
|
class WaterEffectImpl extends Effect {
|
|
20
25
|
constructor({ blendFunction = BlendFunction.NORMAL, factor = 0 } = {}) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Water.js","sources":["../../src/effects/Water.tsx"],"sourcesContent":["import { Uniform } from 'three'\nimport { BlendFunction, Effect, EffectAttribute } from 'postprocessing'\nimport { wrapEffect } from '../util'\n\nconst WaterShader = {\n fragmentShader: `\n
|
|
1
|
+
{"version":3,"file":"Water.js","sources":["../../src/effects/Water.tsx"],"sourcesContent":["import { Uniform } from 'three'\nimport { BlendFunction, Effect, EffectAttribute } from 'postprocessing'\nimport { wrapEffect } from '../util'\n\nconst WaterShader = {\n fragmentShader: /* glsl */ `\n uniform float factor;\n\n void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {\n vec2 vUv = uv;\n float frequency = 6.0 * factor;\n float amplitude = 0.015 * factor;\n float x = vUv.y * frequency + time * 0.7; \n float y = vUv.x * frequency + time * 0.3;\n vUv.x += cos(x + y) * amplitude * cos(y);\n vUv.y += sin(x - y) * amplitude * cos(y);\n vec4 rgba = texture(inputBuffer, vUv);\n outputColor = rgba;\n }\n `,\n}\n\nexport class WaterEffectImpl extends Effect {\n constructor({ blendFunction = BlendFunction.NORMAL, factor = 0 } = {}) {\n super('WaterEffect', WaterShader.fragmentShader, {\n blendFunction,\n attributes: EffectAttribute.CONVOLUTION,\n uniforms: new Map<string, Uniform<number | number[]>>([['factor', new Uniform(factor)]]),\n })\n }\n}\n\nexport const WaterEffect = wrapEffect(WaterEffectImpl, { blendFunction: BlendFunction.NORMAL })\n"],"names":[],"mappings":";;;AAIA,MAAM,cAAc;AAAA,EAClB;AAAA;AAAA,IAA2B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAe7B;AAEO,MAAM,wBAAwB,OAAO;AAAA,EAC1C,YAAY,EAAE,gBAAgB,cAAc,QAAQ,SAAS,EAAM,IAAA,IAAI;AAC/D,UAAA,eAAe,YAAY,gBAAgB;AAAA,MAC/C;AAAA,MACA,YAAY,gBAAgB;AAAA,MAC5B,UAAc,oBAAA,IAAwC,CAAC,CAAC,UAAU,IAAI,QAAQ,MAAM,CAAC,CAAC,CAAC;AAAA,IAAA,CACxF;AAAA,EACH;AACF;AAEO,MAAM,cAAc,WAAW,iBAAiB,EAAE,eAAe,cAAc,OAAQ,CAAA;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-three/postprocessing",
|
|
3
|
-
"version": "2.16.
|
|
3
|
+
"version": "2.16.4",
|
|
4
4
|
"description": "postprocessing wrapper for React and @react-three/fiber",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"postprocessing",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"prepare": "yarn build",
|
|
40
40
|
"eslint": "eslint . --fix --ext=js,ts,jsx,tsx",
|
|
41
41
|
"eslint:ci": "eslint . --ext=js,ts,jsx,tsx",
|
|
42
|
-
"test": "
|
|
42
|
+
"test": "vitest run",
|
|
43
43
|
"typecheck": "tsc --noEmit false --strict --jsx react",
|
|
44
44
|
"release": "semantic-release",
|
|
45
45
|
"storybook": "storybook dev -p 6006",
|
|
@@ -85,7 +85,8 @@
|
|
|
85
85
|
"storybook": "^7.0.10",
|
|
86
86
|
"three": "^0.151.3",
|
|
87
87
|
"typescript": "^5.0.4",
|
|
88
|
-
"vite": "^4.3.5"
|
|
88
|
+
"vite": "^4.3.5",
|
|
89
|
+
"vitest": "^2.1.8"
|
|
89
90
|
},
|
|
90
91
|
"peerDependencies": {
|
|
91
92
|
"@react-three/fiber": ">=8.0",
|