Skip to content

Commit f1839e1

Browse files
committed
feat: n8ao
1 parent c52d828 commit f1839e1

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
},
4949
"dependencies": {
5050
"maath": "^0.5.3",
51+
"n8ao": "^1.2.1",
5152
"postprocessing": "^6.30.2",
5253
"screen-space-reflections": "2.5.0",
5354
"three-stdlib": "^2.21.10"

src/effects/N8AO.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Ref, forwardRef, useLayoutEffect, useMemo } from 'react'
2+
/* @ts-ignore */
3+
import { N8AOPostPass } from 'n8ao'
4+
import { useThree } from '@react-three/fiber'
5+
6+
type N8AOProps = {
7+
aoRadius?: number
8+
distanceFalloff?: number
9+
intensity?: number
10+
}
11+
12+
export const N8AO = forwardRef<N8AOPostPass, N8AOProps>((props, ref: Ref<N8AOPostPass>) => {
13+
const { camera, scene, size } = useThree()
14+
const effect = useMemo(() => new N8AOPostPass(scene, camera, size.width, size.height), [])
15+
useLayoutEffect(() => {
16+
Object.assign(effect.configuration, props)
17+
}, [props])
18+
return <primitive ref={ref} object={effect} />
19+
})

src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export * from './effects/ScanlineEffect'
1818
export * from './effects/SelectiveBloom'
1919
export * from './effects/Sepia'
2020
export * from './effects/SSAO'
21+
export * from './effects/N8AO'
2122
export * from './effects/SMAA'
2223
export * from './effects/Texture'
2324
export * from './effects/ToneMapping'

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7645,6 +7645,11 @@ mute-stream@~1.0.0:
76457645
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-1.0.0.tgz#e31bd9fe62f0aed23520aa4324ea6671531e013e"
76467646
integrity sha512-avsJQhyd+680gKXyG/sQc0nXaC6rBkPOfyHYcFb9+hdkqQkR9bdnkJ0AMZhke0oesPqIO+mFFJ+IdBc7mst4IA==
76477647

7648+
n8ao@^1.2.1:
7649+
version "1.2.1"
7650+
resolved "https://registry.yarnpkg.com/n8ao/-/n8ao-1.2.1.tgz#2c9688ffb8dc6b2364abda134d0498b33d903d97"
7651+
integrity sha512-Mc0JVk3ESA5keQO2hFqeiGJX0CJtEwRpGSR2cd4TZJs8by559ta+iY0A72rFzsfxRZmnMq8jVL7o1ucqNDp0bw==
7652+
76487653
nanoid@^3.3.1, nanoid@^3.3.6:
76497654
version "3.3.6"
76507655
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.6.tgz#443380c856d6e9f9824267d960b4236ad583ea4c"

0 commit comments

Comments
 (0)