Skip to content

Commit c5a4d8a

Browse files
authored
Merge pull request #54 from takuma-hmng8/dev
v1.0.32
2 parents e2953d1 + cf09b3c commit c5a4d8a

10 files changed

+488
-431
lines changed

packages/use-shader-fx/build/use-shader-fx.js

+425-404
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/use-shader-fx/build/use-shader-fx.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/use-shader-fx/build/use-shader-fx.umd.cjs

+12-12
Large diffs are not rendered by default.

packages/use-shader-fx/build/use-shader-fx.umd.cjs.map

+1-1
Large diffs are not rendered by default.

packages/use-shader-fx/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/use-shader-fx/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@hmng8/use-shader-fx",
3-
"version": "1.0.31",
3+
"version": "1.0.32",
44
"description": "wide variety of shader effects for React",
55
"main": "./build/use-shader-fx.umd.cjs",
66
"module": "./build/use-shader-fx.js",

packages/use-shader-fx/src/utils/useDoubleFBO.ts

+17
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const useDoubleFBO = ({
4848
isSizeUpdate = false,
4949
samples = 0,
5050
depthBuffer = false,
51+
depthTexture = false,
5152
}: UseFboProps): UseDoubleFBOReturn => {
5253
const renderTarget = useRef<RenderTarget>({
5354
read: null,
@@ -60,6 +61,7 @@ export const useDoubleFBO = ({
6061
});
6162

6263
const resolution = useResolution(size, dpr);
64+
6365
const initRenderTargets = useMemo(() => {
6466
const read = new THREE.WebGLRenderTarget(resolution.x, resolution.y, {
6567
...FBO_OPTION,
@@ -71,9 +73,24 @@ export const useDoubleFBO = ({
7173
samples,
7274
depthBuffer,
7375
});
76+
77+
if (depthTexture) {
78+
read.depthTexture = new THREE.DepthTexture(
79+
resolution.x,
80+
resolution.y,
81+
THREE.FloatType
82+
);
83+
write.depthTexture = new THREE.DepthTexture(
84+
resolution.x,
85+
resolution.y,
86+
THREE.FloatType
87+
);
88+
}
89+
7490
return { read, write };
7591
// eslint-disable-next-line react-hooks/exhaustive-deps
7692
}, []);
93+
7794
renderTarget.current.read = initRenderTargets.read;
7895
renderTarget.current.write = initRenderTargets.write;
7996

packages/use-shader-fx/src/utils/useSingleFBO.ts

+24-7
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ export type UseFboProps = {
2626
isSizeUpdate?: boolean;
2727
/** Defines the count of MSAA samples. Can only be used with WebGL 2. Default is 0. */
2828
samples?: number;
29-
/** Renders to the depth buffer. Default is false. */
29+
/** Renders to the depth buffer. Unlike the three.js, Default is false. */
3030
depthBuffer?: boolean;
31+
/** If set, the scene depth will be rendered to this texture. Default is false. */
32+
depthTexture?: boolean;
3133
};
3234

3335
type FBOUpdateFunction = (
@@ -51,17 +53,32 @@ export const useSingleFBO = ({
5153
isSizeUpdate = false,
5254
samples = 0,
5355
depthBuffer = false,
56+
depthTexture = false,
5457
}: UseFboProps): UseSingleFBOReturn => {
5558
const renderTarget = useRef<THREE.WebGLRenderTarget>();
5659

5760
const resolution = useResolution(size, dpr);
61+
5862
renderTarget.current = useMemo(
59-
() =>
60-
new THREE.WebGLRenderTarget(resolution.x, resolution.y, {
61-
...FBO_OPTION,
62-
samples,
63-
depthBuffer,
64-
}),
63+
() => {
64+
const target = new THREE.WebGLRenderTarget(
65+
resolution.x,
66+
resolution.y,
67+
{
68+
...FBO_OPTION,
69+
samples,
70+
depthBuffer,
71+
}
72+
);
73+
if (depthTexture) {
74+
target.depthTexture = new THREE.DepthTexture(
75+
resolution.x,
76+
resolution.y,
77+
THREE.FloatType
78+
);
79+
}
80+
return target;
81+
},
6582
// eslint-disable-next-line react-hooks/exhaustive-deps
6683
[]
6784
);

packages/use-shader-fx/types/utils/useDoubleFBO.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ type UseDoubleFBOReturn = [
2222
* @param isSizeUpdate Whether to resize when resizing occurs. If isDpr is true, set FBO to setSize even if dpr is changed, default:false
2323
* @returns [{read:THREE.WebGLRenderTarget,write:THREE.WebGLRenderTarget} , updateFBO] -Receives the RenderTarget as the first argument and the update function as the second argument.
2424
*/
25-
export declare const useDoubleFBO: ({ scene, camera, size, dpr, isSizeUpdate, samples, depthBuffer, }: UseFboProps) => UseDoubleFBOReturn;
25+
export declare const useDoubleFBO: ({ scene, camera, size, dpr, isSizeUpdate, samples, depthBuffer, depthTexture, }: UseFboProps) => UseDoubleFBOReturn;
2626
export {};

packages/use-shader-fx/types/utils/useSingleFBO.d.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ export type UseFboProps = {
1111
isSizeUpdate?: boolean;
1212
/** Defines the count of MSAA samples. Can only be used with WebGL 2. Default is 0. */
1313
samples?: number;
14-
/** Renders to the depth buffer. Default is false. */
14+
/** Renders to the depth buffer. Unlike the three.js, Default is false. */
1515
depthBuffer?: boolean;
16+
/** If set, the scene depth will be rendered to this texture. Default is false. */
17+
depthTexture?: boolean;
1618
};
1719
type FBOUpdateFunction = (gl: THREE.WebGLRenderer,
1820
/** call before FBO is rendered */
@@ -25,5 +27,5 @@ type UseSingleFBOReturn = [THREE.WebGLRenderTarget, FBOUpdateFunction];
2527
* @param isSizeUpdate Whether to resize when resizing occurs. If isDpr is true, set FBO to setSize even if dpr is changed, default:false
2628
* @returns [THREE.WebGLRenderTarget , updateFBO] -Receives the RenderTarget as the first argument and the update function as the second argument.
2729
*/
28-
export declare const useSingleFBO: ({ scene, camera, size, dpr, isSizeUpdate, samples, depthBuffer, }: UseFboProps) => UseSingleFBOReturn;
30+
export declare const useSingleFBO: ({ scene, camera, size, dpr, isSizeUpdate, samples, depthBuffer, depthTexture, }: UseFboProps) => UseSingleFBOReturn;
2931
export {};

0 commit comments

Comments
 (0)